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;
try {
callback();
await callback();
}
finally {
this.changeForbidden = false;

View file

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

View file

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

View file

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