-
Hi! I'd like to register a listener only when text has been inserted. That would be equivalent to checking if I tried using The best I could come up with so far is a combination of Is there a better way to do this? Edit: another way I found is using const contentSize = editorState.read(() => $getRoot().getTextContentSize());
const prevContentSize = prevEditorState.read(() => $getRoot().getTextContentSize());
contentSize <= prevContentSize; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The way you describe above is correct – comparing the text before and after. The reason why So the most consistent way is to use |
Beta Was this translation helpful? Give feedback.
The way you describe above is correct – comparing the text before and after. The reason why
event.inputType
is unreliable is because it's not always fired for all text inputs. For example, it's not guaranteed to fire for composition, and in most cases we actually let the browser do the default thing and read the DOM to ensure cross-browser consistency (especially on Android). Another thing to note, is that the text might not have been inserted the same way – if a transform changes the input or blocks it.So the most consistent way is to use
editor.registerTextContentListener()
and store the previous value, so you can easily compare.registerTextContentListener
will only fire if the text c…