Skip to content

fix: prompt glitch when resizing with cursor in a multiline command - #898

Merged
fdncred merged 3 commits into
nushell:mainfrom
blindFS:prompt_start_row
Jul 11, 2025
Merged

fdncred merged 3 commits into
nushell:mainfrom
blindFS:prompt_start_row

Conversation

@blindFS

@blindFS blindFS commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

Fixes a bug overlooked in #841 (forgot that the before_cursor string could have newlines in it too).

Before:

Screen.Recording.2025-03-26.at.8.46.50.PM.mov

After: stays in the same row.

@blindFS
blindFS force-pushed the prompt_start_row branch from 3c92c73 to cee245d Compare July 11, 2025 10:07
@fdncred

fdncred commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

Thanks

fdncred added a commit to nushell/nushell that referenced this pull request Jul 11, 2025
# Description

This updates to the latest reedline 405299b to include
nushell/reedline#898 for dogfooding.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
Comment thread src/painting/painter.rs
Comment on lines 217 to +230
self.prompt_height = lines.prompt_lines_with_wrap(screen_width) + 1;
let lines_before_cursor = lines.required_lines(screen_width, true, None);

// Handle resize for multi line prompt
// Calibrate prompt start position for multi-line prompt/content before cursor. Check issue #841/#848/#930
if self.just_resized {
self.prompt_start_row = self.prompt_start_row.saturating_sub(
(lines.prompt_str_left.matches('\n').count()
+ lines.prompt_indicator.matches('\n').count()) as u16,
);
self.prompt_start_row = self
.prompt_start_row
.saturating_sub(lines_before_cursor - 1);
self.just_resized = false;
}

// Lines and distance parameters
let remaining_lines = self.remaining_lines();
let required_lines = lines.required_lines(screen_width, menu);
let required_lines = lines.required_lines(screen_width, false, menu);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 217, 218, and 230 share quite a few common computations that hold potential for improving responsiveness.

@fdncred

fdncred commented Jul 11, 2025

Copy link
Copy Markdown
Contributor

I'm not sure whether it is with this PR or not, but I've seen the resizing Windows Terminal to the right works but resizing to the left eats up one line per resize. Here's a quick gif.
resize-glitch

@blindFS

blindFS commented Jul 11, 2025

Copy link
Copy Markdown
Contributor Author

@fdncred Seems different terminal apps behave slightly differently on wrapping texts, I can't reproduce it on my machine.

I'd like to know some details:

  1. Does expanding to the right (by dragging the right boundary) also eat up history?
  2. Does it have something to do with the right prompt? What if it's empty or $env.config.render_right_prompt_on_last_line = true?

@fdncred

fdncred commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor

Seems different terminal apps behave slightly differently on wrapping texts

I'm not surprised. I haven't tested this on Linux or MacOS yet.

Does expanding to the right (by dragging the right boundary) also eat up history?

Yes, and sometimes more than one line at a time. I just had it jump half the width of the screen while expanding from the right side more to the right. Dragging the right boundary towards the left just makes text wrap and doesn't have the same effect.

Does it have something to do with the right prompt? What if it's empty or $env.config.render_right_prompt_on_last_line = true?

It could. My render_right_prompt_on_last_line is set to false. I use the oh-my.nu script in nu_scripts. This is my prompt configuration in config.nu.

# prompt
use modules\prompt\oh-my.nu git_prompt
$env.PROMPT_COMMAND = {|| (git_prompt).left_prompt }
$env.PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt }
$env.PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) { $"(ansi green_bold)\n❯ (ansi reset)" } else { $"(ansi red_bold)\n❯ (ansi reset)" } }
$env.TRANSIENT_PROMPT_COMMAND = ""
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = {|| (git_prompt).right_prompt }
$env.TRANSIENT_PROMPT_INDICATOR = {|| if ($env.LAST_EXIT_CODE == 0) { $"(ansi light_yellow_bold)❯ (ansi reset)" } else { $"(ansi light_red_bold)❯ (ansi reset)" } }
$env.PROMPT_MULTILINE_INDICATOR = {|| $"(ansi -e {fg: '#CB4B16'})(char -u '276f')(ansi -e {fg: '#CACA02'})(char -u '276f')(ansi -e {fg: '#4E9A06'})(char -u '276f')(ansi reset)(char space)" }

