some refactoring etc.

This commit is contained in:
zadam
2019-05-11 19:27:33 +02:00
parent be68391c37
commit 8a501521e8
5 changed files with 191 additions and 164 deletions

View File

@@ -61,6 +61,8 @@ async function switchToNote(notePath) {
await saveNotesIfChanged();
await loadNoteDetail(notePath);
openTabsChanged();
}
function getActiveNoteContent() {
@@ -178,7 +180,7 @@ async function loadNoteDetailToContext(ctx, note, notePath) {
}
}
async function loadNoteDetail(notePath, options) {
async function loadNoteDetail(notePath, options = {}) {
const newTab = !!options.newTab;
const activate = !!options.activate;
@@ -218,6 +220,19 @@ async function loadNote(noteId) {
return new NoteFull(treeCache, row);
}
async function filterTabs(noteId) {
for (const tc of tabContexts) {
chromeTabs.removeTab(tc.tab);
}
await loadNoteDetail(noteId, {
newTab: true,
activate: true
});
await saveOpenTabs();
}
function focusOnTitle() {
getActiveContext().$noteTitle.focus();
}
@@ -280,9 +295,17 @@ chromeTabsEl.addEventListener('activeTabChange', ({ detail }) => {
console.log(`Activated tab ${tabId}`);
});
chromeTabsEl.addEventListener('tabRemove', ({ detail }) => {
chromeTabsEl.addEventListener('tabRemove', async ({ detail }) => {
const tabId = parseInt(detail.tabEl.getAttribute('data-tab-id'));
await saveNotesIfChanged();
const tabContentToDelete = tabContexts.find(nc => nc.tabId === tabId);
if (tabContentToDelete) {
tabContentToDelete.$tabContent.remove();
}
tabContexts = tabContexts.filter(nc => nc.tabId !== tabId);
console.log(`Removed tab ${tabId}`);
@@ -399,5 +422,6 @@ export default {
addDetailLoadedListener,
getActiveContext,
getActiveComponent,
clearOpenTabsTask
clearOpenTabsTask,
filterTabs
};