Merge pull request #54155 from mshoho/plain-text-to-clipboard

An option to copy only plain text to clipboard.
This commit is contained in:
Peng Lyu 2018-09-05 14:27:21 -07:00 committed by GitHub
commit f67fd23ed8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 1 deletions

View file

@ -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';
@ -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).
@ -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)];
@ -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);
},
@ -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;
}

View file

@ -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,

View file

@ -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'
*/
@ -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;
@ -1045,6 +1050,7 @@ export class InternalEditorOptions {
readonly tabFocusMode: boolean;
readonly dragAndDrop: boolean;
readonly emptySelectionClipboard: boolean;
readonly copyWithSyntaxHighlighting: boolean;
// ---- grouped options
readonly layoutInfo: EditorLayoutInfo;
@ -1074,6 +1080,7 @@ export class InternalEditorOptions {
tabFocusMode: boolean;
dragAndDrop: boolean;
emptySelectionClipboard: boolean;
copyWithSyntaxHighlighting: boolean;
layoutInfo: EditorLayoutInfo;
fontInfo: FontInfo;
viewInfo: InternalEditorViewOptions;
@ -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;
@ -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)
@ -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)),
@ -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;
@ -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),
@ -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,
@ -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,
@ -2492,6 +2506,7 @@ export const EDITOR_DEFAULTS: IValidatedEditorOptions = {
autoIndent: true,
dragAndDrop: true,
emptySelectionClipboard: true,
copyWithSyntaxHighlighting: true,
useTabStops: true,
multiCursorModifier: 'altKey',
multiCursorMergeOverlapping: true,

View file

@ -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;
@ -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;

View file

@ -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;
@ -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;

6
src/vs/monaco.d.ts vendored
View file

@ -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'
*/
@ -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;
@ -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;