mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Fixes #46440: Distribute multiline paste to multicursors
This commit is contained in:
parent
c059826ba2
commit
1374fa6aa7
|
@ -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(
|
||||
[
|
||||
|
|
Loading…
Reference in a new issue