|
1 | 1 | import { forceParsing } from "@codemirror/language"; |
2 | 2 | import { EditorSelection, EditorState, type Extension } from "@codemirror/state"; |
3 | | -import { EditorView } from "@codemirror/view"; |
| 3 | +import { drawSelection, EditorView } from "@codemirror/view"; |
4 | 4 | import { afterEach, describe, expect, it, vi } from "vitest"; |
5 | 5 | import { liveMarkdown } from "./index.ts"; |
6 | 6 |
|
@@ -378,6 +378,44 @@ describe("liveMarkdown", () => { |
378 | 378 | }); |
379 | 379 | }); |
380 | 380 |
|
| 381 | + it("hides CodeMirror's drawn selection while an IME composition is active", () => { |
| 382 | + const view = createView({ |
| 383 | + doc: "Compose", |
| 384 | + selection: EditorSelection.range(0, 3), |
| 385 | + extensions: [drawSelection(), liveMarkdown()], |
| 386 | + }); |
| 387 | + const selectionLayer = view.dom.querySelector<HTMLElement>( |
| 388 | + ".cm-selectionLayer", |
| 389 | + ); |
| 390 | + if (!selectionLayer) throw new Error("Expected CodeMirror's selection layer"); |
| 391 | + |
| 392 | + const selectionBackground = document.createElement("div"); |
| 393 | + selectionBackground.className = "cm-selectionBackground"; |
| 394 | + selectionLayer.append(selectionBackground); |
| 395 | + |
| 396 | + expect(getComputedStyle(selectionBackground).backgroundColor).not.toBe( |
| 397 | + "rgba(0, 0, 0, 0)", |
| 398 | + ); |
| 399 | + |
| 400 | + view.contentDOM.dispatchEvent( |
| 401 | + new CompositionEvent("compositionstart", { bubbles: true }), |
| 402 | + ); |
| 403 | + |
| 404 | + expect(view.dom.dataset.markraComposing).toBe("true"); |
| 405 | + expect(getComputedStyle(selectionBackground).backgroundColor).toBe( |
| 406 | + "rgba(0, 0, 0, 0)", |
| 407 | + ); |
| 408 | + |
| 409 | + view.contentDOM.dispatchEvent( |
| 410 | + new CompositionEvent("compositionend", { bubbles: true }), |
| 411 | + ); |
| 412 | + |
| 413 | + expect(view.dom.dataset.markraComposing).toBeUndefined(); |
| 414 | + expect(getComputedStyle(selectionBackground).backgroundColor).not.toBe( |
| 415 | + "rgba(0, 0, 0, 0)", |
| 416 | + ); |
| 417 | + }); |
| 418 | + |
381 | 419 | it("renders task markers as checkboxes that update the Markdown source", () => { |
382 | 420 | const doc = "- [ ] Ship mock release\n\nEdit"; |
383 | 421 | const view = createView({ doc }); |
|
0 commit comments