From b2231e520c2bb029b30d70d469255454c1aa9cc7 Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Wed, 11 Feb 2026 13:09:56 +0100 Subject: [PATCH] :books: Add best practices to text editor README.md --- frontend/text-editor/README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/frontend/text-editor/README.md b/frontend/text-editor/README.md index 705c2277bd..35281f8647 100644 --- a/frontend/text-editor/README.md +++ b/frontend/text-editor/README.md @@ -82,6 +82,26 @@ The `TextEditor` contains a series of references to DOM elements, one of them is `ChangeController` is called by the `TextEditor` instance everytime a change is performed on the content of the `contenteditable` element. +### Best practices + +#### Use `isType` functions + +Instead of handling elements by their properties like this: + +```javascript +if (element.tagName === "SPAN") { + ... +} +``` + +Use functions like `isParagraph`, `isTextSpan` or `isLineBreak`: + +```javascript +if (isTextSpan(element)) { + ... +} +``` + ### Events - `change`: This event is dispatched every time a change is made in the editor. All changes are debounced to prevent dispatching too many change events. This event is also dispatched when there are pending change events and the user blurs the textarea element.