aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
authorBernardo <[email protected]>2018-12-21 19:11:27 +0000
committerBernardo <[email protected]>2018-12-25 19:03:14 +0000
commit1c44ba0f04a0997617d517111d0a08245f0dacac (patch)
treebf5d373e350ab60ea56cf0b84d1dbf6aa6679124 /crates/ra_editor/src
parentd6312085a1ac97030fa768366585b9cfb6c955cd (diff)
simplify newline check with macro
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/line_index_utils.rs34
1 files changed, 14 insertions, 20 deletions
diff --git a/crates/ra_editor/src/line_index_utils.rs b/crates/ra_editor/src/line_index_utils.rs
index e62c5089d..2dd7fd708 100644
--- a/crates/ra_editor/src/line_index_utils.rs
+++ b/crates/ra_editor/src/line_index_utils.rs
@@ -143,35 +143,33 @@ pub fn count_newlines(offset: TextUnit, line_index: &LineIndex, edits: &[AtomTex
143 143
144 let mut lines: u32 = 0; 144 let mut lines: u32 = 0;
145 145
146 macro_rules! test_newline {
147 ($x:ident) => {
148 if offset < $x {
149 return lines;
150 } else {
151 lines += 1;
152 }
153 };
154 }
155
146 for &orig_newline in line_index.newlines() { 156 for &orig_newline in line_index.newlines() {
147 loop { 157 loop {
148 let translated_newline = state.translate(orig_newline); 158 let translated_newline = state.translate(orig_newline);
149 match state.next_newlines(translated_newline) { 159 match state.next_newlines(translated_newline) {
150 NextNewlines::Use => { 160 NextNewlines::Use => {
151 if offset < translated_newline { 161 test_newline!(translated_newline);
152 return lines;
153 } else {
154 lines += 1;
155 }
156 break; 162 break;
157 } 163 }
158 NextNewlines::ReplaceMany(ns) => { 164 NextNewlines::ReplaceMany(ns) => {
159 for n in ns { 165 for n in ns {
160 if offset < n { 166 test_newline!(n);
161 return lines;
162 } else {
163 lines += 1;
164 }
165 } 167 }
166 break; 168 break;
167 } 169 }
168 NextNewlines::AddMany(ns) => { 170 NextNewlines::AddMany(ns) => {
169 for n in ns { 171 for n in ns {
170 if offset < n { 172 test_newline!(n);
171 return lines;
172 } else {
173 lines += 1;
174 }
175 } 173 }
176 } 174 }
177 } 175 }
@@ -183,11 +181,7 @@ pub fn count_newlines(offset: TextUnit, line_index: &LineIndex, edits: &[AtomTex
183 None => break, 181 None => break,
184 Some(ns) => { 182 Some(ns) => {
185 for n in ns { 183 for n in ns {
186 if offset < n { 184 test_newline!(n);
187 return lines;
188 } else {
189 lines += 1;
190 }
191 } 185 }
192 } 186 }
193 } 187 }