aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/util/DocumentManager.ts13
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx22
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx12
-rw-r--r--src/client/views/pdf/PDFViewer.tsx2
-rw-r--r--src/fields/util.ts4
5 files changed, 36 insertions, 17 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 4becdf4a3..ce4e1e378 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -159,17 +159,24 @@ export class DocumentManager {
}
}
if (docView) { // we have a docView already and aren't forced to create a new one ... just focus on the document. TODO move into view if necessary otherwise just highlight?
+ const sameContext = annotatedDoc && annotatedDoc === originatingDoc?.context;
if (originatingDoc?.isPushpin) {
- docView.props.Document.hidden = !docView.props.Document.hidden;
+ const hide = !docView.props.Document.hidden;
+ (!hide || !sameContext) && (docView.props.Document.hidden = !docView.props.Document.hidden);
+ docView.props.focus(docView.props.Document, willZoom, undefined, (notfocused: boolean) => { // bcz: Argh! TODO: Need to add a notFocused argument to the after finish callback function that indicates whether the window had to scroll to show the target
+ notfocused && hide && (docView.props.Document.hidden = true);
+ return focusAndFinish();
+ // @ts-ignore bcz: Argh TODO: Need to add a parameter to focus() everywhere for whether focus should center the target's container in the view or not. // here we don't want to focus the container if the source and target are in the same container
+ }, sameContext);
finished?.();
}
else {
docView.select(false);
docView.props.Document.hidden && (docView.props.Document.hidden = undefined);
// @ts-ignore
- docView.props.focus(docView.props.Document, willZoom, undefined, focusAndFinish, annotatedDoc && annotatedDoc === originatingDoc?.context);
- highlight();
+ docView.props.focus(docView.props.Document, willZoom, undefined, focusAndFinish, sameContext);
}
+ highlight();
} else {
const contextDocs = docContext ? await DocListCastAsync(docContext.data) : undefined;
const contextDoc = contextDocs?.find(doc => Doc.AreProtosEqual(doc, targetDoc)) ? docContext : undefined;
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 35b4c8e98..382929861 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -888,17 +888,27 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
const annotOn = Cast(doc.annotationOn, Doc) as Doc;
let delay = 1000;
if (!annotOn) {
- this.props.focus(doc);
+ !dontCenter && this.props.focus(doc);
+ afterFocus && setTimeout(afterFocus, delay);
} else {
const contextHgt = Doc.AreProtosEqual(annotOn, this.props.Document) && this.props.VisibleHeight ? this.props.VisibleHeight() : NumCast(annotOn._height);
const offset = annotOn && (contextHgt / 2);
- const scrollTo = NumCast(doc.y) - ((Number.isNaN(offset) ? 150 : offset));
- this.props.Document._scrollY = scrollTo;
- delay = Math.abs(scrollTo - NumCast(this.props.Document._scrollTop)) > 5 ? 1000 : 0;
+ const curScroll = NumCast(this.props.Document._scrollTop);
+ let scrollTo = curScroll;
+ if (curScroll + contextHgt < NumCast(doc.y)) {
+ scrollTo = NumCast(doc.y) + NumCast(doc._height) - contextHgt;
+ } else if (curScroll > NumCast(doc.y)) {
+ scrollTo = NumCast(doc.y);
+ }
+ if (curScroll !== scrollTo) {
+ this.props.Document._scrollY = scrollTo;
+ delay = Math.abs(scrollTo - curScroll) > 5 ? 1000 : 0;
+ !dontCenter && delay && this.props.focus(this.props.Document);
+ afterFocus && setTimeout(afterFocus, delay);
+ // @ts-ignore
+ } else afterFocus(true); // bcz: TODO Aragh -- need to add a parameter to afterFocus() functions to indicate whether the focus function didn't need to scroll
}
- !dontCenter && this.props.focus(this.props.Document);
- afterFocus && setTimeout(afterFocus, delay);
} else {
const layoutdoc = Doc.Layout(doc);
const newPanX = NumCast(doc.x) + NumCast(layoutdoc._width) / 2;
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index ef39e6a90..0fccbd8ef 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -916,11 +916,13 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
async (scrollToLinkID) => {
const findLinkFrag = (frag: Fragment, editor: EditorView) => {
const nodes: Node[] = [];
+ let hadStart = start !== 0;
frag.forEach((node, index) => {
const examinedNode = findLinkNode(node, editor);
- if (examinedNode?.textContent) {
- nodes.push(examinedNode);
- !start && (start = index);
+ if (examinedNode?.node.textContent) {
+ nodes.push(examinedNode.node);
+ !hadStart && (start = index + examinedNode.start);
+ hadStart = true;
}
});
return { frag: Fragment.fromArray(nodes), start };
@@ -928,11 +930,11 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
const findLinkNode = (node: Node, editor: EditorView) => {
if (!node.isText) {
const content = findLinkFrag(node.content, editor);
- return node.copy(content.frag);
+ return { node: node.copy(content.frag), start: content.start };
}
const marks = [...node.marks];
const linkIndex = marks.findIndex(mark => mark.type === editor.state.schema.marks.linkAnchor);
- return linkIndex !== -1 && marks[linkIndex].attrs.allLinks.find((item: { href: string }) => scrollToLinkID === item.href.replace(/.*\/doc\//, "")) ? node : undefined;
+ return linkIndex !== -1 && marks[linkIndex].attrs.allLinks.find((item: { href: string }) => scrollToLinkID === item.href.replace(/.*\/doc\//, "")) ? { node, start: 0 } : undefined;
};
let start = 0;
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 3570c565a..606d3e550 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -184,7 +184,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent<IViewerProps, PdfDocu
} else if (!LinkDocPreview.TargetDoc && !FormattedTextBoxComment.linkDoc) { // wait for mainCont and try again to scroll
setTimeout(() => this._mainCont.current && smoothScroll(1000, this._mainCont.current, scrollY || 0), 250);
}
- setTimeout(() => this.Document._scrollY = undefined, 1000);
+ setTimeout(() => { this.Document._scrollTop = scrollY; this.Document._scrollY = undefined; }, 1000);
}
},
{ fireImmediately: true }
diff --git a/src/fields/util.ts b/src/fields/util.ts
index 8a694de83..7293db0c2 100644
--- a/src/fields/util.ts
+++ b/src/fields/util.ts
@@ -385,7 +385,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
receiver[prop].push(...diff.items);
},
undo: action(() => {
- let curList = receiver[prop];
+ const curList = receiver[prop];
//while (curList[ForwardUpates]) curList = curList[ForwardUpates];
diff.items.forEach((doc: any) => {
const ind = curList.indexOf(doc.value());
@@ -396,7 +396,7 @@ export function updateFunction(target: any, prop: any, value: any, receiver: any
diff?.op === "$remFromSet" ?
{
redo: action(() => {
- let curList = receiver[prop];
+ const curList = receiver[prop];
diff.items.forEach((doc: any) => {
const ind = curList.indexOf(doc.value());
ind !== -1 && curList.splice(ind, 1);