2020-05-05 22:50:23 +00:00
|
|
|
//! Handle input from glutin.
|
2016-06-23 16:48:31 +00:00
|
|
|
//!
|
2020-05-05 22:50:23 +00:00
|
|
|
//! Certain key combinations should send some escape sequence back to the PTY.
|
2016-06-23 16:48:31 +00:00
|
|
|
//! In order to figure that out, state about which modifier keys are pressed
|
|
|
|
//! needs to be tracked. Additionally, we need a bit of a state machine to
|
|
|
|
//! determine what to do when a non-modifier key is pressed.
|
2020-06-06 18:49:14 +00:00
|
|
|
|
2017-02-02 06:13:08 +00:00
|
|
|
use std::borrow::Cow;
|
2020-06-18 01:02:56 +00:00
|
|
|
use std::cmp::{max, min, Ordering};
|
2021-12-18 22:18:42 +00:00
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::fmt::Debug;
|
2019-10-05 00:29:26 +00:00
|
|
|
use std::marker::PhantomData;
|
2020-06-18 01:02:56 +00:00
|
|
|
use std::time::{Duration, Instant};
|
2017-01-02 02:28:49 +00:00
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
use glutin::dpi::PhysicalPosition;
|
2019-10-05 00:29:26 +00:00
|
|
|
use glutin::event::{
|
|
|
|
ElementState, KeyboardInput, ModifiersState, MouseButton, MouseScrollDelta, TouchPhase,
|
2019-03-19 19:14:17 +00:00
|
|
|
};
|
2020-02-07 13:44:11 +00:00
|
|
|
use glutin::event_loop::EventLoopWindowTarget;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
use glutin::platform::macos::EventLoopWindowTargetExtMacOS;
|
2019-10-05 00:29:26 +00:00
|
|
|
use glutin::window::CursorIcon;
|
|
|
|
|
|
|
|
use alacritty_terminal::ansi::{ClearMode, Handler};
|
2020-06-18 01:02:56 +00:00
|
|
|
use alacritty_terminal::event::EventListener;
|
2020-07-09 21:45:22 +00:00
|
|
|
use alacritty_terminal::grid::{Dimensions, Scroll};
|
2021-04-13 03:24:42 +00:00
|
|
|
use alacritty_terminal::index::{Boundary, Column, Direction, Point, Side};
|
2020-03-18 02:35:08 +00:00
|
|
|
use alacritty_terminal::selection::SelectionType;
|
2021-01-24 21:45:36 +00:00
|
|
|
use alacritty_terminal::term::search::Match;
|
2020-12-28 09:45:39 +00:00
|
|
|
use alacritty_terminal::term::{ClipboardType, SizeInfo, Term, TermMode};
|
2020-03-18 02:35:08 +00:00
|
|
|
use alacritty_terminal::vi_mode::ViMotion;
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-06-06 21:33:20 +00:00
|
|
|
use crate::clipboard::Clipboard;
|
2021-11-22 18:34:09 +00:00
|
|
|
use crate::config::{Action, BindingMode, Key, MouseAction, SearchAction, UiConfig, ViAction};
|
2021-04-13 03:24:42 +00:00
|
|
|
use crate::display::hint::HintMatch;
|
2021-01-24 21:45:36 +00:00
|
|
|
use crate::display::window::Window;
|
2021-04-15 22:16:31 +00:00
|
|
|
use crate::display::Display;
|
2021-10-23 07:16:47 +00:00
|
|
|
use crate::event::{ClickState, Event, EventType, Mouse, TYPING_SEARCH_DELAY};
|
2020-07-11 17:03:09 +00:00
|
|
|
use crate::message_bar::{self, Message};
|
2021-10-23 07:16:47 +00:00
|
|
|
use crate::scheduler::{Scheduler, TimerId, Topic};
|
2018-07-21 17:17:41 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
/// Font size change interval.
|
2019-11-03 19:02:26 +00:00
|
|
|
pub const FONT_SIZE_STEP: f32 = 0.5;
|
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
/// Interval for mouse scrolling during selection outside of the boundaries.
|
|
|
|
const SELECTION_SCROLLING_INTERVAL: Duration = Duration::from_millis(15);
|
|
|
|
|
|
|
|
/// Minimum number of pixels at the bottom/top where selection scrolling is performed.
|
|
|
|
const MIN_SELECTION_SCROLLING_HEIGHT: f64 = 5.;
|
|
|
|
|
|
|
|
/// Number of pixels for increasing the selection scrolling speed factor by one.
|
|
|
|
const SELECTION_SCROLLING_STEP: f64 = 20.;
|
|
|
|
|
2016-06-23 16:48:31 +00:00
|
|
|
/// Processes input from glutin.
|
|
|
|
///
|
|
|
|
/// An escape sequence may be emitted in case specific keys or key combinations
|
|
|
|
/// are activated.
|
2021-01-24 21:45:36 +00:00
|
|
|
pub struct Processor<T: EventListener, A: ActionContext<T>> {
|
2017-02-02 06:13:08 +00:00
|
|
|
pub ctx: A,
|
2019-10-05 00:29:26 +00:00
|
|
|
_phantom: PhantomData<T>,
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
pub trait ActionContext<T: EventListener> {
|
2021-04-03 23:52:44 +00:00
|
|
|
fn write_to_pty<B: Into<Cow<'static, [u8]>>>(&self, _data: B) {}
|
2021-01-24 21:45:36 +00:00
|
|
|
fn mark_dirty(&mut self) {}
|
2017-02-02 06:13:08 +00:00
|
|
|
fn size_info(&self) -> SizeInfo;
|
2021-01-24 21:45:36 +00:00
|
|
|
fn copy_selection(&mut self, _ty: ClipboardType) {}
|
|
|
|
fn start_selection(&mut self, _ty: SelectionType, _point: Point, _side: Side) {}
|
|
|
|
fn toggle_selection(&mut self, _ty: SelectionType, _point: Point, _side: Side) {}
|
|
|
|
fn update_selection(&mut self, _point: Point, _side: Side) {}
|
|
|
|
fn clear_selection(&mut self) {}
|
2018-10-22 19:39:26 +00:00
|
|
|
fn selection_is_empty(&self) -> bool;
|
2017-02-02 06:13:08 +00:00
|
|
|
fn mouse_mut(&mut self) -> &mut Mouse;
|
2018-09-27 12:12:49 +00:00
|
|
|
fn mouse(&self) -> &Mouse;
|
2017-07-20 17:50:50 +00:00
|
|
|
fn received_count(&mut self) -> &mut usize;
|
|
|
|
fn suppress_chars(&mut self) -> &mut bool;
|
2019-11-11 21:05:24 +00:00
|
|
|
fn modifiers(&mut self) -> &mut ModifiersState;
|
2021-01-24 21:45:36 +00:00
|
|
|
fn scroll(&mut self, _scroll: Scroll) {}
|
2021-04-13 03:24:42 +00:00
|
|
|
fn window(&mut self) -> &mut Window;
|
|
|
|
fn display(&mut self) -> &mut Display;
|
2019-10-05 00:29:26 +00:00
|
|
|
fn terminal(&self) -> &Term<T>;
|
|
|
|
fn terminal_mut(&mut self) -> &mut Term<T>;
|
2021-01-24 21:45:36 +00:00
|
|
|
fn spawn_new_instance(&mut self) {}
|
2021-10-23 07:16:47 +00:00
|
|
|
fn create_new_window(&mut self) {}
|
2021-01-24 21:45:36 +00:00
|
|
|
fn change_font_size(&mut self, _delta: f32) {}
|
|
|
|
fn reset_font_size(&mut self) {}
|
|
|
|
fn pop_message(&mut self) {}
|
2019-10-05 00:29:26 +00:00
|
|
|
fn message(&self) -> Option<&Message>;
|
2021-11-22 18:34:09 +00:00
|
|
|
fn config(&self) -> &UiConfig;
|
2020-02-07 13:44:11 +00:00
|
|
|
fn event_loop(&self) -> &EventLoopWindowTarget<Event>;
|
2020-03-18 02:35:08 +00:00
|
|
|
fn mouse_mode(&self) -> bool;
|
2020-06-18 01:02:56 +00:00
|
|
|
fn clipboard_mut(&mut self) -> &mut Clipboard;
|
|
|
|
fn scheduler_mut(&mut self) -> &mut Scheduler;
|
2021-01-24 21:45:36 +00:00
|
|
|
fn start_search(&mut self, _direction: Direction) {}
|
|
|
|
fn confirm_search(&mut self) {}
|
|
|
|
fn cancel_search(&mut self) {}
|
|
|
|
fn search_input(&mut self, _c: char) {}
|
|
|
|
fn search_pop_word(&mut self) {}
|
|
|
|
fn search_history_previous(&mut self) {}
|
|
|
|
fn search_history_next(&mut self) {}
|
2021-03-30 23:25:38 +00:00
|
|
|
fn search_next(&mut self, origin: Point, direction: Direction, side: Side) -> Option<Match>;
|
2021-01-24 21:45:36 +00:00
|
|
|
fn advance_search_origin(&mut self, _direction: Direction) {}
|
2020-07-09 21:45:22 +00:00
|
|
|
fn search_direction(&self) -> Direction;
|
|
|
|
fn search_active(&self) -> bool;
|
2021-01-24 21:45:36 +00:00
|
|
|
fn on_typing_start(&mut self) {}
|
|
|
|
fn toggle_vi_mode(&mut self) {}
|
2021-03-01 19:50:39 +00:00
|
|
|
fn hint_input(&mut self, _character: char) {}
|
2021-04-13 03:24:42 +00:00
|
|
|
fn trigger_hint(&mut self, _hint: &HintMatch) {}
|
2021-07-29 15:40:51 +00:00
|
|
|
fn expand_selection(&mut self) {}
|
2021-04-03 23:52:44 +00:00
|
|
|
fn paste(&mut self, _text: &str) {}
|
2021-12-18 22:18:42 +00:00
|
|
|
fn spawn_daemon<I, S>(&self, _program: &str, _args: I)
|
|
|
|
where
|
|
|
|
I: IntoIterator<Item = S> + Debug + Copy,
|
|
|
|
S: AsRef<OsStr>,
|
|
|
|
{
|
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 02:35:08 +00:00
|
|
|
impl Action {
|
|
|
|
fn toggle_selection<T, A>(ctx: &mut A, ty: SelectionType)
|
|
|
|
where
|
|
|
|
A: ActionContext<T>,
|
2021-01-24 21:45:36 +00:00
|
|
|
T: EventListener,
|
2020-03-18 02:35:08 +00:00
|
|
|
{
|
2021-03-30 23:25:38 +00:00
|
|
|
ctx.toggle_selection(ty, ctx.terminal().vi_mode_cursor.point, Side::Left);
|
2020-03-18 02:35:08 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Make sure initial selection is not empty.
|
2020-05-30 20:45:44 +00:00
|
|
|
if let Some(selection) = &mut ctx.terminal_mut().selection {
|
2020-03-18 02:35:08 +00:00
|
|
|
selection.include_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-01 19:50:39 +00:00
|
|
|
trait Execute<T: EventListener> {
|
|
|
|
fn execute<A: ActionContext<T>>(&self, ctx: &mut A);
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl<T: EventListener> Execute<T> for Action {
|
2016-11-15 17:38:50 +00:00
|
|
|
#[inline]
|
2020-01-10 00:44:41 +00:00
|
|
|
fn execute<A: ActionContext<T>>(&self, ctx: &mut A) {
|
2021-03-01 19:50:39 +00:00
|
|
|
match self {
|
|
|
|
Action::Esc(s) => {
|
2020-11-23 23:11:03 +00:00
|
|
|
ctx.on_typing_start();
|
2020-05-06 21:58:43 +00:00
|
|
|
|
2019-10-29 16:56:48 +00:00
|
|
|
ctx.clear_selection();
|
2018-03-23 00:01:55 +00:00
|
|
|
ctx.scroll(Scroll::Bottom);
|
2017-02-02 06:13:08 +00:00
|
|
|
ctx.write_to_pty(s.clone().into_bytes())
|
2016-12-26 23:33:27 +00:00
|
|
|
},
|
2021-12-18 22:18:42 +00:00
|
|
|
Action::Command(program) => ctx.spawn_daemon(program.program(), program.args()),
|
2021-03-01 19:50:39 +00:00
|
|
|
Action::Hint(hint) => {
|
2021-04-13 03:24:42 +00:00
|
|
|
ctx.display().hint_state.start(hint.clone());
|
2021-03-01 19:50:39 +00:00
|
|
|
ctx.mark_dirty();
|
2017-05-25 16:19:00 +00:00
|
|
|
},
|
2021-01-24 21:45:36 +00:00
|
|
|
Action::ToggleViMode => ctx.toggle_vi_mode(),
|
2020-07-09 21:45:22 +00:00
|
|
|
Action::ViMotion(motion) => {
|
2020-11-23 23:11:03 +00:00
|
|
|
ctx.on_typing_start();
|
2021-03-01 19:50:39 +00:00
|
|
|
ctx.terminal_mut().vi_motion(*motion);
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-07-09 21:45:22 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::ToggleNormalSelection) => {
|
2021-03-01 19:50:39 +00:00
|
|
|
Self::toggle_selection(ctx, SelectionType::Simple);
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::ToggleLineSelection) => {
|
2021-03-01 19:50:39 +00:00
|
|
|
Self::toggle_selection(ctx, SelectionType::Lines);
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::ToggleBlockSelection) => {
|
2021-03-01 19:50:39 +00:00
|
|
|
Self::toggle_selection(ctx, SelectionType::Block);
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::ToggleSemanticSelection) => {
|
2021-03-01 19:50:39 +00:00
|
|
|
Self::toggle_selection(ctx, SelectionType::Semantic);
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::Open) => {
|
2021-04-13 03:24:42 +00:00
|
|
|
let hint = ctx.display().vi_highlighted_hint.take();
|
|
|
|
if let Some(hint) = &hint {
|
|
|
|
ctx.mouse_mut().block_hint_launcher = false;
|
|
|
|
ctx.trigger_hint(hint);
|
2020-03-18 02:35:08 +00:00
|
|
|
}
|
2021-04-13 03:24:42 +00:00
|
|
|
ctx.display().vi_highlighted_hint = hint;
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::SearchNext) => {
|
2021-01-03 11:24:04 +00:00
|
|
|
let terminal = ctx.terminal();
|
2020-07-09 21:45:22 +00:00
|
|
|
let direction = ctx.search_direction();
|
2021-03-30 23:25:38 +00:00
|
|
|
let vi_point = terminal.vi_mode_cursor.point;
|
2021-01-08 16:40:45 +00:00
|
|
|
let origin = match direction {
|
2021-03-30 23:25:38 +00:00
|
|
|
Direction::Right => vi_point.add(terminal, Boundary::None, 1),
|
|
|
|
Direction::Left => vi_point.sub(terminal, Boundary::None, 1),
|
2021-01-08 16:40:45 +00:00
|
|
|
};
|
2020-07-09 21:45:22 +00:00
|
|
|
|
2021-01-24 21:45:36 +00:00
|
|
|
if let Some(regex_match) = ctx.search_next(origin, direction, Side::Left) {
|
2020-07-09 21:45:22 +00:00
|
|
|
ctx.terminal_mut().vi_goto_point(*regex_match.start());
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-05-06 21:58:43 +00:00
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::SearchPrevious) => {
|
2021-01-03 11:24:04 +00:00
|
|
|
let terminal = ctx.terminal();
|
2020-07-09 21:45:22 +00:00
|
|
|
let direction = ctx.search_direction().opposite();
|
2021-03-30 23:25:38 +00:00
|
|
|
let vi_point = terminal.vi_mode_cursor.point;
|
2021-01-08 16:40:45 +00:00
|
|
|
let origin = match direction {
|
2021-03-30 23:25:38 +00:00
|
|
|
Direction::Right => vi_point.add(terminal, Boundary::None, 1),
|
|
|
|
Direction::Left => vi_point.sub(terminal, Boundary::None, 1),
|
2021-01-08 16:40:45 +00:00
|
|
|
};
|
2020-05-06 21:58:43 +00:00
|
|
|
|
2021-01-24 21:45:36 +00:00
|
|
|
if let Some(regex_match) = ctx.search_next(origin, direction, Side::Left) {
|
2020-07-09 21:45:22 +00:00
|
|
|
ctx.terminal_mut().vi_goto_point(*regex_match.start());
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::SearchStart) => {
|
2020-07-14 15:17:29 +00:00
|
|
|
let terminal = ctx.terminal();
|
2021-03-30 23:25:38 +00:00
|
|
|
let origin = terminal.vi_mode_cursor.point.sub(terminal, Boundary::None, 1);
|
2021-01-03 11:24:04 +00:00
|
|
|
|
2021-01-24 21:45:36 +00:00
|
|
|
if let Some(regex_match) = ctx.search_next(origin, Direction::Left, Side::Left) {
|
2020-07-14 15:17:29 +00:00
|
|
|
ctx.terminal_mut().vi_goto_point(*regex_match.start());
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
2020-05-06 21:58:43 +00:00
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Vi(ViAction::SearchEnd) => {
|
2020-07-14 15:17:29 +00:00
|
|
|
let terminal = ctx.terminal();
|
2021-03-30 23:25:38 +00:00
|
|
|
let origin = terminal.vi_mode_cursor.point.add(terminal, Boundary::None, 1);
|
2021-01-03 11:24:04 +00:00
|
|
|
|
2021-01-24 21:45:36 +00:00
|
|
|
if let Some(regex_match) = ctx.search_next(origin, Direction::Right, Side::Right) {
|
2020-07-09 21:45:22 +00:00
|
|
|
ctx.terminal_mut().vi_goto_point(*regex_match.end());
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Search(SearchAction::SearchFocusNext) => {
|
2020-12-19 04:07:20 +00:00
|
|
|
ctx.advance_search_origin(ctx.search_direction());
|
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Search(SearchAction::SearchFocusPrevious) => {
|
2020-12-19 04:07:20 +00:00
|
|
|
let direction = ctx.search_direction().opposite();
|
|
|
|
ctx.advance_search_origin(direction);
|
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Search(SearchAction::SearchConfirm) => ctx.confirm_search(),
|
|
|
|
Action::Search(SearchAction::SearchCancel) => ctx.cancel_search(),
|
|
|
|
Action::Search(SearchAction::SearchClear) => {
|
2020-12-19 04:07:20 +00:00
|
|
|
let direction = ctx.search_direction();
|
|
|
|
ctx.cancel_search();
|
|
|
|
ctx.start_search(direction);
|
|
|
|
},
|
2021-07-03 03:06:52 +00:00
|
|
|
Action::Search(SearchAction::SearchDeleteWord) => ctx.search_pop_word(),
|
|
|
|
Action::Search(SearchAction::SearchHistoryPrevious) => ctx.search_history_previous(),
|
|
|
|
Action::Search(SearchAction::SearchHistoryNext) => ctx.search_history_next(),
|
2021-07-29 15:40:51 +00:00
|
|
|
Action::Mouse(MouseAction::ExpandSelection) => ctx.expand_selection(),
|
2020-07-15 21:27:32 +00:00
|
|
|
Action::SearchForward => ctx.start_search(Direction::Right),
|
|
|
|
Action::SearchBackward => ctx.start_search(Direction::Left),
|
2020-12-19 04:07:20 +00:00
|
|
|
Action::Copy => ctx.copy_selection(ClipboardType::Clipboard),
|
|
|
|
#[cfg(not(any(target_os = "macos", windows)))]
|
|
|
|
Action::CopySelection => ctx.copy_selection(ClipboardType::Selection),
|
|
|
|
Action::ClearSelection => ctx.clear_selection(),
|
|
|
|
Action::Paste => {
|
|
|
|
let text = ctx.clipboard_mut().load(ClipboardType::Clipboard);
|
2021-04-03 23:52:44 +00:00
|
|
|
ctx.paste(&text);
|
2020-12-19 04:07:20 +00:00
|
|
|
},
|
|
|
|
Action::PasteSelection => {
|
|
|
|
let text = ctx.clipboard_mut().load(ClipboardType::Selection);
|
2021-04-03 23:52:44 +00:00
|
|
|
ctx.paste(&text);
|
2020-12-19 04:07:20 +00:00
|
|
|
},
|
2021-04-13 03:24:42 +00:00
|
|
|
Action::ToggleFullscreen => ctx.window().toggle_fullscreen(),
|
2019-04-23 19:05:47 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
2021-04-13 03:24:42 +00:00
|
|
|
Action::ToggleSimpleFullscreen => ctx.window().toggle_simple_fullscreen(),
|
2020-02-07 13:44:11 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
Action::Hide => ctx.event_loop().hide_application(),
|
2021-04-08 21:01:47 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
Action::HideOtherApplications => ctx.event_loop().hide_other_applications(),
|
2020-02-07 13:44:11 +00:00
|
|
|
#[cfg(not(target_os = "macos"))]
|
2019-10-05 00:29:26 +00:00
|
|
|
Action::Hide => ctx.window().set_visible(false),
|
2020-01-05 01:54:14 +00:00
|
|
|
Action::Minimize => ctx.window().set_minimized(true),
|
2019-10-05 00:29:26 +00:00
|
|
|
Action::Quit => ctx.terminal_mut().exit(),
|
|
|
|
Action::IncreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP),
|
|
|
|
Action::DecreaseFontSize => ctx.change_font_size(FONT_SIZE_STEP * -1.),
|
|
|
|
Action::ResetFontSize => ctx.reset_font_size(),
|
2020-03-18 02:35:08 +00:00
|
|
|
Action::ScrollPageUp => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Move vi mode cursor.
|
2020-03-18 02:35:08 +00:00
|
|
|
let term = ctx.terminal_mut();
|
2021-03-30 23:25:38 +00:00
|
|
|
let scroll_lines = term.screen_lines() as i32;
|
2020-03-18 02:35:08 +00:00
|
|
|
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
|
|
|
|
|
|
|
ctx.scroll(Scroll::PageUp);
|
|
|
|
},
|
|
|
|
Action::ScrollPageDown => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Move vi mode cursor.
|
2020-03-18 02:35:08 +00:00
|
|
|
let term = ctx.terminal_mut();
|
2021-03-30 23:25:38 +00:00
|
|
|
let scroll_lines = -(term.screen_lines() as i32);
|
2020-03-18 02:35:08 +00:00
|
|
|
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
|
|
|
|
|
|
|
ctx.scroll(Scroll::PageDown);
|
|
|
|
},
|
|
|
|
Action::ScrollHalfPageUp => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Move vi mode cursor.
|
2020-03-18 02:35:08 +00:00
|
|
|
let term = ctx.terminal_mut();
|
2021-03-30 23:25:38 +00:00
|
|
|
let scroll_lines = term.screen_lines() as i32 / 2;
|
2020-03-18 02:35:08 +00:00
|
|
|
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
ctx.scroll(Scroll::Delta(scroll_lines));
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
|
|
|
Action::ScrollHalfPageDown => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Move vi mode cursor.
|
2020-03-18 02:35:08 +00:00
|
|
|
let term = ctx.terminal_mut();
|
2021-03-30 23:25:38 +00:00
|
|
|
let scroll_lines = -(term.screen_lines() as i32 / 2);
|
2020-03-18 02:35:08 +00:00
|
|
|
term.vi_mode_cursor = term.vi_mode_cursor.scroll(term, scroll_lines);
|
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
ctx.scroll(Scroll::Delta(scroll_lines));
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2021-03-30 23:25:38 +00:00
|
|
|
Action::ScrollLineUp => ctx.scroll(Scroll::Delta(1)),
|
|
|
|
Action::ScrollLineDown => ctx.scroll(Scroll::Delta(-1)),
|
2020-03-18 02:35:08 +00:00
|
|
|
Action::ScrollToTop => {
|
|
|
|
ctx.scroll(Scroll::Top);
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Move vi mode cursor.
|
2021-03-30 23:25:38 +00:00
|
|
|
let topmost_line = ctx.terminal().topmost_line();
|
|
|
|
ctx.terminal_mut().vi_mode_cursor.point.line = topmost_line;
|
2020-03-18 02:35:08 +00:00
|
|
|
ctx.terminal_mut().vi_motion(ViMotion::FirstOccupied);
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
|
|
|
Action::ScrollToBottom => {
|
|
|
|
ctx.scroll(Scroll::Bottom);
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Move vi mode cursor.
|
2020-03-18 02:35:08 +00:00
|
|
|
let term = ctx.terminal_mut();
|
2021-03-30 23:25:38 +00:00
|
|
|
term.vi_mode_cursor.point.line = term.bottommost_line();
|
2020-05-16 00:16:21 +00:00
|
|
|
|
|
|
|
// Move to beginning twice, to always jump across linewraps.
|
|
|
|
term.vi_motion(ViMotion::FirstOccupied);
|
2020-03-18 02:35:08 +00:00
|
|
|
term.vi_motion(ViMotion::FirstOccupied);
|
2021-01-24 21:45:36 +00:00
|
|
|
ctx.mark_dirty();
|
2020-03-18 02:35:08 +00:00
|
|
|
},
|
2019-10-05 00:29:26 +00:00
|
|
|
Action::ClearHistory => ctx.terminal_mut().clear_screen(ClearMode::Saved),
|
|
|
|
Action::ClearLogNotice => ctx.pop_message(),
|
|
|
|
Action::SpawnNewInstance => ctx.spawn_new_instance(),
|
2021-10-23 07:16:47 +00:00
|
|
|
Action::CreateNewWindow => ctx.create_new_window(),
|
2019-09-28 00:37:22 +00:00
|
|
|
Action::ReceiveChar | Action::None => (),
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-01 19:35:37 +00:00
|
|
|
}
|
|
|
|
|
2021-01-24 21:45:36 +00:00
|
|
|
impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
|
|
|
|
pub fn new(ctx: A) -> Self {
|
|
|
|
Self { ctx, _phantom: Default::default() }
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-24 04:25:37 +00:00
|
|
|
#[inline]
|
2020-06-18 01:02:56 +00:00
|
|
|
pub fn mouse_moved(&mut self, position: PhysicalPosition<f64>) {
|
2019-11-03 20:59:28 +00:00
|
|
|
let size_info = self.ctx.size_info();
|
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
let (x, y) = position.into();
|
|
|
|
|
|
|
|
let lmb_pressed = self.ctx.mouse().left_button_state == ElementState::Pressed;
|
2020-07-27 19:05:25 +00:00
|
|
|
let rmb_pressed = self.ctx.mouse().right_button_state == ElementState::Pressed;
|
2020-11-13 05:40:09 +00:00
|
|
|
if !self.ctx.selection_is_empty() && (lmb_pressed || rmb_pressed) {
|
2020-06-18 01:02:56 +00:00
|
|
|
self.update_selection_scrolling(y);
|
|
|
|
}
|
|
|
|
|
2021-04-15 22:16:31 +00:00
|
|
|
let display_offset = self.ctx.terminal().grid().display_offset();
|
|
|
|
let old_point = self.ctx.mouse().point(&size_info, display_offset);
|
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
let x = min(max(x, 0), size_info.width() as i32 - 1) as usize;
|
|
|
|
let y = min(max(y, 0), size_info.height() as i32 - 1) as usize;
|
2017-02-02 06:13:08 +00:00
|
|
|
self.ctx.mouse_mut().x = x;
|
|
|
|
self.ctx.mouse_mut().y = y;
|
2016-12-12 06:02:03 +00:00
|
|
|
|
2020-08-14 07:26:42 +00:00
|
|
|
let inside_text_area = size_info.contains_point(x, y);
|
2021-03-30 23:25:38 +00:00
|
|
|
let cell_side = self.cell_side(x);
|
2018-03-13 18:00:14 +00:00
|
|
|
|
2021-04-15 22:16:31 +00:00
|
|
|
let point = self.ctx.mouse().point(&size_info, display_offset);
|
|
|
|
let cell_changed = old_point != point;
|
2019-07-08 18:13:55 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// If the mouse hasn't changed cells, do nothing.
|
2019-11-03 20:59:28 +00:00
|
|
|
if !cell_changed
|
|
|
|
&& self.ctx.mouse().cell_side == cell_side
|
2020-08-14 07:26:42 +00:00
|
|
|
&& self.ctx.mouse().inside_text_area == inside_text_area
|
2019-11-03 20:59:28 +00:00
|
|
|
{
|
2019-07-08 18:13:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-10-22 19:39:26 +00:00
|
|
|
|
2020-08-14 07:26:42 +00:00
|
|
|
self.ctx.mouse_mut().inside_text_area = inside_text_area;
|
2019-11-03 20:59:28 +00:00
|
|
|
self.ctx.mouse_mut().cell_side = cell_side;
|
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
// Update mouse state and check for URL change.
|
|
|
|
let mouse_state = self.cursor_state();
|
|
|
|
self.ctx.window().set_mouse_cursor(mouse_state);
|
|
|
|
|
|
|
|
// Prompt hint highlight update.
|
|
|
|
self.ctx.mouse_mut().hint_highlight_dirty = true;
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Don't launch URLs if mouse has moved.
|
2021-04-13 03:24:42 +00:00
|
|
|
self.ctx.mouse_mut().block_hint_launcher = true;
|
2019-04-28 22:36:02 +00:00
|
|
|
|
2020-11-13 05:40:09 +00:00
|
|
|
if (lmb_pressed || rmb_pressed) && (self.ctx.modifiers().shift() || !self.ctx.mouse_mode())
|
2020-06-24 08:29:07 +00:00
|
|
|
{
|
2020-08-14 07:26:42 +00:00
|
|
|
self.ctx.update_selection(point, cell_side);
|
2020-12-13 02:59:30 +00:00
|
|
|
} else if cell_changed
|
2019-11-03 20:59:28 +00:00
|
|
|
&& self.ctx.terminal().mode().intersects(TermMode::MOUSE_MOTION | TermMode::MOUSE_DRAG)
|
2018-03-13 18:00:14 +00:00
|
|
|
{
|
2020-06-18 01:02:56 +00:00
|
|
|
if lmb_pressed {
|
2020-01-05 01:00:50 +00:00
|
|
|
self.mouse_report(32, ElementState::Pressed);
|
2018-09-27 12:12:49 +00:00
|
|
|
} else if self.ctx.mouse().middle_button_state == ElementState::Pressed {
|
2020-01-05 01:00:50 +00:00
|
|
|
self.mouse_report(33, ElementState::Pressed);
|
2018-09-27 12:12:49 +00:00
|
|
|
} else if self.ctx.mouse().right_button_state == ElementState::Pressed {
|
2020-01-05 01:00:50 +00:00
|
|
|
self.mouse_report(34, ElementState::Pressed);
|
2019-02-07 22:36:45 +00:00
|
|
|
} else if self.ctx.terminal().mode().contains(TermMode::MOUSE_MOTION) {
|
2020-01-05 01:00:50 +00:00
|
|
|
self.mouse_report(35, ElementState::Pressed);
|
2016-12-22 18:43:06 +00:00
|
|
|
}
|
2016-12-12 06:02:03 +00:00
|
|
|
}
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 23:25:38 +00:00
|
|
|
/// Check which side of a cell an X coordinate lies on.
|
|
|
|
fn cell_side(&self, x: usize) -> Side {
|
2018-10-22 19:39:26 +00:00
|
|
|
let size_info = self.ctx.size_info();
|
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
let cell_x =
|
|
|
|
x.saturating_sub(size_info.padding_x() as usize) % size_info.cell_width() as usize;
|
|
|
|
let half_cell_width = (size_info.cell_width() / 2.0) as usize;
|
2018-10-22 19:39:26 +00:00
|
|
|
|
2019-02-07 22:36:45 +00:00
|
|
|
let additional_padding =
|
2020-09-27 22:36:08 +00:00
|
|
|
(size_info.width() - size_info.padding_x() * 2.) % size_info.cell_width();
|
|
|
|
let end_of_grid = size_info.width() - size_info.padding_x() - additional_padding;
|
2018-10-22 19:39:26 +00:00
|
|
|
|
|
|
|
if cell_x > half_cell_width
|
2020-05-05 22:50:23 +00:00
|
|
|
// Edge case when mouse leaves the window.
|
2018-10-22 19:39:26 +00:00
|
|
|
|| x as f32 >= end_of_grid
|
|
|
|
{
|
|
|
|
Side::Right
|
|
|
|
} else {
|
|
|
|
Side::Left
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-15 22:16:31 +00:00
|
|
|
fn mouse_report(&mut self, button: u8, state: ElementState) {
|
|
|
|
let display_offset = self.ctx.terminal().grid().display_offset();
|
|
|
|
let point = self.ctx.mouse().point(&self.ctx.size_info(), display_offset);
|
|
|
|
|
|
|
|
// Assure the mouse point is not in the scrollback.
|
2021-04-16 20:23:54 +00:00
|
|
|
if point.line < 0 {
|
2021-04-15 22:16:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate modifiers value.
|
|
|
|
let mut mods = 0;
|
|
|
|
let modifiers = self.ctx.modifiers();
|
|
|
|
if modifiers.shift() {
|
|
|
|
mods += 4;
|
|
|
|
}
|
|
|
|
if modifiers.alt() {
|
|
|
|
mods += 8;
|
|
|
|
}
|
|
|
|
if modifiers.ctrl() {
|
|
|
|
mods += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report mouse events.
|
|
|
|
if self.ctx.terminal().mode().contains(TermMode::SGR_MOUSE) {
|
|
|
|
self.sgr_mouse_report(point, button + mods, state);
|
|
|
|
} else if let ElementState::Released = state {
|
|
|
|
self.normal_mouse_report(point, 3 + mods);
|
|
|
|
} else {
|
|
|
|
self.normal_mouse_report(point, button + mods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn normal_mouse_report(&mut self, point: Point, button: u8) {
|
|
|
|
let Point { line, column } = point;
|
2019-11-04 19:41:13 +00:00
|
|
|
let utf8 = self.ctx.terminal().mode().contains(TermMode::UTF8_MOUSE);
|
2016-12-22 18:43:06 +00:00
|
|
|
|
2019-11-04 19:41:13 +00:00
|
|
|
let max_point = if utf8 { 2015 } else { 223 };
|
|
|
|
|
2021-04-15 22:16:31 +00:00
|
|
|
if line >= max_point || column >= max_point {
|
2019-11-04 19:41:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut msg = vec![b'\x1b', b'[', b'M', 32 + button];
|
|
|
|
|
|
|
|
let mouse_pos_encode = |pos: usize| -> Vec<u8> {
|
|
|
|
let pos = 32 + 1 + pos;
|
|
|
|
let first = 0xC0 + pos / 64;
|
|
|
|
let second = 0x80 + (pos & 63);
|
|
|
|
vec![first as u8, second as u8]
|
|
|
|
};
|
|
|
|
|
|
|
|
if utf8 && column >= Column(95) {
|
|
|
|
msg.append(&mut mouse_pos_encode(column.0));
|
|
|
|
} else {
|
|
|
|
msg.push(32 + 1 + column.0 as u8);
|
|
|
|
}
|
|
|
|
|
2021-03-30 23:25:38 +00:00
|
|
|
if utf8 && line >= 95 {
|
2021-04-15 22:16:31 +00:00
|
|
|
msg.append(&mut mouse_pos_encode(line.0 as usize));
|
2019-11-04 19:41:13 +00:00
|
|
|
} else {
|
2021-04-15 22:16:31 +00:00
|
|
|
msg.push(32 + 1 + line.0 as u8);
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
2019-11-04 19:41:13 +00:00
|
|
|
|
|
|
|
self.ctx.write_to_pty(msg);
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 22:16:31 +00:00
|
|
|
fn sgr_mouse_report(&mut self, point: Point, button: u8, state: ElementState) {
|
2018-01-06 19:39:33 +00:00
|
|
|
let c = match state {
|
|
|
|
ElementState::Pressed => 'M',
|
|
|
|
ElementState::Released => 'm',
|
|
|
|
};
|
2017-01-02 02:28:49 +00:00
|
|
|
|
2021-04-15 22:16:31 +00:00
|
|
|
let msg = format!("\x1b[<{};{};{}{}", button, point.column + 1, point.line + 1, c);
|
2017-02-02 06:13:08 +00:00
|
|
|
self.ctx.write_to_pty(msg.into_bytes());
|
2017-01-02 02:28:49 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 18:23:50 +00:00
|
|
|
fn on_mouse_press(&mut self, button: MouseButton) {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Handle mouse mode.
|
2020-04-10 18:23:50 +00:00
|
|
|
if !self.ctx.modifiers().shift() && self.ctx.mouse_mode() {
|
|
|
|
self.ctx.mouse_mut().click_state = ClickState::None;
|
|
|
|
|
|
|
|
let code = match button {
|
|
|
|
MouseButton::Left => 0,
|
|
|
|
MouseButton::Middle => 1,
|
|
|
|
MouseButton::Right => 2,
|
2020-05-05 22:50:23 +00:00
|
|
|
// Can't properly report more than three buttons..
|
2020-04-10 18:23:50 +00:00
|
|
|
MouseButton::Other(_) => return,
|
|
|
|
};
|
2016-12-22 18:43:06 +00:00
|
|
|
|
2020-04-10 18:23:50 +00:00
|
|
|
self.mouse_report(code, ElementState::Pressed);
|
|
|
|
} else {
|
2020-06-23 09:57:15 +00:00
|
|
|
// Calculate time since the last click to handle double/triple clicks.
|
|
|
|
let now = Instant::now();
|
|
|
|
let elapsed = now - self.ctx.mouse().last_click_timestamp;
|
|
|
|
self.ctx.mouse_mut().last_click_timestamp = now;
|
|
|
|
|
|
|
|
// Update multi-click state.
|
2021-11-22 18:34:09 +00:00
|
|
|
let mouse_config = &self.ctx.config().mouse;
|
2020-06-23 09:57:15 +00:00
|
|
|
self.ctx.mouse_mut().click_state = match self.ctx.mouse().click_state {
|
|
|
|
// Reset click state if button has changed.
|
|
|
|
_ if button != self.ctx.mouse().last_click_button => {
|
|
|
|
self.ctx.mouse_mut().last_click_button = button;
|
|
|
|
ClickState::Click
|
|
|
|
},
|
2020-12-21 02:44:38 +00:00
|
|
|
ClickState::Click if elapsed < mouse_config.double_click.threshold() => {
|
2020-06-23 09:57:15 +00:00
|
|
|
ClickState::DoubleClick
|
|
|
|
},
|
2020-12-21 02:44:38 +00:00
|
|
|
ClickState::DoubleClick if elapsed < mouse_config.triple_click.threshold() => {
|
2020-06-23 09:57:15 +00:00
|
|
|
ClickState::TripleClick
|
|
|
|
},
|
|
|
|
_ => ClickState::Click,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load mouse point, treating message bar and padding as the closest cell.
|
2021-03-30 23:25:38 +00:00
|
|
|
let display_offset = self.ctx.terminal().grid().display_offset();
|
2021-04-15 22:16:31 +00:00
|
|
|
let point = self.ctx.mouse().point(&self.ctx.size_info(), display_offset);
|
2020-06-23 09:57:15 +00:00
|
|
|
|
2021-07-29 15:40:51 +00:00
|
|
|
if let MouseButton::Left = button {
|
|
|
|
self.on_left_click(point)
|
2020-06-23 09:57:15 +00:00
|
|
|
}
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 09:57:15 +00:00
|
|
|
/// Handle left click selection and vi mode cursor movement.
|
|
|
|
fn on_left_click(&mut self, point: Point) {
|
2020-04-10 18:23:50 +00:00
|
|
|
let side = self.ctx.mouse().cell_side;
|
|
|
|
|
2020-06-23 09:57:15 +00:00
|
|
|
match self.ctx.mouse().click_state {
|
|
|
|
ClickState::Click => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Don't launch URLs if this click cleared the selection.
|
2021-04-13 03:24:42 +00:00
|
|
|
self.ctx.mouse_mut().block_hint_launcher = !self.ctx.selection_is_empty();
|
2020-03-19 12:39:00 +00:00
|
|
|
|
2020-04-10 18:23:50 +00:00
|
|
|
self.ctx.clear_selection();
|
2020-03-18 02:35:08 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Start new empty selection.
|
2020-04-10 18:23:50 +00:00
|
|
|
if self.ctx.modifiers().ctrl() {
|
|
|
|
self.ctx.start_selection(SelectionType::Block, point, side);
|
|
|
|
} else {
|
|
|
|
self.ctx.start_selection(SelectionType::Simple, point, side);
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2020-06-23 09:57:15 +00:00
|
|
|
ClickState::DoubleClick => {
|
2021-04-13 03:24:42 +00:00
|
|
|
self.ctx.mouse_mut().block_hint_launcher = true;
|
2020-06-23 09:57:15 +00:00
|
|
|
self.ctx.start_selection(SelectionType::Semantic, point, side);
|
|
|
|
},
|
|
|
|
ClickState::TripleClick => {
|
2021-04-13 03:24:42 +00:00
|
|
|
self.ctx.mouse_mut().block_hint_launcher = true;
|
2020-06-23 09:57:15 +00:00
|
|
|
self.ctx.start_selection(SelectionType::Lines, point, side);
|
|
|
|
},
|
|
|
|
ClickState::None => (),
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
2020-04-10 18:23:50 +00:00
|
|
|
|
2020-06-24 08:29:07 +00:00
|
|
|
// Move vi mode cursor to mouse click position.
|
2020-11-13 05:40:09 +00:00
|
|
|
if self.ctx.terminal().mode().contains(TermMode::VI) && !self.ctx.search_active() {
|
2020-04-10 18:23:50 +00:00
|
|
|
self.ctx.terminal_mut().vi_mode_cursor.point = point;
|
|
|
|
}
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 01:00:50 +00:00
|
|
|
fn on_mouse_release(&mut self, button: MouseButton) {
|
2020-03-18 02:35:08 +00:00
|
|
|
if !self.ctx.modifiers().shift() && self.ctx.mouse_mode() {
|
2019-02-07 22:36:45 +00:00
|
|
|
let code = match button {
|
|
|
|
MouseButton::Left => 0,
|
|
|
|
MouseButton::Middle => 1,
|
|
|
|
MouseButton::Right => 2,
|
2018-01-26 21:28:43 +00:00
|
|
|
// Can't properly report more than three buttons.
|
2019-02-07 22:36:45 +00:00
|
|
|
MouseButton::Other(_) => return,
|
2018-01-26 21:28:43 +00:00
|
|
|
};
|
2020-01-05 01:00:50 +00:00
|
|
|
self.mouse_report(code, ElementState::Released);
|
2016-12-22 18:43:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-12-30 01:39:30 +00:00
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
// Trigger hints highlighted by the mouse.
|
|
|
|
let hint = self.ctx.display().highlighted_hint.take();
|
|
|
|
if let Some(hint) = hint.as_ref().filter(|_| button == MouseButton::Left) {
|
|
|
|
self.ctx.trigger_hint(hint);
|
|
|
|
}
|
|
|
|
self.ctx.display().highlighted_hint = hint;
|
|
|
|
|
2021-10-23 07:16:47 +00:00
|
|
|
let timer_id = TimerId::new(Topic::SelectionScrolling, self.ctx.window().id());
|
|
|
|
self.ctx.scheduler_mut().unschedule(timer_id);
|
2021-04-17 19:28:23 +00:00
|
|
|
|
|
|
|
// Copy selection on release, to prevent flooding the display server.
|
|
|
|
self.ctx.copy_selection(ClipboardType::Selection);
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 01:00:50 +00:00
|
|
|
pub fn mouse_wheel_input(&mut self, delta: MouseScrollDelta, phase: TouchPhase) {
|
2016-11-25 03:50:34 +00:00
|
|
|
match delta {
|
2016-12-12 04:00:00 +00:00
|
|
|
MouseScrollDelta::LineDelta(_columns, lines) => {
|
2020-09-27 22:36:08 +00:00
|
|
|
let new_scroll_px = lines * self.ctx.size_info().cell_height();
|
2020-03-12 22:49:46 +00:00
|
|
|
self.scroll_terminal(f64::from(new_scroll_px));
|
2016-11-25 03:50:34 +00:00
|
|
|
},
|
2018-11-10 16:08:48 +00:00
|
|
|
MouseScrollDelta::PixelDelta(lpos) => {
|
2016-11-25 03:50:34 +00:00
|
|
|
match phase {
|
|
|
|
TouchPhase::Started => {
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset offset to zero.
|
2020-03-02 05:32:18 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px = 0.;
|
2016-11-25 03:50:34 +00:00
|
|
|
},
|
|
|
|
TouchPhase::Moved => {
|
2020-03-02 05:32:18 +00:00
|
|
|
self.scroll_terminal(lpos.y);
|
2016-11-25 03:50:34 +00:00
|
|
|
},
|
|
|
|
_ => (),
|
|
|
|
}
|
2019-03-30 16:48:36 +00:00
|
|
|
},
|
2016-11-25 03:50:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 05:32:18 +00:00
|
|
|
fn scroll_terminal(&mut self, new_scroll_px: f64) {
|
2020-09-27 22:36:08 +00:00
|
|
|
let height = f64::from(self.ctx.size_info().cell_height());
|
2018-03-09 22:02:45 +00:00
|
|
|
|
2020-03-18 02:35:08 +00:00
|
|
|
if self.ctx.mouse_mode() {
|
2019-01-27 21:06:27 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px += new_scroll_px;
|
|
|
|
|
2020-03-02 05:32:18 +00:00
|
|
|
let code = if new_scroll_px > 0. { 64 } else { 65 };
|
|
|
|
let lines = (self.ctx.mouse().scroll_px / height).abs() as i32;
|
2019-01-27 21:06:27 +00:00
|
|
|
|
|
|
|
for _ in 0..lines {
|
2020-01-05 01:00:50 +00:00
|
|
|
self.mouse_report(code, ElementState::Pressed);
|
2019-01-27 21:06:27 +00:00
|
|
|
}
|
2019-11-03 20:59:28 +00:00
|
|
|
} else if self
|
|
|
|
.ctx
|
|
|
|
.terminal()
|
|
|
|
.mode()
|
|
|
|
.contains(TermMode::ALT_SCREEN | TermMode::ALTERNATE_SCROLL)
|
2020-01-05 01:00:50 +00:00
|
|
|
&& !self.ctx.modifiers().shift()
|
2019-11-03 20:59:28 +00:00
|
|
|
{
|
2021-11-22 18:34:09 +00:00
|
|
|
let multiplier = f64::from(self.ctx.config().terminal_config.scrolling.multiplier);
|
2019-10-15 19:13:58 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
|
2019-01-27 21:06:27 +00:00
|
|
|
|
2020-03-02 05:32:18 +00:00
|
|
|
let cmd = if new_scroll_px > 0. { b'A' } else { b'B' };
|
|
|
|
let lines = (self.ctx.mouse().scroll_px / height).abs() as i32;
|
2019-01-27 21:06:27 +00:00
|
|
|
|
|
|
|
let mut content = Vec::with_capacity(lines as usize * 3);
|
|
|
|
for _ in 0..lines {
|
2018-03-09 10:17:47 +00:00
|
|
|
content.push(0x1b);
|
|
|
|
content.push(b'O');
|
|
|
|
content.push(cmd);
|
|
|
|
}
|
|
|
|
self.ctx.write_to_pty(content);
|
2018-02-16 02:35:49 +00:00
|
|
|
} else {
|
2021-11-22 18:34:09 +00:00
|
|
|
let multiplier = f64::from(self.ctx.config().terminal_config.scrolling.multiplier);
|
2019-01-27 21:06:27 +00:00
|
|
|
self.ctx.mouse_mut().scroll_px += new_scroll_px * multiplier;
|
|
|
|
|
|
|
|
let lines = self.ctx.mouse().scroll_px / height;
|
|
|
|
|
2021-03-30 23:25:38 +00:00
|
|
|
self.ctx.scroll(Scroll::Delta(lines as i32));
|
2017-12-25 21:15:41 +00:00
|
|
|
}
|
2019-01-27 21:06:27 +00:00
|
|
|
|
|
|
|
self.ctx.mouse_mut().scroll_px %= height;
|
2017-12-25 21:15:41 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 16:51:49 +00:00
|
|
|
pub fn on_focus_change(&mut self, is_focused: bool) {
|
2019-02-07 22:36:45 +00:00
|
|
|
if self.ctx.terminal().mode().contains(TermMode::FOCUS_IN_OUT) {
|
2019-03-30 16:48:36 +00:00
|
|
|
let chr = if is_focused { "I" } else { "O" };
|
2017-05-29 16:51:49 +00:00
|
|
|
|
|
|
|
let msg = format!("\x1b[{}", chr);
|
|
|
|
self.ctx.write_to_pty(msg.into_bytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-05 01:00:50 +00:00
|
|
|
pub fn mouse_input(&mut self, state: ElementState, button: MouseButton) {
|
2019-01-03 01:56:28 +00:00
|
|
|
match button {
|
|
|
|
MouseButton::Left => self.ctx.mouse_mut().left_button_state = state,
|
|
|
|
MouseButton::Middle => self.ctx.mouse_mut().middle_button_state = state,
|
|
|
|
MouseButton::Right => self.ctx.mouse_mut().right_button_state = state,
|
|
|
|
_ => (),
|
2016-11-24 04:25:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Skip normal mouse events if the message bar has been clicked.
|
2021-04-13 03:24:42 +00:00
|
|
|
if self.message_bar_cursor_state() == Some(CursorIcon::Hand)
|
2020-09-27 22:36:08 +00:00
|
|
|
&& state == ElementState::Pressed
|
|
|
|
{
|
|
|
|
let size = self.ctx.size_info();
|
|
|
|
|
|
|
|
let current_lines = self.ctx.message().map(|m| m.text(&size).len()).unwrap_or(0);
|
|
|
|
|
2019-11-03 20:59:28 +00:00
|
|
|
self.ctx.clear_selection();
|
|
|
|
self.ctx.pop_message();
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Reset cursor when message bar height changed or all messages are gone.
|
2019-11-03 20:59:28 +00:00
|
|
|
let new_lines = self.ctx.message().map(|m| m.text(&size).len()).unwrap_or(0);
|
|
|
|
|
|
|
|
let new_icon = match current_lines.cmp(&new_lines) {
|
|
|
|
Ordering::Less => CursorIcon::Default,
|
|
|
|
Ordering::Equal => CursorIcon::Hand,
|
2019-11-03 23:14:23 +00:00
|
|
|
Ordering::Greater => {
|
2020-03-18 02:35:08 +00:00
|
|
|
if self.ctx.mouse_mode() {
|
2019-11-03 23:14:23 +00:00
|
|
|
CursorIcon::Default
|
|
|
|
} else {
|
|
|
|
CursorIcon::Text
|
|
|
|
}
|
2019-11-03 20:59:28 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
self.ctx.window().set_mouse_cursor(new_icon);
|
2020-11-13 05:40:09 +00:00
|
|
|
} else {
|
2019-02-07 22:36:45 +00:00
|
|
|
match state {
|
|
|
|
ElementState::Pressed => {
|
2021-07-29 15:40:51 +00:00
|
|
|
// Process mouse press before bindings to update the `click_state`.
|
2020-01-05 01:00:50 +00:00
|
|
|
self.on_mouse_press(button);
|
2021-07-29 15:40:51 +00:00
|
|
|
self.process_mouse_bindings(button);
|
2019-02-07 22:36:45 +00:00
|
|
|
},
|
2020-01-05 01:00:50 +00:00
|
|
|
ElementState::Released => self.on_mouse_release(button),
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
2016-09-27 05:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Process key input.
|
2019-11-11 21:05:24 +00:00
|
|
|
pub fn key_input(&mut self, input: KeyboardInput) {
|
2021-03-01 19:50:39 +00:00
|
|
|
// All key bindings are disabled while a hint is being selected.
|
2021-04-13 03:24:42 +00:00
|
|
|
if self.ctx.display().hint_state.active() {
|
2021-03-01 19:50:39 +00:00
|
|
|
*self.ctx.suppress_chars() = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-19 04:07:20 +00:00
|
|
|
// Reset search delay when the user is still typing.
|
|
|
|
if self.ctx.search_active() {
|
2021-10-23 07:16:47 +00:00
|
|
|
let timer_id = TimerId::new(Topic::DelayedSearch, self.ctx.window().id());
|
|
|
|
let scheduler = self.ctx.scheduler_mut();
|
|
|
|
if let Some(timer) = scheduler.unschedule(timer_id) {
|
|
|
|
scheduler.schedule(timer.event, TYPING_SEARCH_DELAY, false, timer.id);
|
2020-12-19 04:07:20 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-09 21:45:22 +00:00
|
|
|
|
2020-12-19 04:07:20 +00:00
|
|
|
match input.state {
|
2018-10-16 18:46:26 +00:00
|
|
|
ElementState::Pressed => {
|
2017-07-20 17:50:50 +00:00
|
|
|
*self.ctx.received_count() = 0;
|
2019-09-28 00:37:22 +00:00
|
|
|
self.process_key_bindings(input);
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2020-12-31 05:06:15 +00:00
|
|
|
ElementState::Released => *self.ctx.suppress_chars() = false,
|
2017-07-20 17:50:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
|
2019-11-11 21:05:24 +00:00
|
|
|
/// Modifier state change.
|
|
|
|
pub fn modifiers_input(&mut self, modifiers: ModifiersState) {
|
|
|
|
*self.ctx.modifiers() = modifiers;
|
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
// Prompt hint highlight update.
|
|
|
|
self.ctx.mouse_mut().hint_highlight_dirty = true;
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Update mouse state and check for URL change.
|
2021-04-13 03:24:42 +00:00
|
|
|
let mouse_state = self.cursor_state();
|
|
|
|
self.ctx.window().set_mouse_cursor(mouse_state);
|
2019-11-11 21:05:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 23:11:03 +00:00
|
|
|
/// Reset mouse cursor based on modifier and terminal state.
|
|
|
|
#[inline]
|
|
|
|
pub fn reset_mouse_cursor(&mut self) {
|
2021-04-13 03:24:42 +00:00
|
|
|
let mouse_state = self.cursor_state();
|
|
|
|
self.ctx.window().set_mouse_cursor(mouse_state);
|
2020-11-23 23:11:03 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Process a received character.
|
2017-07-20 17:50:50 +00:00
|
|
|
pub fn received_char(&mut self, c: char) {
|
2020-07-09 21:45:22 +00:00
|
|
|
let suppress_chars = *self.ctx.suppress_chars();
|
2021-03-01 19:50:39 +00:00
|
|
|
|
|
|
|
// Handle hint selection over anything else.
|
2021-04-13 03:24:42 +00:00
|
|
|
if self.ctx.display().hint_state.active() && !suppress_chars {
|
2021-03-01 19:50:39 +00:00
|
|
|
self.ctx.hint_input(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass keys to search and ignore them during `suppress_chars`.
|
2020-07-09 21:45:22 +00:00
|
|
|
let search_active = self.ctx.search_active();
|
2021-03-01 19:50:39 +00:00
|
|
|
if suppress_chars || search_active || self.ctx.terminal().mode().contains(TermMode::VI) {
|
2020-12-19 04:07:20 +00:00
|
|
|
if search_active && !suppress_chars {
|
|
|
|
self.ctx.search_input(c);
|
2020-07-09 21:45:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 20:23:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-07 06:04:51 +00:00
|
|
|
|
2020-11-23 23:11:03 +00:00
|
|
|
self.ctx.on_typing_start();
|
2020-05-06 21:58:43 +00:00
|
|
|
|
2019-02-16 20:23:23 +00:00
|
|
|
self.ctx.scroll(Scroll::Bottom);
|
|
|
|
self.ctx.clear_selection();
|
2018-12-20 00:33:42 +00:00
|
|
|
|
2019-02-16 20:23:23 +00:00
|
|
|
let utf8_len = c.len_utf8();
|
2021-12-23 10:23:06 +00:00
|
|
|
let mut bytes = vec![0; utf8_len];
|
|
|
|
c.encode_utf8(&mut bytes[..]);
|
2017-07-20 17:50:50 +00:00
|
|
|
|
2021-11-22 18:34:09 +00:00
|
|
|
if self.ctx.config().alt_send_esc
|
2019-02-16 20:23:23 +00:00
|
|
|
&& *self.ctx.received_count() == 0
|
2020-01-05 01:00:50 +00:00
|
|
|
&& self.ctx.modifiers().alt()
|
2019-02-16 20:23:23 +00:00
|
|
|
&& utf8_len == 1
|
|
|
|
{
|
|
|
|
bytes.insert(0, b'\x1b');
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
2019-02-16 20:23:23 +00:00
|
|
|
|
|
|
|
self.ctx.write_to_pty(bytes);
|
|
|
|
|
|
|
|
*self.ctx.received_count() += 1;
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Attempt to find a binding and execute its action.
|
2016-11-15 17:38:50 +00:00
|
|
|
///
|
|
|
|
/// The provided mode, mods, and key must match what is allowed by a binding
|
|
|
|
/// for its action to be executed.
|
2019-09-28 00:37:22 +00:00
|
|
|
fn process_key_bindings(&mut self, input: KeyboardInput) {
|
2020-12-19 04:07:20 +00:00
|
|
|
let mode = BindingMode::new(self.ctx.terminal().mode(), self.ctx.search_active());
|
2020-01-10 00:44:41 +00:00
|
|
|
let mods = *self.ctx.modifiers();
|
2019-10-05 00:29:26 +00:00
|
|
|
let mut suppress_chars = None;
|
2019-09-28 00:37:22 +00:00
|
|
|
|
2021-11-22 18:34:09 +00:00
|
|
|
for i in 0..self.ctx.config().key_bindings().len() {
|
|
|
|
let binding = &self.ctx.config().key_bindings()[i];
|
2019-11-03 19:02:26 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
let key = match (binding.trigger, input.virtual_keycode) {
|
|
|
|
(Key::Scancode(_), _) => Key::Scancode(input.scancode),
|
2020-01-06 22:06:09 +00:00
|
|
|
(_, Some(key)) => Key::Keycode(key),
|
2019-10-05 00:29:26 +00:00
|
|
|
_ => continue,
|
|
|
|
};
|
|
|
|
|
2020-12-19 04:07:20 +00:00
|
|
|
if binding.is_triggered_by(mode, mods, &key) {
|
2020-08-09 23:29:58 +00:00
|
|
|
// Pass through the key if any of the bindings has the `ReceiveChar` action.
|
2019-10-05 00:29:26 +00:00
|
|
|
*suppress_chars.get_or_insert(true) &= binding.action != Action::ReceiveChar;
|
2021-03-01 19:50:39 +00:00
|
|
|
|
|
|
|
// Binding was triggered; run the action.
|
|
|
|
binding.action.clone().execute(&mut self.ctx);
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Don't suppress char if no bindings were triggered.
|
2019-10-05 00:29:26 +00:00
|
|
|
*self.ctx.suppress_chars() = suppress_chars.unwrap_or(false);
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-28 00:37:22 +00:00
|
|
|
/// Attempt to find a binding and execute its action.
|
2016-11-15 17:38:50 +00:00
|
|
|
///
|
|
|
|
/// The provided mode, mods, and key must match what is allowed by a binding
|
|
|
|
/// for its action to be executed.
|
2020-01-05 01:00:50 +00:00
|
|
|
fn process_mouse_bindings(&mut self, button: MouseButton) {
|
2020-12-19 04:07:20 +00:00
|
|
|
let mode = BindingMode::new(self.ctx.terminal().mode(), self.ctx.search_active());
|
2020-03-18 02:35:08 +00:00
|
|
|
let mouse_mode = self.ctx.mouse_mode();
|
2020-12-19 04:07:20 +00:00
|
|
|
let mods = *self.ctx.modifiers();
|
2020-01-10 00:44:41 +00:00
|
|
|
|
2021-11-22 18:34:09 +00:00
|
|
|
for i in 0..self.ctx.config().mouse_bindings().len() {
|
|
|
|
let mut binding = self.ctx.config().mouse_bindings()[i].clone();
|
2019-11-03 19:02:26 +00:00
|
|
|
|
2020-05-05 22:50:23 +00:00
|
|
|
// Require shift for all modifiers when mouse mode is active.
|
2020-01-10 00:44:41 +00:00
|
|
|
if mouse_mode {
|
|
|
|
binding.mods |= ModifiersState::SHIFT;
|
|
|
|
}
|
2019-11-03 19:02:26 +00:00
|
|
|
|
2020-01-10 00:44:41 +00:00
|
|
|
if binding.is_triggered_by(mode, mods, &button) {
|
2021-03-01 19:50:39 +00:00
|
|
|
binding.action.execute(&mut self.ctx);
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-15 17:38:50 +00:00
|
|
|
}
|
2019-02-07 22:36:45 +00:00
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
/// Check mouse icon state in relation to the message bar.
|
|
|
|
fn message_bar_cursor_state(&self) -> Option<CursorIcon> {
|
2020-07-09 21:45:22 +00:00
|
|
|
// Since search is above the message bar, the button is offset by search's height.
|
|
|
|
let search_height = if self.ctx.search_active() { 1 } else { 0 };
|
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
// Calculate Y position of the end of the last terminal line.
|
|
|
|
let size = self.ctx.size_info();
|
|
|
|
let terminal_end = size.padding_y() as usize
|
2021-03-30 23:25:38 +00:00
|
|
|
+ size.cell_height() as usize * (size.screen_lines() + search_height);
|
2020-09-27 22:36:08 +00:00
|
|
|
|
|
|
|
let mouse = self.ctx.mouse();
|
2021-04-15 22:16:31 +00:00
|
|
|
let display_offset = self.ctx.terminal().grid().display_offset();
|
|
|
|
let point = self.ctx.mouse().point(&self.ctx.size_info(), display_offset);
|
|
|
|
|
2020-09-27 22:36:08 +00:00
|
|
|
if self.ctx.message().is_none() || (mouse.y <= terminal_end) {
|
|
|
|
None
|
|
|
|
} else if mouse.y <= terminal_end + size.cell_height() as usize
|
2021-04-15 22:16:31 +00:00
|
|
|
&& point.column + message_bar::CLOSE_BUTTON_TEXT.len() >= size.columns()
|
2020-09-27 22:36:08 +00:00
|
|
|
{
|
2021-04-13 03:24:42 +00:00
|
|
|
Some(CursorIcon::Hand)
|
2020-09-27 22:36:08 +00:00
|
|
|
} else {
|
2021-04-13 03:24:42 +00:00
|
|
|
Some(CursorIcon::Default)
|
2019-11-03 20:59:28 +00:00
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
}
|
2019-08-24 23:18:51 +00:00
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
/// Icon state of the cursor.
|
|
|
|
fn cursor_state(&mut self) -> CursorIcon {
|
|
|
|
let display_offset = self.ctx.terminal().grid().display_offset();
|
2021-04-15 22:16:31 +00:00
|
|
|
let point = self.ctx.mouse().point(&self.ctx.size_info(), display_offset);
|
|
|
|
|
|
|
|
// Function to check if mouse is on top of a hint.
|
|
|
|
let hint_highlighted = |hint: &HintMatch| hint.bounds.contains(&point);
|
2019-11-11 21:05:24 +00:00
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
if let Some(mouse_state) = self.message_bar_cursor_state() {
|
|
|
|
mouse_state
|
|
|
|
} else if self.ctx.display().highlighted_hint.as_ref().map_or(false, hint_highlighted) {
|
|
|
|
CursorIcon::Hand
|
|
|
|
} else if !self.ctx.modifiers().shift() && self.ctx.mouse_mode() {
|
|
|
|
CursorIcon::Default
|
2019-11-11 21:05:24 +00:00
|
|
|
} else {
|
2021-04-13 03:24:42 +00:00
|
|
|
CursorIcon::Text
|
2019-11-11 21:05:24 +00:00
|
|
|
}
|
2019-08-24 23:18:51 +00:00
|
|
|
}
|
2020-06-18 01:02:56 +00:00
|
|
|
|
|
|
|
/// Handle automatic scrolling when selecting above/below the window.
|
|
|
|
fn update_selection_scrolling(&mut self, mouse_y: i32) {
|
2020-09-27 22:36:08 +00:00
|
|
|
let dpr = self.ctx.window().dpr;
|
|
|
|
let size = self.ctx.size_info();
|
2021-10-23 07:16:47 +00:00
|
|
|
let window_id = self.ctx.window().id();
|
2020-06-18 01:02:56 +00:00
|
|
|
let scheduler = self.ctx.scheduler_mut();
|
|
|
|
|
|
|
|
// Scale constants by DPI.
|
2020-09-27 22:36:08 +00:00
|
|
|
let min_height = (MIN_SELECTION_SCROLLING_HEIGHT * dpr) as i32;
|
|
|
|
let step = (SELECTION_SCROLLING_STEP * dpr) as i32;
|
2020-06-18 01:02:56 +00:00
|
|
|
|
|
|
|
// Compute the height of the scrolling areas.
|
2020-09-27 22:36:08 +00:00
|
|
|
let end_top = max(min_height, size.padding_y() as i32);
|
2021-03-30 23:25:38 +00:00
|
|
|
let text_area_bottom = size.padding_y() + size.screen_lines() as f32 * size.cell_height();
|
2020-09-27 22:36:08 +00:00
|
|
|
let start_bottom = min(size.height() as i32 - min_height, text_area_bottom as i32);
|
2020-06-18 01:02:56 +00:00
|
|
|
|
|
|
|
// Get distance from closest window boundary.
|
|
|
|
let delta = if mouse_y < end_top {
|
|
|
|
end_top - mouse_y + step
|
|
|
|
} else if mouse_y >= start_bottom {
|
|
|
|
start_bottom - mouse_y - step
|
|
|
|
} else {
|
2021-10-23 07:16:47 +00:00
|
|
|
scheduler.unschedule(TimerId::new(Topic::SelectionScrolling, window_id));
|
2020-06-18 01:02:56 +00:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Scale number of lines scrolled based on distance to boundary.
|
2021-03-30 23:25:38 +00:00
|
|
|
let delta = delta as i32 / step as i32;
|
2021-10-23 07:16:47 +00:00
|
|
|
let event = Event::new(EventType::Scroll(Scroll::Delta(delta)), Some(window_id));
|
2020-06-18 01:02:56 +00:00
|
|
|
|
|
|
|
// Schedule event.
|
2021-10-23 07:16:47 +00:00
|
|
|
let timer_id = TimerId::new(Topic::SelectionScrolling, window_id);
|
|
|
|
scheduler.unschedule(timer_id);
|
|
|
|
scheduler.schedule(event, SELECTION_SCROLLING_INTERVAL, true, timer_id);
|
2020-06-18 01:02:56 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-06-18 01:02:56 +00:00
|
|
|
use super::*;
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
use glutin::event::{Event as GlutinEvent, VirtualKeyCode, WindowEvent};
|
2016-09-27 15:27:39 +00:00
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
use alacritty_terminal::event::Event as TerminalEvent;
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2021-03-01 19:50:39 +00:00
|
|
|
use crate::config::Binding;
|
2020-07-11 17:03:09 +00:00
|
|
|
use crate::message_bar::MessageBuffer;
|
2016-06-23 16:48:31 +00:00
|
|
|
|
2016-11-15 17:38:50 +00:00
|
|
|
const KEY: VirtualKeyCode = VirtualKeyCode::Key0;
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
struct MockEventProxy;
|
2021-01-24 21:45:36 +00:00
|
|
|
impl EventListener for MockEventProxy {}
|
2019-07-15 21:32:48 +00:00
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
struct ActionContext<'a, T> {
|
|
|
|
pub terminal: &'a mut Term<T>,
|
2017-01-15 01:53:48 +00:00
|
|
|
pub size_info: &'a SizeInfo,
|
|
|
|
pub mouse: &'a mut Mouse,
|
2020-06-06 21:33:20 +00:00
|
|
|
pub clipboard: &'a mut Clipboard,
|
2019-10-05 00:29:26 +00:00
|
|
|
pub message_buffer: &'a mut MessageBuffer,
|
2017-07-20 17:50:50 +00:00
|
|
|
pub received_count: usize,
|
|
|
|
pub suppress_chars: bool,
|
2019-11-11 21:05:24 +00:00
|
|
|
pub modifiers: ModifiersState,
|
2021-11-22 18:34:09 +00:00
|
|
|
config: &'a UiConfig,
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
impl<'a, T: EventListener> super::ActionContext<T> for ActionContext<'a, T> {
|
2021-01-24 21:45:36 +00:00
|
|
|
fn search_next(
|
|
|
|
&mut self,
|
2021-03-30 23:25:38 +00:00
|
|
|
_origin: Point,
|
2021-01-24 21:45:36 +00:00
|
|
|
_direction: Direction,
|
|
|
|
_side: Side,
|
|
|
|
) -> Option<Match> {
|
|
|
|
None
|
|
|
|
}
|
2020-07-15 21:27:32 +00:00
|
|
|
|
2020-07-09 21:45:22 +00:00
|
|
|
fn search_direction(&self) -> Direction {
|
|
|
|
Direction::Right
|
|
|
|
}
|
|
|
|
|
|
|
|
fn search_active(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn terminal(&self) -> &Term<T> {
|
2021-07-03 03:06:52 +00:00
|
|
|
self.terminal
|
2019-02-07 22:36:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-05 00:29:26 +00:00
|
|
|
fn terminal_mut(&mut self) -> &mut Term<T> {
|
2021-12-23 10:23:06 +00:00
|
|
|
self.terminal
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn size_info(&self) -> SizeInfo {
|
|
|
|
*self.size_info
|
|
|
|
}
|
|
|
|
|
2018-10-22 19:39:26 +00:00
|
|
|
fn selection_is_empty(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2018-03-25 19:09:18 +00:00
|
|
|
fn scroll(&mut self, scroll: Scroll) {
|
|
|
|
self.terminal.scroll_display(scroll);
|
|
|
|
}
|
|
|
|
|
2020-03-18 02:35:08 +00:00
|
|
|
fn mouse_mode(&self) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
#[inline]
|
|
|
|
fn mouse_mut(&mut self) -> &mut Mouse {
|
|
|
|
self.mouse
|
|
|
|
}
|
2018-09-27 12:12:49 +00:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn mouse(&self) -> &Mouse {
|
|
|
|
self.mouse
|
|
|
|
}
|
|
|
|
|
2017-07-20 17:50:50 +00:00
|
|
|
fn received_count(&mut self) -> &mut usize {
|
|
|
|
&mut self.received_count
|
|
|
|
}
|
2019-01-05 20:47:12 +00:00
|
|
|
|
2017-07-20 17:50:50 +00:00
|
|
|
fn suppress_chars(&mut self) -> &mut bool {
|
|
|
|
&mut self.suppress_chars
|
|
|
|
}
|
2019-01-05 20:47:12 +00:00
|
|
|
|
2019-11-11 21:05:24 +00:00
|
|
|
fn modifiers(&mut self) -> &mut ModifiersState {
|
2019-08-24 23:18:51 +00:00
|
|
|
&mut self.modifiers
|
2017-07-20 17:50:50 +00:00
|
|
|
}
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
fn window(&mut self) -> &mut Window {
|
2019-10-05 00:29:26 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
2021-04-13 03:24:42 +00:00
|
|
|
fn display(&mut self) -> &mut Display {
|
2019-10-05 00:29:26 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pop_message(&mut self) {
|
|
|
|
self.message_buffer.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn message(&self) -> Option<&Message> {
|
|
|
|
self.message_buffer.message()
|
|
|
|
}
|
2019-11-03 19:02:26 +00:00
|
|
|
|
2021-11-22 18:34:09 +00:00
|
|
|
fn config(&self) -> &UiConfig {
|
2019-11-03 19:02:26 +00:00
|
|
|
self.config
|
|
|
|
}
|
2020-02-07 13:44:11 +00:00
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
fn clipboard_mut(&mut self) -> &mut Clipboard {
|
|
|
|
self.clipboard
|
|
|
|
}
|
|
|
|
|
|
|
|
fn event_loop(&self) -> &EventLoopWindowTarget<Event> {
|
2020-02-07 13:44:11 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
2020-03-18 02:35:08 +00:00
|
|
|
|
2020-06-23 09:57:15 +00:00
|
|
|
fn scheduler_mut(&mut self) -> &mut Scheduler {
|
2020-03-18 02:35:08 +00:00
|
|
|
unimplemented!();
|
|
|
|
}
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! test_clickstate {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
initial_state: $initial_state:expr,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: $initial_button:expr,
|
2017-01-15 01:53:48 +00:00
|
|
|
input: $input:expr,
|
2020-04-10 18:23:50 +00:00
|
|
|
end_state: $end_state:expr,
|
2017-01-15 01:53:48 +00:00
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2020-12-21 02:44:38 +00:00
|
|
|
let mut clipboard = Clipboard::new_nop();
|
2021-11-22 18:34:09 +00:00
|
|
|
let cfg = UiConfig::default();
|
2020-09-27 22:36:08 +00:00
|
|
|
let size = SizeInfo::new(
|
|
|
|
21.0,
|
|
|
|
51.0,
|
|
|
|
3.0,
|
|
|
|
3.0,
|
|
|
|
0.,
|
|
|
|
0.,
|
|
|
|
false,
|
|
|
|
);
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2021-11-22 18:34:09 +00:00
|
|
|
let mut terminal = Term::new(&cfg.terminal_config, size, MockEventProxy);
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2021-01-01 05:07:39 +00:00
|
|
|
let mut mouse = Mouse {
|
|
|
|
click_state: $initial_state,
|
2021-07-29 15:40:51 +00:00
|
|
|
last_click_button: $initial_button,
|
2021-01-01 05:07:39 +00:00
|
|
|
..Mouse::default()
|
|
|
|
};
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2021-10-23 07:16:47 +00:00
|
|
|
let mut message_buffer = MessageBuffer::default();
|
2019-10-05 00:29:26 +00:00
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
let context = ActionContext {
|
|
|
|
terminal: &mut terminal,
|
|
|
|
mouse: &mut mouse,
|
|
|
|
size_info: &size,
|
2020-06-06 21:33:20 +00:00
|
|
|
clipboard: &mut clipboard,
|
2017-07-20 17:50:50 +00:00
|
|
|
received_count: 0,
|
|
|
|
suppress_chars: false,
|
2019-11-11 21:05:24 +00:00
|
|
|
modifiers: Default::default(),
|
2019-10-05 00:29:26 +00:00
|
|
|
message_buffer: &mut message_buffer,
|
2019-11-03 19:02:26 +00:00
|
|
|
config: &cfg,
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
|
|
|
|
2021-01-24 21:45:36 +00:00
|
|
|
let mut processor = Processor::new(context);
|
2017-01-15 01:53:48 +00:00
|
|
|
|
2020-06-18 01:02:56 +00:00
|
|
|
let event: GlutinEvent::<'_, TerminalEvent> = $input;
|
|
|
|
if let GlutinEvent::WindowEvent {
|
2019-11-03 20:59:28 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state,
|
|
|
|
button,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
2020-01-10 01:51:37 +00:00
|
|
|
} = event
|
2019-11-03 20:59:28 +00:00
|
|
|
{
|
2020-01-05 01:00:50 +00:00
|
|
|
processor.mouse_input(state, button);
|
2017-01-15 01:53:48 +00:00
|
|
|
};
|
|
|
|
|
2020-04-10 18:23:50 +00:00
|
|
|
assert_eq!(processor.ctx.mouse.click_state, $end_state);
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 16:48:31 +00:00
|
|
|
macro_rules! test_process_binding {
|
|
|
|
{
|
|
|
|
name: $name:ident,
|
|
|
|
binding: $binding:expr,
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: $triggers:expr,
|
2016-06-23 16:48:31 +00:00
|
|
|
mode: $mode:expr,
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: $mods:expr,
|
2016-06-23 16:48:31 +00:00
|
|
|
} => {
|
|
|
|
#[test]
|
|
|
|
fn $name() {
|
2016-12-27 00:00:27 +00:00
|
|
|
if $triggers {
|
2020-01-10 00:44:41 +00:00
|
|
|
assert!($binding.is_triggered_by($mode, $mods, &KEY));
|
2016-12-27 00:00:27 +00:00
|
|
|
} else {
|
2020-01-10 00:44:41 +00:00
|
|
|
assert!(!$binding.is_triggered_by($mode, $mods, &KEY));
|
2016-12-27 00:00:27 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-15 01:53:48 +00:00
|
|
|
test_clickstate! {
|
|
|
|
name: single_click,
|
|
|
|
initial_state: ClickState::None,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: MouseButton::Other(0),
|
2020-06-18 01:02:56 +00:00
|
|
|
input: GlutinEvent::WindowEvent {
|
2017-07-20 17:50:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Left,
|
2020-04-10 18:23:50 +00:00
|
|
|
device_id: unsafe { std::mem::transmute_copy(&0) },
|
2017-12-29 23:49:20 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2020-04-10 18:23:50 +00:00
|
|
|
window_id: unsafe { std::mem::transmute_copy(&0) },
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
end_state: ClickState::Click,
|
2020-04-10 18:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_clickstate! {
|
|
|
|
name: single_right_click,
|
|
|
|
initial_state: ClickState::None,
|
|
|
|
initial_button: MouseButton::Other(0),
|
2020-06-18 01:02:56 +00:00
|
|
|
input: GlutinEvent::WindowEvent {
|
2020-04-10 18:23:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Right,
|
|
|
|
device_id: unsafe { std::mem::transmute_copy(&0) },
|
|
|
|
modifiers: ModifiersState::default(),
|
|
|
|
},
|
|
|
|
window_id: unsafe { std::mem::transmute_copy(&0) },
|
|
|
|
},
|
2020-06-23 09:57:15 +00:00
|
|
|
end_state: ClickState::Click,
|
2020-04-10 18:23:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_clickstate! {
|
|
|
|
name: single_middle_click,
|
|
|
|
initial_state: ClickState::None,
|
|
|
|
initial_button: MouseButton::Other(0),
|
2020-06-18 01:02:56 +00:00
|
|
|
input: GlutinEvent::WindowEvent {
|
2020-04-10 18:23:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Middle,
|
|
|
|
device_id: unsafe { std::mem::transmute_copy(&0) },
|
|
|
|
modifiers: ModifiersState::default(),
|
|
|
|
},
|
|
|
|
window_id: unsafe { std::mem::transmute_copy(&0) },
|
|
|
|
},
|
2021-07-29 15:40:51 +00:00
|
|
|
end_state: ClickState::Click,
|
2017-01-15 01:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_clickstate! {
|
|
|
|
name: double_click,
|
|
|
|
initial_state: ClickState::Click,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: MouseButton::Left,
|
2020-06-18 01:02:56 +00:00
|
|
|
input: GlutinEvent::WindowEvent {
|
2017-07-20 17:50:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Left,
|
2020-04-10 18:23:50 +00:00
|
|
|
device_id: unsafe { std::mem::transmute_copy(&0) },
|
2017-12-29 23:49:20 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2020-04-10 18:23:50 +00:00
|
|
|
window_id: unsafe { std::mem::transmute_copy(&0) },
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
end_state: ClickState::DoubleClick,
|
|
|
|
}
|
|
|
|
|
|
|
|
test_clickstate! {
|
|
|
|
name: triple_click,
|
|
|
|
initial_state: ClickState::DoubleClick,
|
2019-01-08 07:37:58 +00:00
|
|
|
initial_button: MouseButton::Left,
|
2020-06-18 01:02:56 +00:00
|
|
|
input: GlutinEvent::WindowEvent {
|
2017-07-20 17:50:50 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Left,
|
2020-04-10 18:23:50 +00:00
|
|
|
device_id: unsafe { std::mem::transmute_copy(&0) },
|
2017-12-29 23:49:20 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2020-04-10 18:23:50 +00:00
|
|
|
window_id: unsafe { std::mem::transmute_copy(&0) },
|
2017-07-20 17:50:50 +00:00
|
|
|
},
|
2017-01-15 01:53:48 +00:00
|
|
|
end_state: ClickState::TripleClick,
|
|
|
|
}
|
|
|
|
|
2019-01-08 07:37:58 +00:00
|
|
|
test_clickstate! {
|
|
|
|
name: multi_click_separate_buttons,
|
|
|
|
initial_state: ClickState::DoubleClick,
|
|
|
|
initial_button: MouseButton::Left,
|
2020-06-18 01:02:56 +00:00
|
|
|
input: GlutinEvent::WindowEvent {
|
2019-01-08 07:37:58 +00:00
|
|
|
event: WindowEvent::MouseInput {
|
|
|
|
state: ElementState::Pressed,
|
|
|
|
button: MouseButton::Right,
|
2020-04-10 18:23:50 +00:00
|
|
|
device_id: unsafe { std::mem::transmute_copy(&0) },
|
2019-01-08 07:37:58 +00:00
|
|
|
modifiers: ModifiersState::default(),
|
|
|
|
},
|
2020-04-10 18:23:50 +00:00
|
|
|
window_id: unsafe { std::mem::transmute_copy(&0) },
|
2019-01-08 07:37:58 +00:00
|
|
|
},
|
2020-06-23 09:57:15 +00:00
|
|
|
end_state: ClickState::Click,
|
2019-01-08 07:37:58 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 16:48:31 +00:00
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_shiftmod_require_shift,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::SHIFT, action: Action::from("\x1b[1;2D"), mode: BindingMode::empty(), notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::empty(),
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::SHIFT,
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_nomod_require_shift,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::SHIFT, action: Action::from("\x1b[1;2D"), mode: BindingMode::empty(), notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: false,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::empty(),
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::empty(),
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_controlmod,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::CTRL, action: Action::from("\x1b[1;5D"), mode: BindingMode::empty(), notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::empty(),
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::CTRL,
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_nomod_require_not_appcursor,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1b[D"), mode: BindingMode::empty(), notmode: BindingMode::APP_CURSOR },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::empty(),
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::empty(),
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_appcursormode_nomod_require_appcursor,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1bOD"), mode: BindingMode::APP_CURSOR, notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::APP_CURSOR,
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::empty(),
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_nomode_nomod_require_appcursor,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1bOD"), mode: BindingMode::APP_CURSOR, notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: false,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::empty(),
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::empty(),
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|
2016-07-30 01:27:45 +00:00
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_appcursormode_appkeypadmode_nomod_require_appcursor,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::empty(), action: Action::from("\x1bOD"), mode: BindingMode::APP_CURSOR, notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: true,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::APP_CURSOR | BindingMode::APP_KEYPAD,
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::empty(),
|
2016-07-30 01:27:45 +00:00
|
|
|
}
|
2016-09-27 15:27:39 +00:00
|
|
|
|
|
|
|
test_process_binding! {
|
|
|
|
name: process_binding_fail_with_extra_mods,
|
2020-12-19 04:07:20 +00:00
|
|
|
binding: Binding { trigger: KEY, mods: ModifiersState::LOGO, action: Action::from("arst"), mode: BindingMode::empty(), notmode: BindingMode::empty() },
|
2016-12-27 00:00:27 +00:00
|
|
|
triggers: false,
|
2020-12-19 04:07:20 +00:00
|
|
|
mode: BindingMode::empty(),
|
2020-01-05 01:00:50 +00:00
|
|
|
mods: ModifiersState::ALT | ModifiersState::LOGO,
|
2016-09-27 15:27:39 +00:00
|
|
|
}
|
2016-06-23 16:48:31 +00:00
|
|
|
}
|