* Handle input that's valid in both idle and count states. * Returns null if input is not recognized.
( input: string, count: number, ctx: TransitionContext, )
| 96 | * Returns null if input is not recognized. |
| 97 | */ |
| 98 | function handleNormalInput( |
| 99 | input: string, |
| 100 | count: number, |
| 101 | ctx: TransitionContext, |
| 102 | ): TransitionResult | null { |
| 103 | if (isOperatorKey(input)) { |
| 104 | return { next: { type: 'operator', op: OPERATORS[input], count } } |
| 105 | } |
| 106 | |
| 107 | if (SIMPLE_MOTIONS.has(input)) { |
| 108 | return { |
| 109 | execute: () => { |
| 110 | const target = resolveMotion(input, ctx.cursor, count) |
| 111 | ctx.setOffset(target.offset) |
| 112 | }, |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (FIND_KEYS.has(input)) { |
| 117 | return { next: { type: 'find', find: input as FindType, count } } |
| 118 | } |
| 119 | |
| 120 | if (input === 'g') return { next: { type: 'g', count } } |
| 121 | if (input === 'r') return { next: { type: 'replace', count } } |
| 122 | if (input === '>' || input === '<') { |
| 123 | return { next: { type: 'indent', dir: input, count } } |
| 124 | } |
| 125 | if (input === '~') { |
| 126 | return { execute: () => executeToggleCase(count, ctx) } |
| 127 | } |
| 128 | if (input === 'x') { |
| 129 | return { execute: () => executeX(count, ctx) } |
| 130 | } |
| 131 | if (input === 'J') { |
| 132 | return { execute: () => executeJoin(count, ctx) } |
| 133 | } |
| 134 | if (input === 'p' || input === 'P') { |
| 135 | return { execute: () => executePaste(input === 'p', count, ctx) } |
| 136 | } |
| 137 | if (input === 'D') { |
| 138 | return { execute: () => executeOperatorMotion('delete', '$', 1, ctx) } |
| 139 | } |
| 140 | if (input === 'C') { |
| 141 | return { execute: () => executeOperatorMotion('change', '$', 1, ctx) } |
| 142 | } |
| 143 | if (input === 'Y') { |
| 144 | return { execute: () => executeLineOp('yank', count, ctx) } |
| 145 | } |
| 146 | if (input === 'G') { |
| 147 | return { |
| 148 | execute: () => { |
| 149 | // count=1 means no count given, go to last line |
| 150 | // otherwise go to line N |
| 151 | if (count === 1) { |
| 152 | ctx.setOffset(ctx.cursor.startOfLastLine().offset) |
| 153 | } else { |
| 154 | ctx.setOffset(ctx.cursor.goToLine(count).offset) |
| 155 | } |
no test coverage detected