提交 05fc8ae1 编写于 作者: R rebornix

Move delete all left action to contrib

上级 3e30272d
...@@ -603,16 +603,6 @@ registerCommand(new CoreCommand({ ...@@ -603,16 +603,6 @@ registerCommand(new CoreCommand({
mac: { primary: KeyCode.Delete, secondary: [KeyMod.WinCtrl | KeyCode.KEY_D, KeyMod.WinCtrl | KeyCode.Delete] } mac: { primary: KeyCode.Delete, secondary: [KeyMod.WinCtrl | KeyCode.KEY_D, KeyMod.WinCtrl | KeyCode.Delete] }
} }
})); }));
registerCommand(new CoreCommand({
id: H.DeleteAllLeft,
precondition: EditorContextKeys.Writable,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.TextFocus,
primary: null,
mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace }
}
}));
registerCommand(new CoreCommand({ registerCommand(new CoreCommand({
id: H.DeleteAllRight, id: H.DeleteAllRight,
precondition: EditorContextKeys.Writable, precondition: EditorContextKeys.Writable,
......
...@@ -1009,7 +1009,6 @@ export class Cursor extends EventEmitter { ...@@ -1009,7 +1009,6 @@ export class Cursor extends EventEmitter {
this._handlers[H.DeleteWordStartRight] = (ctx) => this._deleteWordRight(false, WordNavigationType.WordStart, ctx); this._handlers[H.DeleteWordStartRight] = (ctx) => this._deleteWordRight(false, WordNavigationType.WordStart, ctx);
this._handlers[H.DeleteWordEndRight] = (ctx) => this._deleteWordRight(false, WordNavigationType.WordEnd, ctx); this._handlers[H.DeleteWordEndRight] = (ctx) => this._deleteWordRight(false, WordNavigationType.WordEnd, ctx);
this._handlers[H.DeleteAllLeft] = (ctx) => this._deleteAllLeft(ctx);
this._handlers[H.DeleteAllRight] = (ctx) => this._deleteAllRight(ctx); this._handlers[H.DeleteAllRight] = (ctx) => this._deleteAllRight(ctx);
this._handlers[H.Cut] = (ctx) => this._cut(ctx); this._handlers[H.Cut] = (ctx) => this._cut(ctx);
...@@ -1518,10 +1517,6 @@ export class Cursor extends EventEmitter { ...@@ -1518,10 +1517,6 @@ export class Cursor extends EventEmitter {
return this._applyEditForAll(ctx, (cursor) => WordOperations.deleteWordRight(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType)); return this._applyEditForAll(ctx, (cursor) => WordOperations.deleteWordRight(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType));
} }
private _deleteAllLeft(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteAllLeft(cursor.config, cursor.model, cursor.modelState));
}
private _deleteAllRight(ctx: IMultipleCursorOperationContext): boolean { private _deleteAllRight(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteAllRight(cursor.config, cursor.model, cursor.modelState)); return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteAllRight(cursor.config, cursor.model, cursor.modelState));
} }
......
...@@ -164,37 +164,6 @@ export class DeleteOperations { ...@@ -164,37 +164,6 @@ export class DeleteOperations {
}); });
} }
public static deleteAllLeft(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): EditOperationResult {
let r = this.autoClosingPairDelete(config, model, cursor);
if (r) {
// This was a case for an auto-closing pair delete
return r;
}
let selection = cursor.selection;
if (selection.isEmpty()) {
let position = cursor.position;
let lineNumber = position.lineNumber;
let column = position.column;
if (column === 1) {
// Ignore deleting at beginning of line
return null;
}
let deleteSelection = new Range(lineNumber, 1, lineNumber, column);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
return this.deleteLeft(config, model, cursor);
}
public static cut(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, enableEmptySelectionClipboard: boolean): EditOperationResult { public static cut(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, enableEmptySelectionClipboard: boolean): EditOperationResult {
let selection = cursor.selection; let selection = cursor.selection;
......
...@@ -4583,7 +4583,6 @@ export var Handler = { ...@@ -4583,7 +4583,6 @@ export var Handler = {
DeleteWordStartRight: 'deleteWordStartRight', DeleteWordStartRight: 'deleteWordStartRight',
DeleteWordEndRight: 'deleteWordEndRight', DeleteWordEndRight: 'deleteWordEndRight',
DeleteAllLeft: 'deleteAllLeft',
DeleteAllRight: 'deleteAllRight', DeleteAllRight: 'deleteAllRight',
RemoveSecondaryCursors: 'removeSecondaryCursors', RemoveSecondaryCursors: 'removeSecondaryCursors',
......
...@@ -9,6 +9,8 @@ import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes'; ...@@ -9,6 +9,8 @@ import { KeyCode, KeyMod, KeyChord } from 'vs/base/common/keyCodes';
import { SortLinesCommand } from 'vs/editor/contrib/linesOperations/common/sortLinesCommand'; import { SortLinesCommand } from 'vs/editor/contrib/linesOperations/common/sortLinesCommand';
import { TrimTrailingWhitespaceCommand } from 'vs/editor/common/commands/trimTrailingWhitespaceCommand'; import { TrimTrailingWhitespaceCommand } from 'vs/editor/common/commands/trimTrailingWhitespaceCommand';
import { EditorContextKeys, Handler, ICommand, ICommonCodeEditor } from 'vs/editor/common/editorCommon'; import { EditorContextKeys, Handler, ICommand, ICommonCodeEditor } from 'vs/editor/common/editorCommon';
import { ReplaceCommand } from 'vs/editor/common/commands/replaceCommand';
import { Range } from 'vs/editor/common/core/range';
import { editorAction, ServicesAccessor, IActionOptions, EditorAction, HandlerEditorAction } from 'vs/editor/common/editorCommonExtensions'; import { editorAction, ServicesAccessor, IActionOptions, EditorAction, HandlerEditorAction } from 'vs/editor/common/editorCommonExtensions';
import { CopyLinesCommand } from './copyLinesCommand'; import { CopyLinesCommand } from './copyLinesCommand';
import { DeleteLinesCommand } from './deleteLinesCommand'; import { DeleteLinesCommand } from './deleteLinesCommand';
...@@ -346,3 +348,39 @@ class InsertLineAfterAction extends HandlerEditorAction { ...@@ -346,3 +348,39 @@ class InsertLineAfterAction extends HandlerEditorAction {
}); });
} }
} }
@editorAction
export class DeleteAllLeftAction extends EditorAction {
constructor() {
super({
id: 'deleteAllLeft',
label: nls.localize('lines.deleteAllLeft', "Delete All Left"),
alias: 'Delete All Left',
precondition: EditorContextKeys.Writable,
kbOpts: {
kbExpr: EditorContextKeys.TextFocus,
primary: null,
mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace }
}
});
}
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
let selections = editor.getSelections();
let commands: ICommand[] = [];
for (let i = 0, len = selections.length; i < len; i++) {
let selection = selections[i];
if (selection.isEmpty()) {
console.log(selection.startColumn);
commands[i] = new ReplaceCommand(new Range(selection.startLineNumber, 1, selection.startLineNumber, selection.startColumn), '');
} else {
commands[i] = new ReplaceCommand(selection, '');
}
}
editor.executeCommands(this.id, commands);
}
}
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { Selection } from 'vs/editor/common/core/selection';
import { withMockCodeEditor } from 'vs/editor/test/common/mocks/mockCodeEditor';
import { DeleteAllLeftAction } from 'vs/editor/contrib/linesOperations/common/linesOperations';
suite('Editor Contrib - Line Operations', () => {
test('delete all left', function () {
withMockCodeEditor(
[
'one',
'two',
'three',
'one two three four'
], {}, (editor, cursor) => {
let model = editor.getModel();
let joinLinesAction = new DeleteAllLeftAction();
editor.setSelection(new Selection(1, 2, 1, 2));
joinLinesAction.run(null, editor);
assert.equal(model.getLineContent(1), 'ne', '001');
editor.setSelections([new Selection(2, 2, 2, 2), new Selection(3, 2, 3, 2)]);
joinLinesAction.run(null, editor);
assert.equal(model.getLineContent(2), 'wo', '002');
assert.equal(model.getLineContent(3), 'hree', '003');
editor.setSelections([new Selection(4, 5, 4, 5), new Selection(4, 15, 4, 15)]);
joinLinesAction.run(null, editor);
assert.equal(model.getLineContent(4), 'four', '004');
});
});
});
\ No newline at end of file
...@@ -3406,7 +3406,6 @@ declare module monaco.editor { ...@@ -3406,7 +3406,6 @@ declare module monaco.editor {
DeleteWordRight: string; DeleteWordRight: string;
DeleteWordStartRight: string; DeleteWordStartRight: string;
DeleteWordEndRight: string; DeleteWordEndRight: string;
DeleteAllLeft: string;
DeleteAllRight: string; DeleteAllRight: string;
RemoveSecondaryCursors: string; RemoveSecondaryCursors: string;
CancelSelection: string; CancelSelection: string;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册