Skip to content

Commit

Permalink
Add drop into editor option (#147049)
Browse files Browse the repository at this point in the history
* Add drop into editor option

This change adds a new `enableDropIntoEditor` editor option that enables/disables dropping an extermal resources into an editor

Previously this option was exposed `IEditorConstructionOptions`, however this did not correctly disable drop into editor when dragging and dropping unknown types (such as dragging emoji from the MacOS emoji panel)

With this change, disabling `workbench.editor.dropIntoEditor.enabled` should fully disable the new drop into behavior

* Move drop into editor from workbench to editor

This moves the `dropIntoEditorContribution` from the workbench layer to the platform layer

As part of this change, I also add to move `extractEditorsDropData` up to `platform` so that it could be used from the `editor` layer

This change also enables drop into for the SCM message box

* Fixing monaco errors

* Revert id change
  • Loading branch information
mjbvz authored May 17, 2022
1 parent 06cf633 commit 116c10e
Show file tree
Hide file tree
Showing 31 changed files with 734 additions and 641 deletions.
5 changes: 4 additions & 1 deletion src/tsconfig.monaco.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"types": ["trusted-types"],
"types": [
"trusted-types",
"wicg-file-system-access"
],
"paths": {},
"module": "amd",
"moduleResolution": "classic",
Expand Down
File renamed without changes.
6 changes: 0 additions & 6 deletions src/vs/editor/browser/config/editorConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ export interface IEditorConstructionOptions extends IEditorOptions {
* Defaults to an internal DOM node.
*/
overflowWidgetsDomNode?: HTMLElement;
/**
* Enables dropping into the editor.
*
* This shows a preview of the drop location and triggers an `onDropIntoEditor` event.
*/
enableDropIntoEditor?: boolean;
}

export class EditorConfiguration extends Disposable implements IEditorConfiguration {
Expand Down
61 changes: 34 additions & 27 deletions src/vs/editor/browser/widget/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,35 +368,42 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
this._actions[internalAction.id] = internalAction;
});

if (_options.enableDropIntoEditor) {
this._register(new dom.DragAndDropObserver(this._domElement, {
onDragEnter: () => undefined,
onDragOver: e => {
const target = this.getTargetAtClientPoint(e.clientX, e.clientY);
if (target?.position) {
this.showDropIndicatorAt(target.position);
}
},
onDrop: async e => {
this.removeDropIndicator();
this._register(new dom.DragAndDropObserver(this._domElement, {
onDragEnter: () => undefined,
onDragOver: e => {
if (!this._configuration.options.get(EditorOption.enableDropIntoEditor)) {
return;
}

if (!e.dataTransfer) {
return;
}
const target = this.getTargetAtClientPoint(e.clientX, e.clientY);
if (target?.position) {
this.showDropIndicatorAt(target.position);
}
},
onDrop: async e => {
if (!this._configuration.options.get(EditorOption.enableDropIntoEditor)) {
return;
}

this.removeDropIndicator();

if (!e.dataTransfer) {
return;
}

const target = this.getTargetAtClientPoint(e.clientX, e.clientY);
if (target?.position) {
this._onDropIntoEditor.fire({ position: target.position, event: e });
}
},
onDragLeave: () => {
this.removeDropIndicator();
},
onDragEnd: () => {
this.removeDropIndicator();
},
}));

const target = this.getTargetAtClientPoint(e.clientX, e.clientY);
if (target?.position) {
this._onDropIntoEditor.fire({ position: target.position, event: e });
}
},
onDragLeave: () => {
this.removeDropIndicator();
},
onDragEnd: () => {
this.removeDropIndicator();
},
}));
}

this._codeEditorService.addCodeEditor(this);
}
Expand Down
11 changes: 11 additions & 0 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ export interface IEditorOptions {
* Configures bracket pair colorization (disabled by default).
*/
bracketPairColorization?: IBracketPairColorizationOptions;

/**
* Enables dropping into the editor from an external source.
*
* This shows a preview of the drop location and triggers an `onDropIntoEditor` event.
*/
enableDropIntoEditor?: boolean;
}

