aboutsummaryrefslogtreecommitdiff
path: root/alacritty_terminal/src/index.rs
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2019-11-03 21:59:28 +0100
committerGitHub <noreply@github.com>2019-11-03 21:59:28 +0100
commitb47a88b142a8987f1d0d48db8c0db1e5f3048a76 (patch)
tree0863fb40b8e081ccc40f1437e74c49a68f4e6c59 /alacritty_terminal/src/index.rs
parentfa6ceacfa4158c568c55dff85621788ff1df4099 (diff)
downloadalacritty-b47a88b142a8987f1d0d48db8c0db1e5f3048a76.tar.gz
alacritty-b47a88b142a8987f1d0d48db8c0db1e5f3048a76.zip
Fix URL highlighting
Fixes #2898. Fixes #2479.
Diffstat (limited to 'alacritty_terminal/src/index.rs')
-rw-r--r--alacritty_terminal/src/index.rs48
1 files changed, 25 insertions, 23 deletions
diff --git a/alacritty_terminal/src/index.rs b/alacritty_terminal/src/index.rs
index 0a100e18..d40245f3 100644
--- a/alacritty_terminal/src/index.rs
+++ b/alacritty_terminal/src/index.rs
@@ -17,7 +17,7 @@
/// Indexing types and implementations for Grid and Line
use std::cmp::{Ord, Ordering};
use std::fmt;
-use std::ops::{self, Add, AddAssign, Deref, Range, RangeInclusive, Sub, SubAssign};
+use std::ops::{self, Add, AddAssign, Deref, Range, Sub, SubAssign};
use serde::{Deserialize, Serialize};
@@ -41,6 +41,30 @@ impl<L> Point<L> {
pub fn new(line: L, col: Column) -> Point<L> {
Point { line, col }
}
+
+ #[inline]
+ #[must_use = "this returns the result of the operation, without modifying the original"]
+ pub fn sub(mut self, num_cols: usize, length: usize) -> Point<L>
+ where
+ L: Copy + Sub<usize, Output = L>,
+ {
+ let line_changes = f32::ceil(length.saturating_sub(self.col.0) as f32 / num_cols as f32);
+ self.line = self.line - line_changes as usize;
+ self.col = Column((num_cols + self.col.0 - length % num_cols) % num_cols);
+ self
+ }
+
+ #[inline]
+ #[must_use = "this returns the result of the operation, without modifying the original"]
+ pub fn add(mut self, num_cols: usize, length: usize) -> Point<L>
+ where
+ L: Copy + Add<usize, Output = L>,
+ {
+ let line_changes = length.saturating_sub(self.col.0) / num_cols;
+ self.line = self.line + line_changes;
+ self.col = Column((self.col.0 + length) % num_cols);
+ self
+ }
}
impl Ord for Point {
@@ -253,28 +277,6 @@ impl<T> From<Range<T>> for IndexRange<T> {
}
}
-// can be removed if range_contains is stabilized
-pub trait Contains {
- type Content;
- fn contains_(&self, item: Self::Content) -> bool;
-}
-
-impl<T: PartialOrd<T>> Contains for Range<T> {
- type Content = T;
-
- fn contains_(&self, item: Self::Content) -> bool {
- (self.start <= item) && (item < self.end)
- }
-}
-
-impl<T: PartialOrd<T>> Contains for RangeInclusive<T> {
- type Content = T;
-
- fn contains_(&self, item: Self::Content) -> bool {
- (self.start() <= &item) && (&item <= self.end())
- }
-}
-
macro_rules! ops {
($ty:ty, $construct:expr) => {
add!($ty, $construct);