Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set the default behavior of openNote #3936

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions src/public/app/components/tab_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 12 additions & 1 deletion src/public/app/widgets/note_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/public/app/widgets/type_widgets/content_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -82,7 +83,8 @@ const CONTENT_WIDGETS = {
TrayOptions,
NoteErasureTimeoutOptions,
NoteRevisionsSnapshotIntervalOptions,
NetworkConnectionsOptions
NetworkConnectionsOptions,
OpenNoteInOptions
],
_optionsAdvanced: [
DatabaseIntegrityCheckOptions,
Expand Down
27 changes: 27 additions & 0 deletions src/public/app/widgets/type_widgets/options/other/open_note_in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import OptionsWidget from "../options_widget.js";

const TPL = `
<div class="options-section">
<h4>Open Note In</h4>
<select class="open-note-in form-control">
<option value="curtab">Current Tab</option>
<option value="newtab">New Tab</option>
</select>
</div>`;

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);
}
}
1 change: 1 addition & 0 deletions src/routes/api/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const ALLOWED_OPTIONS = new Set([
'disableTray',
'customSearchEngineName',
'customSearchEngineUrl',
'openNoteIn',
]);

function getOptions() {
Expand Down
1 change: 1 addition & 0 deletions src/services/options_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down