Skip to content

Build your personal knowledge base with Trilium Notes

client/text editor/drawing canvas: fix an issue

Adorian Doran7d25b006eda1
diff --git a/apps/client/src/widgets/type_widgets/canvas/drawing_history.spec.tsx b/apps/client/src/widgets/type_widgets/canvas/drawing_history.spec.tsx
index cb64bd1e24..c65270464a 100644
--- a/apps/client/src/widgets/type_widgets/canvas/drawing_history.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/drawing_history.spec.tsx
@@ -231,6 +231,7 @@ describe("DrawingHistory", () => {
await vi.waitFor(() => expect(store.write).toHaveBeenCalledOnce());
await vi.waitFor(() => expect(next.api.updateScene).toHaveBeenCalledTimes(2));
expect(next.getElements()).toMatchObject([ { x: 10 } ]);
+ await vi.waitFor(() => expect(document.activeElement).toBe(next.container));
});
it("undoes and redoes the note with the keys and the buttons of Excalidraw", () => {
diff --git a/apps/client/src/widgets/type_widgets/canvas/drawing_history.tsx b/apps/client/src/widgets/type_widgets/canvas/drawing_history.tsx
index e4befb44b2..f570771f02 100644
--- a/apps/client/src/widgets/type_widgets/canvas/drawing_history.tsx
+++ b/apps/client/src/widgets/type_widgets/canvas/drawing_history.tsx
@@ -239,10 +239,6 @@ export default class DrawingHistory {
if (first && !this.pendingStoreUpdates) {
this.applyToDrawings(step, isUndo);
- // Deferred until after the Undo button of the toolbar focuses the text editor.
- queueMicrotask(() => {
- first.root?.querySelector<HTMLElement>(".excalidraw-container")?.focus();
- });
} else {
// Waits for the steps before it, which read the drawing.
const isShown = !!first;
@@ -259,11 +255,20 @@ export default class DrawingHistory {
return true;
}
+ /** Applies `step` to every Excalidraw that shows the drawing, and focuses the first. */
private applyToDrawings(step: DrawingStep, isUndo: boolean) {
for (const drawing of this.drawings) {
applyToDrawing(drawing, step, isUndo);
}
this.revision++;
+
+ const [ first ] = this.drawings;
+ if (first) {
+ // Deferred until after the Undo button of the toolbar focuses the text editor.
+ queueMicrotask(() => {
+ first.root?.querySelector<HTMLElement>(".excalidraw-container")?.focus();
+ });
+ }
}
}