diff --git a/src/public/app/components/tab_manager.js b/src/public/app/components/tab_manager.js index 53c3ccbbd2..580651c120 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 a1c2fadb6c..a1e9b75cbd 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -366,7 +366,18 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { this.tree.reactivate(true); } else { - node.setActive(); + const openNoteIn = options.get("openNoteIn") + if (openNoteIn === 'curtab') { + node.setActive(); + } else { + const noteId = node.data.noteId; + const notePath = treeService.getNotePath(node); + if (noteId.startsWith('_')) { + node.setActive(); + } else { + appContext.tabManager.openTabWithNoteWithHoisting(notePath, true); + } + } } return false; diff --git a/src/public/app/widgets/type_widgets/content_widget.js b/src/public/app/widgets/type_widgets/content_widget.js index 477e0571e9..db0a5b340b 100644 --- a/src/public/app/widgets/type_widgets/content_widget.js +++ b/src/public/app/widgets/type_widgets/content_widget.js @@ -21,6 +21,7 @@ import BackupOptions from "./options/backup.js"; import SyncOptions from "./options/sync.js"; import SearchEngineOptions from "./options/other/search_engine.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"; @@ -82,7 +83,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 ba8bc7943e..d5190034b5 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -65,6 +65,7 @@ const ALLOWED_OPTIONS = new Set([ 'disableTray', 'customSearchEngineName', 'customSearchEngineUrl', + 'openNoteIn', ]); function getOptions() { diff --git a/src/services/options_init.js b/src/services/options_init.js index b8026d371e..97ec9c16ea 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -92,6 +92,7 @@ const defaultOptions = [ { name: 'disableTray', value: 'false', isSynced: false }, { name: 'customSearchEngineName', value: 'Duckduckgo', isSynced: false }, { name: 'customSearchEngineUrl', value: 'https://duckduckgo.com/?q={keyword}', isSynced: false }, + { name: 'openNoteIn', value: 'curtab', isSynced: true }, ]; function initStartupOptions() {