fix: selected line position after workspace resizing

fix: #929
This commit is contained in:
windingwind 2024-04-09 22:33:25 +08:00
parent 87ae3b022b
commit ee510f0689

View File

@ -5,12 +5,15 @@ import { ContextPane } from "./context";
import { OutlinePane } from "./outlinePane";
export class Workspace extends PluginCEBase {
uid: string = Zotero.Utilities.randomString(8);
_item?: Zotero.Item;
_editorElement!: EditorElement;
_outline!: OutlinePane;
_context!: ContextPane;
resizeOb!: ResizeObserver;
get content() {
return this._parseContentID(
MozXULElement.parseXULToFragment(`
@ -68,9 +71,8 @@ export class Workspace extends PluginCEBase {
// MozXULElement.insertFTLIfNeeded(`${config.addonRef}-workspace.ftl`);
// For note preview section enabled decision
this.dataset.uid = Zotero.Utilities.randomString(8);
this._addon.data.workspace.instances[this.dataset.uid] = new WeakRef(this);
this.dataset.uid = this.uid;
this._addon.data.workspace.instances[this.uid] = new WeakRef(this);
this._outline = this._queryID("left-container") as unknown as OutlinePane;
this._editorElement = this._queryID("editor-main") as EditorElement;
@ -79,9 +81,20 @@ export class Workspace extends PluginCEBase {
this._context = this._queryID("right-container") as unknown as ContextPane;
this._loadPersist();
this.resizeOb = new ResizeObserver(() => {
this._addon.api.editor.scroll(
this.editor,
this._addon.api.editor.getLineAtCursor(this.editor),
);
});
this.resizeOb.observe(this._editorElement);
}
destroy(): void {}
destroy(): void {
this.resizeOb.disconnect();
delete this._addon.data.workspace.instances[this.uid];
}
async render() {
await this._outline.render();