• LongCatIsLooong's avatar
    Changing `TextPainter.getOffsetForCaret` implementation to remove the logarithmic search (#143281) · 3538e4c7
    LongCatIsLooong authored
    The behavior largely remains the same, except:
    
    1. The EOT cursor `(textLength, downstream)` for text ending in the opposite writing direction as the paragraph is now placed at the visual end of the last line. 
      For example, in a LTR paragraph, the EOT cursor for `aA` (lowercase for LTR and uppercase for RTL) is placed to the right of the line: `aA|` (it was `a|A` before). 
      This matches the behavior of most applications that do logical order arrow key navigation instead of visual order navigation. 
      And it makes the navigation order consistent for `aA\naA`:
    ```
      |aA    =>  aA|  => aA|  => aA  => aA   => aA 
       aA        aA      aA     |aA     aA|     aA|     
       (1)       (2)     (3)    (4)    (5)      (6)
    ```
    This is indeed still pretty confusing as (2) and (3), as well as (5) and (6) are hard to distinguish (when the I beam has a large width they are actually visually distinguishable -- they use the same anchor but one gets painted to the left and the other to the right. I noticed that emacs does the same). 
    But logical order navigation will always be confusing in bidi text, in one way or another.
    
    Interestingly there are 3 different behaviors I've observed in chrome:
    - the chrome download dialog (which I think uses GTK text widgets but not sure which version) gives me 2 cursors when navigating bidi text, and 
    - its HTML fields only show one, and presumably they place the I beam at the **trailing edge** of the character (which makes more sense for backspacing I guess). 
    - On the other hand, its (new) omnibar seems to use visual order arrow navigation
    
    Side note: we may need to update the "tap to place the caret here" logic to handle the case where the tap lands outside of the text and the text ends in the opposite writing direction. 
    
    2. Removed the logarithmic search. The same could be done using the characters package but when glyphInfo tells you about the baseline location in the future we probably don't need the `getBoxesForRange` call. This should fix https://github.com/flutter/flutter/issues/123424.
    
    ## Internal Tests
    
    This is going to change the image output of some internal golden tests. I'm planning to merge https://github.com/flutter/flutter/pull/143281 before this to avoid updating the same golden files twice for invalid selections.
    3538e4c7
Name
Last commit
Last update
.github Loading commit data...
.vscode Loading commit data...
bin Loading commit data...
dev Loading commit data...
examples Loading commit data...
packages Loading commit data...
.ci.yaml Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CODEOWNERS Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
CONTRIBUTING.md Loading commit data...
LICENSE Loading commit data...
PATENT_GRANT Loading commit data...
README.md Loading commit data...
TESTOWNERS Loading commit data...
analysis_options.yaml Loading commit data...
dartdoc_options.yaml Loading commit data...
flutter_console.bat Loading commit data...