kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.52k stars 175 forks source link

Fixing hints when not editing at end of line #722

Open jerbs opened 1 year ago

jerbs commented 1 year ago

Currently, hints are only working correctly when editing at the end of the line. Let me describe the current behaviour using a simple example: The line contains "abcd" and the cursor is at position zero when typing "123". That text has the hint "1234567890_".

1) rustyline displays: 123|abcd{456789} 2) After typing a 4: 1234|abcd{56789} 3) After cursor right: 1234a|bcd{56789} 4) After cursor right: 1234ab|cd{56789} 5) After cursor right: 1234abc|d{56789} 6) After cursor right: 1234abcd|{56789} 7) After cursor right: 1234abcd56789_|

The pipe character indicates the cursor position. The curly braces do contain the hint.

Multiple issues:

This pull request fixes all four issues.

gwenn commented 1 year ago

Could you please provide your Hinter implementation ? Or to say otherwise, are you sure that the issue is in rustyline and not in your hinter ?

jerbs commented 1 year ago

Could you please provide your Hinter implementation ? Or to say otherwise, are you sure that the issue is in rustyline and not in your hinter ?

See https://github.com/jerbs/fsidx for my hinter implementation. The main branch uses to official rustyline. The hint branch uses the forked rustyline with my proposed fix.

gwenn commented 1 year ago

I will do some tests with other similar libraries but for me all of them use hint / auto-suggestion at the end of the line. What you propose is more like auto-completion...