/**
Expand Down Expand Up @@ -4431,6 +4438,7 @@ export const enum EditorOption {
disableMonospaceOptimizations,
domReadOnly,
dragAndDrop,
enableDropIntoEditor,
emptySelectionClipboard,
extraEditorClassName,
fastScrollSensitivity,
Expand Down Expand Up @@ -4739,6 +4747,9 @@ export const EditorOptions = {
{ description: nls.localize('dragAndDrop', "Controls whether the editor should allow moving selections via drag and drop.") }
)),
emptySelectionClipboard: register(new EditorEmptySelectionClipboard()),
enableDropIntoEditor: register(new EditorBooleanOption(
EditorOption.enableDropIntoEditor, 'enableDropIntoEditor', true
)),
extraEditorClassName: register(new EditorStringOption(
EditorOption.extraEditorClassName, 'extraEditorClassName', '',
)),
Expand Down
6 changes: 3 additions & 3 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
*--------------------------------------------------------------------------------------------*/

import { CancellationToken } from 'vs/base/common/cancellation';
import { Codicon, CSSIcon } from 'vs/base/common/codicons';
import { Color } from 'vs/base/common/color';
import { IDataTransfer } from 'vs/base/common/dataTransfer';
import { Event } from 'vs/base/common/event';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IDisposable } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
import { ISingleEditOperation } from 'vs/editor/common/core/editOperation';
import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import * as model from 'vs/editor/common/model';
import { TokenizationRegistry as TokenizationRegistryImpl } from 'vs/editor/common/tokenizationRegistry';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IMarkerData } from 'vs/platform/markers/common/markers';
import { Codicon, CSSIcon } from 'vs/base/common/codicons';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { ISingleEditOperation } from 'vs/editor/common/core/editOperation';
import { IDataTransfer } from 'vs/editor/common/dnd';

