zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
50.5k stars 3.13k forks source link

Keeps the cursor always visible while line scrolling #16507

Open weijarz opened 3 months ago

weijarz commented 3 months ago

Check for existing issues

Describe the feature

If you use the Line-Scroll function, the selected line is preserved - even if it leaves the visible area by scrolling. This is quite annoying. There should be an option to make the cursor always visible.

ref: https://github.com/microsoft/vscode/issues/2091

If applicable, add mockups / screenshots to help present your vision of the feature

No response

bennetbo commented 3 months ago

Sounds like you are talking about #8993? See https://github.com/zed-industries/zed/issues/8993#issuecomment-2000147012

weijarz commented 3 months ago

@bennetbo At vscode, I use this keyboard configuration to solve this problem.

    {
        "key": "ctrl+down",
        "command": "editorScroll",
        "args": {
            "to": "down",
            "by": "line",
            "revealCursor": true
        }
    }

I wish Zed had this option revealCursor as well.

bennetbo commented 3 months ago

Oh I see, you're talking about editor: line up/editor: line down and having the ability to pass an option whether the cursor is moved/revealed when it get's out of the screen bounds. I don't think we have something in place for this right now, but it should be pretty straightforward to add.

If anyone wants to pick this up, the relevant code is here: https://github.com/zed-industries/zed/blob/6c790e2ec6dd433f8ee0d6204e49cbe8caf4446e/crates/editor/src/element.rs#L229

We probably need to add a new field to the LineUp struct, like we do it for e.g. Move Page up (https://github.com/zed-industries/zed/blob/6c790e2ec6dd433f8ee0d6204e49cbe8caf4446e/crates/editor/src/actions.rs#L31)

CrackTC commented 1 month ago

I have these keybindings in zed

"alt-n": ["workspace::SendKeystrokes", "5 ctrl-e"],
"alt-p": ["workspace::SendKeystrokes", "5 ctrl-y"],
"ctrl-e": "vim::LineDown",
"ctrl-y": "vim::LineUp", 

It's strange that while scrolling down using alt-n, zed could reveal the cursor according to the vertical_scroll_margin, but this doesn't happens on alt-p.

TwoClocks commented 1 month ago

Maybe related: vim::LineDown keeps the cursor on the screen, but vim::LineUp lets it scroll off. I think LineDown is correct, and LineUp is a bug.