Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1975,9 +1975,14 @@ impl Editor {
tracking: bool,
) -> anyhow::Result<bool> {
// log!("Action: {action:?}");
self.last_error = None;
self.actions.push(action.clone());

// Don't clear error on scroll actions to preserve error messages
match action {
Action::ScrollUp | Action::ScrollDown => {}
_ => self.last_error = None,
}

let mut add_to_history = tracking;

match action {
Expand Down Expand Up @@ -2653,7 +2658,7 @@ impl Editor {
if self.vtop >= scroll_lines {
self.vtop -= scroll_lines;
let desired_cy = self.cy + scroll_lines;
if desired_cy <= self.vheight() {
if desired_cy < self.vheight() {
self.cy = desired_cy;
}
self.render(buffer)?;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/render_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl RenderBuffer {
s
}

pub fn diff(&self, other: &RenderBuffer) -> Vec<Change> {
pub fn diff(&self, other: &RenderBuffer) -> Vec<Change<'_>> {
let mut changes = vec![];
for (pos, cell) in self.cells.iter().enumerate() {
if *cell != other.cells[pos] {
Expand Down
36 changes: 32 additions & 4 deletions src/editor/rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,26 @@ impl Editor {
self.update_and_render_overlays(buffer)?;

// Flush changes to terminal
let diff = buffer.diff(&current_buffer);
let mut diff = buffer.diff(&current_buffer);

// If there's an active error, ensure the error line is always included in the diff
// This prevents scrolling artifacts from corrupting the error display
if self.last_error.is_some() {
let error_line = self.size.1 as usize - 1;
let width = self.size.0 as usize;
// Force all cells on the error line to be included in the diff
for x in 0..width {
let pos = error_line * width + x;
if pos < buffer.cells.len() {
diff.push(Change {
x,
y: error_line,
cell: &buffer.cells[pos],
});
}
}
}

self.render_diff(diff)?;

Ok(())
Expand Down Expand Up @@ -909,14 +928,22 @@ impl Editor {

let mut skip_next = false;
for (i, change) in sorted_changes.iter().enumerate() {
let x = change.x;
let y = change.y;

// Skip the bottom-right corner to prevent scrolling
if x == (self.size.0 as usize).saturating_sub(1)
&& y == (self.size.1 as usize).saturating_sub(1)
{
continue;
}

// Skip if this was a padding space after an emoji
if skip_next {
skip_next = false;
continue;
}

let x = change.x;
let y = change.y;
let cell = change.cell;

// Check if this is an emoji followed by a space (padding)
Expand Down Expand Up @@ -1086,7 +1113,8 @@ impl Editor {
let wc = format!("{:<width$}", wc, width = 10);

if let Some(ref last_error) = self.last_error {
let error = format!("{:width$}", last_error, width = self.size.0 as usize);
let clean_error = last_error.replace('\n', " ");
let error = format!("{:width$}", clean_error, width = self.size.0 as usize - 1);
buffer.set_text(0, self.size.1 as usize - 1, &error, style);
} else {
let clear_line = " ".repeat(self.size.0 as usize - 10);
Expand Down
Loading