mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -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).
|
||||
|
||||
Reference in New Issue
Block a user