aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/words.rs
diff options
context:
space:
mode:
authorPabloMansanet2021-06-11 12:57:07 +0000
committerGitHub2021-06-11 12:57:07 +0000
commit86af55c379c531df2d5dbc72841e28a10fc7938e (patch)
treed2946657e2ca0102c7ddf291b0ffb9819ab001d9 /helix-core/src/words.rs
parent0c2b99327a60d478ff6a4e4a2a15f69e61857569 (diff)
Movement fixes, refactor and unit test suite (#217)
* Add convenience/clarity wrapper for Range initialization * Test horizontal moves * Add column jumping tests * Add failing movement conditions for multi-word moves * Refactor skip_over_next * Add complex forward movement unit tests * Add strict whitespace checks and edge case tests * Restore formatting * Remove unused function * Add empty test case for deletion and fix nth_prev_word_boundary * Add tests for backward motion * Refactor word movement * Address review comments and finish refactoring backwards move * Finish unit test suite * Fmt pass * Fix lint erors * Clean up diff restoring bad 'cargo fmt' actions * Simplify movement closures (thanks Pickfire) * Fmt pass * Replace index-based movement with iterator based movement, ensuring that each move incurs a single call to the RopeSlice API * Break down tuple function * Extract common logic to all movement functions * Split iterator helpers away into their own module * WIP reducing clones * Operate on spans * WIP simplifying iterators * Simplify motion helpers * Fix iterator * Fix all unit tests * Refactor and simplify * Simplify fold
Diffstat (limited to 'helix-core/src/words.rs')
-rw-r--r--helix-core/src/words.rs68
1 files changed, 0 insertions, 68 deletions
diff --git a/helix-core/src/words.rs b/helix-core/src/words.rs
deleted file mode 100644
index 7ecdacba..00000000
--- a/helix-core/src/words.rs
+++ /dev/null
@@ -1,68 +0,0 @@
-use crate::movement::{categorize, is_punctuation, is_word, skip_over_prev};
-use ropey::RopeSlice;
-
-#[must_use]
-pub fn nth_prev_word_boundary(slice: RopeSlice, mut char_idx: usize, count: usize) -> usize {
- let mut with_end = false;
-
- for _ in 0..count {
- if char_idx == 0 {
- break;
- }
-
- // return if not skip while?
- skip_over_prev(slice, &mut char_idx, |ch| ch == '\n');
-
- with_end = skip_over_prev(slice, &mut char_idx, char::is_whitespace);
-
- // refetch
- let ch = slice.char(char_idx);
-
- if is_word(ch) {
- with_end = skip_over_prev(slice, &mut char_idx, is_word);
- } else if is_punctuation(ch) {
- with_end = skip_over_prev(slice, &mut char_idx, is_punctuation);
- }
- }
-
- if with_end || char_idx == 0 {
- char_idx
- } else {
- char_idx + 1
- }
-}
-
-#[test]
-fn different_prev_word_boundary() {
- use ropey::Rope;
- let t = |x, y| {
- let text = Rope::from(x);
- let out = nth_prev_word_boundary(text.slice(..), text.len_chars().saturating_sub(1), 1);
- assert_eq!(text.slice(..out), y, r#"from "{}""#, x);
- };
- t("abcd\nefg\nwrs", "abcd\nefg\n");
- t("abcd\nefg\n", "abcd\n");
- t("abcd\n", "");
- t("hello, world!", "hello, world");
- t("hello, world", "hello, ");
- t("hello, ", "hello");
- t("hello", "");
- t(",", "");
- t("こんにちは、世界!", "こんにちは、世界");
- t("こんにちは、世界", "こんにちは、");
- t("こんにちは、", "こんにちは");
- t("こんにちは", "");
- t("この世界。", "この世界");
- t("この世界", "");
- t("お前はもう死んでいる", "");
- t("その300円です", ""); // TODO: should stop at 300
- t("唱k", ""); // TODO: should stop at 唱
- t(",", "");
- t("1 + 1 = 2", "1 + 1 = ");
- t("1 + 1 =", "1 + 1 ");
- t("1 + 1", "1 + ");
- t("1 + ", "1 ");
- t("1 ", "");
- t("1+1=2", "1+1=");
- t("", "");
-}