feat(text-editor): add clear method to clear content imperatively#4144
feat(text-editor): add clear method to clear content imperatively#4144jecrapo wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
📝 WalkthroughWalkthroughA new Changesclear imperative API
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-4144/ |
bdb0591 to
d23be29
Compare
Assigning an empty `value` prop only clears the editor when the value changes. Because the editor debounces its `change` event, a consumer's bound value can lag the live document, so assigning `''` when the prop was already `''` is skipped by change detection and leaves the content untouched (for example, clearing the editor immediately after a send). clear empties the editor regardless of the prop's change detection, discarding any pending debounced change. It does not emit a `change` event.
d23be29 to
df4fe99
Compare
Problem
limel-text-editoris a controlled component (it has avalueprop), but assigningvalueonly updates the editor when Stencil detects the prop changed. Because the editor debounces itschangeevent, a consumer's bound value can legitimately lag the live document. That produces a case the prop can't express: clearing the editor by assigning''when the previously rendered prop was already''.The clearest example is a chat-style "send box":
''to clear.''. Since the previously rendered value was already'', the prop goes'' → ''— no change — so the editor never re-renders,@Watch('value')never fires, and the document keeps the sent text on screen.The editor receives no signal at all in this case, so it cannot be fixed reactively from inside the component.
flushPendingChanges()(added in #4128) solved the symmetric read problem for this same use case; this adds the write counterpart.Change
Add an imperative
clear()method tolimel-text-editor(and its ProseMirror adapter) that empties the editor's document regardless of the prop's change detection:changeso it can't fire afterward and resurrect old content;changeevent (the caller cleared it, so no echo / re-entrancy).Consumers that previously needed timing workarounds to clear (e.g. deferring by a frame) can call
await editor.clear()instead.Backwards compatible (additive method only).
Tests
clearresolves, including readonly mode where no adapter is rendered.clearempties content thevalueprop never caught up to; discards the pending change so no stalechangeis emitted; does not emit achangeevent.Summary by CodeRabbit
New Features
clear()method for direct programmatic clearing of editor content, including in scenarios with debounced updates.changeevent.Tests
clear()behavior across default and readonly modes.