Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Scroll to ensure the cursor is visible #965

Open
saif-ellafi opened this issue Nov 9, 2024 · 2 comments
Open

[FR] Scroll to ensure the cursor is visible #965

saif-ellafi opened this issue Nov 9, 2024 · 2 comments
Labels

Comments

@saif-ellafi
Copy link
Contributor

Description

Hi all,

I am having a hard time having the editor scroll to ensure the cursor is visible. In smartphones, when the keyboard pops up, the cursor ends up under the keyboard, and users have to manually scroll down (or type something) in order to bring themselves to the cursor.

Any ideas?

Impact

Smartphone users of rich editors!

Additional Context

No response

@LucasXu0 LucasXu0 added the p0 label Dec 11, 2024
@LucasXu0
Copy link
Collaborator

@saif-ellafi The editor will auto-scroll up to ensure the cursor is visible. Did you limit the size of the editor or use full-screen mode?

@saif-ellafi
Copy link
Contributor Author

@LucasXu0 - thanks for taking a look
I am using the RichEditor inside a Dialog, if that helps at all. It is currently expanded to the bottom of the screen to the remaining space of that Dialog.

Currently I am kinda happy with the following workaround:

    _focusNode = FocusNode();
    if (Platform.isAndroid || Platform.isIOS) {
      _focusNode.addListener(
        () {
          if (_focusNode.hasFocus) {
            // delay 500ms
            Future.delayed(Duration(milliseconds: 500), () {
              // check if screen keyboard is visible, if not, return
              if (MediaQuery.of(context).viewInsets.bottom == 0) {
                return;
              }
              var editorState = widget.editorState;
              var selection = editorState.selection;
              if (selection == null) {
                return;
              }
              var node = editorState.getNodeAtPath(selection.start.path);
              if (node == null) {
                return;
              }
              var indexOfNode = editorState.document.root.children.indexOf(node);
              if(indexOfNode == -1) {
                indexOfNode = editorState.document.root.children.indexOf(node.parent!);
                if(indexOfNode == -1) {
                  indexOfNode = editorState.document.root.children.indexOf(node.parent!.parent!);
                  if (indexOfNode == -1) {
                    return;
                  }
                }
              }
              _editorScrollController.itemScrollController.scrollTo(index: indexOfNode, duration: Duration(milliseconds: 500));
            });
          }
        },
      );
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants