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

Fix prompt_start_row reset to 0 when opening a file without newline in Nushell #688

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/painting/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

/// Returns the available lines from the prompt down
pub fn remaining_lines(&self) -> u16 {
self.screen_height().saturating_sub(self.prompt_start_row)

Check warning on line 85 in src/painting/painter.rs

View check run for this annotation

Codecov / codecov/patch

src/painting/painter.rs#L85

Added line #L85 was not covered by tests
}

/// Sets the prompt origin position and screen size for a new line editor
Expand Down Expand Up @@ -151,14 +151,14 @@
// Marking the painter state as larger buffer to avoid animations
self.large_buffer = required_lines >= screen_height;

// This might not be terribly performant. Testing it out
let is_reset = || match cursor::position() {
Ok(position) => position.1 < self.prompt_start_row,
Ok(position) => position.1.abs_diff(self.prompt_start_row) > 1,
Err(_) => false,
};

Check warning on line 158 in src/painting/painter.rs

View check run for this annotation

Codecov / codecov/patch

src/painting/painter.rs#L154-L158

Added lines #L154 - L158 were not covered by tests

// Moving the start position of the cursor based on the size of the required lines
if self.large_buffer || is_reset() {

Check warning on line 161 in src/painting/painter.rs

View check run for this annotation

Codecov / codecov/patch

src/painting/painter.rs#L161

Added line #L161 was not covered by tests
self.prompt_start_row = 0;
} else if required_lines >= remaining_lines {
let extra = required_lines.saturating_sub(remaining_lines);
Expand Down Expand Up @@ -419,8 +419,8 @@
//
// I assume this is a bug with the position() call but haven't figured that
// out yet.
if let Ok(position) = cursor::position() {
self.prompt_start_row = position.1;

Check warning on line 423 in src/painting/painter.rs

View check run for this annotation

Codecov / codecov/patch

src/painting/painter.rs#L422-L423

Added lines #L422 - L423 were not covered by tests
}
}

Expand Down
Loading