diff --git a/src/core/atom-class.ts b/src/core/atom-class.ts index f12bb81a5..68e747b2a 100644 --- a/src/core/atom-class.ts +++ b/src/core/atom-class.ts @@ -534,9 +534,25 @@ export class Atom { applyStyle(style: Style, options?: { unstyledOnly: boolean }): void { this.isDirty = true; - if (options?.unstyledOnly && Object.keys(this.style).length === 0) return; - - this.style = { ...this.style, ...style }; + if (options?.unstyledOnly) { + if (style.color && !this.style.color) this.style.color = style.color; + if (style.backgroundColor && !this.style.backgroundColor) + this.style.backgroundColor = style.backgroundColor; + if (style.fontFamily && !this.style.fontFamily) + this.style.fontFamily = style.fontFamily; + if (style.fontShape && !this.style.fontShape) + this.style.fontShape = style.fontShape; + if (style.fontSeries && !this.style.fontSeries) + this.style.fontSeries = style.fontSeries; + if (style.fontSize && !this.style.fontSize) + this.style.fontSize = style.fontSize; + if (style.variant && !this.style.variant) + this.style.variant = style.variant; + if (style.variantStyle && !this.style.variantStyle) + this.style.variantStyle = style.variantStyle; + } else { + this.style = { ...this.style, ...style }; + } if (this.style.fontFamily === 'none') delete this.style.fontFamily; diff --git a/src/editor-mathfield/autocomplete.ts b/src/editor-mathfield/autocomplete.ts index 0f865d853..3b26531af 100644 --- a/src/editor-mathfield/autocomplete.ts +++ b/src/editor-mathfield/autocomplete.ts @@ -17,6 +17,7 @@ import { } from './mode-editor-latex'; import { ModeEditor } from './mode-editor'; import { ParseMode } from '../public/core-types'; +import { getSelectionStyle } from './keyboard-input'; export function removeSuggestion(mathfield: _Mathfield): void { const group = getLatexGroupBody(mathfield.model).filter( @@ -158,11 +159,16 @@ export function complete( mathfield.switchMode(options?.mode ?? 'math'); if (completion === 'reject') return true; + const style = { + ...getSelectionStyle(mathfield.model), + ...mathfield.defaultStyle, + }; ModeEditor.insert(mathfield.model, latex, { selectionMode: options?.selectItem ?? false ? 'item' : 'placeholder', format: 'latex', mode: 'math', + style, }); mathfield.snapshot(); diff --git a/src/editor-mathfield/keyboard-input.ts b/src/editor-mathfield/keyboard-input.ts index 7427e7367..3247a303b 100644 --- a/src/editor-mathfield/keyboard-input.ts +++ b/src/editor-mathfield/keyboard-input.ts @@ -673,7 +673,7 @@ function insertMathModeChar(mathfield: _Mathfield, c: string): void { mathfield.snapshot(`insert-${model.at(model.position).type}`); } -function getSelectionStyle(model: _Model): Readonly