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

Issues with cursor positioning and scroll behavior during dispatch #1473

Open
devleejb opened this issue Nov 17, 2024 · 4 comments
Open

Issues with cursor positioning and scroll behavior during dispatch #1473

devleejb opened this issue Nov 17, 2024 · 4 comments

Comments

@devleejb
Copy link

Describe the issue

I'm developing the collaborative markdown editor with codemirror.

video.mp4

However, there are following issues.

  1. While dragging with the mouse and executing the following code, the starting point of the drag moves to the topmost position. (Dragging with the keyboard arrow keys works fine.)
  2. If the following code is executed during text input, there are intermittent instances where the scroll jumps to the top and then returns to the current position.
view.dispatch({
    changes: { from: 0, to: view.state.doc.length, insert: text.toString() },
    annotations: [Transaction.remote.of(true)],
    selection: {
        anchor: ...,
        head: ...,
    }
});

Browser and platform

Chrome, macOS (But, maybe all browsers and platforms)

Reproduction link

https://github.com/devleejb/codemirror-dispatch-test

@marijnh
Copy link
Member

marijnh commented Nov 17, 2024

If you replace the entire document, that will reset the editor's scroll position. In most cases, you really want to make the most minimal change possible, rather than a full reset like that. It sounds like you're not actually loading a new document, if you expect the old cursor/scroll position to still make sense, but only modifying the current document.

@devleejb
Copy link
Author

In most cases, I apply only the minimal changes possible. However, due to network delays, there are times when the entire document is replaced. At those moments, I also update the cursor position using the selection field. Is it expected behavior that the cursor still moves to the very top, even when the selection field is provided?

@marijnh
Copy link
Member

marijnh commented Nov 18, 2024

The selection field sets the cursor, so no, that shouldn't be moving to the top. The document scroll position, though, will move, if all content is deleted and re-inserted.

@devleejb
Copy link
Author

But, it seems that there are instances where the scroll jumps to the top and then returns to the current position.

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

No branches or pull requests

2 participants