Skip to content

Commit

Permalink
fix: simplify tab handling in editorStore
Browse files Browse the repository at this point in the history
- Replaced the manual insertion of a tab character with a direct call to vditor's insertValue method, improving code readability and maintainability.
- Removed unnecessary DOM manipulation and selection handling, streamlining the keydown event logic for the Tab key.
  • Loading branch information
blinko-space committed Jan 7, 2025
1 parent 409ade4 commit a8c75e2
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions src/components/Common/Editor/editorStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,7 @@ export class EditorStore {
handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === 'Tab') {
e.preventDefault();
const vditorInput = document.querySelector(`#vditor-${this.mode} .vditor-reset`) as HTMLElement;
if (vditorInput) {

const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) return;

const range = selection.getRangeAt(0);
range.deleteContents();

const tabNode = document.createTextNode('\t');
range.insertNode(tabNode);

range.setStartAfter(tabNode);
range.setEndAfter(tabNode);
selection.removeAllRanges();
selection.addRange(range);
} else {
console.log('vditor not found');
}
this.vditor?.insertValue(' ', true);
}
}
}

0 comments on commit a8c75e2

Please sign in to comment.