Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/insertFinalNewLine/browser/insertFinalNewLine.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, registerEditorAction, ServicesAccessor } from '../../../browser/editorExtensions.js';
8
import { InsertFinalNewLineCommand } from './insertFinalNewLineCommand.js';
9
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
10
import * as nls from '../../../../nls.js';
11
12
export class InsertFinalNewLineAction extends EditorAction {
13
14
public static readonly ID = 'editor.action.insertFinalNewLine';
15
16
constructor() {
17
super({
18
id: InsertFinalNewLineAction.ID,
19
label: nls.localize2('insertFinalNewLine', "Insert Final New Line"),
20
precondition: EditorContextKeys.writable
21
});
22
}
23
24
public run(_accessor: ServicesAccessor, editor: ICodeEditor, args: any): void {
25
const selection = editor.getSelection();
26
if (selection === null) {
27
return;
28
}
29
30
const command = new InsertFinalNewLineCommand(selection);
31
32
editor.pushUndoStop();
33
editor.executeCommands(this.id, [command]);
34
editor.pushUndoStop();
35
}
36
}
37
38
registerEditorAction(InsertFinalNewLineAction);
39
40