Update to latest cosmic-text
This commit is contained in:
parent
7d11d67290
commit
1e2424861d
3 changed files with 670 additions and 333 deletions
954
Cargo.lock
generated
954
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
10
src/tab.rs
10
src/tab.rs
|
|
@ -56,6 +56,7 @@ impl EditorTab {
|
||||||
"",
|
"",
|
||||||
&attrs,
|
&attrs,
|
||||||
Shaping::Advanced,
|
Shaping::Advanced,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
let editor = SyntaxEditor::new(
|
let editor = SyntaxEditor::new(
|
||||||
|
|
@ -139,7 +140,14 @@ impl EditorTab {
|
||||||
let cursor_start: Cursor = cosmic_text::Cursor::new(0, 0);
|
let cursor_start: Cursor = cosmic_text::Cursor::new(0, 0);
|
||||||
let cursor_end = editor.with_buffer(|buffer| {
|
let cursor_end = editor.with_buffer(|buffer| {
|
||||||
let last_line = buffer.lines.len().saturating_sub(1);
|
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
|
// Replace everything in the buffer with the content from disk
|
||||||
|
|
|
||||||
|
|
@ -1207,35 +1207,16 @@ where
|
||||||
}
|
}
|
||||||
Event::Mouse(MouseEvent::WheelScrolled { delta }) => {
|
Event::Mouse(MouseEvent::WheelScrolled { delta }) => {
|
||||||
if let Some(_p) = cursor_position.position_in(layout.bounds()) {
|
if let Some(_p) = cursor_position.position_in(layout.bounds()) {
|
||||||
match delta {
|
let pixels = match delta {
|
||||||
ScrollDelta::Lines { x: _, y } => {
|
ScrollDelta::Lines { x: _, y } => {
|
||||||
//TODO: this adjustment is just a guess!
|
//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());
|
let metrics = editor.with_buffer(|buffer| buffer.metrics());
|
||||||
while state.scroll_pixels <= -metrics.line_height {
|
-y * 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;
|
|
||||||
}
|
}
|
||||||
}
|
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>,
|
editor_offset_x: Cell<i32>,
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
scale_factor: Cell<f32>,
|
scale_factor: Cell<f32>,
|
||||||
scroll_pixels: f32,
|
|
||||||
scrollbar_v_rect: Cell<Rectangle<f32>>,
|
scrollbar_v_rect: Cell<Rectangle<f32>>,
|
||||||
scrollbar_h_rect: Cell<Option<Rectangle<f32>>>,
|
scrollbar_h_rect: Cell<Option<Rectangle<f32>>>,
|
||||||
handle_opt: Mutex<Option<image::Handle>>,
|
handle_opt: Mutex<Option<image::Handle>>,
|
||||||
|
|
@ -1299,7 +1279,6 @@ impl State {
|
||||||
editor_offset_x: Cell::new(0),
|
editor_offset_x: Cell::new(0),
|
||||||
is_focused: false,
|
is_focused: false,
|
||||||
scale_factor: Cell::new(1.0),
|
scale_factor: Cell::new(1.0),
|
||||||
scroll_pixels: 0.0,
|
|
||||||
scrollbar_v_rect: Cell::new(Rectangle::default()),
|
scrollbar_v_rect: Cell::new(Rectangle::default()),
|
||||||
scrollbar_h_rect: Cell::new(None),
|
scrollbar_h_rect: Cell::new(None),
|
||||||
handle_opt: Mutex::new(None),
|
handle_opt: Mutex::new(None),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue