From 8068710597c3d6a38211990af63f57e6e784c096 Mon Sep 17 00:00:00 2001 From: Teven Feng Date: Fri, 28 Apr 2023 07:10:51 +0000 Subject: [PATCH] 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 bc63ea5b1..b2f30f8a3 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 d81fe550a..e187f9b80 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 000000000..74aafac2e --- /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 855672e9a..840770444 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 fd66718f8..e3227b3c4 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() {