From c86cb3966ecb905c2dc6a6236b71d7ce9c8fb80f Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 11 Feb 2021 00:54:52 -0500 Subject: playing with trying to improve chaining of nested focus() method calls. --- src/client/views/collections/TabDocView.tsx | 2 +- .../collectionFreeForm/CollectionFreeFormView.tsx | 56 ++++++++++++---------- 2 files changed, 32 insertions(+), 26 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/TabDocView.tsx b/src/client/views/collections/TabDocView.tsx index 38e1551e6..e1e1c8656 100644 --- a/src/client/views/collections/TabDocView.tsx +++ b/src/client/views/collections/TabDocView.tsx @@ -356,7 +356,7 @@ export class TabDocView extends React.Component { ; } - focusFunc = (doc: Doc, willZoom?: boolean, scale?: number, afterFocus?: DocAfterFocusFunc, dontCenter?: boolean, notFocused?: boolean) => { + focusFunc = (doc: Doc, willZoom?: boolean, scale?: number, afterFocus?: DocAfterFocusFunc) => { if (!this.tab.header.parent._activeContentItem || this.tab.header.parent._activeContentItem !== this.tab.contentItem) { this.tab.header.parent.setActiveContentItem(this.tab.contentItem); // glr: Panning does not work when this is set - (this line is for trying to make a tab that is not topmost become topmost) } diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 68a65dfe7..6fdd569da 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -907,53 +907,59 @@ export class CollectionFreeFormView extends CollectionSubView { - afterFocus && setTimeout(() => { - // @ts-ignore - if (afterFocus?.(didFocus || (newPanX !== savedState.px || newPanY !== savedState.py))) { + !doc.hidden && Doc.linkFollowHighlight(doc); + this.props.focus(this.props.Document, undefined, undefined, (didFocus: boolean) => { + setTimeout(() => { + if (afterFocus?.(didFocus || (px !== savedState.px || py !== savedState.py))) { this.Document._panX = savedState.px; this.Document._panY = savedState.py; this.Document[this.scaleFieldKey] = savedState.s; this.Document._viewTransition = savedState.pt; } doc.hidden && Doc.UnHighlightDoc(doc); - }, newPanX !== savedState.px || newPanY !== savedState.py ? 500 : 0); + }, px !== savedState.px || py !== savedState.py ? 500 : 0); return false; - }; - this.props.focus(this.props.Document, undefined, undefined, newAfterFocus); - !doc.hidden && Doc.linkFollowHighlight(doc); + }); } + } + setPanIntoView = (doc: Doc) => { + const cx = NumCast(this.props.Document._panX); + const cy = NumCast(this.props.Document._panY); + const pwid = this.props.PanelWidth() / NumCast(this.props.Document._viewScale, 1); + const phgt = this.props.PanelHeight() / NumCast(this.props.Document._viewScale, 1); + const screen = { left: cx - pwid / 2, right: cx + pwid / 2, top: cy - phgt / 2, bot: cy + phgt / 2 }; + const bounds = { left: NumCast(doc.x) - pwid / 10, right: NumCast(doc.x) + doc[WidthSym]() + pwid / 10, top: NumCast(doc.y) - phgt / 10, bot: NumCast(doc.y) + doc[HeightSym]() + phgt / 10 }; + return { + px: cx + Math.min(0, bounds.left - screen.left) + Math.max(0, bounds.right - screen.right), + py: cy + Math.min(0, bounds.top - screen.top) + Math.max(0, bounds.bot - screen.bot) + }; } - setScaleToZoom = (doc: Doc, scale: number = 0.75) => { - const pw = this.isAnnotationOverlay ? Doc.NativeWidth(this.props.Document) : this.props.PanelWidth(); - const ph = this.isAnnotationOverlay ? Doc.NativeHeight(this.props.Document) : this.props.PanelHeight(); + setZoomToDoc = (doc: Doc, scale: number = 0.75) => { + const pw = this.props.PanelWidth(); + const ph = this.props.PanelHeight(); pw && ph && (this.Document[this.scaleFieldKey] = scale * Math.min(pw / NumCast(doc._width), ph / NumCast(doc._height))); + const pwid = pw / NumCast(this.props.Document._viewScale, 1); + const phgt = ph / NumCast(this.props.Document._viewScale, 1); + const bounds = { left: NumCast(doc.x) - pwid / 10, right: NumCast(doc.x) + doc[WidthSym]() + pwid / 10, top: NumCast(doc.y) - phgt / 10, bot: NumCast(doc.y) + doc[HeightSym]() + phgt / 10 }; + return { + px: (bounds.left + bounds.right) / 2, + py: (bounds.top + bounds.bot) / 2 + }; } onChildClickHandler = () => this.props.childClickScript || ScriptCast(this.Document.onChildClick); -- cgit v1.2.3-70-g09d2