Repository navigation
[SuperEditor] - Fix: Build only the composing region's component when a composition starts or ends - #3142
[SuperEditor] - Fix: Build only the composing region's component when a composition starts or ends#3142wfeng1 wants to merge 3 commits into
Conversation
…he component that it's in SingleColumnLayoutComposingRegionStyler copied the view model of every component, and set showComposingRegionUnderline on every text component, while a composing region existed. Starting a composition changed the view model of every text component, and ending it changed them back, so the layout built every component of the document twice per composition. A software keyboard on Android composes nearly every word. The styler now copies only the components that the composing region is in, and passes every other one through. Nothing that's drawn changes: a component outside the region has no composing region to underline.
|
This issue seems like it was probably an oversight when composing region underlines were first implemented. So fix seems reasonable. Here's some AI help with implementation:
|
…ing region, and remove the unused node selection code The composing region styler now returns a component's view model as-is, unless the composing region is entirely within that component's node. Only then does it copy the view model, and set its composing region and its underline flag. This replaces the index lookups of the previous commit, and a composing region that spans several nodes, which the styler doesn't underline, no longer rebuilds those nodes' components. The styler no longer computes each node's part of the composing region, which it only logged, so `_computeNodeSelection()` and `_DocumentNodeSelection` are removed.
|
addressed |
| ); | ||
| }); | ||
|
|
||
| testWidgetsOnMobile('a composition ends in', (tester) async { |
There was a problem hiding this comment.
I see a test that mentions "starts in" and one that mentions "ends in". What do these mean? It sounds like you're referring to a composing region that spans multiple nodes, but I'm not sure that's possible WRT how the IME works.
If that is possible, and that's what you're going for, then I'd still break these tests down differently. But I'll wait to hear what you were trying to do.
There was a problem hiding this comment.
I meant starting and ending a composition in one paragraph, not a region across paragraphs. I renamed the tests to “only rebuilds the composing paragraph when a composition starts” and “...ends”.
…n macOS too, and remove the accent test Super Editor only shows the composing underline on macOS, iOS, and Android, so the tests for starting and ending a composition now run on all three. The accent test only repeated the test for starting a composition on macOS, so it's removed.
[SuperEditor] - Fix: Build only the composing region's component when a composition starts or ends
Problem
Every time a composing region starts or ends,
SuperEditorbuilds the component of every node in the document, not only the component of the node that the composing region is in. A software keyboard that composes each word as the user types it (Gboard and Samsung Keyboard on Android, for example) starts and ends a composing region for nearly every word, so each word builds every component twice, and a long document stalls on every word.To reproduce
Minimal, runnable code sample
Cause
While a composing region exists,
SingleColumnLayoutComposingRegionStyler.style()copies the view model of every component (_styler_composing_region.dart:53), and setsshowComposingRegionUnderline = trueon every text component (:101), including the components that the composing region isn't in. When the composing region ends, the styler returns the view models as they came (:42), so the flag goes back tofalse.showComposingRegionUnderlineis part ofTextComponentViewModel's==(text.dart:675), so the presenter reports every text component as changed, and the layout builds every component, both when a composing region starts and when it ends.Change
The styler returns a component's view model as it came, unless the composing region is entirely within that component's node. Only then does it copy the view model, and set its composing region and its underline flag. Every other component keeps the view model that it came with, so it stays equal to its last one, and isn't built again. Nothing that's drawn changes: a component that the composing region isn't in had no composing region to underline.
A composing region that spans several nodes still isn't underlined, as before (the styler's existing TODO), and it now doesn't build those nodes' components either.
The styler also no longer works out each node's part of the composing region, which it only logged, so
_computeNodeSelection()and_DocumentNodeSelectionare removed.Measurements
Starting or ending a composing region, in profile mode on macOS (Apple M3 Max, Flutter 3.44.9), in a document of Frankenstein's paragraphs (the median of 15 changes; the editor's work, then the frame):
The time that's left grows with the document because every change still restyles every component, which is a separate issue.
Breaking changes
None. No public API changes.
Tests
ime_composing_region_test.dartgains two tests, run on macOS, iOS and Android, the platforms with the composing underline. They count the components that are built, by node, through the publiccomponentBuilders:Both fail on
main(every component is built) and pass with this change. The wholesuper_editorsuite passes locally on Flutter 3.44.9.