singerdmx / flutter-quill

Rich text editor for Flutter
https://pub.dev/packages/flutter_quill
MIT License
2.6k stars 840 forks source link

Feature request: scrolling to cursor without requesting focus #2104

Closed Alspb closed 3 months ago

Alspb commented 3 months ago

Is there an existing issue for this?

Use case

Currently the editor doesn't scroll to the cursor/selection set in QuillController without requesting focus.

Proposal

It would be great to be able to scroll to the selection when the editor is open, so that the user starts from the same part of the document he has finished before. Currently it's possible to achieve this by requesting focus. However, in many cases it's convenient to look at the document first, instead of editing it. Moreover, on mobile platforms keyboard appears when focus is on, reducing the editor height, which is also inconvenient when viewing documents.

AtlasAutocode commented 3 months ago

I am currently working on issue 1907 which referenced your issue.

In the current release, you can scroll to the position in the document but there are some gotchas!

How are you trying to set the remembered position? Are you using QuillController TextSelection or are you using ScrollController initialScrollOffset? In QuillEditorConfigurations are you setting autoFocus = true?

If you set autoFocus, it will set the editor to show the current QuillController text selection which is probably at the start of the document - this action prevents ScrollController offset being used. Net effect, you might think that it is not working.

QuillController selection is the offset in characters, ScrollController offset is vertical pixels and not rows.

If you can tell me more about what, and how, you are trying to do it, I may be able to get it working as part of issue 1907.

Alspb commented 3 months ago

Thanks!

I would just like to scroll to a given (remembered) cursor position (in characters) when the editor is open, without requesting focus. I know that it's possible to scroll to offset in pixels, but wouldn't like to use it since this won't work if the offset is saved for portrait orientation, but the user is now in landscape orientation (and vice versa).

AtlasAutocode commented 3 months ago

Don't use scrolling which uses pixels. Use TextSelection when you create the document (or use UpdateSelection). There is also RawEditorState.bringIntoView (TextPos ) which might work for you.

Alspb commented 2 months ago

Use TextSelection when you create the document (or use UpdateSelection).

Do you mean QuillController(..., selection: const TextSelection.collapsed(offset: ...), ... ? Look like it doesn't scroll without explicitly requesting focus.