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

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,7 @@
import optionsInit from './options_init.js';
import server from "./server.js";
import tree from "./tree.js";
import noteDetailService from "./note_detail.js";
let hoistedNoteId;
@ -17,6 +18,10 @@ async function getHoistedNoteId() {
async function setHoistedNoteId(noteId) {
hoistedNoteId = noteId;
if (noteId !== 'root') {
await noteDetailService.filterTabs(noteId);
}
await server.put('options/hoistedNoteId/' + noteId);
await tree.reload();

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
};

View file

@ -531,7 +531,9 @@ async function reload() {
// make sure the reload won't trigger reactivation. This is important especially in cases where we wait for the reload
// to finish to then activate some other note. But since the activate() event is called asynchronously, it may be called
// (or finished calling) after we switched to a different note.
ignoreNextActivationNoteId = getActiveNode().data.noteId;
if (getActiveNode()) {
ignoreNextActivationNoteId = getActiveNode().data.noteId;
}
await getTree().reload(notes);
}

View file

@ -743,7 +743,7 @@ div[data-notify="container"] {
.unhoist-button {
text-decoration: underline !important;
color: blue !important;
color: var(--link-color) !important;
cursor: pointer !important;
}