diff --git a/CHANGELOG.md b/CHANGELOG.md index 93be23c7..108a5e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - improve keyboard navigation, tag removal and focus handling - improve screen reader labels and selection announcements - preserve filters and keep the dropdown open when toggling existing options +- `` + - preserve the editor height when disabled + - apply callback, extension, and appearance changes in place, including `multiline` changes in `` ## [26.2.1] - 2026-11-02 diff --git a/src/components/AutoSuggestion/AutoSuggestion.tsx b/src/components/AutoSuggestion/AutoSuggestion.tsx index 23f61095..29b435da 100644 --- a/src/components/AutoSuggestion/AutoSuggestion.tsx +++ b/src/components/AutoSuggestion/AutoSuggestion.tsx @@ -698,40 +698,25 @@ export const CodeAutocompleteField = ({ effectiveIntent && !["info", "accent", "neutral"].includes(effectiveIntent) ? effectiveIntent : undefined; const inputIntentClass = effectiveIntent ? ` ${eccgui}-intent--${effectiveIntent}` : ""; - const codeEditor = React.useMemo(() => { - return ( - - ); - }, [ - mode, - setCM, - handleChange, - initialValue, - useTabForCompletions, - placeholder, - showScrollBar, - multiline, - handleInputMouseDown, - height, - readOnly, - effectiveIntent, - ]); + const codeEditor = ( + + ); const autoSuggestionInput = (
+ transaction.newDoc.lines > transaction.startState.doc.lines ? [] : transaction, + ), +]; + /** Supports single-line and multiline editing. */ export const ExtendedCodeEditor = ({ multiline = false, @@ -86,12 +92,6 @@ export const ExtendedCodeEditor = ({ readOnly, }: ExtendedCodeEditorProps) => { const initialContent = React.useRef(multiline ? initialValue : initialValue.replace(/[\r\n]/g, " ")); - const multilineExtensions = multiline - ? [lineNumbers(), EditorView.lineWrapping] - : [ - EditorState?.transactionFilter.of((tr) => (tr.newDoc.lines > 1 ? [] : tr)), //prevent multiline, - ]; - return ( ); }; diff --git a/src/components/AutoSuggestion/tests/AutoSuggestion.test.tsx b/src/components/AutoSuggestion/tests/AutoSuggestion.test.tsx index 8577079e..30b91628 100644 --- a/src/components/AutoSuggestion/tests/AutoSuggestion.test.tsx +++ b/src/components/AutoSuggestion/tests/AutoSuggestion.test.tsx @@ -51,6 +51,20 @@ describe("CodeAutocompleteField", () => { expect(getByText(props.label!)).toBeTruthy(); }); + it("forwards focus events to the latest callback after a rerender", async () => { + const { rerender } = render(); + const editor = screen.getByRole("combobox"); + await act(async () => editor.focus()); + expect(props.onFocusChange).toHaveBeenCalledWith(true); + + const nextOnFocusChange = jest.fn(); + rerender(); + await act(async () => editor.blur()); + + expect(nextOnFocusChange).toHaveBeenCalledWith(false); + expect(props.onFocusChange).not.toHaveBeenCalledWith(false); + }); + it("connects the focused editor to the active suggestion", async () => { const { container } = render( { render(); expect(cm?.state.doc.lines).toBe(1); }); + + it.each([ + { multiline: true, draft: "unsaved draft" }, + { multiline: false, draft: "unsaved\nsecond line" }, + ])("preserves the draft and selection when multiline changes to $multiline", ({ multiline, draft }) => { + const editorProps = { ...props, initialValue: "initial" }; + const { rerender } = render(); + const editor = EditorView.findFromDOM(screen.getByRole("textbox")); + + if (!editor) { + throw new Error("Expected the mounted CodeMirror editor"); + } + const selection = { anchor: draft.length, head: 2 }; + act(() => { + editor.dispatch({ changes: { from: 0, to: editor.state.doc.length, insert: draft }, selection }); + }); + expect(editor.state.doc.toString()).toBe(draft); + expect(editor.state.selection.main).toMatchObject(selection); + + rerender(); + + expect(EditorView.findFromDOM(screen.getByRole("textbox"))).toBe(editor); + expect(editor.state.doc.toString()).toBe(draft); + expect(editor.state.selection.main).toMatchObject(selection); + }); + + it("allows editing and removing existing lines after switching to single-line mode", () => { + const editorProps = { ...props, initialValue: "first\nsecond" }; + const { rerender } = render(); + const editor = EditorView.findFromDOM(screen.getByRole("textbox")); + + if (!editor) { + throw new Error("Expected the mounted CodeMirror editor"); + } + rerender(); + + act(() => editor.dispatch({ changes: { from: 0, insert: "draft " } })); + expect(editor.state.doc.toString()).toBe("draft first\nsecond"); + act(() => editor.dispatch({ changes: { from: 0, insert: "\n" } })); + expect(editor.state.doc.toString()).toBe("draft first\nsecond"); + act(() => editor.dispatch({ changes: { from: 11, to: 12, insert: " " } })); + expect(editor.state.doc.toString()).toBe("draft first second"); + }); + + it.each([ + { multiline: true, expectedText: "draft\nnext line" }, + { multiline: false, expectedText: "draft" }, + ])("updates newline handling and wrapping when multiline changes to $multiline", ({ multiline, expectedText }) => { + const editorProps = { ...props, initialValue: "draft" }; + const { rerender } = render(); + const content = screen.getByRole("textbox"); + const editor = EditorView.findFromDOM(content); + + if (!editor) { + throw new Error("Expected the mounted CodeMirror editor"); + } + act(() => editor.dispatch({ selection: { anchor: 5 } })); + + rerender(); + + expect(screen.getByRole("textbox")).toBe(content); + expect(editor.state.selection.main.head).toBe(5); + + act(() => editor.dispatch({ changes: { from: 5, insert: "\nnext line" } })); + + expect({ + text: editor.state.doc.toString(), + wraps: content.classList.contains("cm-lineWrapping"), + }).toEqual({ text: expectedText, wraps: multiline }); + }); }); diff --git a/src/extensions/codemirror/CodeMirror.tsx b/src/extensions/codemirror/CodeMirror.tsx index ba5e0899..45e0ce1c 100644 --- a/src/extensions/codemirror/CodeMirror.tsx +++ b/src/extensions/codemirror/CodeMirror.tsx @@ -2,7 +2,7 @@ import React, { useMemo, useRef } from "react"; import { createPortal } from "react-dom"; import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands"; import { defaultHighlightStyle, foldKeymap } from "@codemirror/language"; -import { Compartment, EditorState, Extension, Prec } from "@codemirror/state"; +import { Compartment, EditorState, Extension, Prec, StateEffect } from "@codemirror/state"; import { DOMEventHandlers, EditorView, @@ -148,7 +148,7 @@ export interface CodeEditorProps */ shouldHighlightActiveLine?: boolean; /** - * additional extensions to customize the editor further + * Additional extensions to customize the editor. Changes are applied to the mounted editor. */ additionalExtensions?: Extension[]; /** @@ -198,11 +198,10 @@ export interface CodeEditorProps } const DEFAULT_BLUR_HINT = "Press Escape then Tab to leave the editor."; +const EMPTY_EXTENSIONS: Extension[] = []; const addExtensionsFor = (flag: boolean, ...extensions: Extension[]) => (flag ? [...extensions] : []); const addToKeyMapConfigFor = (flag: boolean, ...keys: KeyBinding[]) => (flag ? [...keys] : []); -const addHandlersFor = (flag: boolean, handlerName: string, handler: any) => - flag ? ({ [handlerName]: handler } as DOMEventHandlers) : {}; const ModeLinterMap: ReadonlyMap> = new Map([ ["turtle", [turtleLinter]], @@ -252,7 +251,7 @@ export const CodeEditor = ({ tabIntentSize = 2, tabIntentStyle = "tab", placeholder, - additionalExtensions = [], + additionalExtensions = EMPTY_EXTENSIONS, tabForceSpaceForModes = ["python", "yaml"], enableTab: shouldIndentOnTab, height, @@ -279,18 +278,38 @@ export const CodeEditor = ({ }; }, []); const [view, setView] = React.useState(); - const defaultAppearanceForModeWithToolbar = getDefaultAppearanceForModeWithToolbar(useToolbar, mode); - const [editorAppearance, setEditorAppearance] = React.useState<{ [s: string]: boolean }>({ - // we also set the fallback default here - wrapLines: wrapLines ?? defaultAppearanceForModeWithToolbar?.wrapLines ?? false, - preventLineNumbers: preventLineNumbers ?? defaultAppearanceForModeWithToolbar?.preventLineNumbers ?? false, - }); + const defaultAppearance = getDefaultAppearanceForModeWithToolbar(useToolbar, mode); + const [toolbarAppearance, setToolbarAppearance] = React.useState({}); + const effectiveWrapLines = wrapLines ?? toolbarAppearance.wrapLines ?? defaultAppearance?.wrapLines ?? false; + const effectivePreventLineNumbers = + preventLineNumbers ?? toolbarAppearance.preventLineNumbers ?? defaultAppearance?.preventLineNumbers ?? false; + const editorAppearance = { wrapLines: effectiveWrapLines, preventLineNumbers: effectivePreventLineNumbers }; + const updateToolbarAppearance = (update: React.SetStateAction>) => { + const next = typeof update === "function" ? update(editorAppearance) : update; + setToolbarAppearance((previous) => ({ + wrapLines: next.wrapLines === effectiveWrapLines ? previous.wrapLines : next.wrapLines, + preventLineNumbers: + next.preventLineNumbers === effectivePreventLineNumbers + ? previous.preventLineNumbers + : next.preventLineNumbers, + })); + }; + const appearanceExtensions = useMemo( + () => [ + ...addExtensionsFor(!effectivePreventLineNumbers, adaptedLineNumbers()), + ...addExtensionsFor(effectiveWrapLines, EditorView?.lineWrapping), + ], + [effectivePreventLineNumbers, effectiveWrapLines], + ); const currentView = React.useRef(undefined); currentView.current = view; const currentReadOnly = React.useRef(readOnly); currentReadOnly.current = readOnly; - const currentOnChange = React.useRef(onChange); - currentOnChange.current = onChange; + const editorCallbacks = { onChange, onSelection, onMouseDown, onFocusChange, onKeyDown, onCursorChange, onScroll }; + const currentCallbacks = React.useRef(editorCallbacks); + React.useLayoutEffect(() => { + currentCallbacks.current = editorCallbacks; + }); const currentDisabled = React.useRef(disabled); currentDisabled.current = disabled; const currentIntent = React.useRef(intent); @@ -298,8 +317,8 @@ export const CodeEditor = ({ const [showPreview, setShowPreview] = React.useState(false); // CodeMirror Compartments in order to allow for re-configuration after initialization const readOnlyCompartment = React.useRef(compartment()); - const wrapLinesCompartment = React.useRef(compartment()); - const preventLineNumbersCompartment = React.useRef(compartment()); + const appearanceCompartment = React.useRef(compartment()); + const additionalExtensionsCompartment = React.useRef(compartment()); const shouldHaveMinimalSetupCompartment = React.useRef(compartment()); const historyCompartment = React.useRef(compartment()); const placeholderCompartment = React.useRef(compartment()); @@ -328,6 +347,7 @@ export const CodeEditor = ({ }, [mode]); const onKeyDownHandler = (event: KeyboardEvent, view: EditorView) => { + const { onKeyDown } = currentCallbacks.current; if (onKeyDown && !onKeyDown(event)) { if (event.key === "Enter" && !currentReadOnly.current) { const cursor = view.state.selection.main.head; @@ -391,20 +411,16 @@ export const CodeEditor = ({ ); React.useEffect(() => { - const domEventHandlers = { - ...addHandlersFor(!!onScroll, "scroll", onScroll), - ...addHandlersFor( - !!onMouseDown, - "mousedown", - (_: any, view: EditorView) => onMouseDown && onMouseDown(view), - ), + const domEventHandlers: DOMEventHandlers = { + scroll: (event, editorView) => currentCallbacks.current.onScroll?.(event, editorView), + mousedown: (_, editorView) => currentCallbacks.current.onMouseDown?.(editorView), blur: () => { - onFocusChange?.(false); + currentCallbacks.current.onFocusChange?.(false); }, focus: () => { - onFocusChange?.(true); + currentCallbacks.current.onFocusChange?.(true); }, - } as DOMEventHandlers; + }; const extensions = [ historyCompartment.current.of(addExtensionsFor(!shouldHaveMinimalSetup, history())), markField, @@ -418,20 +434,23 @@ export const CodeEditor = ({ disabledCompartment.current.of(EditorView?.editable.of(!disabled)), // Run the consumer's keydown handler before CodeMirror keymaps. A built-in binding such as // Escape's simplifySelection may otherwise consume the event before autocomplete can close its dropdown. - ...addExtensionsFor( - !!onKeyDown, - Prec.highest(AdaptedEditorViewDomEventHandlers({ keydown: onKeyDownHandler }) as Extension), - ), + Prec.highest(AdaptedEditorViewDomEventHandlers({ keydown: onKeyDownHandler }) as Extension), AdaptedEditorViewDomEventHandlers(domEventHandlers) as Extension, EditorView?.updateListener.of((v: ViewUpdate) => { if (currentDisabled.current) return; - if (currentOnChange.current && v.docChanged) { + const { onChange, onSelection, onFocusChange, onCursorChange } = currentCallbacks.current; + if (onChange && v.docChanged) { // Only fire if the text has actually been changed - currentOnChange.current(v.state.doc.toString()); + onChange(v.state.doc.toString()); } - if (onSelection) + const configurationOnly = + !v.docChanged && + !v.selectionSet && + v.transactions.some((transaction) => transaction.reconfigured) && + v.state.selection.eq(v.startState.selection); + if (onSelection && !configurationOnly) onSelection(v.state.selection.ranges.filter((r) => !r.empty).map(({ from, to }) => ({ from, to }))); if ( @@ -462,19 +481,16 @@ export const CodeEditor = ({ } }), shouldHaveMinimalSetupCompartment.current.of(addExtensionsFor(shouldHaveMinimalSetup, minimalSetup)), - preventLineNumbersCompartment.current.of( - addExtensionsFor(!editorAppearance.preventLineNumbers, adaptedLineNumbers()), - ), + appearanceCompartment.current.of(appearanceExtensions), shouldHighlightActiveLineCompartment.current.of( addExtensionsFor(shouldHighlightActiveLine, adaptedHighlightActiveLine()), ), - wrapLinesCompartment.current.of(addExtensionsFor(editorAppearance.wrapLines!, EditorView?.lineWrapping)), supportCodeFoldingCompartment.current.of( addExtensionsFor(supportCodeFolding, adaptedFoldGutter(), adaptedCodeFolding()), ), useLintingCompartment.current.of(addExtensionsFor(useLinting, ...linters)), adaptedSyntaxHighlighting(defaultHighlightStyle), - additionalExtensions, + additionalExtensionsCompartment.current.of(additionalExtensions), ]; const view: EditorView = new AdaptedEditorView({ @@ -567,26 +583,28 @@ export const CodeEditor = ({ }, [intent, view, syncIntentClass]); React.useEffect(() => { - setEditorAppearance({ - ...editorAppearance, - preventLineNumbers: preventLineNumbers ?? editorAppearance?.preventLineNumbers ?? false, - }); - updateExtension( - addExtensionsFor(!editorAppearance.preventLineNumbers, adaptedLineNumbers()), - preventLineNumbersCompartment.current, - ); - }, [preventLineNumbers, editorAppearance.preventLineNumbers]); - - React.useEffect(() => { - setEditorAppearance({ - ...editorAppearance, - wrapLines: wrapLines ?? editorAppearance?.wrapLines ?? false, - }); - updateExtension( - addExtensionsFor(editorAppearance.wrapLines!, EditorView?.lineWrapping), - wrapLinesCompartment.current, - ); - }, [wrapLines, editorAppearance.wrapLines]); + const editor = currentView.current; + if (!editor?.state) return; + + const appearance = appearanceCompartment.current; + const extensions = additionalExtensionsCompartment.current; + const installedExtensions = extensions.get(editor.state); + const effects: StateEffect[] = []; + if (appearance.get(editor.state) !== appearanceExtensions) { + effects.push(appearance.reconfigure(appearanceExtensions)); + } + if ( + !Array.isArray(installedExtensions) || + installedExtensions.length !== additionalExtensions.length || + additionalExtensions.some((extension, index) => extension !== installedExtensions[index]) + ) { + effects.push(extensions.reconfigure(additionalExtensions)); + } + if (effects.length) { + // A filter in the previous configuration must not block its replacement. + editor.dispatch({ effects, filter: false }); + } + }, [appearanceExtensions, additionalExtensions]); React.useEffect(() => { updateExtension( @@ -631,12 +649,12 @@ export const CodeEditor = ({ readonly={readOnly} configMenu={ } diff --git a/src/extensions/codemirror/_codemirror.scss b/src/extensions/codemirror/_codemirror.scss index c39d6a93..7bea5be9 100644 --- a/src/extensions/codemirror/_codemirror.scss +++ b/src/extensions/codemirror/_codemirror.scss @@ -81,10 +81,18 @@ $eccgui-size-codeeditor-toolbar-height: $button-height !default; box-shadow: input-transition-shadow($input-shadow-color-focus), $pt-input-box-shadow; clip-path: unset !important; // we may check later why they set inset(0) now - &.#{eccgui}-disabled { - @extend .#{$ns}-input, .#{$ns}-disabled; + &.#{$eccgui}-disabled { + @include pt-input-disabled; padding: 0; + + .#{$ns}-dark & { + @include pt-dark-input-disabled; + } + + @media (forced-colors: active) and (prefers-color-scheme: dark) { + border: 1px solid $pt-high-contrast-mode-border-color; + } } &:has(.cm-content[aria-readonly="true"]) { diff --git a/src/extensions/codemirror/tests/CodeEditor.test.tsx b/src/extensions/codemirror/tests/CodeEditor.test.tsx index 362f3c81..c13ea909 100644 --- a/src/extensions/codemirror/tests/CodeEditor.test.tsx +++ b/src/extensions/codemirror/tests/CodeEditor.test.tsx @@ -1,10 +1,13 @@ import React from "react"; +import { redo, undo } from "@codemirror/commands"; +import { EditorState } from "@codemirror/state"; +import { EditorView } from "@codemirror/view"; import { act, fireEvent, render, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import { CLASSPREFIX as eccgui } from "../../../configuration/constants"; -import { CodeEditor } from "../CodeMirror"; +import { CodeEditor, CodeEditorProps } from "../CodeMirror"; const contextOverlayClass = `${eccgui}-contextoverlay`; @@ -21,6 +24,160 @@ const setupDocumentRange = () => { }; }; +describe("CodeEditor - prop changes after mount", () => { + beforeAll(() => { + setupDocumentRange(); + }); + + const callbackCases: [keyof CodeEditorProps, (editor: EditorView) => void][] = [ + ["onCursorChange", (editor) => act(() => editor.dispatch({ selection: { anchor: 1 } }))], + ["onKeyDown", (editor) => fireEvent.keyDown(editor.contentDOM, { key: "Enter" })], + ["onMouseDown", (editor) => fireEvent.mouseDown(editor.contentDOM)], + ["onFocusChange", (editor) => fireEvent.focus(editor.contentDOM)], + ["onSelection", (editor) => act(() => editor.dispatch({ selection: { anchor: 0, head: 1 } }))], + ["onScroll", (editor) => fireEvent.scroll(editor.scrollDOM)], + ]; + + const statePreservationCases: [string, Partial, Partial][] = [ + [ + "the callbacks change", + Object.fromEntries(callbackCases.map(([prop]) => [prop, jest.fn(() => true)])), + Object.fromEntries(callbackCases.map(([prop]) => [prop, jest.fn(() => true)])), + ], + [ + "additional extensions change", + { additionalExtensions: [EditorView.contentAttributes.of({ "aria-label": "Source expression" })] }, + { additionalExtensions: [EditorView.contentAttributes.of({ "aria-label": "Target expression" })] }, + ], + [ + "wrapping and line numbers change together", + { wrapLines: false, preventLineNumbers: false }, + { wrapLines: true, preventLineNumbers: true }, + ], + ]; + + it.each(statePreservationCases)("preserves editor state when %s", (_description, before, after) => { + const editorProps = { name: "test-editor", defaultValue: "initial" }; + const { rerender } = render(); + const content = screen.getByRole("textbox"); + const editor = EditorView.findFromDOM(content); + + if (!editor) { + throw new Error("Expected the mounted CodeMirror editor"); + } + const draft = "unsaved draft"; + const selection = { anchor: 8, head: 2 }; + act(() => { + editor.focus(); + editor.dispatch({ + changes: { from: 0, to: editor.state.doc.length, insert: draft }, + selection, + userEvent: "input.type", + }); + }); + expect(content).toHaveFocus(); + + rerender(); + + expect(EditorView.findFromDOM(screen.getByRole("textbox"))).toBe(editor); + expect(editor.state.doc.toString()).toBe(draft); + expect(editor.state.selection.main).toMatchObject(selection); + expect(content).toHaveFocus(); + act(() => { + expect(undo(editor)).toBe(true); + }); + expect(editor.state.doc.toString()).toBe(editorProps.defaultValue); + act(() => { + expect(redo(editor)).toBe(true); + }); + expect(editor.state.doc.toString()).toBe(draft); + }); + + it.each(callbackCases)("uses the latest %s callback", (prop, trigger) => { + const originalCallback = jest.fn(() => true); + const nextCallback = jest.fn(() => true); + const editorProps = { name: "test-editor", defaultValue: "draft" }; + const { rerender } = render(); + const content = screen.getByRole("textbox"); + const editor = EditorView.findFromDOM(content); + + if (!editor) { + throw new Error("Expected the mounted CodeMirror editor"); + } + const coordsAtPos = jest.spyOn(editor, "coordsAtPos").mockReturnValue(new DOMRect(1, 2, 3, 4)); + + try { + trigger(editor); + expect(originalCallback).toHaveBeenCalled(); + + rerender(); + expect(screen.getByRole("textbox")).toBe(content); + originalCallback.mockClear(); + nextCallback.mockClear(); + + trigger(editor); + expect(nextCallback).toHaveBeenCalled(); + expect(originalCallback).not.toHaveBeenCalled(); + } finally { + coordsAtPos.mockRestore(); + } + }); + + it("replaces and removes additional extensions on the mounted editor", () => { + const onSelection = jest.fn(); + const editorProps = { name: "test-editor", defaultValue: "draft", onSelection }; + const firstExtension = EditorView.contentAttributes.of({ "aria-label": "Source expression" }); + const nextExtension = EditorView.contentAttributes.of({ "aria-label": "Target expression" }); + const { rerender } = render(); + const content = screen.getByRole("textbox"); + expect(content).toHaveAccessibleName("Source expression"); + onSelection.mockClear(); + + rerender(); + + expect(screen.getByRole("textbox")).toBe(content); + expect(content).toHaveAccessibleName("Target expression"); + + rerender(); + + expect(screen.getByRole("textbox")).toBe(content); + expect(content).not.toHaveAttribute("aria-label"); + expect(onSelection).not.toHaveBeenCalled(); + }); + + it("can remove an extension whose transaction filter rejects edits", () => { + const blockingExtension = EditorState.transactionFilter.of(() => []); + const { rerender } = render(); + const editor = EditorView.findFromDOM(screen.getByRole("textbox")); + + if (!editor) { + throw new Error("Expected the mounted CodeMirror editor"); + } + act(() => editor.dispatch({ changes: { from: 0, insert: "draft" } })); + expect(editor.state.doc.toString()).toBe(""); + + rerender(); + act(() => editor.dispatch({ changes: { from: 0, insert: "draft" } })); + + expect(editor.state.doc.toString()).toBe("draft"); + }); + + it("updates wrapping and line numbers together", () => { + const { container, rerender } = render( + , + ); + const content = screen.getByRole("textbox"); + expect(content).not.toHaveClass("cm-lineWrapping"); + expect(container.querySelector(".cm-lineNumbers")).toBeInTheDocument(); + + rerender(); + + expect(screen.getByRole("textbox")).toBe(content); + expect(content).toHaveClass("cm-lineWrapping"); + expect(container.querySelector(".cm-lineNumbers")).not.toBeInTheDocument(); + }); +}); + describe("CodeEditor - markdown mode with toolbar", () => { beforeAll(() => { setupDocumentRange(); @@ -42,6 +199,21 @@ describe("CodeEditor - markdown mode with toolbar", () => { expect(container.querySelector(`.${eccgui}-codeeditor__toolbar`)).toBeNull(); }); + it("restores the current appearance defaults when appearance props are cleared", () => { + const { container, rerender } = render( + , + ); + const content = screen.getByRole("textbox"); + + rerender(); + expect(content).toHaveClass("cm-lineWrapping"); + expect(container.querySelector(".cm-lineNumbers")).not.toBeInTheDocument(); + + rerender(); + expect(content).not.toHaveClass("cm-lineWrapping"); + expect(container.querySelector(".cm-lineNumbers")).toBeInTheDocument(); + }); + it("does not render toolbar for non-markdown modes even when useToolbar is true", () => { const { container } = render(); expect(container.querySelector(`.${eccgui}-codeeditor__toolbar`)).toBeNull();