提交 c9a0382f 编写于 作者: J Joao Moreno

fixes #55313

上级 941c0e56
......@@ -8,7 +8,7 @@
import 'vs/css!./gridview';
import { Orientation } from 'vs/base/browser/ui/sash/sash';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { tail2 as tail } from 'vs/base/common/arrays';
import { tail2 as tail, equals } from 'vs/base/common/arrays';
import { orthogonal, IView, GridView, Sizing as GridViewSizing, Box, IGridViewStyles } from './gridview';
import { Event } from 'vs/base/common/event';
......@@ -256,15 +256,27 @@ export class Grid<T extends IView> implements IDisposable {
throw new Error('Can\'t remove last view');
}
if (!this.views.has(view)) {
throw new Error('View not found');
}
const location = this.getViewLocation(view);
this.gridview.removeView(location, sizing === Sizing.Distribute ? GridViewSizing.Distribute : undefined);
this.views.delete(view);
}
moveView(view: T, sizing: number | Sizing, referenceView: T, direction: Direction): void {
const sourceLocation = this.getViewLocation(view);
const [sourceParentLocation, from] = tail(sourceLocation);
const referenceLocation = this.getViewLocation(referenceView);
const targetLocation = getRelativeLocation(this.gridview.orientation, referenceLocation, direction);
const [targetParentLocation, to] = tail(targetLocation);
if (equals(sourceParentLocation, targetParentLocation)) {
this.gridview.moveView(sourceParentLocation, from, to);
} else {
this.removeView(view, typeof sizing === 'number' ? undefined : sizing);
this.addView(view, sizing, referenceView, direction);
}
}
swapViews(from: T, to: T): void {
const fromLocation = this.getViewLocation(from);
const toLocation = this.getViewLocation(to);
......
......@@ -181,9 +181,14 @@ class BranchNode implements ISplitView, IDisposable {
throw new Error('Invalid index');
}
const first = index === 0;
const last = index === this.splitview.length;
this.splitview.addView(node, size, index);
this._addChild(node, index);
this.onDidChildrenChange();
}
private _addChild(node: Node, index: number): void {
const first = index === 0;
const last = index === this.children.length;
this.children.splice(index, 0, node);
node.orthogonalStartSash = this.splitview.sashes[index - 1];
node.orthogonalEndSash = this.splitview.sashes[index];
......@@ -195,8 +200,6 @@ class BranchNode implements ISplitView, IDisposable {
if (!last) {
this.children[index + 1].orthogonalStartSash = this.splitview.sashes[index];
}
this.onDidChildrenChange();
}
removeChild(index: number, sizing?: Sizing): void {
......@@ -204,10 +207,15 @@ class BranchNode implements ISplitView, IDisposable {
throw new Error('Invalid index');
}
const first = index === 0;
const last = index === this.splitview.length - 1;
this.splitview.removeView(index, sizing);
this.children.splice(index, 1);
this._removeChild(index);
this.onDidChildrenChange();
}
private _removeChild(index: number): Node {
const first = index === 0;
const last = index === this.children.length - 1;
const [child] = this.children.splice(index, 1);
if (!first) {
this.children[index - 1].orthogonalEndSash = this.splitview.sashes[index - 1];
......@@ -217,7 +225,30 @@ class BranchNode implements ISplitView, IDisposable {
this.children[index].orthogonalStartSash = this.splitview.sashes[Math.max(index - 1, 0)];
}
this.onDidChildrenChange();
return child;
}
moveChild(from: number, to: number): void {
if (from === to) {
return;
}
if (from < 0 || from >= this.children.length) {
throw new Error('Invalid from index');
}
if (to < 0 || to > this.children.length) {
throw new Error('Invalid to index');
}
if (from < to) {
to--;
}
this.splitview.moveView(from, to);
const child = this._removeChild(from);
this._addChild(child, to);
}
swapChildren(from: number, to: number): void {
......@@ -651,6 +682,16 @@ export class GridView implements IDisposable {
return node.view;
}
moveView(parentLocation: number[], from: number, to: number): void {
const [, parent] = this.getNode(parentLocation);
if (!(parent instanceof BranchNode)) {
throw new Error('Invalid location');
}
parent.moveChild(from, to);
}
swapViews(from: number[], to: number[]): void {
const [fromRest, fromIndex] = tail(from);
const [, fromParent] = this.getNode(fromRest);
......
......@@ -661,8 +661,7 @@ export class EditorPart extends Part implements EditorGroupsServiceImpl, IEditor
const groupHasFocus = isAncestor(document.activeElement, sourceView.element);
// Move is a simple remove and add of the same view
this.gridWidget.removeView(sourceView, Sizing.Distribute);
this.gridWidget.addView(sourceView, Sizing.Distribute, targetView, this.toGridViewDirection(direction));
this.gridWidget.moveView(sourceView, Sizing.Distribute, targetView, this.toGridViewDirection(direction));
// Restore focus if we had it previously (we run this after gridWidget.removeView() is called
// because removing a view can mean to reparent it and thus focus would be removed otherwise)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册