feat(editor): Implement pixel-based scrolling for the Editor (#418)
Refactors the Editor's scrolling implementation to be pixel-based instead of line-based. This provides smoother and more granular scrolling, which works more consistently across different input devices (like trackpads). - The `Action::Scroll` variant now takes `pixels: f32`. - The `Editor` now processes scroll actions using pixel values directly. - Examples have been updated to reflect the new scrolling behavior.
This commit is contained in:
parent
f7033bb043
commit
750e1a4dd1
4 changed files with 23 additions and 31 deletions
|
|
@ -858,11 +858,11 @@ impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
|||
}
|
||||
}
|
||||
}
|
||||
Action::Scroll { lines } => {
|
||||
Action::Scroll { pixels } => {
|
||||
self.with_buffer_mut(|buffer| {
|
||||
let mut scroll = buffer.scroll();
|
||||
//TODO: align to layout lines
|
||||
scroll.vertical += lines as f32 * buffer.metrics().line_height;
|
||||
scroll.vertical += pixels;
|
||||
buffer.set_scroll(scroll);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ pub use self::vi::*;
|
|||
mod vi;
|
||||
|
||||
/// An action to perform on an [`Editor`]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Action {
|
||||
/// Move the cursor with some motion
|
||||
Motion(Motion),
|
||||
|
|
@ -58,9 +58,9 @@ pub enum Action {
|
|||
x: i32,
|
||||
y: i32,
|
||||
},
|
||||
/// Scroll specified number of lines
|
||||
/// Scroll specified number of pixels
|
||||
Scroll {
|
||||
lines: i32,
|
||||
pixels: f32,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue