Skip to content

Commit e70e7ea

Browse files
committed
rename keystroke to keystrokes
1 parent d7caafe commit e70e7ea

File tree

3 files changed

+53
-44
lines changed

3 files changed

+53
-44
lines changed

src/cmd_line/commands/normal.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ export class NormalCommand extends ExCommand {
77
// TODO: support to parse `:normal!`
88
public static readonly argParser: Parser<NormalCommand> = whitespace
99
.then(all)
10-
.map((keystroke) => new NormalCommand(keystroke));
10+
.map((keystrokes) => new NormalCommand(keystrokes));
1111

12-
private readonly keystroke: string;
12+
private readonly keystrokes: string;
1313
constructor(argument: string) {
1414
super();
15-
this.keystroke = argument;
15+
this.keystrokes = argument;
1616
}
1717

1818
override async execute(vimState: VimState): Promise<void> {
19-
const keystroke = this.keystroke;
19+
const keystrokes = this.keystrokes;
2020
const lineNumber = vimState.cursorStopPosition.line;
2121
vimState.recordedState.transformer.addTransformation({
2222
type: 'executeNormal',
23-
keystroke,
23+
keystrokes,
2424
startLineNumber: lineNumber,
2525
endLineNumber: lineNumber,
2626
withRange: false,
2727
});
2828
}
2929

3030
override async executeWithRange(vimState: VimState, lineRange: LineRange): Promise<void> {
31-
const keystroke = this.keystroke;
31+
const keystrokes = this.keystrokes;
3232
const { start, end } = lineRange.resolve(vimState);
3333
vimState.recordedState.transformer.addTransformation({
3434
type: 'executeNormal',
35-
keystroke,
35+
keystrokes,
3636
startLineNumber: start,
3737
endLineNumber: end,
3838
withRange: true,

src/transformations/execute.ts

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '../vimscript/expression';
1717
import {
1818
Dot,
19+
ExecuteNormalTransformation,
1920
InsertTextVSCodeTransformation,
2021
TextTransformations,
2122
Transformation,
@@ -238,42 +239,7 @@ export async function executeTransformations(
238239
break;
239240

240241
case 'executeNormal':
241-
const { keystroke, startLineNumber, endLineNumber, withRange } = transformation;
242-
const stroke = keystrokesExpressionParser.parse(keystroke);
243-
if (!stroke.status) {
244-
throw new Error(`Failed to execute normal command: ${keystroke}`);
245-
}
246-
247-
const resultLineNumbers: number[] = [];
248-
if (withRange) {
249-
for (let i = startLineNumber; i <= endLineNumber; i++) {
250-
resultLineNumbers.push(i);
251-
}
252-
} else {
253-
const selectionList = vimState.editor.selections;
254-
for (const selection of selectionList) {
255-
const { start, end } = selection;
256-
257-
for (let i = start.line; i <= end.line; i++) {
258-
resultLineNumbers.push(i);
259-
}
260-
}
261-
}
262-
263-
vimState.normalCommandState = NormalCommandState.Executing;
264-
vimState.recordedState = new RecordedState();
265-
await vimState.setCurrentMode(Mode.Normal);
266-
for (const lineNumber of resultLineNumbers) {
267-
if (withRange) {
268-
vimState.cursorStopPosition = vimState.cursorStartPosition =
269-
TextEditor.getFirstNonWhitespaceCharOnLine(vimState.document, lineNumber);
270-
}
271-
await modeHandler.handleMultipleKeyEvents(stroke.value);
272-
if (vimState.currentMode === Mode.Insert) {
273-
await modeHandler.handleKeyEvent('<Esc>');
274-
}
275-
}
276-
vimState.normalCommandState = NormalCommandState.Finished;
242+
await doExecuteNormal(modeHandler, transformation);
277243
break;
278244

279245
case 'vscodeCommand':
@@ -335,3 +301,46 @@ export async function executeTransformations(
335301

336302
vimState.recordedState.transformer = new Transformer();
337303
}
304+
305+
const doExecuteNormal = async (
306+
modeHandler: IModeHandler,
307+
transformation: ExecuteNormalTransformation,
308+
) => {
309+
const vimState = modeHandler.vimState;
310+
const { keystrokes, startLineNumber, endLineNumber, withRange } = transformation;
311+
const strokes = keystrokesExpressionParser.parse(keystrokes);
312+
if (!strokes.status) {
313+
throw new Error(`Failed to execute normal command: ${keystrokes}`);
314+
}
315+
316+
const resultLineNumbers: number[] = [];
317+
if (withRange) {
318+
for (let i = startLineNumber; i <= endLineNumber; i++) {
319+
resultLineNumbers.push(i);
320+
}
321+
} else {
322+
const selectionList = vimState.editor.selections;
323+
for (const selection of selectionList) {
324+
const { start, end } = selection;
325+
326+
for (let i = start.line; i <= end.line; i++) {
327+
resultLineNumbers.push(i);
328+
}
329+
}
330+
}
331+
332+
vimState.normalCommandState = NormalCommandState.Executing;
333+
vimState.recordedState = new RecordedState();
334+
await vimState.setCurrentMode(Mode.Normal);
335+
for (const lineNumber of resultLineNumbers) {
336+
if (withRange) {
337+
vimState.cursorStopPosition = vimState.cursorStartPosition =
338+
TextEditor.getFirstNonWhitespaceCharOnLine(vimState.document, lineNumber);
339+
}
340+
await modeHandler.handleMultipleKeyEvents(strokes.value);
341+
if (vimState.currentMode === Mode.Insert) {
342+
await modeHandler.handleKeyEvent('<Esc>');
343+
}
344+
}
345+
vimState.normalCommandState = NormalCommandState.Finished;
346+
};

src/transformations/transformations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export interface ContentChangeTransformation {
188188

189189
export interface ExecuteNormalTransformation {
190190
type: 'executeNormal';
191-
keystroke: string;
191+
keystrokes: string;
192192
startLineNumber: number;
193193
endLineNumber: number;
194194
withRange: boolean;

0 commit comments

Comments
 (0)