Skip to content

Commit c9040d0

Browse files
authored
Fix Drag n Drop behavior in Open Editors with multiple groups (microsoft#203330)
fix microsoft#203179
1 parent 5375e37 commit c9040d0

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/vs/base/browser/ui/list/listView.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ export class ListView<T> implements IListView<T> {
12211221
feedback = distinct(feedback).filter(i => i >= -1 && i < this.length).sort((a, b) => a - b);
12221222
feedback = feedback[0] === -1 ? [-1] : feedback;
12231223

1224-
const dragOverEffectPosition = typeof result !== 'boolean' && result.effect && result.effect.position ? result.effect.position : ListDragOverEffectPosition.Over;
1224+
let dragOverEffectPosition = typeof result !== 'boolean' && result.effect && result.effect.position ? result.effect.position : ListDragOverEffectPosition.Over;
12251225

12261226
if (equalsDragFeedback(this.currentDragFeedback, feedback) && this.currentDragFeedbackPosition === dragOverEffectPosition) {
12271227
return true;
@@ -1244,6 +1244,15 @@ export class ListView<T> implements IListView<T> {
12441244
throw new Error('Can\'t use multiple feedbacks with position different than \'over\'');
12451245
}
12461246

1247+
// Make sure there is no flicker when moving between two items
1248+
// Always use the before feedback if possible
1249+
if (dragOverEffectPosition === ListDragOverEffectPosition.After) {
1250+
if (feedback[0] < this.length - 1) {
1251+
feedback[0] += 1;
1252+
dragOverEffectPosition = ListDragOverEffectPosition.Before;
1253+
}
1254+
}
1255+
12471256
for (const index of feedback) {
12481257
const item = this.items[index]!;
12491258
item.dropTarget = true;

src/vs/base/browser/ui/list/listWidget.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,14 +979,13 @@ export class DefaultStyleController implements IStyleController {
979979
if (styles.listDropBetweenBackground) {
980980
content.push(`
981981
.monaco-list${suffix} .monaco-list-rows.drop-target-before .monaco-list-row:first-child::before,
982-
.monaco-list${suffix} .monaco-list-row.drop-target-after + .monaco-list-row::before,
983982
.monaco-list${suffix} .monaco-list-row.drop-target-before::before {
984983
content: ""; position: absolute; top: 0px; left: 0px; width: 100%; height: 1px;
985984
background-color: ${styles.listDropBetweenBackground};
986985
}`);
987986
content.push(`
988987
.monaco-list${suffix} .monaco-list-rows.drop-target-after .monaco-list-row:last-child::after,
989-
.monaco-list${suffix} .monaco-list-row:last-child.drop-target-after::after {
988+
.monaco-list${suffix} .monaco-list-row.drop-target-after::after {
990989
content: ""; position: absolute; bottom: 0px; left: 0px; width: 100%; height: 1px;
991990
background-color: ${styles.listDropBetweenBackground};
992991
}`);

src/vs/workbench/contrib/files/browser/views/openEditorsView.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { Schemas } from 'vs/base/common/network';
5353
import { extUriIgnorePathCase } from 'vs/base/common/resources';
5454
import { ILocalizedString } from 'vs/platform/action/common/action';
5555
import { mainWindow } from 'vs/base/browser/window';
56+
import { EditorGroupView } from 'vs/workbench/browser/parts/editor/editorGroupView';
5657

5758
const $ = dom.$;
5859

@@ -727,7 +728,7 @@ class OpenEditorsDragAndDrop implements IListDragAndDrop<OpenEditor | IEditorGro
727728
switch (targetSector) {
728729
case ListViewTargetSector.TOP:
729730
case ListViewTargetSector.CENTER_TOP:
730-
dropEffectPosition = ListDragOverEffectPosition.Before; break;
731+
dropEffectPosition = (_targetIndex === 0 && _targetElement instanceof EditorGroupView) ? ListDragOverEffectPosition.After : ListDragOverEffectPosition.Before; break;
731732
case ListViewTargetSector.CENTER_BOTTOM:
732733
case ListViewTargetSector.BOTTOM:
733734
dropEffectPosition = ListDragOverEffectPosition.After; break;
@@ -737,19 +738,29 @@ class OpenEditorsDragAndDrop implements IListDragAndDrop<OpenEditor | IEditorGro
737738
}
738739

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

743744
switch (targetSector) {
745+
case ListViewTargetSector.TOP:
746+
case ListViewTargetSector.CENTER_TOP:
747+
if (targetElement instanceof EditorGroupView && group.index !== 0) {
748+
group = this.editorGroupService.groups[group.index - 1];
749+
targetEditorIndex = group.count;
750+
}
751+
break;
744752
case ListViewTargetSector.BOTTOM:
745753
case ListViewTargetSector.CENTER_BOTTOM:
746-
targetEditorIndex++; break;
754+
if (targetElement instanceof OpenEditor) {
755+
targetEditorIndex++;
756+
}
757+
break;
747758
}
748759

749760
if (data instanceof ElementsDragAndDropData) {
750761
for (const oe of data.elements) {
751762
const sourceEditorIndex = oe.group.getIndexOfEditor(oe.editor);
752-
if (sourceEditorIndex < targetEditorIndex) {
763+
if (oe.group === group && sourceEditorIndex < targetEditorIndex) {
753764
targetEditorIndex--;
754765
}
755766
oe.group.moveEditor(oe.editor, group, { index: targetEditorIndex, preserveFocus: true });

0 commit comments

Comments
 (0)