forked from gj1118/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr.patch
More file actions
179 lines (167 loc) · 6.59 KB
/
Copy pathpr.patch
File metadata and controls
179 lines (167 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
From 97b1f931050a73e031fe0d003caba7152abf5f37 Mon Sep 17 00:00:00 2001
From: TheAvonian <29378966+TheAvonian@users.noreply.github.com>
Date: Tue, 20 Jan 2026 14:37:01 -0500
Subject: [PATCH] fix: finding next and previous char can fail in crlf
---
helix-core/src/text_folding/ropex.rs | 35 ++++---------------
helix-core/src/text_folding/test_utils.rs | 4 +--
.../tests/test/commands/text_folding.rs | 18 ++++++----
3 files changed, 20 insertions(+), 37 deletions(-)
diff --git a/helix-core/src/text_folding/ropex.rs b/helix-core/src/text_folding/ropex.rs
index f58093f6a512..9f111534222c 100644
--- a/helix-core/src/text_folding/ropex.rs
+++ b/helix-core/src/text_folding/ropex.rs
@@ -366,21 +366,14 @@ impl<'a, Items: TextItems<'a>> FoldedTextItems<'a, Items> {
return self.prev_impl();
}
+ let item = self.items.prev_impl()?;
+
self.last_idx = Some(self.idx);
- Some(
- self.items
- .prev_impl()
- .expect("The `idx` field must equal the item index."),
- )
+ Some(item)
}
fn next_impl(&mut self) -> Option<Items::Item> {
- if self.idx == Items::len(self.slice) {
- self.last_idx = None;
- return None;
- }
-
if let Some(position) = Items::consume_next(self.annotations, self.idx) {
self.idx = position + 1;
self.items = Items::at(self.slice, self.idx);
@@ -388,15 +381,12 @@ impl<'a, Items: TextItems<'a>> FoldedTextItems<'a, Items> {
return self.next_impl();
}
- self.last_idx = Some(self.idx);
+ let item = self.items.next_impl()?;
- let result = self
- .items
- .next_impl()
- .expect("The `idx` field must equal the item index.");
+ self.last_idx = Some(self.idx);
self.idx += 1;
- Some(result)
+ Some(item)
}
}
@@ -416,7 +406,6 @@ impl<'a, Items: TextItems<'a>> Iterator for FoldedTextItems<'a, Items> {
trait TextItems<'a>: Iterator {
fn at(slice: RopeSlice<'a>, idx: usize) -> Self;
fn reset_pos(annotations: &FoldAnnotations, idx: usize);
- fn len(slice: RopeSlice) -> usize;
fn prev_impl(&mut self) -> Option<Self::Item>;
fn next_impl(&mut self) -> Option<Self::Item>;
fn consume_prev(annotations: &FoldAnnotations, idx: usize) -> Option<usize>;
@@ -432,10 +421,6 @@ impl<'a> TextItems<'a> for Chars<'a> {
annotations.reset_pos(char_idx, |fold| fold.start.char)
}
- fn len(slice: RopeSlice) -> usize {
- slice.len_chars()
- }
-
fn prev_impl(&mut self) -> Option<Self::Item> {
self.prev()
}
@@ -466,10 +451,6 @@ impl<'a> TextItems<'a> for RopeGraphemes<'a> {
annotations.reset_pos(byte_idx, |fold| fold.start.byte)
}
- fn len(slice: RopeSlice) -> usize {
- slice.len_bytes()
- }
-
fn prev_impl(&mut self) -> Option<Self::Item> {
self.prev()
}
@@ -500,10 +481,6 @@ impl<'a> TextItems<'a> for Lines<'a> {
annotations.reset_pos(line_idx, |fold| fold.start.line)
}
- fn len(slice: RopeSlice) -> usize {
- slice.len_lines()
- }
-
fn prev_impl(&mut self) -> Option<Self::Item> {
self.prev()
}
diff --git a/helix-core/src/text_folding/test_utils.rs b/helix-core/src/text_folding/test_utils.rs
index d03eb76f5d82..d785837997da 100644
--- a/helix-core/src/text_folding/test_utils.rs
+++ b/helix-core/src/text_folding/test_utils.rs
@@ -137,8 +137,8 @@ pub(crate) fn folds_eq_by(
) -> bool {
if container1.len() != container2.len() {
eprintln!(
- "left has lenght = {}\n\
- right has lenght = {}",
+ "left has length = {}\n\
+ right has length = {}",
container1.len(),
container2.len(),
);
diff --git a/helix-term/tests/test/commands/text_folding.rs b/helix-term/tests/test/commands/text_folding.rs
index addc3f05c10e..0f45c137066f 100644
--- a/helix-term/tests/test/commands/text_folding.rs
+++ b/helix-term/tests/test/commands/text_folding.rs
@@ -1499,7 +1499,8 @@ async fn open() -> anyhow::Result<()> {
),
Some(&|app| {
let expected = (" new text\n".into(), 0);
- assert_eq!(result(app, 55), expected);
+ let result = result(app, 55);
+ assert_eq!((result.0.replace("\r\n", "\n"), result.1), expected);
}),
),
(Some("xd"), None),
@@ -1511,7 +1512,8 @@ async fn open() -> anyhow::Result<()> {
),
Some(&|app| {
let expected = (" new text\n".into(), 0);
- assert_eq!(result(app, 55), expected);
+ let result = result(app, 55);
+ assert_eq!((result.0.replace("\r\n", "\n"), result.1), expected);
}),
),
(Some("xd"), None),
@@ -1523,7 +1525,8 @@ async fn open() -> anyhow::Result<()> {
),
Some(&|app| {
let expected = (" new text\n".into(), -1);
- assert_eq!(result(app, 71), expected);
+ let result = result(app, 71);
+ assert_eq!((result.0.replace("\r\n", "\n"), result.1), expected);
}),
),
(
@@ -1545,7 +1548,8 @@ async fn open() -> anyhow::Result<()> {
),
Some(&|app| {
let expected = (" new text\n".into(), -1);
- assert_eq!(result(app, 71), expected);
+ let result = result(app, 71);
+ assert_eq!((result.0.replace("\r\n", "\n"), result.1), expected);
}),
),
(
@@ -1556,7 +1560,8 @@ async fn open() -> anyhow::Result<()> {
),
Some(&|app| {
let expected = ("new text\n".into(), 0);
- assert_eq!(result(app, 4), expected);
+ let result = result(app, 4);
+ assert_eq!((result.0.replace("\r\n", "\n"), result.1), expected);
}),
),
(
@@ -1582,7 +1587,8 @@ async fn open() -> anyhow::Result<()> {
),
Some(&|app| {
let expected = ("//! new text\n".into(), 0);
- assert_eq!(result(app, 4), expected);
+ let result = result(app, 4);
+ assert_eq!((result.0.replace("\r\n", "\n"), result.1), expected);
}),
),
],