Fix: visual block yank, delete and put behavior for single line selections.

Fixes: #3231, #2961, #2336, #2093, #1796
This commit is contained in:
Faddi 2019-01-16 07:22:18 +01:00
parent 01b73fbbd3
commit 34d27e3347
3 changed files with 68 additions and 11 deletions

View File

@ -1411,14 +1411,18 @@ export class PutCommand extends BaseCommand {
.join('\n');
}
if (after) {
if (register.registerMode === RegisterMode.LineWise) {
// P insert before current line
textToAdd = text + '\n';
whereToAddText = dest.getLineBegin();
if (after) {
textToAdd = text + '\n';
whereToAddText = dest.getLineBegin();
} else {
textToAdd = '\n' + text;
whereToAddText = dest.getLineEnd();
}
} else {
// p paste after current line
textToAdd = '\n' + text;
whereToAddText = dest.getLineEnd();
textToAdd = text;
whereToAddText = after ? position : position.getRight();
}
}
@ -1470,10 +1474,20 @@ export class PutCommand extends BaseCommand {
} else {
if (text.indexOf('\n') === -1) {
if (!position.isLineEnd()) {
if (after) {
diff = new PositionDiff(0, -1);
if (
register.registerMode === RegisterMode.BlockWise
) {
if (after) {
diff = new PositionDiff(0, -1 * text.length);
} else {
diff = new PositionDiff(0, 1);
}
} else {
diff = new PositionDiff(0, textToAdd.length);
if (after) {
diff = new PositionDiff(0, -1);
} else {
diff = new PositionDiff(0, textToAdd.length);
}
}
}
} else {
@ -3604,7 +3618,10 @@ class ActionXVisualBlock extends BaseCommand {
}
public async exec(position: Position, vimState: VimState): Promise<VimState> {
for (const { start, end } of Position.IterateLine(vimState)) {
const lines: string[] = [];
for (const { line, start, end } of Position.IterateLine(vimState)) {
lines.push(line);
vimState.recordedState.transformations.push({
type: 'deleteRange',
range: new Range(start, end),
@ -3612,6 +3629,10 @@ class ActionXVisualBlock extends BaseCommand {
});
}
const text = lines.length === 1 ? lines[0] : lines.join('\n');
vimState.currentRegisterMode = RegisterMode.BlockWise;
Register.put(text, vimState, this.multicursorIndex);
const topLeft = VisualBlockMode.getTopLeftPosition(
vimState.cursorPosition,
vimState.cursorStartPosition

View File

@ -648,10 +648,18 @@ export class YankVisualBlockMode extends BaseOperator {
public async run(vimState: VimState, start: Position, end: Position): Promise<VimState> {
let toCopy: string = '';
const isMultiline = start.line !== end.line;
for (const { line } of Position.IterateLine(vimState)) {
toCopy += line + '\n';
if (isMultiline) {
toCopy += line + '\n';
} else {
toCopy = line;
}
}
vimState.currentRegisterMode = RegisterMode.BlockWise;
Register.put(toCopy, vimState, this.multicursorIndex);
const numLinesYanked = toCopy.split('\n').length;

View File

@ -44,4 +44,32 @@ suite('put operator', () => {
keysPressed: '2yyjjpk',
end: ['one', 'two', '|three', 'one', 'two', 'four'],
});
newTest({
title: 'test visual block single line yank p',
start: ['12|345'],
keysPressed: '<C-v>llyhp',
end: ['12|345345'],
});
newTest({
title: 'test visual block single line yank P',
start: ['12|345'],
keysPressed: '<C-v>llyhP',
end: ['1|3452345'],
});
newTest({
title: 'test visual block single line delete p',
start: ['12|345'],
keysPressed: '<C-v>lldhp',
end: ['1|3452'],
});
newTest({
title: 'test visual block single line delete P',
start: ['12|345'],
keysPressed: '<C-v>lldhP',
end: ['|34512'],
});
});