🐛 Fix text editor fills not being updated

This commit is contained in:
Aitor Moreno
2026-02-11 12:06:24 +01:00
parent d991d59852
commit 755d720b34
3 changed files with 25 additions and 35 deletions

View File

@@ -508,12 +508,12 @@
ptk/EffectEvent
(effect [_ state _]
(when (features/active-feature? state "text-editor/v2")
(let [instance (:workspace-editor state)
styles (some-> (editor.v2/getCurrentStyle instance)
(styles/get-styles-from-style-declaration :removed-mixed true)
((comp update-node-fn migrate-node))
(styles/attrs->styles))]
(editor.v2/applyStylesToSelection instance styles)))))))
(when-let [instance (:workspace-editor state)]
(let [styles (some-> (editor.v2/getCurrentStyle instance)
(styles/get-styles-from-style-declaration :removed-mixed true)
((comp update-node-fn migrate-node))
(styles/attrs->styles))]
(editor.v2/applyStylesToSelection instance styles))))))))
;; --- RESIZE UTILS
@@ -782,12 +782,12 @@
ptk/EffectEvent
(effect [_ state _]
(when (features/active-feature? state "text-editor/v2")
(let [instance (:workspace-editor state)
attrs-to-override (some-> (editor.v2/getCurrentStyle instance)
(styles/get-styles-from-style-declaration))
overriden-attrs (merge attrs-to-override attrs)
styles (styles/attrs->styles overriden-attrs)]
(editor.v2/applyStylesToSelection instance styles))))))
(when-let [instance (:workspace-editor state)]
(let [attrs-to-override (some-> (editor.v2/getCurrentStyle instance)
(styles/get-styles-from-style-declaration))
overriden-attrs (merge attrs-to-override attrs)
styles (styles/attrs->styles overriden-attrs)]
(editor.v2/applyStylesToSelection instance styles)))))))
(defn update-all-attrs
[ids attrs]

View File

@@ -326,9 +326,7 @@ export class TextEditor extends EventTarget {
* @param {FocusEvent} e
*/
#onBlur = (e) => {
if (!this.isEmpty) {
this.#changeController.notifyImmediately();
}
this.#changeController.notifyImmediately();
this.#selectionController.saveSelection();
this.dispatchEvent(new FocusEvent(e.type, e));
};
@@ -685,7 +683,7 @@ export function createRootFromString(string) {
* Returns true if the passed object is a TextEditor
* instance.
*
* @param {TextEditor} instance
* @param {*} instance
* @returns {boolean}
*/
export function isTextEditor(instance) {
@@ -702,8 +700,7 @@ export function isEmpty(instance) {
if (isTextEditor(instance)) {
return instance.isEmpty;
}
return null;
// throw new TypeError('Instance is not a TextEditor');
throw new TypeError('Instance is not a TextEditor');
}
/**
@@ -718,7 +715,6 @@ export function getRoot(instance) {
return instance.root;
}
return null;
// throw new TypeError("Instance is not a TextEditor");
}
/**
@@ -731,10 +727,9 @@ export function getRoot(instance) {
export function setRoot(instance, root) {
if (isTextEditor(instance)) {
instance.root = root;
// return instance;
return instance;
}
return instance;
// throw new TypeError("Instance is not a TextEditor");
throw new TypeError("Instance is not a TextEditor");
}
/**
@@ -759,8 +754,7 @@ export function getCurrentStyle(instance) {
if (isTextEditor(instance)) {
return instance.currentStyle;
}
// throw new TypeError("Instance is not a TextEditor");
return null;
throw new TypeError('Instance is not a TextEditor');
}
/**
@@ -775,8 +769,7 @@ export function applyStylesToSelection(instance, styles) {
if (isTextEditor(instance)) {
return instance.applyStylesToSelection(styles);
}
// throw new TypeError("Instance is not a TextEditor");
return null;
throw new TypeError('Instance is not a TextEditor');
}
/**
@@ -790,8 +783,7 @@ export function dispose(instance) {
if (isTextEditor(instance)) {
return instance.dispose();
}
// throw new TypeError("Instance is not a TextEditor");
return null;
throw new TypeError('Instance is not a TextEditor');
}
export default TextEditor;

View File

@@ -1969,11 +1969,9 @@ export class SelectionController extends EventTarget {
setTextSpanStyles(textSpan, newStyles);
}
}
return this.#notifyStyleChange();
// If the startContainer and endContainer are different
// then we need to iterate through those nodes to apply
// the styles.
// If the startContainer and endContainer are different
// then we need to iterate through those nodes to apply
// the styles.
} else if (startNode !== endNode) {
const safeGuard = new SafeGuard("applyStylesTo");
safeGuard.start();
@@ -2022,12 +2020,12 @@ export class SelectionController extends EventTarget {
}
// We've reached the final node so we can return safely.
if (this.#textNodeIterator.currentNode === expectedEndNode) return;
if (this.#textNodeIterator.currentNode === expectedEndNode)
break;
this.#textNodeIterator.nextNode();
} while (this.#textNodeIterator.currentNode);
}
return this.#notifyStyleChange();
}