From 81ca4f3309fc2f6845ca6cd8227705d26c68c0bf Mon Sep 17 00:00:00 2001 From: Teven Feng Date: Fri, 28 Apr 2023 03:51:54 +0000 Subject: [PATCH 1/3] change default action of clicking note to open in new tab --- src/public/app/components/tab_manager.js | 9 +++++++++ src/public/app/widgets/note_tree.js | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js index e5ca32c452..b8296e7ef9 100644 --- a/src/public/app/components/tab_manager.js +++ b/src/public/app/components/tab_manager.js @@ -293,6 +293,15 @@ export default class TabManager extends Component { const hoistedNoteId = opts.hoistedNoteId || 'root'; const viewMode = opts.viewMode || "default"; + const targetNoteId = await treeService.getNoteIdFromNotePath(notePath); + for (const openedNoteContext of this.getNoteContexts()) { + if (openedNoteContext.note && openedNoteContext.note.noteId === targetNoteId) { + this.activateNoteContext(openedNoteContext.ntxId, true); + + return; + } + } + const noteContext = await this.openEmptyTab(ntxId, hoistedNoteId, mainNtxId); if (notePath) { diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index 60f7b34a3b..bc63ea5b1d 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -363,7 +363,13 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { this.tree.reactivate(true); } else { - node.setActive(); + const noteId = node.data.noteId; + const notePath = treeService.getNotePath(node); + if (noteId.startsWith('_')) { + node.setActive(); + } else { + appContext.tabManager.openTabWithNoteWithHoisting(notePath, true); + } } return false; From 8068710597c3d6a38211990af63f57e6e784c096 Mon Sep 17 00:00:00 2001 From: Teven Feng Date: Fri, 28 Apr 2023 07:10:51 +0000 Subject: [PATCH 2/3] add open note in option --- src/public/app/widgets/note_tree.js | 13 ++++++--- .../widgets/type_widgets/content_widget.js | 4 ++- .../options/other/open_note_in.js | 27 +++++++++++++++++++ src/routes/api/options.js | 3 ++- src/services/options_init.js | 1 + 5 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/public/app/widgets/type_widgets/options/other/open_note_in.js diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index bc63ea5b1d..b2f30f8a35 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -363,12 +363,17 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { this.tree.reactivate(true); } else { - const noteId = node.data.noteId; - const notePath = treeService.getNotePath(node); - if (noteId.startsWith('_')) { + const openNoteIn = options.get("openNoteIn") + if (openNoteIn === 'curtab') { node.setActive(); } else { - appContext.tabManager.openTabWithNoteWithHoisting(notePath, true); + const noteId = node.data.noteId; + const notePath = treeService.getNotePath(node); + if (noteId.startsWith('_')) { + node.setActive(); + } else { + appContext.tabManager.openTabWithNoteWithHoisting(notePath, true); + } } } diff --git a/src/public/app/widgets/type_widgets/content_widget.js b/src/public/app/widgets/type_widgets/content_widget.js index d81fe550a4..e187f9b807 100644 --- a/src/public/app/widgets/type_widgets/content_widget.js +++ b/src/public/app/widgets/type_widgets/content_widget.js @@ -19,6 +19,7 @@ import EtapiOptions from "./options/etapi.js"; import BackupOptions from "./options/backup.js"; import SyncOptions from "./options/sync.js"; import TrayOptions from "./options/other/tray.js"; +import OpenNoteInOptions from "./options/other/open_note_in.js" import NoteErasureTimeoutOptions from "./options/other/note_erasure_timeout.js"; import NoteRevisionsSnapshotIntervalOptions from "./options/other/note_revisions_snapshot_interval.js"; import NetworkConnectionsOptions from "./options/other/network_connections.js"; @@ -78,7 +79,8 @@ const CONTENT_WIDGETS = { TrayOptions, NoteErasureTimeoutOptions, NoteRevisionsSnapshotIntervalOptions, - NetworkConnectionsOptions + NetworkConnectionsOptions, + OpenNoteInOptions ], _optionsAdvanced: [ DatabaseIntegrityCheckOptions, diff --git a/src/public/app/widgets/type_widgets/options/other/open_note_in.js b/src/public/app/widgets/type_widgets/options/other/open_note_in.js new file mode 100644 index 0000000000..74aafac2e8 --- /dev/null +++ b/src/public/app/widgets/type_widgets/options/other/open_note_in.js @@ -0,0 +1,27 @@ +import OptionsWidget from "../options_widget.js"; + +const TPL = ` +
+

Open Note In

+ +
`; + +export default class OpenNoteInOptions extends OptionsWidget { + doRender() { + this.$widget = $(TPL); + this.$body = $("body"); + this.$openNoteIn = this.$widget.find(".open-note-in"); + this.$openNoteIn.on('change', () => { + const newopenNoteIn = this.$openNoteIn.val(); + + this.updateOption('openNoteIn', newopenNoteIn); + }); + } + + async optionsLoaded(options) { + this.$openNoteIn.val(options.openNoteIn); + } +} diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 855672e9ab..8407704448 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -61,7 +61,8 @@ const ALLOWED_OPTIONS = new Set([ 'downloadImagesAutomatically', 'minTocHeadings', 'checkForUpdates', - 'disableTray' + 'disableTray', + 'openNoteIn' ]); function getOptions() { diff --git a/src/services/options_init.js b/src/services/options_init.js index fd66718f8c..e3227b3c46 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -89,6 +89,7 @@ const defaultOptions = [ { name: 'minTocHeadings', value: '5', isSynced: true }, { name: 'checkForUpdates', value: 'true', isSynced: true }, { name: 'disableTray', value: 'false', isSynced: false }, + { name: 'openNoteIn', value: 'curtab', isSynced: true }, ]; function initStartupOptions() { From 45c4470f7342ac7ac9524ef88456da00867f1382 Mon Sep 17 00:00:00 2001 From: tevenfeng Date: Sat, 13 May 2023 14:06:14 +0000 Subject: [PATCH 3/3] fix --- src/routes/api/options.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 21ccd70c31..dcb89c63e5 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -63,8 +63,8 @@ const ALLOWED_OPTIONS = new Set([ 'checkForUpdates', 'disableTray', 'customSearchEngineName', - 'customSearchEngineUrl',, - 'openNoteIn' + 'customSearchEngineUrl', + 'openNoteIn', ]); function getOptions() {