From 205b3af889a586326d054755b7bbd99d08a94b7c Mon Sep 17 00:00:00 2001 From: Artem Nistuley Date: Mon, 19 Jan 2026 14:22:13 +0200 Subject: [PATCH] fix: annotation selection, applying formatting --- .../src/components/toolbar/super-toolbar.js | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/super-editor/src/components/toolbar/super-toolbar.js b/packages/super-editor/src/components/toolbar/super-toolbar.js index 9bd092b9b..25a1a75e4 100644 --- a/packages/super-editor/src/components/toolbar/super-toolbar.js +++ b/packages/super-editor/src/components/toolbar/super-toolbar.js @@ -25,6 +25,7 @@ import { isList } from '@core/commands/list-helpers'; import { calculateResolvedParagraphProperties } from '@extensions/paragraph/resolvedPropertiesCache.js'; import { twipsToLines } from '@converter/helpers'; import { parseSizeUnit } from '@core/utilities'; +import { NodeSelection } from 'prosemirror-state'; /** * @typedef {function(CommandItem): void} CommandCallback @@ -367,6 +368,12 @@ export class SuperToolbar extends EventEmitter { * @returns {void} */ setFontSize: ({ item, argument }) => { + if (this.#isFieldAnnotationSelection() && argument) { + this.activeEditor?.commands.setFieldAnnotationsFontSize(argument, true); + this.updateToolbarState(); + return; + } + this.#runCommandWithArgumentOnly({ item, argument }, () => { this.activeEditor?.commands.setFieldAnnotationsFontSize(argument, true); }); @@ -380,6 +387,12 @@ export class SuperToolbar extends EventEmitter { * @returns {void} */ setFontFamily: ({ item, argument }) => { + if (this.#isFieldAnnotationSelection() && argument) { + this.activeEditor?.commands.setFieldAnnotationsFontFamily(argument, true); + this.updateToolbarState(); + return; + } + this.#runCommandWithArgumentOnly({ item, argument }, () => { this.activeEditor?.commands.setFieldAnnotationsFontFamily(argument, true); }); @@ -523,8 +536,13 @@ export class SuperToolbar extends EventEmitter { * @returns {void} */ toggleBold: ({ item, argument }) => { - let command = item.command; + if (this.#isFieldAnnotationSelection()) { + this.activeEditor?.commands.toggleFieldAnnotationsFormat('bold', true); + this.updateToolbarState(); + return; + } + let command = item.command; if (command in this.activeEditor.commands) { this.activeEditor.commands[command](argument); this.activeEditor.commands.toggleFieldAnnotationsFormat('bold', true); @@ -541,8 +559,13 @@ export class SuperToolbar extends EventEmitter { * @returns {void} */ toggleItalic: ({ item, argument }) => { - let command = item.command; + if (this.#isFieldAnnotationSelection()) { + this.activeEditor?.commands.toggleFieldAnnotationsFormat('italic', true); + this.updateToolbarState(); + return; + } + let command = item.command; if (command in this.activeEditor.commands) { this.activeEditor.commands[command](argument); this.activeEditor.commands.toggleFieldAnnotationsFormat('italic', true); @@ -559,8 +582,13 @@ export class SuperToolbar extends EventEmitter { * @returns {void} */ toggleUnderline: ({ item, argument }) => { - let command = item.command; + if (this.#isFieldAnnotationSelection()) { + this.activeEditor?.commands.toggleFieldAnnotationsFormat('underline', true); + this.updateToolbarState(); + return; + } + let command = item.command; if (command in this.activeEditor.commands) { this.activeEditor.commands[command](argument); this.activeEditor.commands.toggleFieldAnnotationsFormat('underline', true); @@ -1295,6 +1323,11 @@ export class SuperToolbar extends EventEmitter { view.dispatch(tr); } + #isFieldAnnotationSelection() { + const selection = this.activeEditor?.state?.selection; + return selection instanceof NodeSelection && selection?.node?.type?.name === 'fieldAnnotation'; + } + /** * Cleans up resources when the toolbar is destroyed. * Clears any pending timeouts to prevent callbacks firing after unmount.