Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/readOnlyMessage/browser/contribution.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 { MarkdownString } from '../../../../base/common/htmlContent.js';
7
import { Disposable } from '../../../../base/common/lifecycle.js';
8
import { ICodeEditor } from '../../../browser/editorBrowser.js';
9
import { EditorContributionInstantiation, registerEditorContribution } from '../../../browser/editorExtensions.js';
10
import { EditorOption } from '../../../common/config/editorOptions.js';
11
import { IEditorContribution } from '../../../common/editorCommon.js';
12
import { MessageController } from '../../message/browser/messageController.js';
13
import * as nls from '../../../../nls.js';
14
15
export class ReadOnlyMessageController extends Disposable implements IEditorContribution {
16
17
public static readonly ID = 'editor.contrib.readOnlyMessageController';
18
19
constructor(
20
private readonly editor: ICodeEditor
21
) {
22
super();
23
this._register(this.editor.onDidAttemptReadOnlyEdit(() => this._onDidAttemptReadOnlyEdit()));
24
}
25
26
private _onDidAttemptReadOnlyEdit(): void {
27
const messageController = MessageController.get(this.editor);
28
if (messageController && this.editor.hasModel()) {
29
let message = this.editor.getOptions().get(EditorOption.readOnlyMessage);
30
if (!message) {
31
if (this.editor.isSimpleWidget) {
32
message = new MarkdownString(nls.localize('editor.simple.readonly', "Cannot edit in read-only input"));
33
} else {
34
message = new MarkdownString(nls.localize('editor.readonly', "Cannot edit in read-only editor"));
35
}
36
}
37
38
messageController.showMessage(message, this.editor.getPosition());
39
}
40
}
41
}
42
43
registerEditorContribution(ReadOnlyMessageController.ID, ReadOnlyMessageController, EditorContributionInstantiation.BeforeFirstInteraction);
44
45