fix: incorrect cursor when text is selected in range (#797)

This commit is contained in:
ChasLui
2022-12-20 20:51:32 +08:00
committed by GitHub
parent 3c2cd43d28
commit b6fe4d914e

View File

@ -179,7 +179,12 @@ const MemoEditor = () => {
} }
if (!isShiftKey && event.key === "Tab") { if (!isShiftKey && event.key === "Tab") {
event.preventDefault(); event.preventDefault();
const selectedContent = editorRef.current.getSelectedContent();
const cursorPosition = editorRef.current.getCursorPosition();
editorRef.current.insertText(" ".repeat(TAB_SPACE_WIDTH)); editorRef.current.insertText(" ".repeat(TAB_SPACE_WIDTH));
if (selectedContent) {
editorRef.current.setCursorPosition(cursorPosition + TAB_SPACE_WIDTH);
}
return; return;
} }