(core) Fixing bug with the import preview being not responsive

Summary: Fixing the bug by setting viewInstance on the temp viewsection record

Test Plan: Added

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: dsagal

Differential Revision: https://phab.getgrist.com/D3848
This commit is contained in:
Jarosław Sadziński
2023-04-04 09:51:34 +02:00
parent 5730262c69
commit 7aa83858bd
2 changed files with 23 additions and 3 deletions

View File

@@ -393,7 +393,16 @@ export class GristDoc extends DisposableWithEvents {
}));
// Importer takes a function for creating previews.
const createPreview = (vs: ViewSectionRec) => GridView.create(this, vs, true);
const createPreview = (vs: ViewSectionRec) => {
const preview = GridView.create(this, vs, true);
// We need to set the instance to the newly created section. This is important, as
// GristDoc is responsible for changing the cursor position not the cursor itself. Final
// cursor position is determined by finding active (or visible) section and passing this
// command (setCursor) to its instance.
vs.viewInstance(preview);
preview.autoDisposeCallback(() => vs.viewInstance(null));
return preview;
};
const importSourceElems = ImportSourceElement.fromArray(this.docPluginManager.pluginsList);
const importMenuItems = [
@@ -593,6 +602,16 @@ export class GristDoc extends DisposableWithEvents {
public async setCursorPos(cursorPos: CursorPos) {
if (cursorPos.sectionId && cursorPos.sectionId !== this.externalSectionId.get()) {
const desiredSection: ViewSectionRec = this.docModel.viewSections.getRowModel(cursorPos.sectionId);
// If this is completely unknown section (without a parent), it is probably an import preview.
if (!desiredSection.parentId.peek() && !desiredSection.isRaw.peek()) {
const view = desiredSection.viewInstance.peek();
// Make sure we have a view instance here - it will prove our assumption that this is
// an import preview. Section might also be disconnected during undo/redo.
if (view && !view.isDisposed()) {
view.setCursorPos(cursorPos);
return;
}
}
if (desiredSection.view.peek().getRowId() !== this.activeViewId.get()) {
// This may be asynchronous. In other cases, the change is synchronous, and some code
// relies on it (doesn't wait for this function to resolve).