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
fe5ba685
Unverified
Commit
fe5ba685
authored
Oct 23, 2022
by
boojack
Committed by
GitHub
Oct 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update insert content in editor (#336)
parent
5690dab6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
28 deletions
+26
-28
Editor.tsx
web/src/components/Editor/Editor.tsx
+3
-3
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+23
-25
No files found.
web/src/components/Editor/Editor.tsx
View file @
fe5ba685
...
@@ -47,19 +47,19 @@ const Editor = forwardRef((props: Props, ref: React.ForwardedRef<EditorRefAction
...
@@ -47,19 +47,19 @@ const Editor = forwardRef((props: Props, ref: React.ForwardedRef<EditorRefAction
focus
:
()
=>
{
focus
:
()
=>
{
editorRef
.
current
?.
focus
();
editorRef
.
current
?.
focus
();
},
},
insertText
:
(
content
=
""
,
prefix
=
""
,
suffix
=
prefix
)
=>
{
insertText
:
(
content
=
""
,
prefix
=
""
,
suffix
=
""
)
=>
{
if
(
!
editorRef
.
current
)
{
if
(
!
editorRef
.
current
)
{
return
;
return
;
}
}
const
cursorPosition
=
editorRef
.
current
.
selectionStart
;
const
cursorPosition
=
editorRef
.
current
.
selectionStart
;
const
endPosition
=
editorRef
.
current
.
selectionEnd
;
const
endPosition
=
editorRef
.
current
.
selectionEnd
;
const
prevValue
=
editorRef
.
current
.
value
;
const
prevValue
=
editorRef
.
current
.
value
;
const
value
=
const
value
=
prevValue
.
slice
(
0
,
cursorPosition
)
+
prevValue
.
slice
(
0
,
cursorPosition
)
+
prefix
+
prefix
+
prevValue
.
slice
(
cursorPosition
,
endPosition
)
+
(
content
||
prevValue
.
slice
(
cursorPosition
,
endPosition
)
)
+
suffix
+
suffix
+
content
+
prevValue
.
slice
(
endPosition
);
prevValue
.
slice
(
endPosition
);
editorRef
.
current
.
value
=
value
;
editorRef
.
current
.
value
=
value
;
...
...
web/src/components/MemoEditor.tsx
View file @
fe5ba685
...
@@ -76,38 +76,36 @@ const MemoEditor: React.FC = () => {
...
@@ -76,38 +76,36 @@ const MemoEditor: React.FC = () => {
prevGlobalStateRef
.
current
=
editorState
;
prevGlobalStateRef
.
current
=
editorState
;
},
[
state
,
editorState
.
editMemoId
]);
},
[
state
,
editorState
.
editMemoId
]);
const
handleInsertMark
=
(
mark
:
string
)
=>
{
editorRef
.
current
?.
insertText
(
""
,
mark
);
};
const
handleKeyDown
=
(
event
:
React
.
KeyboardEvent
)
=>
{
const
handleKeyDown
=
(
event
:
React
.
KeyboardEvent
)
=>
{
if
(
event
.
key
===
"Escape"
&&
state
.
fullscreen
)
{
if
(
event
.
key
===
"Escape"
&&
state
.
fullscreen
)
{
handleFullscreenBtnClick
();
handleFullscreenBtnClick
();
return
;
return
;
}
}
if
(
event
.
key
===
"Enter"
&&
(
event
.
ctrlKey
||
event
.
metaKey
))
{
handleSaveBtnClick
();
return
;
}
if
(
event
.
key
===
"Tab"
)
{
if
(
event
.
key
===
"Tab"
)
{
event
.
preventDefault
();
event
.
preventDefault
();
editorRef
.
current
?.
insertText
(
" "
.
repeat
(
TAB_SPACE_WIDTH
));
editorRef
.
current
?.
insertText
(
" "
.
repeat
(
TAB_SPACE_WIDTH
));
return
;
return
;
}
}
if
(
event
.
ctrlKey
||
event
.
metaKey
)
{
if
(
event
.
ctrlKey
||
event
.
metaKey
)
{
event
.
preventDefault
();
if
(
event
.
key
===
"Enter"
)
{
switch
(
event
.
key
)
{
handleSaveBtnClick
();
case
"b"
:
return
;
handleInsertMark
(
"**"
);
}
break
;
if
(
event
.
key
===
"b"
)
{
case
"i"
:
event
.
preventDefault
();
handleInsertMark
(
"*"
);
editorRef
.
current
?.
insertText
(
""
,
"**"
,
"**"
);
break
;
return
;
case
"e"
:
}
handleInsertMark
(
"`"
);
if
(
event
.
key
===
"i"
)
{
break
;
event
.
preventDefault
();
editorRef
.
current
?.
insertText
(
""
,
"*"
,
"*"
);
return
;
}
if
(
event
.
key
===
"e"
)
{
event
.
preventDefault
();
editorRef
.
current
?.
insertText
(
""
,
"`"
,
"`"
);
return
;
}
}
return
;
}
}
};
};
...
@@ -235,9 +233,9 @@ const MemoEditor: React.FC = () => {
...
@@ -235,9 +233,9 @@ const MemoEditor: React.FC = () => {
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
const
prevValue
=
editorRef
.
current
.
getContent
().
slice
(
0
,
cursorPosition
);
const
prevValue
=
editorRef
.
current
.
getContent
().
slice
(
0
,
cursorPosition
);
if
(
prevValue
===
""
||
prevValue
.
endsWith
(
"
\n
"
))
{
if
(
prevValue
===
""
||
prevValue
.
endsWith
(
"
\n
"
))
{
editorRef
.
current
?.
insertText
(
"- [ ] "
);
editorRef
.
current
?.
insertText
(
"
"
,
"
- [ ] "
);
}
else
{
}
else
{
editorRef
.
current
?.
insertText
(
"
\n
- [ ] "
);
editorRef
.
current
?.
insertText
(
"
"
,
"
\n
- [ ] "
);
}
}
};
};
...
@@ -249,9 +247,9 @@ const MemoEditor: React.FC = () => {
...
@@ -249,9 +247,9 @@ const MemoEditor: React.FC = () => {
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
const
cursorPosition
=
editorRef
.
current
.
getCursorPosition
();
const
prevValue
=
editorRef
.
current
.
getContent
().
slice
(
0
,
cursorPosition
);
const
prevValue
=
editorRef
.
current
.
getContent
().
slice
(
0
,
cursorPosition
);
if
(
prevValue
===
""
||
prevValue
.
endsWith
(
"
\n
"
))
{
if
(
prevValue
===
""
||
prevValue
.
endsWith
(
"
\n
"
))
{
editorRef
.
current
?.
insertText
(
"
```
\n
\n
```"
);
editorRef
.
current
?.
insertText
(
"
"
,
"```
\n
"
,
"
\n
```"
);
}
else
{
}
else
{
editorRef
.
current
?.
insertText
(
"
\n
```
\n
\n
```"
);
editorRef
.
current
?.
insertText
(
"
"
,
"
\n
```
\n
"
,
"
\n
```"
);
}
}
};
};
...
@@ -375,7 +373,7 @@ const MemoEditor: React.FC = () => {
...
@@ -375,7 +373,7 @@ const MemoEditor: React.FC = () => {
)
}
)
}
</
div
>
</
div
>
</
div
>
</
div
>
<
button
className=
"action-btn"
>
<
button
className=
"action-btn
!hidden sm:!flex
"
>
<
Icon
.
Smile
className=
"icon-img"
onClick=
{
handleEmojiPickerBtnClick
}
/>
<
Icon
.
Smile
className=
"icon-img"
onClick=
{
handleEmojiPickerBtnClick
}
/>
</
button
>
</
button
>
<
button
className=
"action-btn"
>
<
button
className=
"action-btn"
>
...
...
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