feat(editor): word and line movement/deletion keys - #34
Open
heeseon87 wants to merge 1 commit into
Open
Conversation
Handle the readline-style sequences terminals emit for Option/Command combinations: ESC b/f and modifier-3 arrows move by word, Ctrl+A/E and modifier-9 arrows jump to line edges, Ctrl+W / Meta+Backspace delete the previous word, Ctrl+U deletes to the line start.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The comment editor only handles single-character Backspace/Left/Right. Every modifier combination is dropped, because the keypress handler ignores
ctrl/metaand falls through to the text-insert branch guarded by!key.ctrl && !key.meta.Terminals translate the usual macOS/Linux editing keys into readline (Emacs) sequences, which every shell and REPL already understands:
ESC b/ESC forESC [1;3D/ESC [1;3C^A/^EorESC [1;9D/ESC [1;9C^WorESC DEL^USo in the editor these keys either did nothing or moved one character, while they work as expected in the shell right next to it.
Change
src/edit-keys.tswith pure helpers (wordStart,wordEnd,lineStart,lineEnd) andresolveEditKey, which maps a readlineKeyto an edit action.key.meta, soresolveEditKeyinspectskey.sequenceto tell word moves from line moves.src/editor.tsapplies the resolved action before the existing single-character handling; everything else is unchanged.test/edit-keys.test.tscovers word/line boundaries (including CJK runs and newlines) and each sequence above.bun test(68 pass) andbunx tsc --noEmitare clean.