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

Cursor jumps on :reload-all #4884

Closed
michaelst0 opened this issue Nov 25, 2022 · 10 comments · Fixed by #4901
Closed

Cursor jumps on :reload-all #4884

michaelst0 opened this issue Nov 25, 2022 · 10 comments · Fixed by #4901
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Milestone

Comments

@michaelst0
Copy link

Summary

When I do :reload-all, the content of the window jump. Sometimes the cursor is positioned at the top of what looks like a blank buffer, but scrolling up reveals the contents of the file.

Note that the file I'm looking at has not changed.

Reproduction Steps

I tried this:

  1. hx
  2. Open some file
  3. Do :reload-all

I expected this to happen:

Contents to be reloaded from disk. Cursor remains in current position.

Instead, this happened:

Contents reloaded from disk. Cursor jumps to random(?) position.

Helix log

~/.cache/helix/helix.log
please provide a copy of `~/.cache/helix/helix.log` here if possible, you may need to redact some of the lines

Platform

macOS

Terminal Emulator

kitty

Helix Version

helix 22.08.1 (e6dad96)

@michaelst0 michaelst0 added the C-bug Category: This is a bug label Nov 25, 2022
@michaelst0 michaelst0 changed the title Screen jumps on :reload-all Cursor jumps on :reload-all Nov 25, 2022
@David-Else
Copy link
Contributor

@mangas it seems like reload-all has problems as it is reported to panic too #4878 , could you take a look?

@mangas
Copy link
Contributor

mangas commented Nov 25, 2022

I am not able to replicate this. Can you maybe create an example with a few files where this happens? Or maybe a repo that you were using?

@michaelst0
Copy link
Author

This happens when I edit Go files.

I use gopls, and golines for formatting.

I use Helix at work so I don’t currently have any example files or repos to share. I’ll try putting something together that triggers this that I can share.

@mangas
Copy link
Contributor

mangas commented Nov 25, 2022

awesome, thanks !

@michaelst0
Copy link
Author

michaelst0 commented Nov 25, 2022

I checked out https://github.com/GoogleCloudPlatform/cloud-sql-proxy repo in order to reproduce this bug.

  1. hx
  2. Open cmd/root.go
  3. Split window into left / right
  4. Open internal/proxy/proxy.go in right window
  5. Move cursor in right window to line 35
  6. :reload-all
  7. Contents of right window shift up so that line 35 is now 6 lines from the top of the window

Where to move the cursor in step 5. and what happens at step 7. seem a bit random to me.

I tested this in kitty and iTerm2 and I get the same behaviour in both.

Let me know if you need any more info.

config.toml

theme =  "onelight"

[editor]
rulers = [100]
cursorline = true
color-modes = true

[editor.file-picker]
hidden = false

[editor.indent-guides]
render = true

[editor.cursor-shape]
insert = "bar"
normal = "block"
select = "underline"

[editor.lsp]
auto-signature-help = false

[keys.normal]
"esc" = ":wa"
C-r = ":reload-all"

[keys.insert]
C-p = "signature_help"

languages.toml

[[language]]
name = "python"
language-server = { command = "pyright-langserver", args = ["--stdio"] }
config = ""
formatter = { command = "poetry", args = ["run", "black","-"]}
auto-format = true

[[language]]
name = "go"
formatter = { command = "golines"}
auto-format = true

@mangas
Copy link
Contributor

mangas commented Nov 25, 2022

@mchlstckl I'm unable to replicate this on linux 🤔 @the-mikedavis any ideas?

@gabydd
Copy link
Member

gabydd commented Nov 26, 2022

I wonder if this stems from formatting?

@the-mikedavis
Copy link
Member

I can reproduce:
bug

You need a short enough terminal size to see the jump.

The problem is calling View::ensure_cursor_in_view for all view_ids. View::ensure_cursor_in_view moves the viewport to ensure that the given document's cursor is visible. In the reproduction case, when reloading the right-hand side split, we first ensure that the cursor for root.go (on line 1) is in view, then ensure that the cursor for proxy.go (on line 35) is in view. This shifts the view so that the cursor is at the bottom of the visible viewport (minus scrolloff).

We should only call View::ensure_cursor_in_view if the view is currently looking at the document (view.doc == doc_id). We lazily ensure that the cursor is in view when we switch a view to look at another document in Editor::replace_document_in_view (called from Editor::switch) so it's only necessary to update the view if it's currently focused on the doc.

@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Nov 26, 2022
@the-mikedavis the-mikedavis added this to the 22.11 milestone Nov 26, 2022
@mangas
Copy link
Contributor

mangas commented Nov 26, 2022

@mchlstckl @the-mikedavis can you please test #4901 and let me know if you can still replicate the behavior? I wasn't able to replicate locally but I think this may fix it according to Mike's explanation

@michaelst0
Copy link
Author

I checked out your branch and installed hx from it. I went through the reproduction steps. The window no longer jumps. Looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants