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

Fix drag and drop target position calculation #201872

Merged
merged 1 commit into from
Jan 5, 2024
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
22 changes: 14 additions & 8 deletions src/vs/workbench/contrib/debug/browser/watchExpressionsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,22 @@ class WatchExpressionsDragAndDrop implements ITreeDragAndDrop<IExpression> {

const watches = this.debugService.getModel().getWatchExpressions();
const sourcePosition = watches.indexOf(draggedElement);
let targetPosition = targetElement instanceof Expression ? watches.indexOf(targetElement) : watches.length - 1;

switch (targetSector) {
case ListViewTargetSector.TOP:
case ListViewTargetSector.CENTER_TOP:
targetPosition -= 1; break;
}
let targetPosition;
if (targetElement instanceof Expression) {
targetPosition = watches.indexOf(targetElement);

switch (targetSector) {
case ListViewTargetSector.BOTTOM:
case ListViewTargetSector.CENTER_BOTTOM:
targetPosition++; break;
}

if (sourcePosition >= targetPosition) {
targetPosition += 1;
if (sourcePosition < targetPosition) {
targetPosition--;
}
} else {
targetPosition = watches.length - 1;
}

this.debugService.moveWatchExpression(draggedElement.getId(), targetPosition);
Expand Down
25 changes: 12 additions & 13 deletions src/vs/workbench/contrib/files/browser/views/openEditorsView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,27 +738,26 @@ class OpenEditorsDragAndDrop implements IListDragAndDrop<OpenEditor | IEditorGro

drop(data: IDragAndDropData, targetElement: OpenEditor | IEditorGroup | undefined, _targetIndex: number, targetSector: ListViewTargetSector | undefined, originalEvent: DragEvent): void {
const group = targetElement instanceof OpenEditor ? targetElement.group : targetElement || this.editorGroupService.groups[this.editorGroupService.count - 1];
const targetEditorIndex = targetElement instanceof OpenEditor ? targetElement.group.getIndexOfEditor(targetElement.editor) : 0;
let targetEditorIndex = targetElement instanceof OpenEditor ? targetElement.group.getIndexOfEditor(targetElement.editor) : 0;

let targetIndex = targetEditorIndex;
switch (targetSector) {
case ListViewTargetSector.TOP:
case ListViewTargetSector.CENTER_TOP:
targetIndex -= 1; break;
case ListViewTargetSector.BOTTOM:
case ListViewTargetSector.CENTER_BOTTOM:
targetEditorIndex++; break;
}

if (data instanceof ElementsDragAndDropData) {
let offset = 0;
data.elements.forEach((oe: OpenEditor) => {
// Moving an editor which is located before the target location does not change the index of the target
if (oe.group.getIndexOfEditor(oe.editor) >= targetEditorIndex) {
offset += 1;
for (const oe of data.elements) {
const sourceEditorIndex = oe.group.getIndexOfEditor(oe.editor);
if (sourceEditorIndex < targetEditorIndex) {
targetEditorIndex--;
}
oe.group.moveEditor(oe.editor, group, { index: targetIndex + offset, preserveFocus: true });
});
oe.group.moveEditor(oe.editor, group, { index: targetEditorIndex, preserveFocus: true });
targetEditorIndex++;
}
this.editorGroupService.activateGroup(group);
} else {
this.dropHandler.handleDrop(originalEvent, mainWindow, () => group, () => group.focus(), { index: targetIndex + 1 });
this.dropHandler.handleDrop(originalEvent, mainWindow, () => group, () => group.focus(), { index: targetEditorIndex });
}
}

Expand Down