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();
|
this.tabsUpdate.scheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
noteContextReorderEvent({ntxIdsInOrder}) {
|
noteContextReorderEvent({ntxIdsInOrder, mainNtxIdsInOrder}) {
|
||||||
const order = {};
|
const order = Object.fromEntries(ntxIdsInOrder.map((v, i) => [v, i]));
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
for (const ntxId of ntxIdsInOrder) {
|
|
||||||
order[ntxId] = i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.children.sort((a, b) => order[a.ntxId] < order[b.ntxId] ? -1 : 1);
|
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();
|
this.tabsUpdate.scheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@ export default class ClosePaneButton extends OnClickButtonWidget {
|
|||||||
&& this.noteContext && !!this.noteContext.mainNtxId;
|
&& this.noteContext && !!this.noteContext.mainNtxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async noteContextReorderEvent({ntxIdsInOrder}) {
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
@ -83,32 +83,36 @@ export default class SplitNoteContainer extends FlexContainer {
|
|||||||
const contexts = appContext.tabManager.noteContexts;
|
const contexts = appContext.tabManager.noteContexts;
|
||||||
|
|
||||||
const currentIndex = contexts.findIndex(c => c.ntxId === ntxId);
|
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!");
|
logError("invalid context!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contexts[currentIndex].isEmpty() && contexts[otherIndex].isEmpty())
|
if (contexts[leftIndex].isEmpty() && contexts[leftIndex + 1].isEmpty())
|
||||||
// no op
|
// no op
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const currentId = contexts[currentIndex].ntxId;
|
const ntxIds = contexts.map(c => c.ntxId);
|
||||||
const currentPath = contexts[currentIndex].notePath;
|
const mainNtxIds = contexts.map(c => c.mainNtxId);
|
||||||
|
|
||||||
const otherId = contexts[otherIndex].ntxId;
|
this.triggerCommand("noteContextReorder", {
|
||||||
const otherPath = contexts[otherIndex].notePath;
|
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)
|
||||||
|
});
|
||||||
|
|
||||||
if (!!currentPath)
|
this.$widget.find(`[data-ntx-id="${ntxIds[leftIndex]}"]`)
|
||||||
await appContext.tabManager.switchToNoteContext(otherId, currentPath);
|
.insertAfter(this.$widget.find(`[data-ntx-id="${ntxIds[leftIndex + 1]}"]`));
|
||||||
if (!!otherPath)
|
|
||||||
await appContext.tabManager.switchToNoteContext(currentId, otherPath);
|
|
||||||
|
|
||||||
// activate context that now contains the original note
|
// activate context that now contains the original note
|
||||||
await appContext.tabManager.activateNoteContext(otherId);
|
await appContext.tabManager.activateNoteContext(isMovingLeft ? ntxIds[leftIndex + 1] : ntxIds[leftIndex]);
|
||||||
|
|
||||||
this.triggerEvent('noteContextSwitch');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
activeContextChangedEvent() {
|
activeContextChangedEvent() {
|
||||||
|
@ -609,6 +609,22 @@ export default class TabRowWidget extends BasicWidget {
|
|||||||
this.updateTabById(noteContext.mainNtxId || noteContext.ntxId);
|
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) {
|
updateTabById(ntxId) {
|
||||||
const $tab = this.getTabById(ntxId);
|
const $tab = this.getTabById(ntxId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user