@blindFS

blindFS commented Jul 11, 2025 •

Copy link
Copy Markdown
Contributor Author

According to my knowledge, It's more buggy when render_right_prompt_on_last_line is set to false, #897 .
But what I have experienced is opposite to your gif, i.e. prompt duplication.

If the bug requires a non-empty right prompt text, it probably has nothing to do with this PR, not so sure.

I mean theoretically, this is a follow-up fix for some edge cases if we persist how we handle prompt positioning while resizing:

  1. get cursor position
  2. rewinds back to prompt starting point according to the content between them (right prompt is ignored here, maybe that's the problem)

This PR fixes some imprecise calculations of step 2.
However it seems this whole plan is not perfect, take #897 as a counter example.

collinmurch pushed a commit to collinmurch/reedline that referenced this pull request Jul 30, 2025
…ushell#898)

* fix: prompt glitch when resizing with cursor in a multiline command

* fix: considering line wraps

* fix: clippy
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Aug 25, 2025
# Description

This updates to the latest reedline 405299b to include
nushell/reedline#898 for dogfooding.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use toolkit.nu; toolkit test stdlib"` to run the
tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
benvansleen added a commit to benvansleen/reedline that referenced this pull request Oct 26, 2025
* fix: prompt glitch when resizing with cursor in a multiline command (nushell#898)

* fix: prompt glitch when resizing with cursor in a multiline command

* fix: considering line wraps

* fix: clippy

* Bump version to `0.41.0` (nushell#936)

* Protect against invalid suggestion spans (nushell#915)

* Protect against invalid suggestion spans

* Protect against start > end

* feat: Builder option to immediately accept input (nushell#933)

* feat: Option to immediately accept input

* chore: PR feedback

* feat: add `ViChangeMode` event (nushell#932)

* feat: add `ViChangeMode` event

* fix: use `FromStr` trait

* fix: undo unused change

* fix: clippy

* Fix `mismatched_lifetime_syntaxes` (nushell#947)

From Rust 1.89.0 on this lints.
https://blog.rust-lang.org/2025/08/07/Rust-1.89.0/#mismatched-lifetime-syntaxes-lint

* Fix missing import in README.md (nushell#942)

Co-authored-by: sholderbach <[email protected]>

* fix: dislocation of cursor after previous_history navigation to a multiline entry (nushell#899)

* bumping version to 42 (nushell#949)

Co-authored-by: Jack Wright <[email protected]>

* Bump `rusqlite` to 0.37 (nushell#950)

* feat: make columnar menu traversal direction configurable (nushell#951)

* Make columnar menu traversal direction configurable

* Add tests for columnar menu selection position updates

* Apply changes based on review

* Upgrade GitHub Actions and Rust toolchain versions (nushell#954)

* Upgrade GitHub Actions and Rust toolchain versions

* Update .github/workflows/ci.yml

* Vi mode text objects for word, WORD, brackets and quotes (nushell#939)

* Addd initial change inner and around word text objects and handle whitespace

Note a buffer full of whitespace is not properly considered and still
causing incorrect behaviour. TODO fix this.

* Renaming functions and fix default value of current_whitespace_range_start

* Rename cut/yank inside enums and methods to cut/yank inside pair and add general yank/cut range methods

* Use TextObject enum instead of passing through the character

* WIP: Add quote and bracket text objects and add jumping if not inside objects

* Add my own methods for finding matching pair and jumping

* Fix bugs in new function to get matching pair range and it's finish features

- Now handles jumps to next open/close or equal symbol pairs if not in a
pair already
- Searching only on current line for equal symbol pairs e.g. quotes
- Correctly handles graphemes

* Simplify heirarchy of pair range finding functions

- Refactor the structure of the methods to get ranges, don't need to
pass in depth unecessarily, high level functions don't require cursor
passed in.
- Now two seperate functions for ranges, one "next" and one "current"
range that gets you either the range inside next text object or inside
current one depending on position of cursor.
- Finilise logic to correctly handle graphemes (not byte sized chars)

TODO Update unit tests

* Refactoring range functions and tidy up/extend unit test cases and coverage

* More refactoring

- Improve some text object ranges to use iterators rather than complex
logic
- Clean up documentation, add consts etc
- Look through and refactor some editor functions

* Move text object range methods into line_buffer from editor

* Combine line_buffer quote and pair text object functions into generic and rewrite a lot of doc strings

* Testing for quote and bracket text object functions in editor.rs

* Whitespace

* Rework unit tests for new function structure

* Remove angle brackets from b text object

* Rename yank text object functions to copy

* Add bracket test cases to range_inside_next_pair_in_group unit tests

* Add more detailed unicode safety tests

* Fix display enum string for renamed enums

* Unicode and overflow/underflow safety when expanding text object ranges

* Pass through matching pair group const for quote and bracket text object functions

* Rename yank_range -> copy_range for consistency with other methods

* Remove unecessary guard clause from expand_range_to_include_pair

* Correct display string for CutInsidePair

* Make text object types public (nushell#957)

* Make TextObject, TextObjectScope and TextObjectType public

* Correct CopyInsidePair and CopyAroundPair EditType to NoOp

* fix: dislocation of cursor during history navigation (nushell#959)

* fix: dislocation of cursor during history navigation

* test: new test case by Claude Sonnet

* simplify

* Fix typos (nushell#962)

* Bump version for `0.43.0` release (nushell#961)

* Fix shift selection in vi (insert) & emacs mode (nushell#927)

* Add match_indices field to Suggestion (nushell#798)

* Add match_indices field to Suggestion

Make columnar_menu use match indices

Make ide menu use match indices

Add fuzzy completions example

Test style_suggestion

Make doctests in default.rs pass

Highlight entire graphemes

Extract ANSI escapes from strings to apply match highlighting

Fix clippy lint for fuzzy completion example

Shut the typo checker up

Use existing variable `escape`

Copy regex from parse-ansi crate

* replace LazyLock with lazy_static that works with Rust 1.63.0 (#2)

* Homegrown ANSI parser

Fix padding for columnar menu

Highlight substring matches too by default

Simplify (?) columnar menu

* Fix clippy lints after rebase

* Use get_match_indices helper

* Stop using 'fo' because it's a typo? Fo shizzle.

* Use to_string() instead of as_str()

* Style entire suggestion same color

* RESET after suggestion

---------

Co-authored-by: Divanshu Grover <[email protected]>

* fix bashism parsing (nushell#958)

* refactor: use crossterm `supports_keyboard_enhancement` once when KittyProtocolGuard is initialized (nushell#920)

Co-authored-by: Pierre POLLET <[email protected]>

---------

Co-authored-by: zc he <[email protected]>
Co-authored-by: Stefan Holderbach <[email protected]>
Co-authored-by: Yash Thakur <[email protected]>
Co-authored-by: Stuart Carnie <[email protected]>
Co-authored-by: Daniel Bonofiglio <[email protected]>
Co-authored-by: Daniel del Castillo <[email protected]>
Co-authored-by: Jack Wright <[email protected]>
Co-authored-by: Jack Wright <[email protected]>
Co-authored-by: Piepmatz <[email protected]>
Co-authored-by: simonborje <[email protected]>
Co-authored-by: Darren Schroeder <[email protected]>
Co-authored-by: JonLD <[email protected]>
Co-authored-by: Collin Murch <[email protected]>
Co-authored-by: Divanshu Grover <[email protected]>
Co-authored-by: migraine-user <[email protected]>
Co-authored-by: PtiBouchon <[email protected]>
Co-authored-by: Pierre POLLET <[email protected]>
@blindFS
blindFS deleted the prompt_start_row branch November 15, 2025 15:25
kronberger-droid pushed a commit to skull-squadron/reedline that referenced this pull request Jun 1, 2026
…ushell#898)

* fix: prompt glitch when resizing with cursor in a multiline command

* fix: considering line wraps

* fix: clippy
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

Successfully merging this pull request may close these issues.

2 participants