Skip to content

Commit

Permalink
Запоминаем позицию скроллинга Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
lintest committed Nov 27, 2021
1 parent 9a9cc7f commit 5bb9bc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/vanessa-tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ class VanessaTabItem {
if (node.nextSibling)
node.parentElement.appendChild(node);
this.editor?.focus();
if (this.editor instanceof VanessaViwer) {
this.editor.restoreScroll();
}
}
setTimeout(() => show(), 100);
this.owner.timer = setTimeout(() => show(), 300);
};

public select = () => {
if (this.owner.current && this.owner.current.editor instanceof VanessaViwer) {
this.owner.current.editor.saveScroll();
}
const className = "vanessa-tab-select";
let tabDomElement = this.domNode.parentElement.firstElementChild;
while (tabDomElement) {
Expand Down
3 changes: 3 additions & 0 deletions src/vanessa-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class VanessaViwer implements IVanessaEditor {

private _domNode: HTMLElement;
private _domInner: HTMLElement;
private _scrollTop: number;

constructor(uri: string, src: string, markdown: boolean = true) {
this.editor = new VanessaViewEditor(uri);
Expand Down Expand Up @@ -122,4 +123,6 @@ export class VanessaViwer implements IVanessaEditor {
}

public get type() { return VAEditorType.MarkdownViwer; }
public saveScroll() { this._scrollTop = this._domInner.scrollTop; }
public restoreScroll() { this._domInner.scrollTop = this._scrollTop; }
}

0 comments on commit 5bb9bc7

Please sign in to comment.