aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorBlaž Hrastnik2020-09-28 16:00:35 +0000
committerBlaž Hrastnik2020-09-28 16:00:35 +0000
commit3020077da8efbf914a9cb0a2cbb50362d339a39a (patch)
treeaf8eaf9c016ac5116f6349a6b5ebb79e77f8efb5 /helix-core
parentfbe313779e83728b7dca7925df722c7fb4228d98 (diff)
Extend selection commands.
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/Cargo.toml15
-rw-r--r--helix-core/src/lib.rs1
-rw-r--r--helix-core/src/selection.rs29
-rw-r--r--helix-core/src/syntax.rs6
-rw-r--r--helix-core/src/transaction.rs5
5 files changed, 44 insertions, 12 deletions
diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml
index 6a4b09e5..09d9c829 100644
--- a/helix-core/Cargo.toml
+++ b/helix-core/Cargo.toml
@@ -9,12 +9,13 @@ edition = "2018"
[dependencies]
helix-syntax = { path = "../helix-syntax" }
-ropey = "1.2.0"
-anyhow = "1.0.31"
-smallvec = "1.4.0"
+ropey = "1.2"
+anyhow = "1"
+smallvec = "1.4"
tendril = { git = "https://github.com/servo/tendril" }
-unicode-segmentation = "1.6.0"
-unicode-width = "0.1.7"
+unicode-segmentation = "1.6"
+unicode-width = "0.1"
# slab = "0.4.2"
-tree-sitter = "0.16.1"
-once_cell = "1.4.1"
+tree-sitter = "0.17"
+once_cell = "1.4"
+regex = "1"
diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs
index e97c16be..9705deaa 100644
--- a/helix-core/src/lib.rs
+++ b/helix-core/src/lib.rs
@@ -8,6 +8,7 @@ pub mod syntax;
mod transaction;
pub use ropey::{Rope, RopeSlice};
+
pub use tendril::StrTendril as Tendril;
pub use position::Position;
diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs
index 80bb6a0c..f934f74d 100644
--- a/helix-core/src/selection.rs
+++ b/helix-core/src/selection.rs
@@ -60,6 +60,18 @@ impl Range {
}
}
+ pub fn contains(&self, pos: usize) -> bool {
+ if self.is_empty() {
+ return false;
+ }
+
+ if self.anchor < self.head {
+ self.anchor <= pos && pos < self.head
+ } else {
+ self.head < pos && pos <= self.anchor
+ }
+ }
+
/// Map a range through a set of changes. Returns a new range representing the same position
/// after the changes are applied.
pub fn map(self, changes: &ChangeSet) -> Self {
@@ -283,4 +295,21 @@ mod test {
assert_eq!(res, "8/10,10/12");
}
+
+ #[test]
+ fn test_contains() {
+ let range = Range::new(10, 12);
+
+ assert_eq!(range.contains(9), false);
+ assert_eq!(range.contains(10), true);
+ assert_eq!(range.contains(11), true);
+ assert_eq!(range.contains(12), false);
+ assert_eq!(range.contains(13), false);
+
+ let range = Range::new(9, 6);
+ assert_eq!(range.contains(9), true);
+ assert_eq!(range.contains(7), true);
+ assert_eq!(range.contains(6), false);
+ }
+
}
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 26897ab3..9b09bb58 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -48,7 +48,7 @@ impl LanguageConfiguration {
if highlights_query.is_empty() {
Ok(None)
} else {
- let language = get_language(&self.language_id);
+ let language = get_language(self.language_id);
let mut config = HighlightConfiguration::new(
language,
&highlights_query,
@@ -1456,7 +1456,7 @@ fn test_parser() {
.map(String::from)
.collect();
- let language = get_language(&LANG::Rust);
+ let language = get_language(LANG::Rust);
let mut config = HighlightConfiguration::new(
language,
&std::fs::read_to_string(
@@ -1478,7 +1478,7 @@ fn test_parser() {
fn main() {}
",
);
- let syntax = Syntax::new(LANG::Rust, &source, config);
+ let syntax = Syntax::new(&source, Arc::new(config));
let tree = syntax.root_layer.tree.unwrap();
let root = tree.root_node();
assert_eq!(root.kind(), "source_file");
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 127cdaee..278e071b 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -1,4 +1,5 @@
use crate::{Range, Rope, Selection, State, Tendril};
+use std::convert::TryFrom;
/// (from, to, replacement)
pub type Change = (usize, usize, Option<Tendril>);
@@ -112,7 +113,7 @@ impl ChangeSet {
let (pos, _) = s.char_indices().nth(len - j).unwrap();
// calculate the difference
let to_drop = s.len() - pos;
- s.pop_back(to_drop as u32);
+ s.pop_back(u32::try_from(to_drop).unwrap());
head_a = Some(Insert(s));
head_b = changes_b.next();
}
@@ -136,7 +137,7 @@ impl ChangeSet {
let (pos, _) = s.char_indices().nth(j).unwrap();
// calculate the difference
let to_drop = s.len() - pos;
- s.pop_back(to_drop as u32);
+ s.pop_back(u32::try_from(to_drop).unwrap());
head_a = Some(Insert(s));
head_b = changes_b.next();
}