nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
547 stars 152 forks source link

Cursor slowdown when pressing left/right arrows and there is a lot of text in the prompt #795

Open rendarz opened 5 months ago

rendarz commented 5 months ago

I have just an hello world project with few lines of code:

use reedline::{DefaultPrompt, DefaultPromptSegment, Reedline, Signal};

fn main() {
    let mut line_editor = Reedline::create();
    let prompt = DefaultPrompt::new(DefaultPromptSegment::Basic("ok".to_string()), DefaultPromptSegment::Empty);

    loop {
            let sig = line_editor.read_line(&prompt);
            match sig {
                Ok(Signal::Success(buffer)) => {
                    println!("We processed: {}", buffer);
                 },
                Ok(Signal::CtrlD) | Ok(Signal::CtrlC) => {
                    println!("\nAborted!");
                    break;
                 },
                 _ => { },
             }
         }
    }   
}

When I run this very simple project, with a very short text prompt, I have noticed that when I press the left or right arrows, there is some kind of delay - internally - that makes the cursor not responsive! Indeed, if I leave the arrow keys, I noticed that the cursor is still moving, and doesn't stop immediately. Again, it's like there is a little and subtle delay, but very annoying. I've attached a video to show this, as you can see from the video, when I leave my finger from the arrow key, the cursor is still moving... NOTE: This DOES NOT happen with other command-lines prompt crates.

https://github.com/nushell/reedline/assets/12814431/c77d4c7d-5766-4d83-ad85-0fd1110cdee1

fdncred commented 5 months ago

Maybe I'm missing the point here, but it looks like the repeat setting for your keyboard is very fast. If you hold in a key, it typically repeats, like it did when you held in the l key. That repeat speed is usually controllable. If you hold it in and reedline hears 100 left repeats before you release the button, I'm not sure how to tell it, "I'm just kidding. I don't want 100, I only want 5.", or however many.

rendarz commented 5 months ago

Maybe I'm missing the point here, but it looks like the repeat setting for your keyboard is very fast. If you hold in a key, it typically repeats, like it did when you held in the l key. That repeat speed is usually controllable. If you hold it in and reedline hears 100 left repeats before you release the button, I'm not sure how to tell it, "I'm just kidding. I don't want 100, I only want 5.", or however many.

Hi, yes my keyboard repeat is fast, that's a fact, but it doesn't mean the crate hasn't a bug... when I release my arrow key the cursor should stop immediately, like it happens with EVERTHING else, console, vim, emacs, terminal, even LibreOffice, or gedit, or even the competing rustyline crate! Trust me, there is something wrong. Why are left and right arrows so unnaturally lagged? I think it's worth investigating.