Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An option to copy only plain text to clipboard. #54155

Merged
merged 5 commits into from Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/vs/editor/browser/controller/textAreaHandler.ts
Expand Up @@ -8,7 +8,7 @@ import 'vs/css!./textAreaHandler';
import * as platform from 'vs/base/common/platform';
import * as browser from 'vs/base/browser/browser';
import * as strings from 'vs/base/common/strings';
import { TextAreaInput, ITextAreaInputHost, IPasteData, ICompositionData } from 'vs/editor/browser/controller/textAreaInput';
import { TextAreaInput, ITextAreaInputHost, IPasteData, ICompositionData, CopyOptions } from 'vs/editor/browser/controller/textAreaInput';
import { ISimpleModel, ITypeData, TextAreaState, PagedScreenReaderStrategy } from 'vs/editor/browser/controller/textAreaState';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
Expand Down Expand Up @@ -100,6 +100,7 @@ export class TextAreaHandler extends ViewPart {
private _fontInfo: BareFontInfo;
private _lineHeight: number;
private _emptySelectionClipboard: boolean;
private _copyWithSyntaxHighlighting: boolean;

/**
* Defined only when the text area is visible (composition case).
Expand Down Expand Up @@ -128,6 +129,7 @@ export class TextAreaHandler extends ViewPart {
this._fontInfo = conf.fontInfo;
this._lineHeight = conf.lineHeight;
this._emptySelectionClipboard = conf.emptySelectionClipboard;
this._copyWithSyntaxHighlighting = conf.copyWithSyntaxHighlighting;

this._visibleTextArea = null;
this._selections = [new Selection(1, 1, 1, 1)];
Expand Down Expand Up @@ -191,6 +193,10 @@ export class TextAreaHandler extends ViewPart {
},

getHTMLToCopy: (): string => {
if (!this._copyWithSyntaxHighlighting && !CopyOptions.forceCopyWithSyntaxHighlighting) {
return null;
}

return this._context.model.getHTMLToCopy(this._selections, this._emptySelectionClipboard);
},

Expand Down Expand Up @@ -387,6 +393,9 @@ export class TextAreaHandler extends ViewPart {
if (e.emptySelectionClipboard) {
this._emptySelectionClipboard = conf.emptySelectionClipboard;
}
if (e.copyWithSyntaxHighlighting) {
this._copyWithSyntaxHighlighting = conf.copyWithSyntaxHighlighting;
}

return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/vs/editor/common/config/commonEditorConfig.ts
Expand Up @@ -589,6 +589,11 @@ const editorConfiguration: IConfigurationNode = {
'default': EDITOR_DEFAULTS.emptySelectionClipboard,
'description': nls.localize('emptySelectionClipboard', "Controls whether copying without a selection copies the current line.")
},
'editor.copyWithSyntaxHighlighting': {
'type': 'boolean',
'default': EDITOR_DEFAULTS.copyWithSyntaxHighlighting,
'description': nls.localize('copyWithSyntaxHighlighting', "Controls whether syntax highlighting should be copied into the clipboard.")
},
'editor.wordBasedSuggestions': {
'type': 'boolean',
'default': EDITOR_DEFAULTS.contribInfo.wordBasedSuggestions,
Expand Down
15 changes: 15 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Expand Up @@ -543,6 +543,10 @@ export interface IEditorOptions {
* Copying without a selection copies the current line.
*/
emptySelectionClipboard?: boolean;
/**
* Syntax highlighting is copied.
*/
copyWithSyntaxHighlighting?: boolean;
/**
* Enable word based suggestions. Defaults to 'true'
*/
Expand Down Expand Up @@ -1006,6 +1010,7 @@ export interface IValidatedEditorOptions {
readonly autoIndent: boolean;
readonly dragAndDrop: boolean;
readonly emptySelectionClipboard: boolean;
readonly copyWithSyntaxHighlighting: boolean;
readonly useTabStops: boolean;
readonly multiCursorModifier: 'altKey' | 'ctrlKey' | 'metaKey';
readonly multiCursorMergeOverlapping: boolean;
Expand Down Expand Up @@ -1045,6 +1050,7 @@ export class InternalEditorOptions {
readonly tabFocusMode: boolean;
readonly dragAndDrop: boolean;
readonly emptySelectionClipboard: boolean;
readonly copyWithSyntaxHighlighting: boolean;

// ---- grouped options
readonly layoutInfo: EditorLayoutInfo;
Expand Down Expand Up @@ -1074,6 +1080,7 @@ export class InternalEditorOptions {
tabFocusMode: boolean;
dragAndDrop: boolean;
emptySelectionClipboard: boolean;
copyWithSyntaxHighlighting: boolean;
layoutInfo: EditorLayoutInfo;
fontInfo: FontInfo;
viewInfo: InternalEditorViewOptions;
Expand All @@ -1098,6 +1105,7 @@ export class InternalEditorOptions {
this.tabFocusMode = source.tabFocusMode;
this.dragAndDrop = source.dragAndDrop;
this.emptySelectionClipboard = source.emptySelectionClipboard;
this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting;
this.layoutInfo = source.layoutInfo;
this.fontInfo = source.fontInfo;
this.viewInfo = source.viewInfo;
Expand Down Expand Up @@ -1129,6 +1137,7 @@ export class InternalEditorOptions {
&& this.dragAndDrop === other.dragAndDrop
&& this.showUnused === other.showUnused
&& this.emptySelectionClipboard === other.emptySelectionClipboard
&& this.copyWithSyntaxHighlighting === other.copyWithSyntaxHighlighting
&& InternalEditorOptions._equalsLayoutInfo(this.layoutInfo, other.layoutInfo)
&& this.fontInfo.equals(other.fontInfo)
&& InternalEditorOptions._equalsViewOptions(this.viewInfo, other.viewInfo)
Expand Down Expand Up @@ -1159,6 +1168,7 @@ export class InternalEditorOptions {
tabFocusMode: (this.tabFocusMode !== newOpts.tabFocusMode),
dragAndDrop: (this.dragAndDrop !== newOpts.dragAndDrop),
emptySelectionClipboard: (this.emptySelectionClipboard !== newOpts.emptySelectionClipboard),
copyWithSyntaxHighlighting: (this.copyWithSyntaxHighlighting !== newOpts.copyWithSyntaxHighlighting),
layoutInfo: (!InternalEditorOptions._equalsLayoutInfo(this.layoutInfo, newOpts.layoutInfo)),
fontInfo: (!this.fontInfo.equals(newOpts.fontInfo)),
viewInfo: (!InternalEditorOptions._equalsViewOptions(this.viewInfo, newOpts.viewInfo)),
Expand Down Expand Up @@ -1542,6 +1552,7 @@ export interface IConfigurationChangedEvent {
readonly tabFocusMode: boolean;
readonly dragAndDrop: boolean;
readonly emptySelectionClipboard: boolean;
readonly copyWithSyntaxHighlighting: boolean;
readonly layoutInfo: boolean;
readonly fontInfo: boolean;
readonly viewInfo: boolean;
Expand Down Expand Up @@ -1751,6 +1762,7 @@ export class EditorOptionsValidator {
autoIndent: _boolean(opts.autoIndent, defaults.autoIndent),
dragAndDrop: _boolean(opts.dragAndDrop, defaults.dragAndDrop),
emptySelectionClipboard: _boolean(opts.emptySelectionClipboard, defaults.emptySelectionClipboard),
copyWithSyntaxHighlighting: _boolean(opts.copyWithSyntaxHighlighting, defaults.copyWithSyntaxHighlighting),
useTabStops: _boolean(opts.useTabStops, defaults.useTabStops),
multiCursorModifier: multiCursorModifier,
multiCursorMergeOverlapping: _boolean(opts.multiCursorMergeOverlapping, defaults.multiCursorMergeOverlapping),
Expand Down Expand Up @@ -2034,6 +2046,7 @@ export class InternalEditorOptionsFactory {
autoIndent: opts.autoIndent,
dragAndDrop: opts.dragAndDrop,
emptySelectionClipboard: opts.emptySelectionClipboard,
copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting,
useTabStops: opts.useTabStops,
multiCursorModifier: opts.multiCursorModifier,
multiCursorMergeOverlapping: opts.multiCursorMergeOverlapping,
Expand Down Expand Up @@ -2259,6 +2272,7 @@ export class InternalEditorOptionsFactory {
tabFocusMode: opts.readOnly ? true : env.tabFocusMode,
dragAndDrop: opts.dragAndDrop,
emptySelectionClipboard: opts.emptySelectionClipboard && env.emptySelectionClipboard,
copyWithSyntaxHighlighting: opts.copyWithSyntaxHighlighting,
layoutInfo: layoutInfo,
fontInfo: env.fontInfo,
viewInfo: opts.viewInfo,
Expand Down Expand Up @@ -2492,6 +2506,7 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
autoIndent: true,
dragAndDrop: true,
emptySelectionClipboard: true,
copyWithSyntaxHighlighting: true,
useTabStops: true,
multiCursorModifier: 'altKey',
multiCursorMergeOverlapping: true,
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/common/controller/cursorCommon.ts
Expand Up @@ -82,6 +82,7 @@ export class CursorConfiguration {
public readonly useTabStops: boolean;
public readonly wordSeparators: string;
public readonly emptySelectionClipboard: boolean;
public readonly copyWithSyntaxHighlighting: boolean;
public readonly multiCursorMergeOverlapping: boolean;
public readonly autoClosingBrackets: EditorAutoClosingStrategy;
public readonly autoClosingQuotes: EditorAutoClosingStrategy;
Expand Down Expand Up @@ -129,6 +130,7 @@ export class CursorConfiguration {
this.useTabStops = c.useTabStops;
this.wordSeparators = c.wordSeparators;
this.emptySelectionClipboard = c.emptySelectionClipboard;
this.copyWithSyntaxHighlighting = c.copyWithSyntaxHighlighting;
this.multiCursorMergeOverlapping = c.multiCursorMergeOverlapping;
this.autoClosingBrackets = c.autoClosingBrackets;
this.autoClosingQuotes = c.autoClosingQuotes;
Expand Down
2 changes: 2 additions & 0 deletions src/vs/editor/common/view/viewEvents.ts
Expand Up @@ -42,6 +42,7 @@ export class ViewConfigurationChangedEvent {
public readonly readOnly: boolean;
public readonly accessibilitySupport: boolean;
public readonly emptySelectionClipboard: boolean;
public readonly copyWithSyntaxHighlighting: boolean;
public readonly layoutInfo: boolean;
public readonly fontInfo: boolean;
public readonly viewInfo: boolean;
Expand All @@ -55,6 +56,7 @@ export class ViewConfigurationChangedEvent {
this.readOnly = source.readOnly;
this.accessibilitySupport = source.accessibilitySupport;
this.emptySelectionClipboard = source.emptySelectionClipboard;
this.copyWithSyntaxHighlighting = source.copyWithSyntaxHighlighting;
this.layoutInfo = source.layoutInfo;
this.fontInfo = source.fontInfo;
this.viewInfo = source.viewInfo;
Expand Down
6 changes: 6 additions & 0 deletions src/vs/monaco.d.ts
Expand Up @@ -2897,6 +2897,10 @@ declare namespace monaco.editor {
* Copying without a selection copies the current line.
*/
emptySelectionClipboard?: boolean;
/**
* Syntax highlighting is copied.
*/
copyWithSyntaxHighlighting?: boolean;
/**
* Enable word based suggestions. Defaults to 'true'
*/
Expand Down Expand Up @@ -3295,6 +3299,7 @@ declare namespace monaco.editor {
readonly tabFocusMode: boolean;
readonly dragAndDrop: boolean;
readonly emptySelectionClipboard: boolean;
readonly copyWithSyntaxHighlighting: boolean;
readonly layoutInfo: EditorLayoutInfo;
readonly fontInfo: FontInfo;
readonly viewInfo: InternalEditorViewOptions;
Expand Down Expand Up @@ -3435,6 +3440,7 @@ declare namespace monaco.editor {
readonly tabFocusMode: boolean;
readonly dragAndDrop: boolean;
readonly emptySelectionClipboard: boolean;
readonly copyWithSyntaxHighlighting: boolean;
readonly layoutInfo: boolean;
readonly fontInfo: boolean;
readonly viewInfo: boolean;
Expand Down