Skip to content

Build your personal knowledge base with Trilium Notes

new tab now has note autocomplete

zadam8b030a23235b
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js
index 3f6cc3a92b..0a7ac4f753 100644
--- a/src/public/javascripts/services/note_detail.js
+++ b/src/public/javascripts/services/note_detail.js
@@ -310,14 +310,16 @@ $tabContentsContainer.on("drop", e => {
});
});
-tabRow.addListener('newTab', async () => {
+async function createEmptyTab() {
const ctx = new TabContext(tabRow);
tabContexts.push(ctx);
- renderComponent(ctx);
+ await renderComponent(ctx);
await tabRow.setCurrentTab(ctx.tab);
-});
+}
+
+tabRow.addListener('newTab', createEmptyTab);
tabRow.addListener('activeTabChange', async ({ detail }) => {
const tabId = detail.tabEl.getAttribute('data-tab-id');
@@ -360,13 +362,14 @@ $(tabRow.el).on('contextmenu', '.note-tab', e => {
});
if (utils.isElectron()) {
+ utils.bindShortcut('ctrl+t', () => {
+ createEmptyTab();
+ });
+
utils.bindShortcut('ctrl+w', () => {
- if (tabContexts.length === 1) {
- // at least one tab must be present
- return;
+ if (tabRow.activeTabEl) {
+ tabRow.removeTab(tabRow.activeTabEl);
}
-
- tabRow.removeTab(tabRow.activeTabEl);
});
utils.bindShortcut('ctrl+tab', () => {
@@ -415,7 +418,7 @@ async function saveOpenTabs() {
const tabId = tabEl.getAttribute('data-tab-id');
const tabContext = tabContexts.find(tc => tc.tabId === tabId);
- if (tabContext) {
+ if (tabContext && tabContext.notePath) {
openTabs.push({
notePath: tabContext.notePath,
active: activeTabEl === tabEl
diff --git a/src/public/javascripts/services/note_detail_empty.js b/src/public/javascripts/services/note_detail_empty.js
new file mode 100644
index 0000000000..bc9e51c091
--- /dev/null
+++ b/src/public/javascripts/services/note_detail_empty.js
@@ -0,0 +1,42 @@
+import noteAutocompleteService from '../services/note_autocomplete.js';
+import treeService from "./tree.js";
+
+class NoteDetailEmpty {
+ /**
+ * @param {TabContext} ctx
+ */
+ constructor(ctx) {
+ this.ctx = ctx;
+ this.$component = ctx.$tabContent.find('.note-detail-empty');
+ this.$autoComplete = ctx.$tabContent.find(".note-autocomplete");
+ }
+
+ render() {
+ this.$component.show();
+ this.ctx.$noteTitleRow.hide();
+
+ noteAutocompleteService.initNoteAutocomplete(this.$autoComplete, { hideGoToSelectedNoteButton: true })
+ .on('autocomplete:selected', function(event, suggestion, dataset) {
+ if (!suggestion.path) {
+ return false;
+ }
+
+ treeService.activateNote(suggestion.path);
+ });
+
+ noteAutocompleteService.showRecentNotes(this.$autoComplete);
+ this.$autoComplete.focus();
+ }
+
+ getContent() {}
+
+ focus() {}
+
+ onNoteChange() {}
+
+ cleanup() {}
+
+ scrollToTop() {}
+}
+
+export default NoteDetailEmpty;
\ No newline at end of file
diff --git a/src/public/javascripts/services/tab_row.js b/src/public/javascripts/services/tab_row.js
index 258f2df68a..647058c7a6 100644
--- a/src/public/javascripts/services/tab_row.js
+++ b/src/public/javascripts/services/tab_row.js
@@ -244,9 +244,9 @@ class TabRow {
async removeTab(tabEl) {
if (tabEl === this.activeTabEl) {
- if (tabEl.nextElementSibling) {
+ if (tabEl.nextElementSibling && tabEl.nextElementSibling.classList.contains("note-tab")) {
await this.setCurrentTab(tabEl.nextElementSibling)
- } else if (tabEl.previousElementSibling) {
+ } else if (tabEl.previousElementSibling && tabEl.previousElementSibling.classList.contains("note-tab")) {
await this.setCurrentTab(tabEl.previousElementSibling)
}
}
diff --git a/src/public/stylesheets/style.css b/src/public/stylesheets/style.css
index 7ba6bc1d4e..024bead6b7 100644
--- a/src/public/stylesheets/style.css
+++ b/src/public/stylesheets/style.css
@@ -835,4 +835,8 @@ a.external:after, a[href^="http://"]:after, a[href^="https://"]:after {
.protected-session-password-component {
width: 300px;
margin: 30px auto auto;
+}
+
+.note-detail-empty {
+ margin: 50px;
}
\ No newline at end of file
diff --git a/src/views/details/empty.ejs b/src/views/details/empty.ejs
new file mode 100644
index 0000000000..a3cea38d09
--- /dev/null
+++ b/src/views/details/empty.ejs
@@ -0,0 +1,8 @@
+<div class="note-detail-empty note-detail-component">
+ <div class="form-group">
+ <label>Open note by typing note's title into input below or choose a note in the tree.</label>
+ <div class="input-group">
+ <input class="form-control note-autocomplete" placeholder="search for note by its name">
+ </div>
+ </div>
+</div>
\ No newline at end of file