Commit 7ac0ac2c42
Verified · cmc
Layout: unified · split
Sources/OrgEditorAppKit/Modal.swift +6
| @@ -36,6 +36,12 @@ extension OrgEditor { | |||
| 36 | return feedVim(keys) | 36 | return feedVim(keys) |
| 37 | case .undefined(let keys): | 37 | case .undefined(let keys): |
| 38 | onKeysPending?(nil, []) | 38 | onKeysPending?(nil, []) |
| 39 | // The leader and Emacs prefixes (C-c, C-x) mean nothing to evil: the sequence is | ||
| 40 | // undefined, as in Doom. Other prefixes (g, z, [, ]) are evil's too. | ||
| 41 | if let first = keys.first, first == KeyChord("SPC") || !first.modifiers.isDisjoint(with: [.control, .meta]) { | ||
| 42 | onMessage?("\(KeySequence.format(keys)) is undefined") | ||
| 43 | return true | ||
| 44 | } | ||
| 39 | return feedVim(keys) | 45 | return feedVim(keys) |
| 40 | case .unbound: | 46 | case .unbound: |
| 41 | return feedVim([chord]) | 47 | return feedVim([chord]) |
Tests/OrgEditorAppKitTests/ModalTests.swift +19
| @@ -72,6 +72,25 @@ struct ModalTests { | |||
| 72 | #expect(h.editor.vim.mode == .normal) | 72 | #expect(h.editor.vim.mode == .normal) |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | @Test func undefinedLeaderSequencesDoNothing() { | ||
| 76 | let h = doom("* Task\nbody text\n") | ||
| 77 | var messages: [String] = [] | ||
| 78 | h.editor.onMessage = { messages.append($0) } | ||
| 79 | h.caret(at: 0) | ||
| 80 | type(h, "SPC m z") | ||
| 81 | #expect(messages.last == "SPC m z is undefined") | ||
| 82 | #expect(h.textView.selectedRange().location == 0) | ||
| 83 | // No mark z was set: a jump to it fails and the caret stays. | ||
| 84 | type(h, "j ' z") | ||
| 85 | #expect(h.textView.selectedRange().location == 7) | ||
| 86 | type(h, "C-c z") | ||
| 87 | #expect(messages.last == "C-c z is undefined") | ||
| 88 | #expect(h.editor.document.text == "* Task\nbody text\n") | ||
| 89 | // Evil's own prefixes still reach it. | ||
| 90 | type(h, "g g") | ||
| 91 | #expect(h.textView.selectedRange().location == 0) | ||
| 92 | } | ||
| 93 | |||
| 75 | @Test func keyHintsFollowContext() { | 94 | @Test func keyHintsFollowContext() { |
| 76 | let h = doom("* a\n#+begin_src sh\necho\n#+end_src\n") | 95 | let h = doom("* a\n#+begin_src sh\necho\n#+end_src\n") |
| 77 | var hints: [(key: String, title: String)] = [] | 96 | var hints: [(key: String, title: String)] = [] |