Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions packages/super-editor/src/components/toolbar/super-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand Down