提交 0baba800 编写于 作者: A Alex Dima

Fixes #10212: Paste on new line only if selection does not cover entire line

上级 8575dcd1
......@@ -1770,18 +1770,28 @@ export class OneCursorOp {
public static paste(cursor:OneCursor, text: string, pasteOnNewLine: boolean, ctx: IOneCursorOperationContext): boolean {
let position = cursor.getPosition();
let selection = cursor.getSelection();
ctx.cursorPositionChangeReason = editorCommon.CursorChangeReason.Paste;
if (pasteOnNewLine && text.charAt(text.length - 1) === '\n') {
if (text.indexOf('\n') === text.length - 1) {
// Paste entire line at the beginning of line
let typeSelection = new Range(position.lineNumber, 1, position.lineNumber, 1);
ctx.executeCommand = new ReplaceCommand(typeSelection, text);
return true;
}
if (pasteOnNewLine && text.indexOf('\n') !== text.length - 1) {
pasteOnNewLine = false;
}
if (pasteOnNewLine && selection.startLineNumber !== selection.endLineNumber) {
pasteOnNewLine = false;
}
if (pasteOnNewLine && selection.startColumn === cursor.model.getLineMinColumn(selection.startLineNumber) && selection.endColumn === cursor.model.getLineMaxColumn(selection.startLineNumber)) {
pasteOnNewLine = false;
}
if (pasteOnNewLine) {
// Paste entire line at the beginning of line
let typeSelection = new Range(position.lineNumber, 1, position.lineNumber, 1);
ctx.executeCommand = new ReplaceCommand(typeSelection, text);
return true;
}
ctx.executeCommand = new ReplaceCommand(cursor.getSelection(), text);
ctx.executeCommand = new ReplaceCommand(selection, text);
return true;
}
......
......@@ -1504,6 +1504,24 @@ suite('Editor Controller - Regression tests', () => {
});
});
test('issue #10212: Pasting entire line does not replace selection', () => {
usingCursor({
text: [
'line1',
'line2'
],
}, (model, cursor) => {
moveTo(cursor, 2, 1, false);
moveTo(cursor, 2, 6, true);
cursorCommand(cursor, H.Paste, { text: 'line1\n', pasteOnNewLine: true });
assert.equal(model.getLineContent(1), 'line1');
assert.equal(model.getLineContent(2), 'line1');
assert.equal(model.getLineContent(3), '');
});
});
test('issue #3071: Investigate why undo stack gets corrupted', () => {
usingCursor({
text: [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册