Skip to content

Commit

Permalink
fix insert wiki title bug (#7398)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuntian authored Jan 20, 2025
1 parent 22c08df commit 3a71b7d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion frontend/src/pages/wiki2/wiki-right-header/page-title-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ function PageTitleEditor({ isUpdateBySide, currentPageConfig, onUpdatePage }) {
const { startContainer, startOffset, endContainer, endOffset } = selectionRef.current;
// modify pageName by side panel
if (pageName.length < startOffset) return;

if (pageName.length === 1 && startOffset === 1) {
const range = document.createRange();
const selection = window.getSelection();
range.selectNodeContents(contentEditableRef.current);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
return;
}
const range = window.document.createRange();
range.setStart(startContainer, startOffset);
range.setEnd(endContainer, endOffset);
Expand All @@ -34,7 +44,7 @@ function PageTitleEditor({ isUpdateBySide, currentPageConfig, onUpdatePage }) {
selection.removeAllRanges();
selection.addRange(range);
}
}, [pageName.length]);
}, [pageName]);

const onKeyDown = (event) => {
if (event.keyCode === 13) {
Expand Down

0 comments on commit 3a71b7d

Please sign in to comment.