Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/caretOperations/browser/caretOperations.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { ICodeEditor } from '../../../browser/editorBrowser.js';
7
import { EditorAction, IActionOptions, registerEditorAction, ServicesAccessor } from '../../../browser/editorExtensions.js';
8
import { ICommand } from '../../../common/editorCommon.js';
9
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
10
import { MoveCaretCommand } from './moveCaretCommand.js';
11
import * as nls from '../../../../nls.js';
12
13
class MoveCaretAction extends EditorAction {
14
15
private readonly left: boolean;
16
17
constructor(left: boolean, opts: IActionOptions) {
18
super(opts);
19
20
this.left = left;
21
}
22
23
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
24
if (!editor.hasModel()) {
25
return;
26
}
27
28
const commands: ICommand[] = [];
29
const selections = editor.getSelections();
30
31
for (const selection of selections) {
32
commands.push(new MoveCaretCommand(selection, this.left));
33
}
34
35
editor.pushUndoStop();
36
editor.executeCommands(this.id, commands);
37
editor.pushUndoStop();
38
}
39
}
40
41
class MoveCaretLeftAction extends MoveCaretAction {
42
constructor() {
43
super(true, {
44
id: 'editor.action.moveCarretLeftAction',
45
label: nls.localize2('caret.moveLeft', "Move Selected Text Left"),
46
precondition: EditorContextKeys.writable
47
});
48
}
49
}
50
51
class MoveCaretRightAction extends MoveCaretAction {
52
constructor() {
53
super(false, {
54
id: 'editor.action.moveCarretRightAction',
55
label: nls.localize2('caret.moveRight', "Move Selected Text Right"),
56
precondition: EditorContextKeys.writable
57
});
58
}
59
}
60
61
registerEditorAction(MoveCaretLeftAction);
62
registerEditorAction(MoveCaretRightAction);
63
64