From 04ea8dd4b341a209871198b709c4c3afc4764848 Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 13 Oct 2020 22:03:16 +0200 Subject: [PATCH] fix scroll to top for read only / editable text note after switching note --- src/public/app/services/link.js | 12 ++++++++++-- .../app/widgets/type_widgets/read_only_text.js | 4 ---- src/public/app/widgets/type_widgets/type_widget.js | 8 +++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/public/app/services/link.js b/src/public/app/services/link.js index 10136b9b5..20fbd7c46 100644 --- a/src/public/app/services/link.js +++ b/src/public/app/services/link.js @@ -2,6 +2,7 @@ import treeService from './tree.js'; import contextMenu from "./context_menu.js"; import appContext from "./app_context.js"; import treeCache from "./tree_cache.js"; +import utils from "./utils.js"; function getNotePathFromUrl(url) { const notePathMatch = /#(root[A-Za-z0-9/]*)$/.exec(url); @@ -89,9 +90,16 @@ function goToLink(e) { || $link.hasClass("ck-link-actions__preview") // within edit link dialog single click suffices ) { const address = $link.attr('href'); +console.log("address", address); + if (address) { + if (address.toLowerCase().startsWith('http')) { + window.open(address, '_blank'); + } + else if (address.toLowerCase().startsWith('file:') && utils.isElectron()) { + const electron = utils.dynamicRequire('electron'); - if (address && address.startsWith('http')) { - window.open(address, '_blank'); + electron.shell.openPath(address); + } } } } diff --git a/src/public/app/widgets/type_widgets/read_only_text.js b/src/public/app/widgets/type_widgets/read_only_text.js index 9a25f086d..d9f9ffdee 100644 --- a/src/public/app/widgets/type_widgets/read_only_text.js +++ b/src/public/app/widgets/type_widgets/read_only_text.js @@ -65,10 +65,6 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { this.$content.html(''); } - scrollToTop() { - this.$content.scrollTop(0); - } - async doRefresh(note) { const noteComplement = await treeCache.getNoteComplement(note.noteId); diff --git a/src/public/app/widgets/type_widgets/type_widget.js b/src/public/app/widgets/type_widgets/type_widget.js index 4b0cdb9f2..e0b72701d 100644 --- a/src/public/app/widgets/type_widgets/type_widget.js +++ b/src/public/app/widgets/type_widgets/type_widget.js @@ -25,6 +25,12 @@ export default class TypeWidget extends TabAwareWidget { } } + async noteSwitched() { + this.scrollToTop(); + + await super.noteSwitched(); + } + isActive() { return this.$widget.is(":visible"); } @@ -54,4 +60,4 @@ export default class TypeWidget extends TabAwareWidget { this.refresh(); } } -} \ No newline at end of file +}