(core) Fixing anchor link navigation.

Summary: Last document position was overwritting anchor link navigation.

Test Plan: Browser tests

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D2934
This commit is contained in:
Jarosław Sadziński
2021-07-22 11:14:35 +02:00
parent f8e4fe54ba
commit a07395855a
3 changed files with 38 additions and 9 deletions

View File

@@ -1,8 +1,8 @@
import { CursorPos } from "app/client/components/Cursor";
import { getStorage } from "app/client/lib/localStorageObs";
import { IDocPage } from "app/common/gristUrls";
import { Disposable } from "grainjs";
import { GristDoc } from "app/client/components/GristDoc";
import {CursorPos} from 'app/client/components/Cursor';
import {GristDoc} from 'app/client/components/GristDoc';
import {getStorage} from 'app/client/lib/localStorageObs';
import {IDocPage} from 'app/common/gristUrls';
import {Disposable} from 'grainjs';
/**
* Enriched cursor position with a view id
@@ -54,6 +54,12 @@ export class CursorMonitor extends Disposable {
}
private _whenDocumentLoadsRestorePosition(doc: GristDoc) {
// if doc was opened with a hash link, don't restore last position
if (doc.hasCustomNav.get()) {
this._restored = true;
return;
}
// on view shown
this.autoDispose(doc.currentView.addListener(async view => {
// if the position was restored for this document do nothing

View File

@@ -43,7 +43,7 @@ import {isSchemaAction} from 'app/common/DocActions';
import {OpenLocalDocResult} from 'app/common/DocListAPI';
import {HashLink, IDocPage} from 'app/common/gristUrls';
import {RecalcWhen} from 'app/common/gristTypes';
import {encodeQueryParams, waitObs} from 'app/common/gutil';
import {encodeQueryParams, undef, waitObs} from 'app/common/gutil';
import {StringUnion} from 'app/common/StringUnion';
import {TableData} from 'app/common/TableData';
import {DocStateComparison} from 'app/common/UserAPI';
@@ -106,7 +106,8 @@ export class GristDoc extends DisposableWithEvents {
public editorMonitor: EditorMonitor;
// component for keeping track of a cell that is being edited
public draftMonitor: Drafts;
// will document perform its own navigation (from anchor link)
public hasCustomNav: Observable<boolean>;
// Emitter triggered when the main doc area is resized.
public readonly resizeEmitter = this.autoDispose(new Emitter());
@@ -297,6 +298,11 @@ export class GristDoc extends DisposableWithEvents {
return undefined;
});
this.hasCustomNav = Computed.create(this, urlState().state, (_, state) => {
const hash = state.hash;
return !!(hash && (undef(hash.colRef, hash.rowId, hash.sectionId) !== undefined));
});
this.draftMonitor = Drafts.create(this, this);
this.cursorMonitor = CursorMonitor.create(this, this);
this.editorMonitor = EditorMonitor.create(this, this);