/**
* Open ended enum at runtime
Expand Down
203 changes: 102 additions & 101 deletions src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,107 +199,108 @@ export enum EditorOption {
disableMonospaceOptimizations = 29,
domReadOnly = 30,
dragAndDrop = 31,
emptySelectionClipboard = 32,
extraEditorClassName = 33,
fastScrollSensitivity = 34,
find = 35,
fixedOverflowWidgets = 36,
folding = 37,
foldingStrategy = 38,
foldingHighlight = 39,
foldingImportsByDefault = 40,
foldingMaximumRegions = 41,
unfoldOnClickAfterEndOfLine = 42,
fontFamily = 43,
fontInfo = 44,
fontLigatures = 45,
fontSize = 46,
fontWeight = 47,
formatOnPaste = 48,
formatOnType = 49,
glyphMargin = 50,
gotoLocation = 51,
hideCursorInOverviewRuler = 52,
hover = 53,
inDiffEditor = 54,
inlineSuggest = 55,
letterSpacing = 56,
lightbulb = 57,
lineDecorationsWidth = 58,
lineHeight = 59,
lineNumbers = 60,
lineNumbersMinChars = 61,
linkedEditing = 62,
links = 63,
matchBrackets = 64,
minimap = 65,
mouseStyle = 66,
mouseWheelScrollSensitivity = 67,
mouseWheelZoom = 68,
multiCursorMergeOverlapping = 69,
multiCursorModifier = 70,
multiCursorPaste = 71,
occurrencesHighlight = 72,
overviewRulerBorder = 73,
overviewRulerLanes = 74,
padding = 75,
parameterHints = 76,
peekWidgetDefaultFocus = 77,
definitionLinkOpensInPeek = 78,
quickSuggestions = 79,
quickSuggestionsDelay = 80,
readOnly = 81,
renameOnType = 82,
renderControlCharacters = 83,
renderFinalNewline = 84,
renderLineHighlight = 85,
renderLineHighlightOnlyWhenFocus = 86,
renderValidationDecorations = 87,
renderWhitespace = 88,
revealHorizontalRightPadding = 89,
roundedSelection = 90,
rulers = 91,
scrollbar = 92,
scrollBeyondLastColumn = 93,
scrollBeyondLastLine = 94,
scrollPredominantAxis = 95,
selectionClipboard = 96,
selectionHighlight = 97,
selectOnLineNumbers = 98,
showFoldingControls = 99,
showUnused = 100,
snippetSuggestions = 101,
smartSelect = 102,
smoothScrolling = 103,
stickyTabStops = 104,
stopRenderingLineAfter = 105,
suggest = 106,
suggestFontSize = 107,
suggestLineHeight = 108,
suggestOnTriggerCharacters = 109,
suggestSelection = 110,
tabCompletion = 111,
tabIndex = 112,
unicodeHighlighting = 113,
unusualLineTerminators = 114,
useShadowDOM = 115,
useTabStops = 116,
wordSeparators = 117,
wordWrap = 118,
wordWrapBreakAfterCharacters = 119,
wordWrapBreakBeforeCharacters = 120,
wordWrapColumn = 121,
wordWrapOverride1 = 122,
wordWrapOverride2 = 123,
wrappingIndent = 124,
wrappingStrategy = 125,
showDeprecated = 126,
inlayHints = 127,
editorClassName = 128,
pixelRatio = 129,
tabFocusMode = 130,
layoutInfo = 131,
wrappingInfo = 132
enableDropIntoEditor = 32,
emptySelectionClipboard = 33,
extraEditorClassName = 34,
fastScrollSensitivity = 35,
find = 36,
fixedOverflowWidgets = 37,
folding = 38,
foldingStrategy = 39,
foldingHighlight = 40,
foldingImportsByDefault = 41,
foldingMaximumRegions = 42,
unfoldOnClickAfterEndOfLine = 43,
fontFamily = 44,
fontInfo = 45,
fontLigatures = 46,
fontSize = 47,
fontWeight = 48,
formatOnPaste = 49,
formatOnType = 50,
glyphMargin = 51,
gotoLocation = 52,
hideCursorInOverviewRuler = 53,
hover = 54,
inDiffEditor = 55,
inlineSuggest = 56,
letterSpacing = 57,
lightbulb = 58,
lineDecorationsWidth = 59,
lineHeight = 60,
lineNumbers = 61,
lineNumbersMinChars = 62,
linkedEditing = 63,
links = 64,
matchBrackets = 65,
minimap = 66,
mouseStyle = 67,
mouseWheelScrollSensitivity = 68,
mouseWheelZoom = 69,
multiCursorMergeOverlapping = 70,
multiCursorModifier = 71,
multiCursorPaste = 72,
occurrencesHighlight = 73,
overviewRulerBorder = 74,
overviewRulerLanes = 75,
padding = 76,
parameterHints = 77,
peekWidgetDefaultFocus = 78,
definitionLinkOpensInPeek = 79,
quickSuggestions = 80,
quickSuggestionsDelay = 81,
readOnly = 82,
renameOnType = 83,
renderControlCharacters = 84,
renderFinalNewline = 85,
renderLineHighlight = 86,
renderLineHighlightOnlyWhenFocus = 87,
renderValidationDecorations = 88,
renderWhitespace = 89,
revealHorizontalRightPadding = 90,
roundedSelection = 91,
rulers = 92,
scrollbar = 93,
scrollBeyondLastColumn = 94,
scrollBeyondLastLine = 95,
scrollPredominantAxis = 96,
selectionClipboard = 97,
selectionHighlight = 98,
selectOnLineNumbers = 99,
showFoldingControls = 100,
showUnused = 101,
snippetSuggestions = 102,
smartSelect = 103,
smoothScrolling = 104,
stickyTabStops = 105,
stopRenderingLineAfter = 106,
suggest = 107,
suggestFontSize = 108,
suggestLineHeight = 109,
suggestOnTriggerCharacters = 110,
suggestSelection = 111,
tabCompletion = 112,
tabIndex = 113,
unicodeHighlighting = 114,
unusualLineTerminators = 115,
useShadowDOM = 116,
useTabStops = 117,
wordSeparators = 118,
wordWrap = 119,
wordWrapBreakAfterCharacters = 120,
wordWrapBreakBeforeCharacters = 121,
wordWrapColumn = 122,
wordWrapOverride1 = 123,
wordWrapOverride2 = 124,
wrappingIndent = 125,
wrappingStrategy = 126,
showDeprecated = 127,
inlayHints = 128,
editorClassName = 129,
pixelRatio = 130,
tabFocusMode = 131,
layoutInfo = 132,
wrappingInfo = 133
}

/**
Expand Down
Loading

0 comments on commit 116c10e

Please sign in to comment.