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

Limit highlighting on drag over open editors by checking if dragged item can be dropped #52623

Merged
merged 2 commits into from
Jun 22, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { fillInContextMenuActions } from 'vs/platform/actions/browser/menuItemAc
import { IMenuService, MenuId, IMenu } from 'vs/platform/actions/common/actions';
import { DirtyEditorContext, OpenEditorsGroupContext } from 'vs/workbench/parts/files/electron-browser/fileCommands';
import { ResourceContextKey } from 'vs/workbench/common/resources';
import { fillResourceDataTransfers, ResourcesDropHandler, LocalSelectionTransfer } from 'vs/workbench/browser/dnd';
import { fillResourceDataTransfers, ResourcesDropHandler, LocalSelectionTransfer, CodeDataTransfers } from 'vs/workbench/browser/dnd';
import { ViewletPanel, IViewletPanelOptions } from 'vs/workbench/browser/parts/views/panelViewlet';
import { IViewletViewOptions } from 'vs/workbench/browser/parts/views/viewsViewlet';

Expand Down Expand Up @@ -506,6 +506,32 @@ class OpenEditorsDelegate implements IDelegate<OpenEditor | IEditorGroup> {
}
}

/**
* Check if the item being dragged is one of the supported types that can be dropped on an
* open editor or editor group. Fixes https://github.com/Microsoft/vscode/issues/52344.
* @param e
* @returns true if dropping is supported.
*/
function dropOnEditorSupported(e: DragEvent): boolean {
// DataTransfer types are automatically converted to lower case, except Files.
const supportedTransferTypes = {
openEditor: CodeDataTransfers.EDITORS.toLowerCase(),
externalFile: 'Files',
codeFile: CodeDataTransfers.FILES.toLowerCase()
};

if (
e.dataTransfer.types.indexOf(supportedTransferTypes.openEditor) !== -1 ||
e.dataTransfer.types.indexOf(supportedTransferTypes.externalFile) !== -1 ||
// All Code files should already register as normal files, but just to be safe:
e.dataTransfer.types.indexOf(supportedTransferTypes.codeFile) !== -1
) {
return true;
} else {
return false;
}
}

class EditorGroupRenderer implements IRenderer<IEditorGroup, IEditorGroupTemplateData> {
static readonly ID = 'editorgroup';

Expand Down Expand Up @@ -538,8 +564,10 @@ class EditorGroupRenderer implements IRenderer<IEditorGroup, IEditorGroupTemplat
editorGroupTemplate.actionBar.push(closeGroupAction, { icon: true, label: false, keybinding: closeGroupActionKey ? closeGroupActionKey.getLabel() : void 0 });

editorGroupTemplate.toDispose = [];
editorGroupTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_OVER, () => {
dom.addClass(container, 'focused');
editorGroupTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_OVER, (e: DragEvent) => {
if (dropOnEditorSupported(e)) {
dom.addClass(container, 'focused');
}
}));
editorGroupTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_LEAVE, () => {
dom.removeClass(container, 'focused');
Expand Down Expand Up @@ -624,8 +652,10 @@ class OpenEditorRenderer implements IRenderer<OpenEditor, IOpenEditorTemplateDat
this.instantiationService.invokeFunction(fillResourceDataTransfers, dragged.map(d => d.getResource()), e);
}
}));
editorTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_OVER, () => {
dom.addClass(container, 'focused');
editorTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_OVER, (e: DragEvent) => {
if (dropOnEditorSupported(e)) {
dom.addClass(container, 'focused');
}
}));
editorTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_LEAVE, () => {
dom.removeClass(container, 'focused');
Expand Down