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
client/text editor: fix some issues
Adorian Doran94063d9143d0
diff --git a/apps/client/src/stylesheets/theme-next/notes/text.css b/apps/client/src/stylesheets/theme-next/notes/text.cssindex 1d7424de99..3fe60e674e 100644--- a/apps/client/src/stylesheets/theme-next/notes/text.css+++ b/apps/client/src/stylesheets/theme-next/notes/text.css@@ -637,7 +637,6 @@ div.ck-template-form .ck-search__info span:nth-child(2) {/* Math popup */-/* Save and cancel buttons, drawn as the color picker's */:root .ck-math-form .ck-math-button-row {--ck-button-border-radius: var(--ck-border-radius);}@@ -655,7 +654,6 @@ div.ck-template-form .ck-search__info span:nth-child(2) {padding-inline: 16px;}-/* MathLive's keyboard and menu toggles, in the colors of icon buttons (buttons.css) */:root .ck-math-form math-field::part(virtual-keyboard-toggle),:root .ck-math-form math-field::part(menu-toggle) {color: var(--icon-button-color);@@ -667,7 +665,6 @@ div.ck-template-form .ck-search__info span:nth-child(2) {color: var(--icon-button-hover-color);}-/* MathLive's menu, drawn as a CKEditor dropdown menu */:root .ck-math-form math-field {--ui-font-family: var(--ck-font-face);--ui-font-size: 0.9rem;@@ -680,13 +677,12 @@ div.ck-template-form .ck-search__info span:nth-child(2) {--ui-menu-divider: var(--menu-item-delimiter-color);--ui-menu-shadow: 0px 10px 20px rgba(0, 0, 0, var(--dropdown-shadow-opacity));- /* Rows placed as CKEditor's list rows: 27px tall, 4px apart, 11px from the menu's edge */+ /* CKEditor's list row geometry: 27px tall, 4px apart, 11px from the menu's edge */--ui-line-height: 21px;--ck-math-menu-item-margin: 4px 11px;--ck-math-menu-item-padding: 1px 15px;--ck-math-menu-item-border-radius: 6px;- /* Headings drawn as the app menus' (menus.css) */--ck-math-menu-heading-margin: 0 0 8px;--ck-math-menu-heading-padding: 2px 26px 1px;--ck-math-menu-heading-border: 1px solid var(--menu-item-delimiter-color);@@ -697,14 +693,11 @@ div.ck-template-form .ck-search__info span:nth-child(2) {--ck-math-menu-heading-text-transform: uppercase;--ck-math-menu-heading-color: var(--menu-item-group-header-color);- /* Checkmarks drawn as the app menus' trailing checks (menus.css), as far from the row's end as- its text is from the start */--ck-math-menu-checkmark-order: 1;--ck-math-menu-checkmark-margin-inline: 12px 2px;--ck-math-menu-checkmark-color: var(--menu-item-icon-color);--ck-math-menu-checkmark-indent: 0;- /* Color cells drawn as the tiles of CKEditor's color grids */--ck-math-menu-swatch-size: var(--ck-color-grid-tile-size);--ck-math-menu-swatch-gap: 8px;--ck-math-menu-swatch-background: transparent;@@ -713,7 +706,7 @@ div.ck-template-form .ck-search__info span:nth-child(2) {}:root .ck-math-form math-field::part(ui-menu-container) {- /* An outline, as a border would take the room of the color grid's fourth column */+ /* An outline takes no room from the four swatch columns of `.swatches-submenu` */outline: 1px solid var(--ck-editor-popup-border-color);outline-offset: -1px;border-radius: var(--dropdown-border-radius);diff --git a/packages/ckeditor5/src/plugins/math/math_input_view.spec.ts b/packages/ckeditor5/src/plugins/math/math_input_view.spec.tsindex 3124068fd0..084b22760f 100644--- a/packages/ckeditor5/src/plugins/math/math_input_view.spec.ts+++ b/packages/ckeditor5/src/plugins/math/math_input_view.spec.ts@@ -214,6 +214,86 @@ describe( 'MathInputView', () => {expect( look( swatchMark ) ).toEqual( [ '0', '0px', '0px', 'rgb(255, 255, 255)' ] );} );+ describe( 'MathLive\'s own menu', () => {+ let menu: Element | null = null;++ /** Open the menu of a math field from its toggle, as a user does. */+ async function showMenu( theme: Record<string, string> ): Promise<Element> {+ const mathfield = await renderAndWait();+ for ( const [ name, value ] of Object.entries( theme ) ) {+ mathfield.style.setProperty( `--ck-math-menu-${ name }`, value );+ }+ const toggle = mathfield.shadowRoot?.querySelector( '[part=menu-toggle]' ) as Element;+ toggle.dispatchEvent( new PointerEvent( 'pointerdown', { bubbles: true } ) );+ menu = mathfield.shadowRoot?.querySelector( '.ui-menu-container' ) ?? null;+ expect( menu ).not.toBeNull();+ return menu as Element;+ }++ /** The row of a menu with the given label. */+ function menuRow( parent: Element, label: string ): Element {+ const row = Array.from( parent.children )+ .find( item => item.querySelector( ':scope > .label' )?.textContent === label );+ expect( row, label ).toBeDefined();+ return row as Element;+ }++ /** Click a row of a menu and return the submenu it opens. */+ function openSubmenu( row: Element ): Element {+ // MathLive selects on `pointerup`, or on `click` if the menu opened under 120ms ago.+ row.dispatchEvent( new PointerEvent( 'pointerup', { bubbles: true } ) );+ row.dispatchEvent( new MouseEvent( 'click', { bubbles: true } ) );+ const scrim = row.parentElement?.parentElement as Element;+ const menus = scrim.querySelectorAll( ':scope > .ui-menu-container' );+ expect( menus.length ).toBeGreaterThan( 1 );+ return menus[ menus.length - 1 ];+ }++ // MathLive's menus share one scrim, so a menu left open blocks the next one.+ afterEach( () => {+ menu?.dispatchEvent( new KeyboardEvent( 'keydown', { key: 'Escape', bubbles: true } ) );+ menu = null;+ } );++ it( 'lets a theme style its rows, headings and checkmarks', async () => {+ const root = await showMenu( {+ 'item-padding': '1px 15px', 'heading-padding': '2px 26px 1px',+ 'heading-text-transform': 'uppercase', 'checkmark-order': '1',+ 'checkmark-indent': '0px'+ } );+ const insert = menuRow( root, 'Insert' );+ const divider = root.querySelector( ':scope > [role=divider]' ) as Element;+ const heading = openSubmenu( insert ).querySelector( ':scope > li > .heading' );+ const headingRow = heading?.parentElement as Element;+ const math = menuRow( openSubmenu( menuRow( root, 'Mode' ) ), 'Math' );+ const mark = math.querySelector( ':scope > .ui-checkmark' ) as Element;+ const label = math.querySelector( ':scope > .label' ) as Element;++ expect( spacing( insert ) ).toEqual( [ '0px 6px', '1px 15px', '4px' ] );+ expect( spacing( divider ) ).toEqual( [ '0px 15px 5px', '5px 0px 0px', '0px' ] );+ expect( getComputedStyle( headingRow ).padding ).toBe( '2px 26px 1px' );+ expect( getComputedStyle( heading as Element ).textTransform ).toBe( 'uppercase' );+ expect( getComputedStyle( mark ).order ).toBe( '1' );+ expect( getComputedStyle( label ).marginInlineStart ).toBe( '0px' );+ } );++ it( 'lets a theme draw its color swatches, but not space its matrix cells', async () => {+ const root = await showMenu( {+ 'item-margin': '4px 10px', 'item-padding': '1px 15px', 'item-border-radius': '6px',+ 'swatch-size': '24px', 'swatch-gap': '8px', 'swatch-border-radius': '4px'+ } );+ const colors = openSubmenu( menuRow( root, 'Color' ) );+ const color = colors.querySelector( '.menu-swatch > .label > span' ) as Element;+ const matrix = openSubmenu( menuRow( root, 'Insert Matrix' ) );+ const cell = matrix.querySelector( ':scope > li' ) as Element;++ expect( getComputedStyle( colors ).maxWidth ).toBe( '144px' );+ expect( getComputedStyle( color ).borderRadius ).toBe( '4px' );+ expect( getComputedStyle( color ).minWidth ).toBe( '24px' );+ expect( spacing( cell ) ).toEqual( [ '0px', '0px', '0px' ] );+ } );+ } );+it( 'anchors the tooltips of the toggles to them, out of the scrolling field', async () => {onTestFinished( () => document.body.style.removeProperty( 'padding-top' ) );document.body.style.paddingTop = '100px';