Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MarkCommand to handle mark creation in command line #9483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/cmd_line/commands/marks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,22 @@ export class DeleteMarksCommand extends ExCommand {
vimState.historyTracker.removeMarks(marks);
}
}

export class MarkCommand extends ExCommand {
public static readonly argParser: Parser<MarkCommand> = seq(
optWhitespace,
regexp(/[a-zA-Z'`<>[\].]/).desc('mark name'),
optWhitespace,
).map(([, markName]) => new MarkCommand(markName));

private markName: string;
constructor(markName: string) {
super();
this.markName = markName;
}

async execute(vimState: VimState): Promise<void> {
const position = vimState.cursorStopPosition;
vimState.historyTracker.addMark(vimState.document, position, this.markName);
}
}
4 changes: 2 additions & 2 deletions src/vimscript/exCommandParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { GotoLineCommand } from '../cmd_line/commands/gotoLine';
import { HistoryCommand } from '../cmd_line/commands/history';
import { ClearJumpsCommand, JumpsCommand } from '../cmd_line/commands/jumps';
import { CenterCommand, LeftCommand, RightCommand } from '../cmd_line/commands/leftRightCenter';
import { DeleteMarksCommand, MarksCommand } from '../cmd_line/commands/marks';
import { DeleteMarksCommand, MarksCommand, MarkCommand } from '../cmd_line/commands/marks';
import { ExploreCommand } from '../cmd_line/commands/explore';
import { MoveCommand } from '../cmd_line/commands/move';
import { NohlCommand } from '../cmd_line/commands/nohl';
Expand Down Expand Up @@ -350,7 +350,7 @@ export const builtinExCommands: ReadonlyArray<[[string, string], ArgParser | und
[['lvimgrepa', 'dd'], undefined],
[['lw', 'indow'], succeed(new VsCodeCommand('workbench.action.focusCommentsPanel'))],
[['m', 'ove'], MoveCommand.argParser],
[['ma', 'rk'], undefined],
[['ma', 'rk'], MarkCommand.argParser],
[['mak', 'e'], undefined],
[['map', ''], undefined],
[['mapc', 'lear'], undefined],
Expand Down
7 changes: 6 additions & 1 deletion test/vimscript/exCommandParse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GotoLineCommand } from '../../src/cmd_line/commands/gotoLine';
import { HistoryCommand, HistoryCommandType } from '../../src/cmd_line/commands/history';
import { LeftCommand, RightCommand } from '../../src/cmd_line/commands/leftRightCenter';
import { LetCommand } from '../../src/cmd_line/commands/let';
import { DeleteMarksCommand, MarksCommand } from '../../src/cmd_line/commands/marks';
import { DeleteMarksCommand, MarksCommand, MarkCommand } from '../../src/cmd_line/commands/marks';
import { PutExCommand } from '../../src/cmd_line/commands/put';
import { QuitCommand } from '../../src/cmd_line/commands/quit';
import { ReadCommand } from '../../src/cmd_line/commands/read';
Expand Down Expand Up @@ -382,6 +382,11 @@ suite('Ex command parsing', () => {
exParseTest(':marks 0 1', new MarksCommand(['0', '1']));
});

suite(':mark', () => {
exParseTest(':mark a', new MarkCommand('a'));
exParseTest(':mark `', new MarkCommand('`'));
});

suite(':p[rint]', () => {
// TODO
});
Expand Down