Path: blob/main/src/vs/editor/contrib/caretOperations/browser/caretOperations.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { ICodeEditor } from '../../../browser/editorBrowser.js';6import { EditorAction, IActionOptions, registerEditorAction, ServicesAccessor } from '../../../browser/editorExtensions.js';7import { ICommand } from '../../../common/editorCommon.js';8import { EditorContextKeys } from '../../../common/editorContextKeys.js';9import { MoveCaretCommand } from './moveCaretCommand.js';10import * as nls from '../../../../nls.js';1112class MoveCaretAction extends EditorAction {1314private readonly left: boolean;1516constructor(left: boolean, opts: IActionOptions) {17super(opts);1819this.left = left;20}2122public run(accessor: ServicesAccessor, editor: ICodeEditor): void {23if (!editor.hasModel()) {24return;25}2627const commands: ICommand[] = [];28const selections = editor.getSelections();2930for (const selection of selections) {31commands.push(new MoveCaretCommand(selection, this.left));32}3334editor.pushUndoStop();35editor.executeCommands(this.id, commands);36editor.pushUndoStop();37}38}3940class MoveCaretLeftAction extends MoveCaretAction {41constructor() {42super(true, {43id: 'editor.action.moveCarretLeftAction',44label: nls.localize2('caret.moveLeft', "Move Selected Text Left"),45precondition: EditorContextKeys.writable46});47}48}4950class MoveCaretRightAction extends MoveCaretAction {51constructor() {52super(false, {53id: 'editor.action.moveCarretRightAction',54label: nls.localize2('caret.moveRight', "Move Selected Text Right"),55precondition: EditorContextKeys.writable56});57}58}5960registerEditorAction(MoveCaretLeftAction);61registerEditorAction(MoveCaretRightAction);626364