Skip to content

Commit 10fe85a

Browse files
authored
Merge pull request microsoft#13678 from kaiwood/empty-selection-clipboard
Add setting to prevent copying empty selections
2 parents e2702b8 + 954b93a commit 10fe85a

5 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/vs/editor/common/config/commonEditorConfig.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class InternalEditorOptionsHelper {
310310
suggestOnTriggerCharacters: toBoolean(opts.suggestOnTriggerCharacters),
311311
acceptSuggestionOnEnter: toBoolean(opts.acceptSuggestionOnEnter),
312312
snippetSuggestions: opts.snippetSuggestions,
313+
emptySelectionClipboard: opts.emptySelectionClipboard,
313314
tabCompletion: opts.tabCompletion,
314315
wordBasedSuggestions: opts.wordBasedSuggestions,
315316
suggestFontSize: opts.suggestFontSize,
@@ -762,6 +763,11 @@ let editorConfiguration: IConfigurationNode = {
762763
'default': DefaultConfig.editor.snippetSuggestions,
763764
'description': nls.localize('snippetSuggestions', "Controls whether snippets are shown with other suggestions and how they are sorted.")
764765
},
766+
'editor.emptySelectionClipboard': {
767+
'type': 'boolean',
768+
'default': DefaultConfig.editor.emptySelectionClipboard,
769+
'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.")
770+
},
765771
'editor.wordBasedSuggestions': {
766772
'type': 'boolean',
767773
'default': DefaultConfig.editor.wordBasedSuggestions,

src/vs/editor/common/config/defaultConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class ConfigClass implements IConfiguration {
8585
suggestOnTriggerCharacters: true,
8686
acceptSuggestionOnEnter: true,
8787
snippetSuggestions: 'bottom',
88+
emptySelectionClipboard: true,
8889
tabCompletion: false,
8990
wordBasedSuggestions: true,
9091
suggestFontSize: 0,

src/vs/editor/common/editorCommon.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ export interface IEditorOptions {
401401
* Enable snippet suggestions. Default to 'true'.
402402
*/
403403
snippetSuggestions?: 'top' | 'bottom' | 'inline' | 'none';
404+
/**
405+
* Copying without a selection copies the current line.
406+
*/
407+
emptySelectionClipboard?: boolean;
404408
/**
405409
* Enable tab completion. Defaults to 'false'
406410
*/
@@ -861,6 +865,7 @@ export class EditorContribOptions {
861865
readonly suggestOnTriggerCharacters: boolean;
862866
readonly acceptSuggestionOnEnter: boolean;
863867
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
868+
readonly emptySelectionClipboard: boolean;
864869
readonly tabCompletion: boolean;
865870
readonly wordBasedSuggestions: boolean;
866871
readonly suggestFontSize: number;
@@ -884,6 +889,7 @@ export class EditorContribOptions {
884889
suggestOnTriggerCharacters: boolean;
885890
acceptSuggestionOnEnter: boolean;
886891
snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
892+
emptySelectionClipboard: boolean;
887893
tabCompletion: boolean;
888894
wordBasedSuggestions: boolean;
889895
suggestFontSize: number;
@@ -903,6 +909,7 @@ export class EditorContribOptions {
903909
this.suggestOnTriggerCharacters = Boolean(source.suggestOnTriggerCharacters);
904910
this.acceptSuggestionOnEnter = Boolean(source.acceptSuggestionOnEnter);
905911
this.snippetSuggestions = source.snippetSuggestions;
912+
this.emptySelectionClipboard = source.emptySelectionClipboard;
906913
this.tabCompletion = source.tabCompletion;
907914
this.wordBasedSuggestions = source.wordBasedSuggestions;
908915
this.suggestFontSize = source.suggestFontSize;
@@ -928,6 +935,7 @@ export class EditorContribOptions {
928935
&& this.suggestOnTriggerCharacters === other.suggestOnTriggerCharacters
929936
&& this.acceptSuggestionOnEnter === other.acceptSuggestionOnEnter
930937
&& this.snippetSuggestions === other.snippetSuggestions
938+
&& this.emptySelectionClipboard === other.emptySelectionClipboard
931939
&& this.tabCompletion === other.tabCompletion
932940
&& this.wordBasedSuggestions === other.wordBasedSuggestions
933941
&& this.suggestFontSize === other.suggestFontSize

src/vs/editor/contrib/clipboard/browser/clipboard.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ class ExecCommandCutAction extends ExecCommandAction {
7373
}
7474

7575
public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
76-
if (!browser.enableEmptySelectionClipboard && editor.getSelection().isEmpty()) {
76+
var enableEmptySelectionClipboard = editor.getConfiguration().contribInfo.emptySelectionClipboard && browser.enableEmptySelectionClipboard;
77+
78+
if (!enableEmptySelectionClipboard && editor.getSelection().isEmpty()) {
7779
return;
7880
}
7981

@@ -103,7 +105,9 @@ class ExecCommandCopyAction extends ExecCommandAction {
103105
}
104106

105107
public run(accessor: ServicesAccessor, editor: editorCommon.ICommonCodeEditor): void {
106-
if (!browser.enableEmptySelectionClipboard && editor.getSelection().isEmpty()) {
108+
var enableEmptySelectionClipboard = editor.getConfiguration().contribInfo.emptySelectionClipboard && browser.enableEmptySelectionClipboard;
109+
110+
if (!enableEmptySelectionClipboard && editor.getSelection().isEmpty()) {
107111
return;
108112
}
109113

src/vs/monaco.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,10 @@ declare module monaco.editor {
12621262
* Enable snippet suggestions. Default to 'true'.
12631263
*/
12641264
snippetSuggestions?: 'top' | 'bottom' | 'inline' | 'none';
1265+
/**
1266+
* Copying without a selection copies the current line.
1267+
*/
1268+
emptySelectionClipboard?: boolean;
12651269
/**
12661270
* Enable tab completion. Defaults to 'false'
12671271
*/
@@ -1458,6 +1462,7 @@ declare module monaco.editor {
14581462
readonly suggestOnTriggerCharacters: boolean;
14591463
readonly acceptSuggestionOnEnter: boolean;
14601464
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
1465+
readonly emptySelectionClipboard: boolean;
14611466
readonly tabCompletion: boolean;
14621467
readonly wordBasedSuggestions: boolean;
14631468
readonly suggestFontSize: number;

0 commit comments

Comments
 (0)