Skip to content

Build your personal knowledge base with Trilium Notes

fixes

zadam18ee2393620f
diff --git a/src/public/javascripts/services/app_context.js b/src/public/javascripts/services/app_context.js
index 3565ecbb8e..ef13166755 100644
--- a/src/public/javascripts/services/app_context.js
+++ b/src/public/javascripts/services/app_context.js
@@ -13,7 +13,7 @@ class AppContext {
constructor(layout) {
this.layout = layout;
this.tabManager = new TabManager(this);
- this.components = [this.tabManager];
+ this.components = [];
}
async start() {
@@ -32,6 +32,7 @@ class AppContext {
$("body").append(rootContainer.render());
this.components = [
+ this.tabManager,
rootContainer,
new Entrypoints(this),
new DialogEventComponent(this)
@@ -112,7 +113,7 @@ $(window).on('hashchange', function() {
if (isNotePathInAddress()) {
const [notePath, tabId] = getHashValueFromAddress();
- appContext.switchToTab(tabId, notePath);
+ appContext.tabManager.switchToTab(tabId, notePath);
}
});
diff --git a/src/public/javascripts/services/link_map.js b/src/public/javascripts/services/link_map.js
index c7c1299bf5..7adf1a66e2 100644
--- a/src/public/javascripts/services/link_map.js
+++ b/src/public/javascripts/services/link_map.js
@@ -176,7 +176,7 @@ export default class LinkMap {
.addClass('link-' + edge.target.id);
}
else {
- console.debug(`connection not created for`, edge);
+ //console.debug(`connection not created for`, edge);
}
});
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index 3eced57d20..5a8ef60b5f 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -20,7 +20,7 @@ class TabContext extends Component {
this.tabId = state.tabId || utils.randomString(4);
this.state = state;
- this.trigger('tabOpened', {tabId: this.tabId});
+ this.trigger('newTabOpened', {tabId: this.tabId});
}
async setNote(inputNotePath) {
diff --git a/src/public/javascripts/services/tab_manager.js b/src/public/javascripts/services/tab_manager.js
index 05819f8c2e..2f38e07a89 100644
--- a/src/public/javascripts/services/tab_manager.js
+++ b/src/public/javascripts/services/tab_manager.js
@@ -201,10 +201,6 @@ export default class TabManager extends Component {
this.trigger('activeTabChanged', { oldActiveTabId, newActiveTabId: tabId });
}
- newTabListener() {
- this.openAndActivateEmptyTab();
- }
-
async removeTab(tabId) {
const tabContextToRemove = this.tabContexts.find(tc => tc.tabId === tabId);
@@ -258,6 +254,10 @@ export default class TabManager extends Component {
this.removeTab(this.activeTabId);
}
+ beforeUnloadListener() {
+ this.tabsUpdate.updateNowIfNecessary();
+ }
+
openNewTabListener() {
this.openAndActivateEmptyTab();
}
diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js
index ea796842e3..798e62fd1c 100644
--- a/src/public/javascripts/widgets/note_title.js
+++ b/src/public/javascripts/widgets/note_title.js
@@ -1,7 +1,6 @@
import TabAwareWidget from "./tab_aware_widget.js";
import utils from "../services/utils.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
-import treeCache from "../services/tree_cache.js";
import server from "../services/server.js";
import SpacedUpdate from "../services/spaced_update.js";
@@ -40,7 +39,7 @@ export default class NoteTitleWidget extends TabAwareWidget {
this.$widget = $(TPL);
this.$noteTitle = this.$widget.find(".note-title");
- this.$noteTitle.on('input', () => this.titleChanged());
+ this.$noteTitle.on('input', () => this.spacedUpdate.scheduleUpdate());
utils.bindElShortcut(this.$noteTitle, 'return', () => {
this.trigger('focusOnDetail', {tabId: this.tabContext.tabId});
@@ -49,27 +48,6 @@ export default class NoteTitleWidget extends TabAwareWidget {
return this.$widget;
}
- async titleChanged() {
- const {note} = this.tabContext;
-
- if (!note) {
- return;
- }
-
- note.title = this.$noteTitle.val();
-
- this.spacedUpdate.scheduleUpdate();
-
- const noteFromCache = await treeCache.getNote(note.noteId);
- noteFromCache.title = note.title;
-
- this.trigger(`noteTitleChanged`, {
- tabId: this.tabContext.tabId, // used to identify that the event comes from this tab so we should not update this tab's input
- title: note.title,
- noteId: note.noteId
- });
- }
-
async refreshWithNote(note) {
this.$noteTitle.val(note.title);
diff --git a/src/public/javascripts/widgets/protected_note_switch.js b/src/public/javascripts/widgets/protected_note_switch.js
index 72e724b626..8fd7d7d6fd 100644
--- a/src/public/javascripts/widgets/protected_note_switch.js
+++ b/src/public/javascripts/widgets/protected_note_switch.js
@@ -1,6 +1,7 @@
import BasicWidget from "./basic_widget.js";
import protectedSessionService from "../services/protected_session.js";
import protectedSessionHolder from "../services/protected_session_holder.js";
+import TabAwareWidget from "./tab_aware_widget.js";
const TPL = `
<div class="btn-group btn-group-xs" style="margin-left: 10px; margin-right: 10px;">
@@ -15,7 +16,7 @@ const TPL = `
</button>
</div>`;
-export default class ProtectedNoteSwitchWidget extends BasicWidget {
+export default class ProtectedNoteSwitchWidget extends TabAwareWidget {
doRender() {
this.$widget = $(TPL);
diff --git a/src/public/javascripts/widgets/tab_caching_widget.js b/src/public/javascripts/widgets/tab_caching_widget.js
index 62c14fac91..a8f6c98379 100644
--- a/src/public/javascripts/widgets/tab_caching_widget.js
+++ b/src/public/javascripts/widgets/tab_caching_widget.js
@@ -8,6 +8,10 @@ export default class TabCachingWidget extends TabAwareWidget {
this.widgets = {};
}
+ async isEnabled() {
+ return this.tabContext.isActive();
+ }
+
doRender() {
this.$widget = $(`<div class="marker" style="display: none;">`);
return this.$widget;
@@ -53,9 +57,12 @@ export default class TabCachingWidget extends TabAwareWidget {
}
}
- toggle(show) {
+ async toggle(show) {
for (const tabId in this.widgets) {
- this.widgets[tabId].toggle(show && this.tabContext && tabId === this.tabContext.tabId);
+ this.widgets[tabId].toggle(
+ show
+ && this.tabContext && tabId === this.tabContext.tabId
+ && await this.widgets[tabId].isEnabled());
}
}
}
\ No newline at end of file
diff --git a/src/public/javascripts/widgets/tab_row.js b/src/public/javascripts/widgets/tab_row.js
index dce17a458f..9c3c24e2cc 100644
--- a/src/public/javascripts/widgets/tab_row.js
+++ b/src/public/javascripts/widgets/tab_row.js
@@ -421,7 +421,7 @@ export default class TabRowWidget extends BasicWidget {
tabEl.setAttribute('active', '');
}
- tabOpenedListener({tabId}) {
+ newTabOpenedListener({tabId}) {
this.addTab(tabId);
}
@@ -553,7 +553,7 @@ export default class TabRowWidget extends BasicWidget {
this.$tabContainer.append(this.$newTab);
- this.$newTab.on('click', _ => this.trigger('newTab'));
+ this.$newTab.on('click', _ => this.trigger('openNewTab'));
}
setupFiller() {