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
8b92021b
Unverified
Commit
8b92021b
authored
Feb 07, 2023
by
Stephen Zhou
Committed by
GitHub
Feb 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: editor cursor not in view after smart editing (#1043)
parent
7cd474db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
2 deletions
+12
-2
Editor.tsx
web/src/components/Editor/Editor.tsx
+5
-0
MemoEditor.tsx
web/src/components/MemoEditor.tsx
+7
-2
No files found.
web/src/components/Editor/Editor.tsx
View file @
8b92021b
...
@@ -3,6 +3,7 @@ import "../../less/editor.less";
...
@@ -3,6 +3,7 @@ import "../../less/editor.less";
export
interface
EditorRefActions
{
export
interface
EditorRefActions
{
focus
:
FunctionType
;
focus
:
FunctionType
;
scrollToCursor
:
FunctionType
;
insertText
:
(
text
:
string
,
prefix
?:
string
,
suffix
?:
string
)
=>
void
;
insertText
:
(
text
:
string
,
prefix
?:
string
,
suffix
?:
string
)
=>
void
;
removeText
:
(
start
:
number
,
length
:
number
)
=>
void
;
removeText
:
(
start
:
number
,
length
:
number
)
=>
void
;
setContent
:
(
text
:
string
)
=>
void
;
setContent
:
(
text
:
string
)
=>
void
;
...
@@ -52,6 +53,10 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
...
@@ -52,6 +53,10 @@ const Editor = forwardRef(function Editor(props: Props, ref: React.ForwardedRef<
focus
:
()
=>
{
focus
:
()
=>
{
editorRef
.
current
?.
focus
();
editorRef
.
current
?.
focus
();
},
},
scrollToCursor
:
()
=>
{
editorRef
.
current
?.
blur
();
editorRef
.
current
?.
focus
();
},
insertText
:
(
content
=
""
,
prefix
=
""
,
suffix
=
""
)
=>
{
insertText
:
(
content
=
""
,
prefix
=
""
,
suffix
=
""
)
=>
{
if
(
!
editorRef
.
current
)
{
if
(
!
editorRef
.
current
)
{
return
;
return
;
...
...
web/src/components/MemoEditor.tsx
View file @
8b92021b
...
@@ -402,6 +402,7 @@ const MemoEditor = () => {
...
@@ -402,6 +402,7 @@ const MemoEditor = () => {
}
else
{
}
else
{
editorRef
.
current
?.
insertText
(
""
,
"
\n
- [ ] "
);
editorRef
.
current
?.
insertText
(
""
,
"
\n
- [ ] "
);
}
}
editorRef
.
current
?.
scrollToCursor
();
};
};
const
handleCodeBlockBtnClick
=
()
=>
{
const
handleCodeBlockBtnClick
=
()
=>
{
...
@@ -416,6 +417,7 @@ const MemoEditor = () => {
...
@@ -416,6 +417,7 @@ const MemoEditor = () => {
}
else
{
}
else
{
editorRef
.
current
?.
insertText
(
""
,
"
\n
```
\n
"
,
"
\n
```"
);
editorRef
.
current
?.
insertText
(
""
,
"
\n
```
\n
"
,
"
\n
```"
);
}
}
editorRef
.
current
?.
scrollToCursor
();
};
};
const
handleUploadFileBtnClick
=
()
=>
{
const
handleUploadFileBtnClick
=
()
=>
{
...
@@ -438,7 +440,7 @@ const MemoEditor = () => {
...
@@ -438,7 +440,7 @@ const MemoEditor = () => {
const
handleTagSelectorClick
=
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
const
handleTagSelectorClick
=
useCallback
((
event
:
React
.
MouseEvent
)
=>
{
if
(
tagSelectorRef
.
current
!==
event
.
target
&&
tagSelectorRef
.
current
?.
contains
(
event
.
target
as
Node
))
{
if
(
tagSelectorRef
.
current
!==
event
.
target
&&
tagSelectorRef
.
current
?.
contains
(
event
.
target
as
Node
))
{
editorRef
.
current
?.
insertText
(
`#
${(
event
.
target
as
HTMLElement
).
textContent
}
`
??
""
);
editorRef
.
current
?.
insertText
(
`#
${(
event
.
target
as
HTMLElement
).
textContent
}
`
??
""
);
handleEditorFocus
();
editorRef
.
current
?.
scrollToCursor
();
}
}
},
[]);
},
[]);
...
@@ -481,7 +483,10 @@ const MemoEditor = () => {
...
@@ -481,7 +483,10 @@ const MemoEditor = () => {
<
div
<
div
className=
{
`memo-editor-container ${isEditing ? "edit-ing" : ""} ${state.fullscreen ? "fullscreen" : ""}`
}
className=
{
`memo-editor-container ${isEditing ? "edit-ing" : ""} ${state.fullscreen ? "fullscreen" : ""}`
}
tabIndex=
{
0
}
tabIndex=
{
0
}
onKeyDown=
{
handleKeyDown
}
onKeyDown=
{
(
e
)
=>
{
handleKeyDown
(
e
);
editorRef
.
current
?.
scrollToCursor
();
}
}
onDrop=
{
handleDropEvent
}
onDrop=
{
handleDropEvent
}
onFocus=
{
handleEditorFocus
}
onFocus=
{
handleEditorFocus
}
onBlur=
{
handleEditorBlur
}
onBlur=
{
handleEditorBlur
}
...
...
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