提交 328939fd 编写于 作者: A Alex Dima

Move deleteAllRight out of the editor core (#8575)

上级 c47b8c87
......@@ -603,16 +603,6 @@ registerCommand(new CoreCommand({
mac: { primary: KeyCode.Delete, secondary: [KeyMod.WinCtrl | KeyCode.KEY_D, KeyMod.WinCtrl | KeyCode.Delete] }
}
}));
registerCommand(new CoreCommand({
id: H.DeleteAllRight,
precondition: EditorContextKeys.Writable,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.TextFocus,
primary: null,
mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_K, secondary: [KeyMod.CtrlCmd | KeyCode.Delete] }
}
}));
registerCommand(new WordCommand(H.CursorWordStartLeft, false, KeyCode.LeftArrow));
......
......@@ -1001,7 +1001,6 @@ export class Cursor extends EventEmitter {
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.DeleteAllRight] = (ctx) => this._deleteAllRight(ctx);
this._handlers[H.Cut] = (ctx) => this._cut(ctx);
this._handlers[H.ExpandLineSelection] = (ctx) => this._expandLineSelection(ctx);
......@@ -1509,10 +1508,6 @@ export class Cursor extends EventEmitter {
return this._applyEditForAll(ctx, (cursor) => WordOperations.deleteWordRight(cursor.config, cursor.model, cursor.modelState, whitespaceHeuristics, wordNavigationType));
}
private _deleteAllRight(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.deleteAllRight(cursor.config, cursor.model, cursor.modelState));
}
private _cut(ctx: IMultipleCursorOperationContext): boolean {
return this._applyEditForAll(ctx, (cursor) => DeleteOperations.cut(cursor.config, cursor.model, cursor.modelState, this.enableEmptySelectionClipboard));
}
......
......@@ -43,32 +43,6 @@ export class DeleteOperations {
});
}
public static deleteAllRight(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): EditOperationResult {
let selection = cursor.selection;
if (selection.isEmpty()) {
let position = cursor.position;
let lineNumber = position.lineNumber;
let column = position.column;
let maxColumn = model.getLineMaxColumn(lineNumber);
if (column === maxColumn) {
// Ignore deleting at end of file
return null;
}
let deleteSelection = new Range(lineNumber, column, lineNumber, maxColumn);
if (!deleteSelection.isEmpty()) {
return new EditOperationResult(new ReplaceCommand(deleteSelection, ''), {
shouldPushStackElementBefore: false,
shouldPushStackElementAfter: false
});
}
}
return this.deleteRight(config, model, cursor);
}
public static autoClosingPairDelete(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): EditOperationResult {
if (!config.autoClosingBrackets) {
return null;
......
......@@ -4472,8 +4472,6 @@ export var Handler = {
DeleteWordStartRight: 'deleteWordStartRight',
DeleteWordEndRight: 'deleteWordEndRight',
DeleteAllRight: 'deleteAllRight',
RemoveSecondaryCursors: 'removeSecondaryCursors',
CancelSelection: 'cancelSelection',
......
......@@ -403,6 +403,59 @@ export class DeleteAllLeftAction extends EditorAction {
}
}
@editorAction
export class DeleteAllRightAction extends EditorAction {
constructor() {
super({
id: 'deleteAllRight',
label: nls.localize('lines.deleteAllRight', "Delete All Right"),
alias: 'Delete All Right',
precondition: EditorContextKeys.Writable,
kbOpts: {
kbExpr: EditorContextKeys.TextFocus,
primary: null,
mac: { primary: KeyMod.WinCtrl | KeyCode.KEY_K, secondary: [KeyMod.CtrlCmd | KeyCode.Delete] }
}
});
}
public run(accessor: ServicesAccessor, editor: ICommonCodeEditor): void {
let model = editor.getModel();
let rangesToDelete: Range[] = editor.getSelections().map((sel) => {
if (sel.isEmpty()) {
let maxColumn = model.getLineMaxColumn(sel.startLineNumber);
return new Range(sel.startLineNumber, sel.startColumn, sel.startLineNumber, maxColumn);
}
return sel;
});
rangesToDelete.sort(Range.compareRangesUsingStarts);
// merge overlapping selections
let effectiveRanges: Range[] = [];
for (let i = 0, count = rangesToDelete.length - 1; i < count; i++) {
let range = rangesToDelete[i];
let nextRange = rangesToDelete[i + 1];
if (Range.intersectRanges(range, nextRange) === null) {
effectiveRanges.push(range);
} else {
rangesToDelete[i + 1] = Range.plusRange(range, nextRange);
}
}
effectiveRanges.push(rangesToDelete[rangesToDelete.length - 1]);
let edits: IIdentifiedSingleEditOperation[] = effectiveRanges.map(range => {
return EditOperation.replace(range, '');
});
editor.executeEdits(this.id, edits);
}
}
@editorAction
export class JoinLinesAction extends EditorAction {
constructor() {
......
......@@ -3383,7 +3383,6 @@ declare module monaco.editor {
DeleteWordRight: string;
DeleteWordStartRight: string;
DeleteWordEndRight: string;
DeleteAllRight: string;
RemoveSecondaryCursors: string;
CancelSelection: string;
Cut: string;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册