diff --git a/package-lock.json b/package-lock.json index a1737e8ba..7cb9c5a65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "trilium", - "version": "0.40.0-beta", + "version": "0.40.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3987,12 +3987,12 @@ } }, "file-type": { - "version": "13.1.0", - "resolved": "https://registry.npmjs.org/file-type/-/file-type-13.1.0.tgz", - "integrity": "sha512-nr4fSvwYSlQl7YmaWS8rsvDrAm6VgCeb2ysHh18+YBSH4RxewhPKUQrj2XRuEMBNnH6E4xw+yWTL7+jiMrh6GA==", + "version": "13.1.1", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-13.1.1.tgz", + "integrity": "sha512-HEb3tepyq8KzKSFEGMJSIxqn8uC1n3AM8OKME5+BIgq0bErRzcDPOdmnyPKtfjStSpIvuk0Rle8mvuG4824caQ==", "requires": { "readable-web-to-node-stream": "^2.0.0", - "strtok3": "^5.0.1", + "strtok3": "^5.0.2", "token-types": "^2.0.0", "typedarray-to-buffer": "^3.1.5" } @@ -9649,11 +9649,11 @@ } }, "strtok3": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-5.0.1.tgz", - "integrity": "sha512-AWliiIjyb87onqO8pM+1Hozm+PPcR4YYIWbFUT5OKQ+tOMwgdT8HwJd/IS8v3/gKdAtE5aE2p3FhcWqryuZPLQ==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/strtok3/-/strtok3-5.0.2.tgz", + "integrity": "sha512-EFeVpFC5qDsqPEJSrIYyS/ueFBknGhgSK9cW+YAJF/cgJG/KSjoK7X6rK5xnpcLe7y1LVkVFCXWbAb+ClNKzKQ==", "requires": { - "@tokenizer/token": "^0.1.0", + "@tokenizer/token": "^0.1.1", "debug": "^4.1.1", "peek-readable": "^3.1.0" } diff --git a/package.json b/package.json index fece093b4..fa5dbe9f1 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "electron-window-state": "5.0.3", "express": "4.17.1", "express-session": "1.17.0", - "file-type": "13.1.0", + "file-type": "13.1.1", "fs-extra": "8.1.0", "helmet": "3.21.2", "html": "1.0.0", diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js index d982b0d23..b47809e6b 100644 --- a/src/public/javascripts/services/app_context.js +++ b/src/public/javascripts/services/app_context.js @@ -264,11 +264,17 @@ class AppContext { } } - async openEmptyTab() { + async openAndActivateEmptyTab() { + const tabContext = this.openEmptyTab(); + + await this.activateTab(tabContext.tabId); + } + + openEmptyTab() { const tabContext = new TabContext(this, this.tabRow); this.tabContexts.push(tabContext); - await this.activateTab(tabContext.tabId); + return tabContext; } async filterTabs(noteId) { @@ -279,7 +285,7 @@ class AppContext { } if (this.tabContexts.length === 0) { - this.openEmptyTab() + this.openAndActivateEmptyTab() } await this.saveOpenTabs(); @@ -327,7 +333,7 @@ class AppContext { } newTabListener() { - this.openEmptyTab(); + this.openAndActivateEmptyTab(); } async removeTab(tabId) { @@ -339,11 +345,11 @@ class AppContext { } if (this.tabContexts.length === 0) { - this.openEmptyTab(); + this.openAndActivateEmptyTab(); } else { const oldIdx = tabIdsInOrder.findIndex(tid => tid === tabId); - const newActiveTabId = tabIdsInOrder[oldIdx === tabIdsInOrder.length ? oldIdx - 1 : oldIdx + 1]; + const newActiveTabId = tabIdsInOrder[oldIdx === tabIdsInOrder.length - 1 ? oldIdx - 1 : oldIdx + 1]; if (newActiveTabId) { this.activateTab(newActiveTabId); @@ -378,6 +384,30 @@ class AppContext { // run async bundleService.executeRelationBundles(activeTabContext.note, 'runOnNoteChange', activeTabContext); } + + activateNextTabListener() { + const tabIdsInOrder = this.tabRow.getTabIdsInOrder(); + const oldIdx = tabIdsInOrder.findIndex(tid => tid === this.activeTabId); + const newActiveTabId = tabIdsInOrder[oldIdx === tabIdsInOrder.length - 1 ? 0 : oldIdx + 1]; + + this.activateTab(newActiveTabId); + } + + activatePreviousTabListener() { + const tabIdsInOrder = this.tabRow.getTabIdsInOrder(); + const oldIdx = tabIdsInOrder.findIndex(tid => tid === this.activeTabId); + const newActiveTabId = tabIdsInOrder[oldIdx === 0 ? tabIdsInOrder.length - 1 : oldIdx - 1]; + + this.activateTab(newActiveTabId); + } + + closeActiveTabListener() { + this.removeTab(this.activeTabId); + } + + openNewTabListener() { + this.openAndActivateEmptyTab(); + } } const appContext = new AppContext(); diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js index 6efe54746..f641c88ce 100644 --- a/src/public/javascripts/services/keyboard_actions.js +++ b/src/public/javascripts/services/keyboard_actions.js @@ -10,9 +10,9 @@ const keyboardActionsLoaded = server.get('keyboard-actions').then(actions => { for (const shortcut of action.effectiveShortcuts || []) { if (shortcut && !shortcut.startsWith("global:")) { // global shortcuts should be handled in the electron code - const eventName = action.actionName.charAt(0).toUpperCase() + action.actionName.slice(1); + const eventName = action.actionName.charAt(0).toLowerCase() + action.actionName.slice(1); - utils.bindGlobalShortcut(shortcut, appContext.trigger(eventName)); + utils.bindGlobalShortcut(shortcut, () => appContext.trigger(eventName)); } } } @@ -103,34 +103,6 @@ function updateDisplayedShortcuts($container) { $(() => updateDisplayedShortcuts($(document))); -setGlobalActionHandler('OpenNewTab', () => { - appContext.openEmptyTab(); -}); - -setGlobalActionHandler('CloseActiveTab', () => { - if (this.tabRow.activeTabEl) { - this.tabRow.removeTab(this.tabRow.activeTabId); - } -}); - -setGlobalActionHandler('ActivateNextTab', () => { - const nextTab = this.tabRow.nextTabEl; - - if (nextTab) { - // FIXME - this.tabRow.activateTab(nextTab); - } -}); - -setGlobalActionHandler('ActivatePreviousTab', () => { - const prevTab = this.tabRow.previousTabEl; - - if (prevTab) { - // FIXME - this.tabRow.activateTab(prevTab); - } -}); - export default { setGlobalActionHandler, setElementActionHandler, diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index 5199f75fd..a94dabdd5 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -31,6 +31,8 @@ class TabContext extends Component { this.attributes = new Attributes(this.appContext, this); this.children.push(this.attributes); + + this.trigger('tabOpened', {tabId: this.tabId}); } async setNote(notePath) { diff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.js index 9505b9757..4a700b23b 100644 --- a/src/public/javascripts/widgets/attributes.js +++ b/src/public/javascripts/widgets/attributes.js @@ -24,7 +24,7 @@ class AttributesWidget extends StandardWidget { } async refreshWithNote() { - const attributes = await this.tabContext.attributes.getAttributes();console.log("attributes", attributes); + const attributes = await this.tabContext.attributes.getAttributes(); const ownedAttributes = attributes.filter(attr => attr.noteId === this.tabContext.note.noteId); if (attributes.length === 0) { diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js index a8680de17..3f1fc5339 100644 --- a/src/public/javascripts/widgets/note_info.js +++ b/src/public/javascripts/widgets/note_info.js @@ -64,7 +64,7 @@ class NoteInfoWidget extends StandardWidget { } syncDataListener({data}) { - if (data.find(sd => sd.entityName === 'notes' && sd.entityId === this.tabContext.note.noteId)) { + if (data.find(sd => sd.entityName === 'notes' && this.isNote(sd.entityId))) { this.refresh(); } } diff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.js index 757c84034..314f46197 100644 --- a/src/public/javascripts/widgets/tab_row.js +++ b/src/public/javascripts/widgets/tab_row.js @@ -473,6 +473,10 @@ export default class TabRowWidget extends BasicWidget { tabEl.setAttribute('active', ''); } + tabOpenedListener({tabId}) { + this.addTab(tabId); + } + removeTab(tabId) { const tabEl = this.getTabById(tabId)[0]; @@ -595,7 +599,7 @@ export default class TabRowWidget extends BasicWidget { if (destinationIndex < originIndex) { tabEl.parentNode.insertBefore(tabEl, this.tabEls[destinationIndex]); } else { - const beforeEl = this.tabEls[destinationIndex + 1] || this.$newTab; + const beforeEl = this.tabEls[destinationIndex + 1] || this.$newTab[0]; tabEl.parentNode.insertBefore(tabEl, beforeEl); }