Skip to content

Commit 954b93a

Browse files
author
Kai Wood
committed
Add setting to prevent copying empty selections
1 parent 47e2a84 commit 954b93a

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
@@ -402,6 +402,10 @@ export interface IEditorOptions {
402402
* Enable snippet suggestions. Default to 'true'.
403403
*/
404404
snippetSuggestions?: 'top' | 'bottom' | 'inline' | 'none';
405+
/**
406+
* Copying without a selection copies the current line.
407+
*/
408+
emptySelectionClipboard?: boolean;
405409
/**
406410
* Enable tab completion. Defaults to 'false'
407411
*/
@@ -862,6 +866,7 @@ export class EditorContribOptions {
862866
readonly suggestOnTriggerCharacters: boolean;
863867
readonly acceptSuggestionOnEnter: boolean;
864868
readonly snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
869+
readonly emptySelectionClipboard: boolean;
865870
readonly tabCompletion: boolean;
866871
readonly wordBasedSuggestions: boolean;
867872
readonly suggestFontSize: number;
@@ -885,6 +890,7 @@ export class EditorContribOptions {
885890
suggestOnTriggerCharacters: boolean;
886891
acceptSuggestionOnEnter: boolean;
887892
snippetSuggestions: 'top' | 'bottom' | 'inline' | 'none';
893+
emptySelectionClipboard: boolean;
888894
tabCompletion: boolean;
889895
wordBasedSuggestions: boolean;
890896
suggestFontSize: number;
@@ -904,6 +910,7 @@ export class EditorContribOptions {
904910
this.suggestOnTriggerCharacters = Boolean(source.suggestOnTriggerCharacters);
905911
this.acceptSuggestionOnEnter = Boolean(source.acceptSuggestionOnEnter);
906912
this.snippetSuggestions = source.snippetSuggestions;
913+
this.emptySelectionClipboard = source.emptySelectionClipboard;
907914
this.tabCompletion = source.tabCompletion;
908915
this.wordBasedSuggestions = source.wordBasedSuggestions;
909916
this.suggestFontSize = source.suggestFontSize;
@@ -929,6 +936,7 @@ export class EditorContribOptions {
929936
&& this.suggestOnTriggerCharacters === other.suggestOnTriggerCharacters
930937
&& this.acceptSuggestionOnEnter === other.acceptSuggestionOnEnter
931938
&& this.snippetSuggestions === other.snippetSuggestions
939+
&& this.emptySelectionClipboard === other.emptySelectionClipboard
932940
&& this.tabCompletion === other.tabCompletion
933941
&& this.wordBasedSuggestions === other.wordBasedSuggestions
934942
&& 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)