Skip to content
Merged
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
21 changes: 10 additions & 11 deletions crates/edit/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1707,16 +1707,14 @@ impl TextBuffer {
}

fn set_cursor_internal(&mut self, cursor: Cursor) {
debug_assert!(
cursor.offset <= self.text_length()
&& cursor.logical_pos.x >= 0
&& cursor.logical_pos.y >= 0
&& cursor.logical_pos.y <= self.stats.logical_lines
&& cursor.visual_pos.x >= 0
&& (self.word_wrap_column <= 0 || cursor.visual_pos.x <= self.word_wrap_column)
&& cursor.visual_pos.y >= 0
&& cursor.visual_pos.y <= self.stats.visual_lines
);
debug_assert!(cursor.offset <= self.text_length());
debug_assert!(cursor.logical_pos.x >= 0);
debug_assert!(cursor.logical_pos.y >= 0);
debug_assert!(cursor.logical_pos.y <= self.stats.logical_lines);
debug_assert!(cursor.visual_pos.x >= 0);
debug_assert!(self.word_wrap_column <= 0 || cursor.visual_pos.x <= self.word_wrap_column);
debug_assert!(cursor.visual_pos.y >= 0);
debug_assert!(cursor.visual_pos.y <= self.stats.visual_lines);
Comment on lines +1710 to +1717
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed these to track down the issue. I kept it this way since it seems better.

self.cursor = cursor;
}

Expand Down Expand Up @@ -2258,7 +2256,8 @@ impl TextBuffer {
{
let cursor = self.cursor;
self.edit_write(if self.newlines_are_crlf { b"\r\n" } else { b"\n" });
self.set_cursor_internal(cursor);
// Can't use `set_cursor_internal` here, because we haven't updated the line stats yet.
self.cursor = cursor;
}

self.edit_end();
Expand Down
75 changes: 35 additions & 40 deletions crates/edit/src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,15 +973,13 @@ impl Tui {
}

match &mut node.content {
NodeContent::Modal(title) => {
if !title.is_empty() {
self.framebuffer.replace_text(
node.outer.top,
node.outer.left + 2,
node.outer.right - 1,
title,
);
}
NodeContent::Modal(title) if !title.is_empty() => {
self.framebuffer.replace_text(
node.outer.top,
node.outer.left + 2,
node.outer.right - 1,
title,
);
}
NodeContent::Text(content) => self.render_styled_text(
inner,
Expand Down Expand Up @@ -2864,39 +2862,36 @@ impl<'a> Context<'a, '_> {
self.set_input_consumed();
} else if self.tui.mouse_state != InputMouseState::None {
match self.tui.mouse_state {
InputMouseState::Left => {
if self.tui.mouse_is_drag {
// We don't need to look up the previous track node,
// since it has a fixed size based on the container size.
let track_rect = Rect {
left: container_rect.right,
top: container_rect.top,
right: container_rect.right + 1,
bottom: container_rect.bottom,
};
if track_rect.contains(self.tui.mouse_down_position) {
if sc.scroll_offset_y_drag_start == CoordType::MIN {
sc.scroll_offset_y_drag_start = sc.scroll_offset.y;
}

let content = prev_container.children.first.unwrap().borrow();
let content_rect = content.inner;
let content_height = content_rect.height();
let track_height = track_rect.height();
let scrollable_height = content_height - track_height;

if scrollable_height > 0 {
let trackable = track_height - sc.thumb_height;
let delta_y =
self.tui.mouse_position.y - self.tui.mouse_down_position.y;
sc.scroll_offset.y = sc.scroll_offset_y_drag_start
+ (delta_y as i64 * scrollable_height as i64
/ trackable as i64)
as CoordType;
}
InputMouseState::Left if self.tui.mouse_is_drag => {
// We don't need to look up the previous track node,
// since it has a fixed size based on the container size.
let track_rect = Rect {
left: container_rect.right,
top: container_rect.top,
right: container_rect.right + 1,
bottom: container_rect.bottom,
};
if track_rect.contains(self.tui.mouse_down_position) {
if sc.scroll_offset_y_drag_start == CoordType::MIN {
sc.scroll_offset_y_drag_start = sc.scroll_offset.y;
}

self.set_input_consumed();
let content = prev_container.children.first.unwrap().borrow();
let content_rect = content.inner;
let content_height = content_rect.height();
let track_height = track_rect.height();
let scrollable_height = content_height - track_height;

if scrollable_height > 0 {
let trackable = track_height - sc.thumb_height;
let delta_y =
self.tui.mouse_position.y - self.tui.mouse_down_position.y;
sc.scroll_offset.y = sc.scroll_offset_y_drag_start
+ (delta_y as i64 * scrollable_height as i64 / trackable as i64)
as CoordType;
}

self.set_input_consumed();
}
}
InputMouseState::Release => {
Expand Down
Loading