Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
40f39fd6
Unverified
Commit
40f39fd6
authored
Dec 20, 2022
by
ChasLui
Committed by
GitHub
Dec 20, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use shift+tab to unindent (#799)
* feat: Use shift+tab to unindent, just like vscode * fix: shit+tab return
parent
3b419768
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
6 deletions
+31
-6
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+31
-6
No files found.
web/src/components/MemoEditor.tsx
View file @
40f39fd6
...
@@ -177,16 +177,41 @@ const MemoEditor = () => {
...
@@ -177,16 +177,41 @@ const MemoEditor = () => {
}
}
return
;
return
;
}
}
if
(
!
isShiftKey
&&
event
.
key
===
"Tab"
)
{
if
(
event
.
key
===
"Tab"
)
{
event
.
preventDefault
();
event
.
preventDefault
();
const
selectedContent
=
editorRef
.
current
.
getSelectedContent
(
);
const
tabSpace
=
" "
.
repeat
(
TAB_SPACE_WIDTH
);
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
editorRef
.
current
.
insertText
(
" "
.
repeat
(
TAB_SPACE_WIDTH
));
const
selectedContent
=
editorRef
.
current
.
getSelectedContent
();
if
(
isShiftKey
)
{
const
beforeContent
=
editorRef
.
current
.
getContent
().
slice
(
0
,
cursorPosition
);
for
(
let
i
=
beforeContent
.
length
-
1
;
i
>=
0
;
i
--
)
{
if
(
beforeContent
[
i
]
!==
"
\n
"
)
{
continue
;
}
const
rowStart
=
i
+
1
;
const
isTabSpace
=
beforeContent
.
substring
(
rowStart
,
i
+
TAB_SPACE_WIDTH
+
1
)
===
tabSpace
;
const
isSpace
=
beforeContent
.
substring
(
rowStart
,
i
+
2
)
===
" "
;
if
(
!
isTabSpace
&&
!
isSpace
)
{
break
;
}
const
removeLength
=
isTabSpace
?
TAB_SPACE_WIDTH
:
1
;
editorRef
.
current
.
removeText
(
rowStart
,
removeLength
);
const
startPos
=
cursorPosition
-
removeLength
;
let
endPos
=
startPos
;
if
(
selectedContent
)
{
endPos
+=
selectedContent
.
length
;
}
editorRef
.
current
.
setCursorPosition
(
startPos
,
endPos
);
}
return
;
}
else
{
editorRef
.
current
.
insertText
(
tabSpace
);
if
(
selectedContent
)
{
if
(
selectedContent
)
{
editorRef
.
current
.
setCursorPosition
(
cursorPosition
+
TAB_SPACE_WIDTH
);
editorRef
.
current
.
setCursorPosition
(
cursorPosition
+
TAB_SPACE_WIDTH
);
}
}
return
;
return
;
}
}
}
for
(
const
symbol
of
pairSymbols
)
{
for
(
const
symbol
of
pairSymbols
)
{
if
(
event
.
key
===
symbol
[
0
])
{
if
(
event
.
key
===
symbol
[
0
])
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment