Update to latest cosmic-text

This commit is contained in:
Jeremy Soller 2025-09-07 19:45:52 -06:00
parent 7d11d67290
commit 1e2424861d
No known key found for this signature in database
GPG key ID: 670FDFB5428E05CA
3 changed files with 670 additions and 333 deletions

954
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -56,6 +56,7 @@ impl EditorTab {
"",
&attrs,
Shaping::Advanced,
None,
);
let editor = SyntaxEditor::new(
@ -134,19 +135,26 @@ impl EditorTab {
// Store the entire operation as a single change for undo
editor.start_change();
// Grab everything in the buffer
let cursor_start: Cursor = cosmic_text::Cursor::new(0, 0);
let cursor_end = editor.with_buffer(|buffer| {
let last_line = buffer.lines.len().saturating_sub(1);
cosmic_text::Cursor::new(last_line, buffer.lines.get(last_line).map(|line| line.text().len()).unwrap_or(0))
cosmic_text::Cursor::new(
last_line,
buffer
.lines
.get(last_line)
.map(|line| line.text().len())
.unwrap_or(0),
)
});
// Replace everything in the buffer with the content from disk
editor.delete_range(cursor_start, cursor_end);
editor.insert_at(cursor_start, &file_content, None);
editor.set_cursor(cursor_start);
editor.finish_change();
editor.set_changed(false);
}

View file

@ -1207,35 +1207,16 @@ where
}
Event::Mouse(MouseEvent::WheelScrolled { delta }) => {
if let Some(_p) = cursor_position.position_in(layout.bounds()) {
match delta {
let pixels = match delta {
ScrollDelta::Lines { x: _, y } => {
//TODO: this adjustment is just a guess!
state.scroll_pixels = 0.0;
let lines = (-y * 6.0) as i32;
if lines != 0 {
editor.action(Action::Scroll { lines });
}
status = Status::Captured;
}
ScrollDelta::Pixels { x: _, y } => {
//TODO: this adjustment is just a guess!
state.scroll_pixels -= y * 6.0;
let mut lines = 0;
let metrics = editor.with_buffer(|buffer| buffer.metrics());
while state.scroll_pixels <= -metrics.line_height {
lines -= 1;
state.scroll_pixels += metrics.line_height;
}
while state.scroll_pixels >= metrics.line_height {
lines += 1;
state.scroll_pixels -= metrics.line_height;
}
if lines != 0 {
editor.action(Action::Scroll { lines });
}
status = Status::Captured;
-y * metrics.line_height
}
}
ScrollDelta::Pixels { x: _, y } => y,
};
editor.action(Action::Scroll { pixels });
status = Status::Captured;
}
}
_ => (),
@ -1283,7 +1264,6 @@ pub struct State {
editor_offset_x: Cell<i32>,
is_focused: bool,
scale_factor: Cell<f32>,
scroll_pixels: f32,
scrollbar_v_rect: Cell<Rectangle<f32>>,
scrollbar_h_rect: Cell<Option<Rectangle<f32>>>,
handle_opt: Mutex<Option<image::Handle>>,
@ -1299,7 +1279,6 @@ impl State {
editor_offset_x: Cell::new(0),
is_focused: false,
scale_factor: Cell::new(1.0),
scroll_pixels: 0.0,
scrollbar_v_rect: Cell::new(Rectangle::default()),
scrollbar_h_rect: Cell::new(None),
handle_opt: Mutex::new(None),