fix setting path

This commit is contained in:
zadam 2020-02-08 21:23:42 +01:00
parent 18ee239362
commit 9f4a514562
4 changed files with 27 additions and 30 deletions

View File

@ -36,11 +36,11 @@ export default class SpacedUpdate {
} }
} }
allowUpdateWithoutChange(callback) { async allowUpdateWithoutChange(callback) {
this.changeForbidden = true; this.changeForbidden = true;
try { try {
callback(); await callback();
} }
finally { finally {
this.changeForbidden = false; this.changeForbidden = false;

View File

@ -69,8 +69,6 @@ class TabContext extends Component {
tabId: this.tabId, tabId: this.tabId,
notePath: this.notePath notePath: this.notePath
}); });
this.trigger('openTabsChanged');
} }
/** @property {NoteShort} */ /** @property {NoteShort} */
@ -99,14 +97,10 @@ class TabContext extends Component {
return { return {
tabId: this.tabId, tabId: this.tabId,
notePath: this.notePath, notePath: this.notePath,
active: this.tabManager.activeTabId === this.tabId active: this.isActive()
} }
} }
stateChanged() {
appContext.openTabsChangedListener();
}
noteDeletedListener({noteId}) { noteDeletedListener({noteId}) {
if (this.noteId === noteId) { if (this.noteId === noteId) {
this.noteId = null; this.noteId = null;

View File

@ -83,10 +83,10 @@ export default class TabManager extends Component {
filteredTabs[0].active = true; filteredTabs[0].active = true;
} }
this.tabsUpdate.allowUpdateWithoutChange(() => { await this.tabsUpdate.allowUpdateWithoutChange(async () => {
for (const tab of filteredTabs) { for (const tab of filteredTabs) {
const tabContext = this.openEmptyTab(); const tabContext = this.openEmptyTab();
tabContext.setNote(tab.notePath); await tabContext.setNote(tab.notePath);
if (tab.active) { if (tab.active) {
this.activateTab(tabContext.tabId); this.activateTab(tabContext.tabId);
@ -97,11 +97,13 @@ export default class TabManager extends Component {
tabNoteSwitchedListener({tabId}) { tabNoteSwitchedListener({tabId}) {
if (tabId === this.activeTabId) { if (tabId === this.activeTabId) {
this._setCurrentNotePathToHash(); this.setCurrentNotePathToHash();
} }
this.tabsUpdate.scheduleUpdate();
} }
_setCurrentNotePathToHash() { setCurrentNotePathToHash() {
const activeTabContext = this.getActiveTabContext(); const activeTabContext = this.getActiveTabContext();
if (activeTabContext && activeTabContext.notePath) { if (activeTabContext && activeTabContext.notePath) {
@ -185,10 +187,6 @@ export default class TabManager extends Component {
await tabContext.setNote(noteId); await tabContext.setNote(noteId);
} }
openTabsChangedListener() {
this.tabsUpdate.scheduleUpdate();
}
activateTab(tabId) { activateTab(tabId) {
if (tabId === this.activeTabId) { if (tabId === this.activeTabId) {
return; return;
@ -199,6 +197,10 @@ export default class TabManager extends Component {
this.activeTabId = tabId; this.activeTabId = tabId;
this.trigger('activeTabChanged', { oldActiveTabId, newActiveTabId: tabId }); this.trigger('activeTabChanged', { oldActiveTabId, newActiveTabId: tabId });
this.tabsUpdate.scheduleUpdate();
this.setCurrentNotePathToHash();
} }
async removeTab(tabId) { async removeTab(tabId) {
@ -221,7 +223,7 @@ export default class TabManager extends Component {
this.trigger('tabRemoved', {tabId}); this.trigger('tabRemoved', {tabId});
this.openTabsChangedListener(); this.tabsUpdate.scheduleUpdate();
} }
tabReorderListener({tabIdsInOrder}) { tabReorderListener({tabIdsInOrder}) {
@ -233,7 +235,7 @@ export default class TabManager extends Component {
this.tabContexts.sort((a, b) => order[a.tabId] < order[b.tabId] ? -1 : 1); this.tabContexts.sort((a, b) => order[a.tabId] < order[b.tabId] ? -1 : 1);
this.openTabsChangedListener(); this.tabsUpdate.scheduleUpdate();
} }
activateNextTabListener() { activateNextTabListener() {

View File

@ -5,6 +5,7 @@ import LoadResults from "./load_results.js";
import Branch from "../entities/branch.js"; import Branch from "../entities/branch.js";
import Attribute from "../entities/attribute.js"; import Attribute from "../entities/attribute.js";
import options from "./options.js"; import options from "./options.js";
import treeCache from "./tree_cache.js";
const $outstandingSyncsCount = $("#outstanding-syncs-count"); const $outstandingSyncsCount = $("#outstanding-syncs-count");
@ -203,7 +204,7 @@ async function processSyncRows(syncRows) {
const loadResults = new LoadResults(this); const loadResults = new LoadResults(this);
syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => { syncRows.filter(sync => sync.entityName === 'notes').forEach(sync => {
const note = this.notes[sync.entityId]; const note = treeCache.notes[sync.entityId];
if (note) { if (note) {
note.update(sync.entity); note.update(sync.entity);
@ -212,9 +213,9 @@ async function processSyncRows(syncRows) {
}); });
syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => { syncRows.filter(sync => sync.entityName === 'branches').forEach(sync => {
let branch = this.branches[sync.entityId]; let branch = treeCache.branches[sync.entityId];
const childNote = this.notes[sync.entity.noteId]; const childNote = treeCache.notes[sync.entity.noteId];
const parentNote = this.notes[sync.entity.parentNoteId]; const parentNote = treeCache.notes[sync.entity.parentNoteId];
if (branch) { if (branch) {
if (sync.entity.isDeleted) { if (sync.entity.isDeleted) {
@ -244,7 +245,7 @@ async function processSyncRows(syncRows) {
else if (!sync.entity.isDeleted) { else if (!sync.entity.isDeleted) {
if (childNote || parentNote) { if (childNote || parentNote) {
branch = new Branch(this, sync.entity); branch = new Branch(this, sync.entity);
this.branches[branch.branchId] = branch; treeCache.branches[branch.branchId] = branch;
loadResults.addBranch(sync.entityId, sync.sourceId); loadResults.addBranch(sync.entityId, sync.sourceId);
@ -261,7 +262,7 @@ async function processSyncRows(syncRows) {
syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => { syncRows.filter(sync => sync.entityName === 'note_reordering').forEach(sync => {
for (const branchId in sync.positions) { for (const branchId in sync.positions) {
const branch = this.branches[branchId]; const branch = treeCache.branches[branchId];
if (branch) { if (branch) {
branch.notePosition = sync.positions[branchId]; branch.notePosition = sync.positions[branchId];
@ -273,9 +274,9 @@ async function processSyncRows(syncRows) {
// missing reloading the relation target note // missing reloading the relation target note
syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => { syncRows.filter(sync => sync.entityName === 'attributes').forEach(sync => {
let attribute = this.attributes[sync.entityId]; let attribute = treeCache.attributes[sync.entityId];
const sourceNote = this.notes[sync.entity.noteId]; const sourceNote = treeCache.notes[sync.entity.noteId];
const targetNote = sync.entity.type === 'relation' && this.notes[sync.entity.value]; const targetNote = sync.entity.type === 'relation' && treeCache.notes[sync.entity.value];
if (attribute) { if (attribute) {
attribute.update(sync.entity); attribute.update(sync.entity);
@ -295,7 +296,7 @@ async function processSyncRows(syncRows) {
if (sourceNote || targetNote) { if (sourceNote || targetNote) {
attribute = new Attribute(this, sync.entity); attribute = new Attribute(this, sync.entity);
this.attributes[attribute.attributeId] = attribute; treeCache.attributes[attribute.attributeId] = attribute;
loadResults.addAttribute(sync.entityId, sync.sourceId); loadResults.addAttribute(sync.entityId, sync.sourceId);
@ -311,7 +312,7 @@ async function processSyncRows(syncRows) {
}); });
syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => { syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => {
delete this.noteComplementPromises[sync.entityId]; delete treeCache.noteComplementPromises[sync.entityId];
loadResults.addNoteContent(sync.entityId, sync.sourceId); loadResults.addNoteContent(sync.entityId, sync.sourceId);
}); });