From 87e5b1aa25ea61937fa5f79668d2a46e88707c5e Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 18 Jun 2020 01:02:56 +0000 Subject: Add automatic scrolling during selection This adds a new `Scheduler` which allows for staging events to be processed at a later time. If there is a selection active and the mouse is above or below the window, the viewport will now scroll torwards the direction of the mouse. The amount of lines scrolled depends on the distance of the mouse to the boundaries used for selection scrolling. To make it possible to scroll while in fullscreen, the selection scrolling area includes the padding of the window and is at least 5 pixels high in case there is not enough padding present. --- alacritty_terminal/src/util.rs | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'alacritty_terminal/src/util.rs') diff --git a/alacritty_terminal/src/util.rs b/alacritty_terminal/src/util.rs index fde06966..f996359a 100644 --- a/alacritty_terminal/src/util.rs +++ b/alacritty_terminal/src/util.rs @@ -1,6 +1,6 @@ use std::ffi::OsStr; +use std::io; use std::process::{Command, Stdio}; -use std::{cmp, io}; #[cfg(not(windows))] use std::os::unix::process::CommandExt; @@ -13,22 +13,18 @@ use winapi::um::winbase::{CREATE_NEW_PROCESS_GROUP, CREATE_NO_WINDOW}; /// Threading utilities. pub mod thread { /// Like `thread::spawn`, but with a `name` argument. - pub fn spawn_named(name: S, f: F) -> ::std::thread::JoinHandle + pub fn spawn_named(name: S, f: F) -> std::thread::JoinHandle where F: FnOnce() -> T + Send + 'static, T: Send + 'static, S: Into, { - ::std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works") + std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works") } pub use std::thread::*; } -pub fn limit(value: T, min: T, max: T) -> T { - cmp::min(cmp::max(value, min), max) -} - #[cfg(not(windows))] pub fn start_daemon(program: &str, args: I) -> io::Result<()> where @@ -79,15 +75,3 @@ where .spawn() .map(|_| ()) } - -#[cfg(test)] -mod tests { - use super::limit; - - #[test] - fn limit_works() { - assert_eq!(10, limit(10, 0, 100)); - assert_eq!(10, limit(5, 10, 100)); - assert_eq!(100, limit(1000, 10, 100)); - } -} -- cgit