提交 1374fa6a 编写于 作者: A Alex Dima

Fixes #46440: Distribute multiline paste to multicursors

上级 c059826b
......@@ -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;
}
......
......@@ -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(
[
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册