visual-space / visual-editor

Rich text editor for Flutter based on Delta format (Quill fork)
MIT License
290 stars 46 forks source link

[Mobile] Text Selection only preserves the last boundary update, all previous updates are lost during the same session #67

Closed adrian-moisa closed 2 years ago

adrian-moisa commented 2 years ago

My issue is about [Android] on Quill Version 5.03 read only editor with enableinteractiveselection set to true

I have tried running example directory successfully before creating an issue here.

Issue Description and steps to reproduce:

Given text "... abcdefghijklmn ...", follow the following steps:

long press on character e, now text becomes abcdEfghijklmn ... [correct so far] extend the starting boundary from before e to before d, now text becomes abcDEfghijklmn ... [correct so far] extend the ending boundary from after e to after f, now text becomes abcdEFghijklmn ... [incorrect] Desired behavior

should produce abcDEFghijklmn ... after step 3.

Analysis

The problem could be fixed in either

widgets/controller.dart [line 326] _updateSelection(textSelection, source) method widgets/text_selection.dart [line 517] _handleDragUpdate(details) changes to the text selection is originally generated in _handleDragUpdate, however when newSelection is generated, in line 531 and/or line 539, it does not take into account of the old selection's value because by the time execution reaches 529, the original value in widget.selection is already overwritten. So even though line 531/539 APPEARS to take into account of the old value on the supposedly 'not updated' boundary,

When the inaccurate newSelection is passed downstream at line 554, unfortuntely the important information of _TextSelectionHandlePosition is forever lost, hence controller.dart _updateSelection(textSelection, source) method does not have enough information at this stage to merge old and not-so-accurate-new-value into the correct new value at line 326@controllder.dart.

Furthermore, I am not sure about the rationale behind line 327 to 331 in controller.dart _updateSelection method void _updateSelection(TextSelection textSelection, ChangeSource source) { _selection = textSelection; final end = document.length - 1; _selection = selection.copyWith( baseOffset: math.min(selection.baseOffset, end), extentOffset: math.min(selection.extentOffset, end));

simply by static analysis, at this stage the aforemetioned lines is just equivalent to _selection = textSelection;

I propose either directly produce the correct newSelection value in text_selection.dart or modify the api to accomodate passing _TextSelectionHandlePosition flag info downstream so that _updateSelection in controller.dart can reconstruct the correct final value.

Original issue: https://github.com/singerdmx/flutter-quill/issues/865

Join on discord to get advice and help or follow us on YouTube Visual Coding to learn more about the architecture of Visual Editor and other Flutter apps.

adrian-moisa commented 2 years ago

Closed the issue, could not clearly understand what the reporter wanted.