diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 3f6cc3a92..0a7ac4f75 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+w', () => { - if (tabContexts.length === 1) { - // at least one tab must be present - return; - } + utils.bindShortcut('ctrl+t', () => { + createEmptyTab(); + }); - tabRow.removeTab(tabRow.activeTabEl); + utils.bindShortcut('ctrl+w', () => { + if (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 000000000..bc9e51c09 --- /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 258f2df68..647058c7a 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 7ba6bc1d4..024bead6b 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 000000000..a3cea38d0 --- /dev/null +++ b/src/views/details/empty.ejs @@ -0,0 +1,8 @@ +
+
+ +
+ +
+
+
\ No newline at end of file