-
Notifications
You must be signed in to change notification settings - Fork 236
fix: Vim keymap insert mode exiting after single keystroke #10714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| const onSaveRef = useRef(onSave); | ||
| useEffect(() => { | ||
| onSaveRef.current = onSave; | ||
| }, [onSave]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useRef を用意し、引数から渡ってきた onSave を常に最新のも参照させるための useEffect
| }; | ||
| settingKeyMap(keymapMode); | ||
| }, [keymapMode, onSave]); | ||
| }, [keymapMode]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この useEffect の依存配列から引数から渡ってきた onSave を抜いて keymapExtension state を複数回更新させないように修正
| setKeymapExtension(await getKeymap(name, stableOnSave)); | ||
| }; | ||
| settingKeyMap(keymapMode); | ||
| }, [keymapMode, onSave]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
バグの原因
useKeymapExtension フック内で onSave が useEffect の依存配列に入っていたことで onSave が変更される度に keymapExtension state が更新されていた。keymapExtension が更新されることで下記の useEffect により codeMirrorEditor?.appendExtensions が呼ばれていたことが原因
growi/packages/editor/src/client/stores/use-editor-settings.ts
Lines 111 to 121 in 0d126d8
| useEffect(() => { | |
| if (keymapExtension == null) { | |
| return; | |
| } | |
| const cleanupFunction = codeMirrorEditor?.appendExtensions( | |
| Prec.low(keymapExtension), | |
| ); | |
| return cleanupFunction; | |
| }, [codeMirrorEditor, keymapExtension]); | |
| }; |
Task
https://redmine.weseek.co.jp/issues/176960