mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
Use noteContextReorder event instead
This commit is contained in:
parent
2a39906993
commit
735852b3c1
@ -451,16 +451,15 @@ export default class TabManager extends Component {
|
||||
this.tabsUpdate.scheduleUpdate();
|
||||
}
|
||||
|
||||
noteContextReorderEvent({ntxIdsInOrder}) {
|
||||
const order = {};
|
||||
let i = 0;
|
||||
|
||||
for (const ntxId of ntxIdsInOrder) {
|
||||
order[ntxId] = i++;
|
||||
}
|
||||
noteContextReorderEvent({ntxIdsInOrder, mainNtxIdsInOrder}) {
|
||||
const order = Object.fromEntries(ntxIdsInOrder.map((v, i) => [v, i]));
|
||||
|
||||
this.children.sort((a, b) => order[a.ntxId] < order[b.ntxId] ? -1 : 1);
|
||||
|
||||
if (!!mainNtxIdsInOrder && mainNtxIdsInOrder.length === this.children.length) {
|
||||
this.children.forEach((c, i) => c.mainNtxId = mainNtxIdsInOrder[i]);
|
||||
}
|
||||
|
||||
this.tabsUpdate.scheduleUpdate();
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,10 @@ export default class ClosePaneButton extends OnClickButtonWidget {
|
||||
&& this.noteContext && !!this.noteContext.mainNtxId;
|
||||
}
|
||||
|
||||
async noteContextReorderEvent({ntxIdsInOrder}) {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
@ -83,32 +83,36 @@ export default class SplitNoteContainer extends FlexContainer {
|
||||
const contexts = appContext.tabManager.noteContexts;
|
||||
|
||||
const currentIndex = contexts.findIndex(c => c.ntxId === ntxId);
|
||||
const otherIndex = currentIndex + (isMovingLeft ? -1 : 1);
|
||||
const leftIndex = isMovingLeft ? currentIndex - 1 : currentIndex;
|
||||
|
||||
if (currentIndex === -1 || otherIndex < 0 || otherIndex >= contexts.length) {
|
||||
if (currentIndex === -1 || leftIndex < 0 || leftIndex + 1 >= contexts.length) {
|
||||
logError("invalid context!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (contexts[currentIndex].isEmpty() && contexts[otherIndex].isEmpty())
|
||||
if (contexts[leftIndex].isEmpty() && contexts[leftIndex + 1].isEmpty())
|
||||
// no op
|
||||
return;
|
||||
|
||||
const currentId = contexts[currentIndex].ntxId;
|
||||
const currentPath = contexts[currentIndex].notePath;
|
||||
|
||||
const otherId = contexts[otherIndex].ntxId;
|
||||
const otherPath = contexts[otherIndex].notePath;
|
||||
|
||||
if (!!currentPath)
|
||||
await appContext.tabManager.switchToNoteContext(otherId, currentPath);
|
||||
if (!!otherPath)
|
||||
await appContext.tabManager.switchToNoteContext(currentId, otherPath);
|
||||
const ntxIds = contexts.map(c => c.ntxId);
|
||||
const mainNtxIds = contexts.map(c => c.mainNtxId);
|
||||
|
||||
this.triggerCommand("noteContextReorder", {
|
||||
ntxIdsInOrder: [
|
||||
...ntxIds.slice(0, leftIndex),
|
||||
ntxIds[leftIndex + 1],
|
||||
ntxIds[leftIndex],
|
||||
...ntxIds.slice(leftIndex + 2),
|
||||
],
|
||||
oldNtxIdsInOrder: ntxIds,
|
||||
mainNtxIdsInOrder: mainNtxIds.map(id => id === ntxIds[leftIndex] ? ntxIds[leftIndex + 1] : id)
|
||||
});
|
||||
|
||||
this.$widget.find(`[data-ntx-id="${ntxIds[leftIndex]}"]`)
|
||||
.insertAfter(this.$widget.find(`[data-ntx-id="${ntxIds[leftIndex + 1]}"]`));
|
||||
|
||||
// activate context that now contains the original note
|
||||
await appContext.tabManager.activateNoteContext(otherId);
|
||||
|
||||
this.triggerEvent('noteContextSwitch');
|
||||
await appContext.tabManager.activateNoteContext(isMovingLeft ? ntxIds[leftIndex + 1] : ntxIds[leftIndex]);
|
||||
}
|
||||
|
||||
activeContextChangedEvent() {
|
||||
|
@ -609,6 +609,22 @@ export default class TabRowWidget extends BasicWidget {
|
||||
this.updateTabById(noteContext.mainNtxId || noteContext.ntxId);
|
||||
}
|
||||
|
||||
noteContextReorderEvent({ntxIdsInOrder, oldNtxIdsInOrder, mainNtxIdsInOrder}) {
|
||||
if (!oldNtxIdsInOrder || !mainNtxIdsInOrder
|
||||
|| ntxIdsInOrder.length !== oldNtxIdsInOrder.length
|
||||
|| ntxIdsInOrder.length !== mainNtxIdsInOrder.length
|
||||
)
|
||||
return;
|
||||
|
||||
ntxIdsInOrder.forEach((id, i) => {
|
||||
// update main context that is not a tab
|
||||
if (!mainNtxIdsInOrder[i] && this.getTabById(id).length === 0) {
|
||||
this.getTabById(oldNtxIdsInOrder[i]).attr("data-ntx-id", id);
|
||||
this.updateTabById(id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateTabById(ntxId) {
|
||||
const $tab = this.getTabById(ntxId);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user