| 121 | } |
| 122 | |
| 123 | handleKeyChar(keyChar) { |
| 124 | // A count prefix applies only so long a keyChar is mapped in @keyState[0]; e.g. 7gj should be 1j. |
| 125 | if (!(keyChar in this.keyState[0])) { |
| 126 | this.countPrefix = 0; |
| 127 | } |
| 128 | |
| 129 | // Advance the key state. The new key state is the current mappings of keyChar, plus @keyMapping. |
| 130 | const state = this.keyState.filter((mapping) => keyChar in mapping).map((mapping) => |
| 131 | mapping[keyChar] |
| 132 | ); |
| 133 | state.push(this.keyMapping); |
| 134 | this.keyState = state; |
| 135 | |
| 136 | if (this.keyState[0].command != null) { |
| 137 | const command = this.keyState[0]; |
| 138 | const count = this.countPrefix > 0 ? this.countPrefix : null; |
| 139 | this.reset(); |
| 140 | this.commandHandler({ command, count }); |
| 141 | if ((this.options.count != null) && (--this.options.count <= 0)) { |
| 142 | this.exit(); |
| 143 | } |
| 144 | } |
| 145 | return this.suppressEvent; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | globalThis.KeyHandlerMode = KeyHandlerMode; |