aboutsummaryrefslogtreecommitdiff
path: root/helix-core
diff options
context:
space:
mode:
authorPascal Kuthe2023-02-09 07:19:29 +0000
committerGitHub2023-02-09 07:19:29 +0000
commit7ebcf4e919a27b60610ba8f3a24a213282eb9ee6 (patch)
treececdae3f902af192ddb5adb8b3202f060f88bfa4 /helix-core
parent8a602995fa71bee009c0ab1e67b78828a731ca75 (diff)
properly handle LSP position encoding (#5711)
* properly handle LSP position encoding * add debug assertion to Transaction::change * Apply suggestions from code review Co-authored-by: Michael Davis <mcarsondavis@gmail.com> --------- Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'helix-core')
-rw-r--r--helix-core/src/line_ending.rs7
-rw-r--r--helix-core/src/transaction.rs5
2 files changed, 12 insertions, 0 deletions
diff --git a/helix-core/src/line_ending.rs b/helix-core/src/line_ending.rs
index 09e92523..953d567d 100644
--- a/helix-core/src/line_ending.rs
+++ b/helix-core/src/line_ending.rs
@@ -203,6 +203,13 @@ pub fn line_end_char_index(slice: &RopeSlice, line: usize) -> usize {
.unwrap_or(0)
}
+pub fn line_end_byte_index(slice: &RopeSlice, line: usize) -> usize {
+ slice.line_to_byte(line + 1)
+ - get_line_ending(&slice.line(line))
+ .map(|le| le.as_str().len())
+ .unwrap_or(0)
+}
+
/// Fetches line `line_idx` from the passed rope slice, sans any line ending.
pub fn line_without_line_ending<'a>(slice: &'a RopeSlice, line_idx: usize) -> RopeSlice<'a> {
let start = slice.line_to_char(line_idx);
diff --git a/helix-core/src/transaction.rs b/helix-core/src/transaction.rs
index 482fd6d9..d2f4de07 100644
--- a/helix-core/src/transaction.rs
+++ b/helix-core/src/transaction.rs
@@ -481,6 +481,11 @@ impl Transaction {
for (from, to, tendril) in changes {
// Verify ranges are ordered and not overlapping
debug_assert!(last <= from);
+ // Verify ranges are correct
+ debug_assert!(
+ from <= to,
+ "Edit end must end before it starts (should {from} <= {to})"
+ );
// Retain from last "to" to current "from"
changeset.retain(from - last);