From aed4a386bf57ba7b1b144bacd39f9f9ccabe0dfd Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 10 Feb 2021 22:32:29 -0500 Subject: simplified focus'ing on documents. refactored scrollFocus code. changed focus in 2D to move doc into view but not center. --- .../collectionFreeForm/CollectionFreeFormView.tsx | 44 ++++++---------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index a52522def..68a65dfe7 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -885,7 +885,7 @@ export class CollectionFreeFormView extends CollectionSubView { + focusDocument = (doc: Doc, willZoom?: boolean, scale?: number, afterFocus?: DocAfterFocusFunc) => { const state = HistoryUtil.getState(); // TODO This technically isn't correct if type !== "doc", as @@ -903,31 +903,7 @@ export class CollectionFreeFormView extends CollectionSubView NumCast(doc.y)) { - scrollTo = Math.max(0, NumCast(doc.y) - 50); - } - if (curScroll !== scrollTo || this.props.Document._viewTransition) { - delay = Math.abs(scrollTo - curScroll) > 5 ? 1000 : 0; - !dontCenter && this.props.focus(this.props.Document); - afterFocus && setTimeout(() => afterFocus?.(delay ? true : false), delay); - } else { - !dontCenter && delay && this.props.focus(this.props.Document); - afterFocus?.(!dontCenter && delay ? true : false); - } - } - + this.props.focus(doc, undefined, undefined, afterFocus); } else { const layoutdoc = Doc.Layout(doc); const savedState = { px: NumCast(this.Document._panX), py: NumCast(this.Document._panY), s: this.Document[this.scaleFieldKey], pt: this.Document._viewTransition }; @@ -937,8 +913,14 @@ export class CollectionFreeFormView extends CollectionSubView { afterFocus && setTimeout(() => { // @ts-ignore - if (afterFocus?.(!dontCenter && (didFocus || (newPanX !== savedState.px || newPanY !== savedState.py)))) { + if (afterFocus?.(didFocus || (newPanX !== savedState.px || newPanY !== savedState.py))) { this.Document._panX = savedState.px; this.Document._panY = savedState.py; this.Document[this.scaleFieldKey] = savedState.s; @@ -964,7 +944,7 @@ export class CollectionFreeFormView extends CollectionSubView