提交 1bd2b99b 编写于 作者: A Alex Dima

All cursors should do the same thing when deleting left

上级 6dbc39c7
......@@ -49,54 +49,68 @@ export class DeleteOperations {
});
}
private static autoClosingPairDelete(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): CommandResult {
private static _isAutoClosingPairDelete(config: CursorConfiguration, model: ICursorSimpleModel, cursors: SingleCursorState[]): boolean {
if (!config.autoClosingBrackets) {
return null;
return false;
}
if (!cursor.selection.isEmpty()) {
return null;
}
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
const selection = cursor.selection;
const position = cursor.position;
let position = cursor.position;
if (!selection.isEmpty()) {
return false;
}
let lineText = model.getLineContent(position.lineNumber);
let character = lineText[position.column - 2];
const lineText = model.getLineContent(position.lineNumber);
const character = lineText[position.column - 2];
if (!config.autoClosingPairsOpen.hasOwnProperty(character)) {
return null;
}
if (!config.autoClosingPairsOpen.hasOwnProperty(character)) {
return false;
}
let afterCharacter = lineText[position.column - 1];
let closeCharacter = config.autoClosingPairsOpen[character];
const afterCharacter = lineText[position.column - 1];
const closeCharacter = config.autoClosingPairsOpen[character];
if (afterCharacter !== closeCharacter) {
return null;
if (afterCharacter !== closeCharacter) {
return false;
}
}
let deleteSelection = new Range(
position.lineNumber,
position.column - 1,
position.lineNumber,
position.column + 1
);
return true;
}
return new CommandResult(new ReplaceCommand(deleteSelection, ''), false);
private static _runAutoClosingPairDelete(config: CursorConfiguration, model: ICursorSimpleModel, cursors: SingleCursorState[]): EditOperationResult {
let commands: CommandResult[] = [];
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
const position = cursor.position;
const deleteSelection = new Range(
position.lineNumber,
position.column - 1,
position.lineNumber,
position.column + 1
);
commands[i] = new CommandResult(new ReplaceCommand(deleteSelection, ''), false);
}
return new EditOperationResult(commands, {
shouldPushStackElementBefore: true,
shouldPushStackElementAfter: false
});
}
public static deleteLeft(config: CursorConfiguration, model: ICursorSimpleModel, cursors: SingleCursorState[]): EditOperationResult {
if (this._isAutoClosingPairDelete(config, model, cursors)) {
return this._runAutoClosingPairDelete(config, model, cursors);
}
let commands: CommandResult[] = [];
let shouldPushStackElementBefore = false;
for (let i = 0, len = cursors.length; i < len; i++) {
const cursor = cursors[i];
let r = this.autoClosingPairDelete(config, model, cursor);
if (r) {
// This was a case for an auto-closing pair delete
commands[i] = r;
continue;
}
let deleteSelection: Range = cursor.selection;
if (deleteSelection.isEmpty()) {
......
......@@ -3120,4 +3120,26 @@ suite('autoClosingPairs', () => {
});
mode.dispose();
});
test('All cursors should do the same thing when deleting left', () => {
let mode = new AutoClosingMode();
usingCursor({
text: [
'var a = ()'
],
languageIdentifier: mode.getLanguageIdentifier()
}, (model, cursor) => {
cursor.setSelections('test', [
new Selection(1, 4, 1, 4),
new Selection(1, 10, 1, 10),
]);
// delete left
cursorCommand(cursor, H.DeleteLeft, null, 'keyboard');
assert.equal(model.getValue(), 'va a = )');
});
mode.dispose();
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册