Skip to content

Fixed "d" and "D" in multicursor mode #1029

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

Merged
merged 8 commits into from
Dec 18, 2016
Merged
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
31 changes: 18 additions & 13 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ export abstract class BaseCommand extends BaseAction {
}

export class BaseOperator extends BaseAction {
constructor(multicursorIndex?: number) {
super();
this.multicursorIndex = multicursorIndex;
}
canBeRepeatedWithDot = true;

/**
Expand Down Expand Up @@ -1787,7 +1791,7 @@ export class DeleteOperator extends BaseOperator {
}

if (yank) {
Register.put(text, vimState);
Register.put(text, vimState, this.multicursorIndex);
}

let diff = new PositionDiff(0, 0);
Expand Down Expand Up @@ -1838,7 +1842,7 @@ export class DeleteOperatorVisual extends BaseOperator {
public modes = [ModeName.Visual, ModeName.VisualLine];

public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {
return await new DeleteOperator().run(vimState, start, end);
return await new DeleteOperator(this.multicursorIndex).run(vimState, start, end);
}
}

Expand Down Expand Up @@ -1907,7 +1911,7 @@ export class DeleteOperatorXVisual extends BaseOperator {
public modes = [ModeName.Visual, ModeName.VisualLine];

public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {
return await new DeleteOperator().run(vimState, start, end);
return await new DeleteOperator(this.multicursorIndex).run(vimState, start, end);
}
}

Expand Down Expand Up @@ -2045,9 +2049,9 @@ export class ChangeOperator extends BaseOperator {
// the line. We do want to run delete if it is a multiline change though ex. c}
if (Position.getLineLength(TextEditor.getLineAt(start).lineNumber) !== 0 || (end.line !== start.line)) {
if (isEndOfLine) {
state = await new DeleteOperator().run(vimState, start, end.getLeftThroughLineBreaks());
state = await new DeleteOperator(this.multicursorIndex).run(vimState, start, end.getLeftThroughLineBreaks());
} else {
state = await new DeleteOperator().run(vimState, start, end);
state = await new DeleteOperator(this.multicursorIndex).run(vimState, start, end);
}
}

Expand Down Expand Up @@ -2322,7 +2326,7 @@ export class PutCommandVisual extends BaseCommand {
[start, end] = [end, start];
}

const result = await new DeleteOperator().run(vimState, start, end, false);
const result = await new DeleteOperator(this.multicursorIndex).run(vimState, start, end, false);

return await new PutCommand().exec(start, result, true);
}
Expand Down Expand Up @@ -2666,13 +2670,14 @@ class CommandDeleteToLineEnd extends BaseCommand {
modes = [ModeName.Normal];
keys = ["D"];
canBeRepeatedWithDot = true;
runsOnceForEveryCursor() { return true; }

public async exec(position: Position, vimState: VimState): Promise<VimState> {
if (position.isLineEnd()) {
return vimState;
}

return await new DeleteOperator().run(vimState, position, position.getLineEnd().getLeft());
return await new DeleteOperator(this.multicursorIndex).run(vimState, position, position.getLineEnd().getLeft());
}
}

Expand Down Expand Up @@ -3857,7 +3862,7 @@ class ActionDeleteChar extends BaseCommand {
return vimState;
}

const state = await new DeleteOperator().run(vimState, position, position);
const state = await new DeleteOperator(this.multicursorIndex).run(vimState, position, position);

state.currentMode = ModeName.Normal;

Expand All @@ -3878,7 +3883,7 @@ class ActionDeleteCharWithDeleteKey extends BaseCommand {
return vimState;
}

const state = await new DeleteOperator().run(vimState, position, position);
const state = await new DeleteOperator(this.multicursorIndex).run(vimState, position, position);

state.currentMode = ModeName.Normal;

Expand All @@ -3897,7 +3902,7 @@ class ActionDeleteLastChar extends BaseCommand {
return vimState;
}

return await new DeleteOperator().run(vimState, position.getLeft(), position.getLeft());
return await new DeleteOperator(this.multicursorIndex).run(vimState, position.getLeft(), position.getLeft());
}
}

Expand Down Expand Up @@ -4310,7 +4315,7 @@ class ActionJoinNoWhitespace extends BaseCommand {

let resultLine = lineOne + lineTwo;

let newState = await new DeleteOperator().run(
let newState = await new DeleteOperator(this.multicursorIndex).run(
vimState,
position.getLineBegin(),
lineTwo.length > 0 ?
Expand Down Expand Up @@ -4749,7 +4754,7 @@ export class YankVisualBlockMode extends BaseOperator {
toCopy += line + '\n';
}

Register.put(toCopy, vimState);
Register.put(toCopy, vimState, this.multicursorIndex);

vimState.currentMode = ModeName.Normal;
vimState.cursorPosition = start;
Expand Down Expand Up @@ -4905,7 +4910,7 @@ class ActionDeleteLineVisualMode extends BaseCommand {
keys = ["X"];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
return await new DeleteOperator().run(vimState, position.getLineBegin(), position.getLineEnd());
return await new DeleteOperator(this.multicursorIndex).run(vimState, position.getLineBegin(), position.getLineEnd());
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1391,4 +1391,24 @@ suite("Mode Normal", () => {
keysPressed: '#',
end: ['test aaa test aaa test aaa |test aaa test'],
});

newTest({
title: "Can 'D'elete the characters under the cursor until the end of the line",
start: ['test aaa test aaa test aaa test |aaa test'],
keysPressed: 'D',
end: ['test aaa test aaa test aaa test| ']
});

newTest({
title: "Can 'D'elete the characters under multiple cursors until the end of the line",
start: [
'test aaa test aaa test aaa test |aaa test',
'test aaa test aaa test aaa test aaa test'
],
keysPressed: '<C-alt+down>D<Esc>',
end: [
'test aaa test aaa test aaa tes|t ',
'test aaa test aaa test aaa test '
]
});
});