diff options
Diffstat (limited to 'src/client/views/DocumentDecorations.tsx')
-rw-r--r-- | src/client/views/DocumentDecorations.tsx | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/client/views/DocumentDecorations.tsx b/src/client/views/DocumentDecorations.tsx index e412d39ac..2914e5ad4 100644 --- a/src/client/views/DocumentDecorations.tsx +++ b/src/client/views/DocumentDecorations.tsx @@ -144,18 +144,28 @@ export class DocumentDecorations extends React.Component<{ PanelWidth: number, P return true; } - _iconifyTimeout: NodeJS.Timeout | undefined; + _iconifyingCount = 0; + _deleteAfterIconify = false; + _iconifyBatch: UndoManager.Batch | undefined; onCloseClick = (force = false) => { if (this.canDelete) { const views = SelectionManager.Views().slice().filter(v => v); - const icons = this._iconifyTimeout || force ? views : views.filter(view => view.rootDoc.layoutKey === "layout_icon"); - const others = this._iconifyTimeout || force ? [] : views.filter(view => view.rootDoc.layoutKey !== "layout_icon"); - icons.forEach(iconView => iconView.props.removeDocument?.(iconView.props.Document)); - others.forEach(dv => dv.iconify()); - others.length && (this._iconifyTimeout = setTimeout(() => { - views.forEach(view => SelectionManager.DeselectView(view)); - this._iconifyTimeout = undefined; - }, 1000)); + if (force) this._deleteAfterIconify = true; + if (!this._iconifyBatch) this._iconifyBatch = UndoManager.StartBatch("iconifying"); + else this._deleteAfterIconify = true; + this._iconifyingCount = views.length; + const finished = () => { + if (this._deleteAfterIconify || --this._iconifyingCount <= 0) { + this._iconifyingCount = 0; + SelectionManager.DeselectAll(); + if (this._deleteAfterIconify) views.forEach(iconView => iconView.props.removeDocument?.(iconView.props.Document)); + this._deleteAfterIconify = false; + this._iconifyBatch?.end(); + this._iconifyBatch = undefined; + } + } + if (!this._deleteAfterIconify) views.forEach(dv => dv.iconify(finished)); + else finished(); } } onMaximizeDown = (e: React.PointerEvent) => { |