mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
fix some dnd issues after getting feedback
This commit is contained in:
parent
ecc90f44b4
commit
8ddffb5cd2
|
@ -373,7 +373,10 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
|
|||
}
|
||||
|
||||
// Resource URLs: allows to drop multiple resources to a target in VS Code (not directories)
|
||||
event.dataTransfer.setData(DataTransfers.RESOURCES, JSON.stringify(sources.filter(s => !s.isDirectory).map(s => s.resource.toString())));
|
||||
const files = sources.filter(s => !s.isDirectory);
|
||||
if (files.length) {
|
||||
event.dataTransfer.setData(DataTransfers.RESOURCES, JSON.stringify(files.map(f => f.resource.toString())));
|
||||
}
|
||||
|
||||
// Editors: enables cross window DND of tabs into the editor area
|
||||
const textFileService = accessor.get(ITextFileService);
|
||||
|
@ -381,7 +384,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
|
|||
const editorService = accessor.get(IWorkbenchEditorService);
|
||||
|
||||
const draggedEditors: ISerializedDraggedEditor[] = [];
|
||||
sources.forEach(source => {
|
||||
files.forEach(file => {
|
||||
|
||||
// Try to find editor view state from the visible editors that match given resource
|
||||
let viewState: IEditorViewState;
|
||||
|
@ -391,7 +394,7 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
|
|||
const codeEditor = getCodeEditor(editor);
|
||||
if (codeEditor) {
|
||||
const model = codeEditor.getModel();
|
||||
if (model && model.uri && model.uri.toString() === source.resource.toString()) {
|
||||
if (model && model.uri && model.uri.toString() === file.resource.toString()) {
|
||||
viewState = codeEditor.saveViewState();
|
||||
break;
|
||||
}
|
||||
|
@ -400,13 +403,15 @@ export function fillResourceDataTransfers(accessor: ServicesAccessor, resources:
|
|||
|
||||
// Add as dragged editor
|
||||
draggedEditors.push({
|
||||
resource: source.resource.toString(),
|
||||
backupResource: textFileService.isDirty(source.resource) ? backupFileService.toBackupResource(source.resource).toString() : void 0,
|
||||
resource: file.resource.toString(),
|
||||
backupResource: textFileService.isDirty(file.resource) ? backupFileService.toBackupResource(file.resource).toString() : void 0,
|
||||
viewState
|
||||
});
|
||||
});
|
||||
|
||||
event.dataTransfer.setData(CodeDataTransfers.EDITORS, JSON.stringify(draggedEditors));
|
||||
if (draggedEditors.length) {
|
||||
event.dataTransfer.setData(CodeDataTransfers.EDITORS, JSON.stringify(draggedEditors));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,7 +50,7 @@ import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
|
|||
import { IThemeService } from 'vs/platform/theme/common/themeService';
|
||||
import { IWindowService } from 'vs/platform/windows/common/windows';
|
||||
import { IWorkspaceEditingService } from 'vs/workbench/services/workspace/common/workspaceEditing';
|
||||
import { extractResources, SimpleFileResourceDragAndDrop, CodeDataTransfers } from 'vs/workbench/browser/dnd';
|
||||
import { extractResources, SimpleFileResourceDragAndDrop, CodeDataTransfers, fillResourceDataTransfers } from 'vs/workbench/browser/dnd';
|
||||
import { relative } from 'path';
|
||||
import { distinctParents } from 'vs/base/common/resources';
|
||||
import { WorkbenchTree, WorkbenchTreeController } from 'vs/platform/list/browser/listService';
|
||||
|
@ -729,12 +729,14 @@ export class FileDragAndDrop extends SimpleFileResourceDragAndDrop {
|
|||
});
|
||||
|
||||
// Apply some datatransfer types to allow for dragging the element outside of the application
|
||||
super.onDragStart(tree, data, originalEvent);
|
||||
this.instantiationService.invokeFunction(fillResourceDataTransfers, sources, originalEvent);
|
||||
|
||||
// The only custom data transfer we set from the explorer is a file transfer
|
||||
// to be able to DND between multiple code file explorers across windows
|
||||
const fileResources = sources.filter(s => !s.isDirectory && s.resource.scheme === Schemas.file).map(r => r.resource.fsPath);
|
||||
originalEvent.dataTransfer.setData(CodeDataTransfers.FILES, JSON.stringify(fileResources));
|
||||
if (fileResources.length) {
|
||||
originalEvent.dataTransfer.setData(CodeDataTransfers.FILES, JSON.stringify(fileResources));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -544,16 +544,16 @@ class OpenEditorRenderer implements IRenderer<OpenEditor, IOpenEditorTemplateDat
|
|||
editorTemplate.toDispose = [];
|
||||
|
||||
editorTemplate.toDispose.push(dom.addDisposableListener(container, dom.EventType.DRAG_START, (e: DragEvent) => {
|
||||
const dragged = <OpenEditor[]>this.getSelectedElements().filter(e => e instanceof OpenEditor && !!e.getResource());
|
||||
|
||||
const dragImage = document.createElement('div');
|
||||
e.dataTransfer.effectAllowed = 'copyMove';
|
||||
dragImage.className = 'monaco-tree-drag-image';
|
||||
dragImage.textContent = editorTemplate.openEditor.editor.getName();
|
||||
dragImage.textContent = dragged.length === 1 ? editorTemplate.openEditor.editor.getName() : String(dragged.length);
|
||||
document.body.appendChild(dragImage);
|
||||
e.dataTransfer.setDragImage(dragImage, -10, -10);
|
||||
setTimeout(() => document.body.removeChild(dragImage), 0);
|
||||
|
||||
const dragged = <OpenEditor[]>this.getSelectedElements().filter(e => e instanceof OpenEditor && !!e.getResource());
|
||||
this.transfer.setData(dragged, OpenEditor.prototype);
|
||||
|
||||
if (editorTemplate.openEditor && editorTemplate.openEditor.editor) {
|
||||
|
|
Loading…
Reference in a new issue