Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix some issues
Adorian Doranade91bf3df5d
diff --git a/apps/client/src/widgets/find_in_code.ts b/apps/client/src/widgets/find_in_code.tsindex c53566fb8f..cac9bd53b2 100644--- a/apps/client/src/widgets/find_in_code.ts+++ b/apps/client/src/widgets/find_in_code.ts@@ -165,6 +165,14 @@ export class CodeMirrorFindTarget implements FindTarget {return true;}+ watchContent(callback: () => void) {+ return this.view.addUpdateListener((update) => {+ if (update.docChanged) {+ callback();+ }+ });+ }+/** Searches again after a replace, whose matches the editor does not follow. */private async searchAgain() {return this.search ? this.find(this.search.term, this.search.options) : 0;diff --git a/apps/client/src/widgets/find_in_text.spec.ts b/apps/client/src/widgets/find_in_text.spec.tsindex 4814d39390..372d60b792 100644--- a/apps/client/src/widgets/find_in_text.spec.ts+++ b/apps/client/src/widgets/find_in_text.spec.ts@@ -105,13 +105,16 @@ describe("TextEditorFindTarget", () => {});describe("FindInText", () => {- it("drives the find bar, and marks it stale as embeds change", async () => {+ it("drives the find bar, and marks it stale as embeds or the content change", async () => {const parent = {noteContext: { getTextEditor: async () => editor },invalidateResults: vi.fn()};const handler = new FindInText(parent as unknown as FindWidget);- registerEmbedTarget(1, false);+ const embedTarget = registerEmbedTarget(1, false);+ const changeEmbed = () => {+ for (const watcher of embedTarget.watchers) watcher();+ };expect(await handler.performFind("needle", false, false)).toEqual({ totalFound: 4, currentFound: 1 });@@ -119,15 +122,24 @@ describe("FindInText", () => {expect(handler.canReplace()).toBe(false);await handler.findNext(1, 1, 3);expect(handler.canReplace()).toBe(true);+ expect(parent.invalidateResults).not.toHaveBeenCalled();expect(await handler.replace("pin")).toEqual({ totalFound: 3, currentFound: 1 });expect(editor.getData()).toContain("<p>pin two</p>");expect(await handler.replaceAll("pin")).toEqual({ totalFound: 1, currentFound: 1 });+ parent.invalidateResults.mockClear();registerEmbedTarget(0);- expect(parent.invalidateResults).toHaveBeenCalledOnce();+ changeEmbed();+ typeText("needle");+ expect(parent.invalidateResults).toHaveBeenCalledTimes(3);await handler.findBoxClosed(1, 1);registerEmbedTarget(0);- expect(parent.invalidateResults).toHaveBeenCalledOnce();+ changeEmbed();+ typeText("needle");+ expect(parent.invalidateResults).toHaveBeenCalledTimes(3);++ embedTarget.unregister();+ expect(embedTarget.watchers.size).toBe(0);});});@@ -147,6 +159,7 @@ function EmbedSchema(target: Editor) {function registerEmbedTarget(count: number, isEditable = true) {const embed = editor.editing.view.getDomRoot()?.querySelector<HTMLElement>(".include-note");if (!embed) throw new Error("The editor shows no embed.");+ const watchers = new Set<() => void>();const target = {find: vi.fn(async () => count),highlight: vi.fn((_index: number | null) => {}),@@ -154,10 +167,24 @@ function registerEmbedTarget(count: number, isEditable = true) {canReplace: () => isEditable,replace: async () => count,replaceAll: async () => count,- close: () => false+ close: () => false,+ watchContent: (callback: () => void) => {+ watchers.add(callback);+ return () => watchers.delete(callback);+ }} satisfies FindTarget;- cleanups.push(registerEmbedFindTarget(embed, target));- return target;+ const unregister = registerEmbedFindTarget(embed, target);+ cleanups.push(unregister);+ return Object.assign(target, { watchers, unregister });+}++/** Types `text` at the start of the first paragraph. */+function typeText(text: string) {+ editor.model.change((writer) => {+ const paragraph = editor.model.document.getRoot()?.getChild(0);+ if (!paragraph?.is("element")) throw new Error("Expected a first paragraph.");+ writer.insertText(text, paragraph, 0);+ });}/** The text of the block that holds the highlighted match, or `null` without one. */diff --git a/apps/client/src/widgets/find_in_text.ts b/apps/client/src/widgets/find_in_text.tsindex 560d3c5508..ac1fdcc584 100644--- a/apps/client/src/widgets/find_in_text.ts+++ b/apps/client/src/widgets/find_in_text.ts@@ -95,7 +95,13 @@ export default class FindInText {const root = textEditor.editing.view.getDomRoot();if (!this.stopWatching && root) {- this.stopWatching = watchEmbedFindTargets(root, () => this.parent.invalidateResults());+ const invalidate = () => this.parent.invalidateResults();+ const stopWatchingEmbeds = watchEmbedFindTargets(root, invalidate);+ const stopWatchingText = this.find.watchContent(invalidate);+ this.stopWatching = () => {+ stopWatchingEmbeds();+ stopWatchingText();+ };}return this.find;}@@ -238,6 +244,12 @@ export class TextEditorFindTarget implements HostFindTarget {}}+ watchContent(callback: () => void) {+ const modelDocument = this.editor.model.document;+ modelDocument.on("change:data", callback);+ return () => modelDocument.off("change:data", callback);+ }+/** Takes the matches that the find commands left, as a replace removes the ones it replaced. */private readResults() {const state = this.getFinder()?.state;diff --git a/apps/client/src/widgets/merged_find.spec.ts b/apps/client/src/widgets/merged_find.spec.tsindex d943c87c91..ab5139c824 100644--- a/apps/client/src/widgets/merged_find.spec.ts+++ b/apps/client/src/widgets/merged_find.spec.ts@@ -50,7 +50,7 @@ describe("MergedFind", () => {]);});- it("reveals the embed of a match before highlighting it, and hides it once left", async () => {+ it("clears the match it leaves before revealing and highlighting the next", async () => {const { find } = setUp();await find.find("needle", OPTIONS);@@ -58,20 +58,20 @@ describe("MergedFind", () => {log = [];find.highlight(2);expect(log).toEqual([- "host.revealEmbed(a)", "a.box(true)", "a.highlight(0)", "host.highlight(null)"+ "host.highlight(null)", "host.revealEmbed(a)", "a.box(true)", "a.highlight(0)"]);log = [];find.highlight(4);expect(log).toEqual([- "host.revealEmbed(c)", "c.box(true)", "c.highlight(0)",- "a.highlight(null)", "a.box(false)"+ "a.highlight(null)", "host.revealEmbed(c)", "c.box(true)", "c.highlight(0)",+ "a.box(false)"]);log = [];find.highlight(5);expect(log).toEqual([- "host.highlight(2)", "c.highlight(null)", "c.box(false)", "host.revealEmbed(null)"+ "c.highlight(null)", "host.highlight(2)", "c.box(false)", "host.revealEmbed(null)"]);log = [];@@ -130,6 +130,18 @@ describe("MergedFind", () => {expect(find.canReplace(0)).toBe(false);});+ it("watches the content of its host, where the host can change", () => {+ const { find, host } = setUp();+ expect(() => find.watchContent(vi.fn())()).not.toThrow();++ const stop = vi.fn();+ const watchContent = vi.fn((_callback: () => void) => stop);+ Object.assign(host, { watchContent });+ const callback = vi.fn();+ expect(find.watchContent(callback)).toBe(stop);+ expect(watchContent).toHaveBeenCalledWith(callback);+ });+it("closes the targets of embeds that left, and ignores an overtaken search", async () => {const { find, host, targets, unregisterA } = setUp();await find.find("needle", OPTIONS);diff --git a/apps/client/src/widgets/merged_find.ts b/apps/client/src/widgets/merged_find.tsindex f8df4548fa..21ac7c0609 100644--- a/apps/client/src/widgets/merged_find.ts+++ b/apps/client/src/widgets/merged_find.ts@@ -32,6 +32,11 @@ export interface FindTarget {* and returns whether it did.*/close(index: number | null): boolean;+ /**+ * Calls `callback` when the content changes, as typing in it does, until the returned function+ * is called. A target over content that cannot change leaves it out.+ */+ watchContent?(callback: () => void): () => void;}/** Content with embeds, whose matches `MergedFind` places among the matches of the content. */@@ -97,6 +102,10 @@ export default class MergedFind implements FindTarget {const next = match?.run ?? null;const previous = this.current;+ // `FindReveal` shows a highlighted match of the host over `revealEmbed()`.+ if (previous && previous.target !== next?.target) {+ previous.target.highlight(null);+ }// The content of an embed shows before its target scrolls to the match.if (next?.embed && next.embed !== previous?.embed) {this.host.revealEmbed(next.embed);@@ -105,9 +114,6 @@ export default class MergedFind implements FindTarget {if (match) {match.run.target.highlight(match.local);}- if (previous && previous.target !== next?.target) {- previous.target.highlight(null);- }if (previous?.embed && previous.embed !== next?.embed) {revealContentEmbed(previous.embed, false);if (!next?.embed) {@@ -183,6 +189,11 @@ export default class MergedFind implements FindTarget {return isFocused;}+ /** Watches the content of the host. The embeds are targets of their own. */+ watchContent(callback: () => void) {+ return this.host.watchContent?.(callback) ?? (() => {});+ }+/** Splits the matches of the host around each embed with matches. */private layOut() {const runs: Run[] = [];diff --git a/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsx b/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsxindex f0342b3f11..aabed616e9 100644--- a/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsx+++ b/apps/client/src/widgets/type_widgets/code/CodeEmbed.spec.tsx@@ -79,6 +79,8 @@ describe("CodeEmbed", () => {const view = await findView(figure);const target = getEmbedFindTarget(figure);if (!(target instanceof CodeMirrorFindTarget)) throw new Error("Expected a code target.");+ const onContentChange = vi.fn();+ const stopWatching = target.watchContent(onContentChange);expect(await target.find("print", { matchCase: false, wholeWord: false })).toBe(2);expect(figure.querySelectorAll(".cm-activeMatch")).toHaveLength(0);@@ -88,11 +90,16 @@ describe("CodeEmbed", () => {expect(figure.querySelectorAll(".cm-activeMatch")).toHaveLength(0);expect(target.getFirstMatchBelow(-Infinity)).toBe(0);expect(target.getFirstMatchBelow(Infinity)).toBeNull();+ expect(onContentChange).not.toHaveBeenCalled();expect(await target.replace(1, "log")).toBe(1);expect(view.state.doc.toString()).toBe("print(1)\nlog(2)");+ expect(onContentChange).toHaveBeenCalledOnce();expect(target.close(0)).toBe(true);expect([ view.state.selection.main.from, view.state.selection.main.to ]).toEqual([ 0, 5 ]);+ stopWatching();+ act(() => view.dispatch({ changes: { from: 0, insert: "#" } }));+ expect(onContentChange).toHaveBeenCalledOnce();await act(async () => {delete figure.dataset.editable;diff --git a/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsx b/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsxindex 15be00e85e..cbd4a3c86a 100644--- a/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsx+++ b/apps/client/src/widgets/type_widgets/text/TextEmbed.spec.tsx@@ -80,7 +80,11 @@ describe("TextEmbed", () => {await vi.waitFor(() => expect(editorProps).toHaveBeenCalled(), { timeout: 5000 });const { parentComponent, ntxId } = editorProps.mock.calls[0][0] as TypeWidgetProps;const root = figure.querySelector<HTMLElement>(".ck-editor__editable");- const editor = { editing: { view: { getDomRoot: () => root } } } as unknown as CKTextEditor;+ const modelDocument = { on: vi.fn(), off: vi.fn() };+ const editor = {+ editing: { view: { getDomRoot: () => root } },+ model: { document: modelDocument }+ } as unknown as CKTextEditor;act(() => {parentComponent?.handleEvent("textEditorRefreshed", { ntxId: "_other", editor });@@ -92,6 +96,7 @@ describe("TextEmbed", () => {const target = getEmbedFindTarget(figure);expect(target instanceof MergedFind && target.host instanceof TextEditorFindTarget&& target.host.editor).toBe(editor);+ expect(modelDocument.on).toHaveBeenCalledWith("change:data", expect.any(Function));});it("uses the floating toolbar inside an editor that has one", async () => {diff --git a/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts b/apps/client/src/widgets/type_widgets/text/content_embed_tools.tsindex b8af5e4ead..0d152749b6 100644--- a/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts+++ b/apps/client/src/widgets/type_widgets/text/content_embed_tools.ts@@ -143,7 +143,9 @@ export function enterContentEmbed(embed: HTMLElement, edge: EmbedEdge) {export function registerEmbedFindTarget(element: HTMLElement, target: FindTarget) {findTargets.set(element, target);notifyFindWatchers(element);+ const stopWatching = target.watchContent?.(() => notifyFindWatchers(element));return () => {+ stopWatching?.();findTargets.delete(element);notifyFindWatchers(element);};@@ -163,7 +165,8 @@ export function getEmbedFindTarget(embed: HTMLElement) {/*** Calls `callback` when the targets that search the embeds inside `container` change, as when the- * editor of an included note replaces its preview. Stops when the returned function is called.+ * editor of an included note replaces its preview, or when the content they search changes.+ * Stops when the returned function is called.*/export function watchEmbedFindTargets(container: HTMLElement, callback: () => void) {const watcher = { container, callback };diff --git a/apps/client/src/widgets/type_widgets/text/editable_embed.tsx b/apps/client/src/widgets/type_widgets/text/editable_embed.tsxindex d2243b6c55..a93fd6702e 100644--- a/apps/client/src/widgets/type_widgets/text/editable_embed.tsx+++ b/apps/client/src/widgets/type_widgets/text/editable_embed.tsx@@ -106,7 +106,8 @@ export interface EmbeddedCaretEditor {focusAt(edge: EmbedEdge): void;/*** The edge of the content that the arrow key of `event` moves the caret past, or `null` for- * any other key and while the caret stays in the content.+ * any other key, while the caret stays in the content and while a list of the editor, such as+ * its completions, takes the key.*/getEdgeLeftBy(event: KeyboardEvent): EmbedEdge | null;}diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.tsindex d14b434996..a8936871dd 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.spec.ts@@ -5,6 +5,7 @@ import {type ClassicEditor,Essentials,HorizontalLine,+ MentionEditing,Paragraph,Table,Widget@@ -13,6 +14,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { createTestEditor, destroyTrackedEditors, pressKey } from "../../../test/editor-kit.js";import { installGlobMock } from "../../../test/globals-test-kit.js";+import TriliumMentionUI from "../mention/trilium_mention_ui.js";+import type { MentionHostedList } from "../mention/types.js";import ContentEmbed from "./content_embed.js";import ContentEmbedCaret from "./content_embed_caret.js";@@ -270,12 +273,12 @@ describe("ContentEmbedCaret as the editor of an embed", () => {plugin = editor.plugins.get(ContentEmbedCaret);});- /** The edge that `plugin` reports for `key` pressed in the editing root. */- function getEdge(key: string, init: KeyboardEventInit = {}) {- const root = getDomRoot(editor);+ /** The edge that the plugin of `target` reports for `key` pressed in its editing root. */+ function getEdge(key: string, init: KeyboardEventInit = {}, target = editor) {+ const root = getDomRoot(target);let edge: string | null | undefined;root.addEventListener("keydown", (event) => {- edge = plugin.getEdgeLeftBy(event);+ edge = target.plugins.get(ContentEmbedCaret).getEdgeLeftBy(event);}, { once: true });root.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, ...init }));return edge;@@ -380,6 +383,29 @@ describe("ContentEmbedCaret as the editor of an embed", () => {expect(getEdge("ArrowLeft")).toBe("start");});+ it("leaves the arrow keys to an open mention list", async () => {+ const list = {+ element: null as HTMLElement | null,+ show: () => { list.element = document.body; },+ hide: () => { list.element = null; },+ handleKeyDown: () => true+ } satisfies MentionHostedList;+ const mentionEditor = await createTestEditor(+ [ ...TEXT_PLUGINS, MentionEditing, TriliumMentionUI ],+ { mention: { feeds: [], hostedFeeds: [ { marker: "/", list: () => list } ] } }+ );+ setModelData(mentionEditor.model, "<paragraph>[]</paragraph>");+ mentionEditor.model.change((writer) => {+ mentionEditor.model.insertContent(writer.createText("/"));+ });++ expect(list.element).not.toBeNull();+ expect(getEdge("ArrowDown", {}, mentionEditor)).toBe(null);+ expect(getEdge("ArrowRight", {}, mentionEditor)).toBe(null);+ list.hide();+ expect(getEdge("ArrowDown", {}, mentionEditor)).toBe("end");+ });+it("ignores modified keys, a selection of text and keys from other elements", () => {setModelData(editor.model, "<paragraph>ab[]</paragraph>");expect(getEdge("ArrowRight", { shiftKey: true })).toBe(null);diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.tsindex b07a20cd7c..29aa4db475 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed_caret.ts@@ -10,6 +10,7 @@ import {scrollViewportToShowTarget} from "ckeditor5";+import TriliumMentionUI from "../mention/trilium_mention_ui.js";import { addEditingKeydownCapture } from "../move_block_updown.js";import {getCaption, getContentEmbedAt, getContentEmbedDom, isContentEmbed@@ -110,12 +111,15 @@ export default class ContentEmbedCaret extends Plugin {/*** The edge of the content that the arrow key of `event`, pressed in this editor, moves the- * caret past, or `null` while the caret stays in the content.+ * caret past, or `null` while the caret stays in the content or the mention list takes the key.*/getEdgeLeftBy(event: KeyboardEvent): EmbedEdge | null {const editor = this.editor;const move = getArrowMove(event, this.isRtl());- if (!move || !isFromEditable(editor, event)) {+ const mentions = editor.plugins.has(TriliumMentionUI)+ ? editor.plugins.get(TriliumMentionUI)+ : null;+ if (!move || !isFromEditable(editor, event) || mentions?.isListShown) {return null;}diff --git a/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.spec.ts b/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.spec.tsindex 952d189fab..f226d1c915 100644--- a/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.spec.ts+++ b/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.spec.ts@@ -105,14 +105,20 @@ describe("TriliumMentionUI", () => {it("shows a marker's list the query typed after it, the caret and the editable", () => {expect(TriliumMentionUI.pluginName).toBe("TriliumMentionUI");+ const plugin = editor.plugins.get(TriliumMentionUI);+ expect(plugin.isListShown).toBe(false);type("@my no");+ expect(plugin.isListShown).toBe(true);expect(notes.state?.query).toBe("my no");expect(notes.state?.caretRect().height).toBeGreaterThan(0);expect(notes.state?.editable).toBe(editor.editing.view.getDomRoot());type("te");expect(notes.state?.query).toBe("my note");expect(labels.show).not.toHaveBeenCalled();++ press(keyCodes.esc);+ expect(plugin.isListShown).toBe(false);});it("closes one marker's list when another marker is typed", () => {diff --git a/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.ts b/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.tsindex 84189e1083..6d3844fbe4 100644--- a/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.ts+++ b/packages/ckeditor5/src/plugins/mention/trilium_mention_ui.ts@@ -66,6 +66,11 @@ export default class TriliumMentionUI extends Plugin {return "TriliumMentionUI" as const;}+ /** Whether a list shows entries, which take the arrow keys. */+ get isListShown() {+ return !!this._open?.hostedList.element;+ }+init() {const editor = this.editor;@@ -84,7 +89,7 @@ export default class TriliumMentionUI extends Plugin {clickOutsideHandler({emitter: this._domEmitter,- activator: () => !!this._open?.hostedList.element,+ activator: () => this.isListShown,/* v8 ignore next -- `clickOutsideHandler` only calls `contextElements()` once the activator reported the list showing, so its element is never null */contextElements: () => {const element = this._open?.hostedList.element;diff --git a/packages/ckeditor5/src/plugins/scrollable_bar.ts b/packages/ckeditor5/src/plugins/scrollable_bar.tsindex a2b56bacf8..f01da9e0b0 100644--- a/packages/ckeditor5/src/plugins/scrollable_bar.ts+++ b/packages/ckeditor5/src/plugins/scrollable_bar.ts@@ -84,6 +84,8 @@ export function createScrollableBarEdge(* viewport's width; holding the button down scrolls continuously until it is released. A press on* the bar outside the viewport does not move the focus and does not reach the listeners of the* bar's ancestors, such as an editor's.+ *+ * Items size relative to the bar, in `cqi` units, not to the viewport, which the edges narrow.*/export function attachScrollableBar(bar: HTMLElement, viewport: HTMLElement): ScrollableBar {const document = bar.ownerDocument;diff --git a/packages/ckeditor5/src/plugins/tabs/tabs_layout.spec.ts b/packages/ckeditor5/src/plugins/tabs/tabs_layout.spec.tsindex 39a6d55aff..5c32d5e3c2 100644--- a/packages/ckeditor5/src/plugins/tabs/tabs_layout.spec.ts+++ b/packages/ckeditor5/src/plugins/tabs/tabs_layout.spec.ts@@ -32,11 +32,11 @@ function manyTabsHtml(alignment: TabAlignment | null = null) {return `<div class="trilium-tabs"${attribute}>${tabs.join("")}</div>`;}-/** Saved `html` that `applyTabs()` set up, in a 400px container. */-function renderSaved(html: string) {+/** Saved `html` that `applyTabs()` set up, in a container `width` pixels wide. */+function renderSaved(html: string, width = 400) {const container = document.createElement("div");container.className = "ck-content";- container.style.width = "400px";+ container.style.width = `${width}px`;container.innerHTML = html;document.body.appendChild(container);const dispose = applyTabs(container, OPTIONS);@@ -289,6 +289,25 @@ describe("tabs layout styles", () => {}});+ it("keeps the buttons of titles that fit the bar only without them", async () => {+ const tabs = Array.from({ length: 4 }, (_, index) =>+ tab(`Step ${index + 1} of a long guide`, "<p>Body</p>"));+ const { container } = renderSaved(`<div class="trilium-tabs">${tabs.join("")}</div>`, 300);+ const { bar, titles } = barOf(container);+ let toggles = 0;+ const observer = new MutationObserver(() => toggles++);+ observer.observe(bar, { attributeFilter: ["class"] });+ onTestFinished(() => observer.disconnect());++ for (let frame = 0; frame < 10; frame++) {+ await new Promise(requestAnimationFrame);+ }+ expect(isOverflowing(bar)).toBe(true);+ expect(toggles).toBeLessThanOrEqual(1);+ expect(titles[0].getBoundingClientRect().width / bar.getBoundingClientRect().width)+ .toBeCloseTo(0.3, 2);+ });+it("scrolls the titles with the buttons, and reveals the title of the shown tab", async () => {document.body.classList.add("motion-disabled");onTestFinished(() => document.body.classList.remove("motion-disabled"));diff --git a/packages/ckeditor5/src/theme/scrollable_bar.css b/packages/ckeditor5/src/theme/scrollable_bar.cssindex f646873456..83be526a93 100644--- a/packages/ckeditor5/src/theme/scrollable_bar.css+++ b/packages/ckeditor5/src/theme/scrollable_bar.css@@ -11,6 +11,7 @@.scrollable-bar {display: flex;+ container-type: inline-size;min-width: 0;& > .scrollable-bar-viewport {diff --git a/packages/ckeditor5/src/theme/tabs.css b/packages/ckeditor5/src/theme/tabs.cssindex 6f2f3c90a2..d29c1f139a 100644--- a/packages/ckeditor5/src/theme/tabs.css+++ b/packages/ckeditor5/src/theme/tabs.css@@ -29,7 +29,7 @@flex: none;box-sizing: border-box;min-width: 4em;- max-width: 30%;+ max-width: 30cqi;margin: 0 0 var(--_tabs-delimiter-width);padding: 6px 1rem;border-radius: var(--_tabs-border-radius) var(--_tabs-border-radius) 0 0;@@ -53,7 +53,7 @@}body.mobile & {- max-width: 45%;+ max-width: 45cqi;}}diff --git a/packages/codemirror/src/index.spec.ts b/packages/codemirror/src/index.spec.tsindex 4563f7d18e..5a7012a9e6 100644--- a/packages/codemirror/src/index.spec.ts+++ b/packages/codemirror/src/index.spec.ts@@ -1,3 +1,4 @@+import { closeCompletion, completionStatus, startCompletion } from "@codemirror/autocomplete";import { indentUnit } from "@codemirror/language";import { EditorSelection, EditorState, StateEffect } from "@codemirror/state";import { EditorView, showTooltip, type ViewUpdate } from "@codemirror/view";@@ -409,6 +410,23 @@ describe("CodeMirror", () => {instance.dispatch({ selection: EditorSelection.create(cursors) });expect(instance.getEdgeLeftBy(arrowLeft)).toBe(null);});++ it("leaves the arrow keys to an open completion list", async () => {+ const instance = build();+ editor = instance;+ instance.setText("ab");+ instance.setCompletionSource("test", (context) => ({+ from: context.pos, options: [ { label: "alpha" }, { label: "beta" } ]+ }));+ instance.dispatch({ selection: EditorSelection.cursor(2) });+ startCompletion(instance);+ await vi.waitFor(() => expect(completionStatus(instance.state)).toBe("active"));++ const arrowDown = createKeydown("ArrowDown", instance.contentDOM);+ expect(instance.getEdgeLeftBy(arrowDown)).toBe(null);+ closeCompletion(instance);+ expect(instance.getEdgeLeftBy(arrowDown)).toBe("end");+ });});describe("find and replace", () => {diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.tsindex c36bcf671b..cbb3d639a4 100644--- a/packages/codemirror/src/index.ts+++ b/packages/codemirror/src/index.ts@@ -3,7 +3,7 @@ import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, toolimport { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching, foldGutter, codeFolding } from "@codemirror/language";import { Compartment, EditorSelection, EditorState, StateEffect, type Extension } from "@codemirror/state";import { highlightSelectionMatches } from "@codemirror/search";-import { autocompletion, type CompletionSource } from "@codemirror/autocomplete";+import { autocompletion, completionStatus, type CompletionSource } from "@codemirror/autocomplete";import { vim } from "@replit/codemirror-vim";import { indentationMarkers } from "@replit/codemirror-indentation-markers";import byMimeType, { MIME_ALIASES } from "./syntax_highlighting.js";@@ -331,13 +331,14 @@ export default class CodeMirror extends EditorView {/*** The edge of the document that the arrow key of `event`, pressed without modifiers, moves- * the cursor past, or `null` for any other key and while the cursor stays in the document.+ * the cursor past, or `null` for any other key, while the cursor stays in the document and+ * while the completion list is open.*/getEdgeLeftBy(event: KeyboardEvent): DocumentEdge | null {const { ranges, main } = this.state.selection;const hasModifier = event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;if (event.target !== this.contentDOM || hasModifier || event.isComposing- || ranges.length > 1 || !main.empty) {+ || ranges.length > 1 || !main.empty || completionStatus(this.state) === "active") {return null;}