Fixes #46440: Distribute multiline paste to multicursors

This commit is contained in:
Alex Dima 2018-03-27 23:37:30 +02:00
parent c059826ba2
commit 1374fa6aa7
2 changed files with 58 additions and 0 deletions

View file

@ -18,6 +18,7 @@ import { IndentAction, EnterAction } from 'vs/editor/common/modes/languageConfig
import { SurroundSelectionCommand } from 'vs/editor/common/commands/surroundSelectionCommand';
import { IElectricAction } from 'vs/editor/common/modes/supports/electricCharacter';
import { getMapForWordSeparators, WordCharacterClass } from 'vs/editor/common/controller/wordCharacterClassifier';
import { CharCode } from 'vs/base/common/charCode';
export class TypeOperations {
@ -123,6 +124,15 @@ export class TypeOperations {
return multicursorText;
}
// Remove trailing \n if present
if (text.charCodeAt(text.length - 1) === CharCode.LineFeed) {
text = text.substr(0, text.length - 1);
}
let lines = text.split(/\r\n|\r|\n/);
if (lines.length === selections.length) {
return lines;
}
return null;
}

View file

@ -1550,6 +1550,54 @@ suite('Editor Controller - Regression tests', () => {
});
});
test('issue #46440: (1) Pasting a multi-line selection pastes entire selection into every insertion point', () => {
usingCursor({
text: [
'line1',
'line2',
'line3'
],
}, (model, cursor) => {
cursor.setSelections('test', [new Selection(1, 1, 1, 1), new Selection(2, 1, 2, 1), new Selection(3, 1, 3, 1)]);
cursorCommand(cursor, H.Paste, {
text: 'a\nb\nc',
pasteOnNewLine: false,
multicursorText: null
});
assert.equal(model.getValue(), [
'aline1',
'bline2',
'cline3'
].join('\n'));
});
});
test('issue #46440: (2) Pasting a multi-line selection pastes entire selection into every insertion point', () => {
usingCursor({
text: [
'line1',
'line2',
'line3'
],
}, (model, cursor) => {
cursor.setSelections('test', [new Selection(1, 1, 1, 1), new Selection(2, 1, 2, 1), new Selection(3, 1, 3, 1)]);
cursorCommand(cursor, H.Paste, {
text: 'a\nb\nc\n',
pasteOnNewLine: false,
multicursorText: null
});
assert.equal(model.getValue(), [
'aline1',
'bline2',
'cline3'
].join('\n'));
});
});
test('issue #3071: Investigate why undo stack gets corrupted', () => {
let model = TextModel.createFromString(
[