From 0166c59671f8d268c3b7d142682d9755e8462feb Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nikitarevenco@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:28:06 +0000 Subject: [PATCH] feat: re-use logic for sub word movement in subword text object --- helix-core/src/movement.rs | 2 +- helix-core/src/textobject.rs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/helix-core/src/movement.rs b/helix-core/src/movement.rs index e446d8cc4..299d02a6b 100644 --- a/helix-core/src/movement.rs +++ b/helix-core/src/movement.rs @@ -502,7 +502,7 @@ fn is_long_word_boundary(a: char, b: char) -> bool { } } -fn is_sub_word_boundary(a: char, b: char, dir: Direction) -> bool { +pub fn is_sub_word_boundary(a: char, b: char, dir: Direction) -> bool { match (categorize_char(a), categorize_char(b)) { (CharCategory::Word, CharCategory::Word) => { if (a == '_') != (b == '_') { diff --git a/helix-core/src/textobject.rs b/helix-core/src/textobject.rs index 9c81f9148..f2a8f30e1 100644 --- a/helix-core/src/textobject.rs +++ b/helix-core/src/textobject.rs @@ -6,7 +6,7 @@ use tree_sitter::{Node, QueryCursor}; use crate::chars::{categorize_char, char_is_subword_delimiter, char_is_whitespace, CharCategory}; use crate::graphemes::{next_grapheme_boundary, prev_grapheme_boundary}; use crate::line_ending::rope_is_line_ending; -use crate::movement::Direction; +use crate::movement::{is_sub_word_boundary, Direction}; use crate::syntax::LanguageConfiguration; use crate::Range; use crate::{surround, Syntax}; @@ -64,11 +64,12 @@ fn find_word_boundary( && pos != slice.len_chars(); let matches_subword = is_subword - && ((char_is_subword_delimiter(prev_ch) || char_is_subword_delimiter(ch)) - || match direction { - Direction::Forward => prev_ch.is_lowercase() && ch.is_uppercase(), - Direction::Backward => prev_ch.is_uppercase() && ch.is_lowercase(), - }); + && match direction { + Direction::Forward => is_sub_word_boundary(prev_ch, ch, Direction::Forward), + Direction::Backward => { + is_sub_word_boundary(prev_ch, ch, Direction::Backward) + } + }; if matches_subword { return pos;