mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
better UX when deleting notes - focus in note tree is moved to the next/previous note
This commit is contained in:
parent
30b9ef8604
commit
4f50864ec8
@ -37,6 +37,10 @@ function subscribeToMessages(messageHandler) {
|
|||||||
// used to serialize sync operations
|
// used to serialize sync operations
|
||||||
let consumeQueuePromise = null;
|
let consumeQueuePromise = null;
|
||||||
|
|
||||||
|
// most sync events are sent twice - once immediatelly after finishing the transaction and once during the scheduled ping
|
||||||
|
// but we want to process only once
|
||||||
|
const receivedSyncIds = new Set();
|
||||||
|
|
||||||
async function handleMessage(event) {
|
async function handleMessage(event) {
|
||||||
const message = JSON.parse(event.data);
|
const message = JSON.parse(event.data);
|
||||||
|
|
||||||
@ -52,14 +56,19 @@ async function handleMessage(event) {
|
|||||||
|
|
||||||
if (syncRows.length > 0) {
|
if (syncRows.length > 0) {
|
||||||
const filteredRows = syncRows.filter(row =>
|
const filteredRows = syncRows.filter(row =>
|
||||||
row.entityName !== 'recent_notes'
|
!receivedSyncIds.has(row.id)
|
||||||
|
&& row.entityName !== 'recent_notes'
|
||||||
&& (row.entityName !== 'options' || row.entityId !== 'openTabs'));
|
&& (row.entityName !== 'options' || row.entityId !== 'openTabs'));
|
||||||
|
|
||||||
if (filteredRows.length > 0) {
|
if (filteredRows.length > 0) {
|
||||||
console.debug(utils.now(), "Sync data: ", filteredRows);
|
console.debug(utils.now(), "Sync data: ", filteredRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
syncDataQueue.push(...syncRows);
|
for (const row of filteredRows) {
|
||||||
|
receivedSyncIds.add(row.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
syncDataQueue.push(...filteredRows);
|
||||||
|
|
||||||
// we set lastAcceptedSyncId even before sync processing and send ping so that backend can start sending more updates
|
// we set lastAcceptedSyncId even before sync processing and send ping so that backend can start sending more updates
|
||||||
lastAcceptedSyncId = Math.max(lastAcceptedSyncId, syncRows[syncRows.length - 1].id);
|
lastAcceptedSyncId = Math.max(lastAcceptedSyncId, syncRows[syncRows.length - 1].id);
|
||||||
|
@ -804,7 +804,9 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
|
|
||||||
async entitiesReloadedEvent({loadResults}) {
|
async entitiesReloadedEvent({loadResults}) {
|
||||||
const activeNode = this.getActiveNode();
|
const activeNode = this.getActiveNode();
|
||||||
|
const nextNode = activeNode ? (activeNode.getNextSibling() || activeNode.getPrevSibling() || activeNode.getParent()) : null;
|
||||||
const activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null;
|
const activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null;
|
||||||
|
const nextNotePath = nextNode ? treeService.getNotePath(nextNode) : null;
|
||||||
const activeNoteId = activeNode ? activeNode.data.noteId : null;
|
const activeNoteId = activeNode ? activeNode.data.noteId : null;
|
||||||
|
|
||||||
const noteIdsToUpdate = new Set();
|
const noteIdsToUpdate = new Set();
|
||||||
@ -926,6 +928,17 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
if (node) {
|
if (node) {
|
||||||
node.setActive(true, {noEvents: true});
|
node.setActive(true, {noEvents: true});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// this is used when original note has been deleted and we want to move the focus to the note above/below
|
||||||
|
node = await this.expandToNote(nextNotePath);
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
this.tree.setFocus();
|
||||||
|
node.setFocus(true);
|
||||||
|
|
||||||
|
await appContext.tabManager.getActiveTabContext().setNote(nextNotePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,6 +614,7 @@ export default class TabRowWidget extends BasicWidget {
|
|||||||
|
|
||||||
if (!note) {
|
if (!note) {
|
||||||
this.updateTitle($tab, 'New tab');
|
this.updateTitle($tab, 'New tab');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateTitle($tab, note.title);
|
this.updateTitle($tab, note.title);
|
||||||
|
@ -221,6 +221,7 @@ async function transactional(func) {
|
|||||||
|
|
||||||
await commit();
|
await commit();
|
||||||
|
|
||||||
|
// note that sync rows sent from this action will be sent again by scheduled periodic ping
|
||||||
require('./ws.js').sendPingToAllClients();
|
require('./ws.js').sendPingToAllClients();
|
||||||
|
|
||||||
transactionActive = false;
|
transactionActive = false;
|
||||||
@ -267,4 +268,4 @@ module.exports = {
|
|||||||
executeScript,
|
executeScript,
|
||||||
transactional,
|
transactional,
|
||||||
upsert
|
upsert
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user