aboutsummaryrefslogtreecommitdiff
path: root/src/selection.rs
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2018-10-22 19:39:26 +0000
committerGitHub <noreply@github.com>2018-10-22 19:39:26 +0000
commit8ee0d2b5b26faacb5f2663bae1fc056ac5ee26bf (patch)
tree093022ebdb474b891c8946ae42972dc23f73fefe /src/selection.rs
parent4380d0864b1098909bdcfec132b866c34924517e (diff)
downloadalacritty-8ee0d2b5b26faacb5f2663bae1fc056ac5ee26bf.tar.gz
alacritty-8ee0d2b5b26faacb5f2663bae1fc056ac5ee26bf.zip
Add option to open URLs on click
This adds the option to automatically launch URLs with a specified program when clicking on them. The config option `mouse.url_launcher` has been added to specify which program should be used to open the URL. The URL is always passed as the last parameter to the specified command. It is not always desired for URLs to open automatically when clicking on them. To resolve this a new `modifiers` field has been introduced to the config, which allows specifying which keyboard modifiers need to be held down to launch URLs in the specified launcher. Some tests have been added to make sure that the edge-cases of the URL parsing are protected against future regressions. To make testing easier the parsing method has been moved into the `SemanticSearch` trait. The name of the trait has also been changed to just `Search` and it has been moved to `src/term/mod.rs` to fit the additional functionality. This fixes #113.
Diffstat (limited to 'src/selection.rs')
-rw-r--r--src/selection.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/selection.rs b/src/selection.rs
index 932a61ee..8eb08d70 100644
--- a/src/selection.rs
+++ b/src/selection.rs
@@ -22,6 +22,7 @@ use std::cmp::{min, max};
use std::ops::Range;
use index::{Point, Column, Side};
+use term::Search;
/// Describes a region of a 2-dimensional area
///
@@ -71,17 +72,6 @@ impl Anchor {
}
}
-/// A type that can expand a given point to a region
-///
-/// Usually this is implemented for some 2-D array type since
-/// points are two dimensional indices.
-pub trait SemanticSearch {
- /// Find the nearest semantic boundary _to the left_ of provided point.
- fn semantic_search_left(&self, _: Point<usize>) -> Point<usize>;
- /// Find the nearest semantic boundary _to the point_ of provided point.
- fn semantic_search_right(&self, _: Point<usize>) -> Point<usize>;
-}
-
/// A type that has 2-dimensional boundaries
pub trait Dimensions {
/// Get the size of the area
@@ -151,7 +141,7 @@ impl Selection {
pub fn to_span<G>(&self, grid: &G, alt_screen: bool) -> Option<Span>
where
- G: SemanticSearch + Dimensions,
+ G: Search + Dimensions,
{
match *self {
Selection::Simple { ref region } => {
@@ -166,12 +156,24 @@ impl Selection {
}
}
+ pub fn is_empty(&self) -> bool
+ {
+ match *self {
+ Selection::Simple { ref region } => {
+ region.start == region.end && region.start.side == region.end.side
+ },
+ Selection::Semantic { .. } | Selection::Lines { .. } => {
+ false
+ },
+ }
+ }
+
fn span_semantic<G>(
grid: &G,
region: &Range<Point<isize>>,
alt_screen: bool,
) -> Option<Span>
- where G: SemanticSearch + Dimensions
+ where G: Search + Dimensions
{
let cols = grid.dimensions().col;
let lines = grid.dimensions().line.0 as isize;
@@ -448,9 +450,10 @@ mod test {
}
}
- impl super::SemanticSearch for Dimensions {
+ impl super::Search for Dimensions {
fn semantic_search_left(&self, point: Point<usize>) -> Point<usize> { point }
fn semantic_search_right(&self, point: Point<usize>) -> Point<usize> { point }
+ fn url_search(&self, _: Point<usize>) -> Option<String> { None }
}
/// Test case of single cell selection