Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/lineSelection/browser/lineSelection.ts
5272 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 { KeyCode, KeyMod } from '../../../../base/common/keyCodes.js';
7
import { ICodeEditor } from '../../../browser/editorBrowser.js';
8
import { EditorAction, registerEditorAction, ServicesAccessor } from '../../../browser/editorExtensions.js';
9
import { CursorChangeReason } from '../../../common/cursorEvents.js';
10
import { CursorMoveCommands } from '../../../common/cursor/cursorMoveCommands.js';
11
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
12
import * as nls from '../../../../nls.js';
13
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
14
15
interface ExpandLinesSelectionArgs {
16
source?: string;
17
}
18
19
export class ExpandLineSelectionAction extends EditorAction {
20
constructor() {
21
super({
22
id: 'expandLineSelection',
23
label: nls.localize2('expandLineSelection', "Expand Line Selection"),
24
precondition: undefined,
25
kbOpts: {
26
weight: KeybindingWeight.EditorCore,
27
kbExpr: EditorContextKeys.textInputFocus,
28
primary: KeyMod.CtrlCmd | KeyCode.KeyL
29
},
30
});
31
}
32
33
public run(_accessor: ServicesAccessor, editor: ICodeEditor, args: ExpandLinesSelectionArgs): void {
34
args = args || {};
35
if (!editor.hasModel()) {
36
return;
37
}
38
const viewModel = editor._getViewModel();
39
viewModel.model.pushStackElement();
40
viewModel.setCursorStates(
41
args.source,
42
CursorChangeReason.Explicit,
43
CursorMoveCommands.expandLineSelection(viewModel, viewModel.getCursorStates())
44
);
45
viewModel.revealAllCursors(args.source, true);
46
}
47
}
48
49
registerEditorAction(ExpandLineSelectionAction);
50
51