summaryrefslogtreecommitdiffstats
path: root/alacritty_terminal/src/index.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2020-03-18 02:35:08 +0000
committerGitHub <noreply@github.com>2020-03-18 02:35:08 +0000
commit1a8cd172e520e493bacc9c6a2ae6f80de086eaa3 (patch)
tree0b837f1f52f72fe00e258afc34094d60b5d18f04 /alacritty_terminal/src/index.rs
parent64db7d3daaed4e06fb8292227622bbc4cdaa2cf0 (diff)
Add modal keyboard motion mode
This implements a basic mode for navigating inside of Alacritty's history with keyboard bindings. They're bound by default to vi's motion shortcuts but are fully customizable. Since this relies on key bindings only single key bindings are currently supported (so no `ge`, or repetition). Other than navigating the history and moving the viewport, this mode should enable making use of all available selection modes to copy content to the clipboard and launch URLs below the cursor. This also changes the rendering of the block cursor at the side of selections, since previously it could be inverted to be completely invisible. Since that would have caused some troubles with this keyboard selection mode, the block cursor now is no longer inverted when it is at the edges of a selection. Fixes #262.
Diffstat (limited to 'alacritty_terminal/src/index.rs')
-rw-r--r--alacritty_terminal/src/index.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/alacritty_terminal/src/index.rs b/alacritty_terminal/src/index.rs
index 56d32003..1334a74e 100644
--- a/alacritty_terminal/src/index.rs
+++ b/alacritty_terminal/src/index.rs
@@ -30,6 +30,15 @@ pub enum Side {
Right,
}
+impl Side {
+ pub fn opposite(self) -> Self {
+ match self {
+ Side::Right => Side::Left,
+ Side::Left => Side::Right,
+ }
+ }
+}
+
/// Index in the grid using row, column notation
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize, PartialOrd)]
pub struct Point<L = Line> {
@@ -49,7 +58,7 @@ impl<L> Point<L> {
L: Copy + Default + Into<Line> + Add<usize, Output = L> + Sub<usize, Output = L>,
{
let line_changes =
- f32::ceil(rhs.saturating_sub(self.col.0) as f32 / num_cols as f32) as usize;
+ (rhs.saturating_sub(self.col.0) as f32 / num_cols as f32).ceil() as usize;
if self.line.into() > Line(line_changes) {
self.line = self.line - line_changes;
} else {
@@ -63,12 +72,40 @@ impl<L> Point<L> {
#[must_use = "this returns the result of the operation, without modifying the original"]
pub fn add(mut self, num_cols: usize, rhs: usize) -> Point<L>
where
- L: Add<usize, Output = L> + Sub<usize, Output = L>,
+ L: Copy + Default + Into<Line> + Add<usize, Output = L> + Sub<usize, Output = L>,
{
self.line = self.line + (rhs + self.col.0) / num_cols;
self.col = Column((self.col.0 + rhs) % num_cols);
self
}
+
+ #[inline]
+ #[must_use = "this returns the result of the operation, without modifying the original"]
+ pub fn sub_absolute(mut self, num_cols: usize, rhs: usize) -> Point<L>
+ where
+ L: Copy + Default + Into<Line> + Add<usize, Output = L> + Sub<usize, Output = L>,
+ {
+ self.line =
+ self.line + (rhs.saturating_sub(self.col.0) as f32 / num_cols as f32).ceil() as usize;
+ self.col = Column((num_cols + self.col.0 - rhs % num_cols) % num_cols);
+ self
+ }
+
+ #[inline]
+ #[must_use = "this returns the result of the operation, without modifying the original"]
+ pub fn add_absolute(mut self, num_cols: usize, rhs: usize) -> Point<L>
+ where
+ L: Copy + Default + Into<Line> + Add<usize, Output = L> + Sub<usize, Output = L>,
+ {
+ let line_changes = (rhs + self.col.0) / num_cols;
+ if self.line.into() > Line(line_changes) {
+ self.line = self.line - line_changes;
+ } else {
+ self.line = Default::default();
+ }
+ self.col = Column((self.col.0 + rhs) % num_cols);
+ self
+ }
}
impl Ord for Point {