properly working vim like movements in the read only mode
This commit is contained in:
@@ -575,25 +575,46 @@ impl EventHandler {
|
||||
// Find the end of the current/next word
|
||||
fn find_word_end(&self, text: &str, current_pos: usize) -> usize {
|
||||
let chars: Vec<char> = text.chars().collect();
|
||||
if chars.is_empty() || current_pos >= chars.len() - 1 {
|
||||
return if chars.is_empty() { 0 } else { chars.len() - 1 };
|
||||
if chars.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If already at the end of the text, stay there
|
||||
if current_pos >= chars.len() - 1 {
|
||||
return chars.len() - 1;
|
||||
}
|
||||
|
||||
let mut pos = current_pos;
|
||||
|
||||
// Skip whitespace to find the next word
|
||||
while pos < chars.len() && Self::get_char_type(chars[pos]) == CharType::Whitespace {
|
||||
pos += 1;
|
||||
// If we're on whitespace, move forward to the next word
|
||||
if Self::get_char_type(chars[pos]) == CharType::Whitespace {
|
||||
// Skip whitespace to find the next word
|
||||
while pos < chars.len() && Self::get_char_type(chars[pos]) == CharType::Whitespace {
|
||||
pos += 1;
|
||||
}
|
||||
} else {
|
||||
// We're on a word character - check if we're at the end of the current word
|
||||
let current_type = Self::get_char_type(chars[pos]);
|
||||
if pos + 1 < chars.len() && Self::get_char_type(chars[pos + 1]) != current_type {
|
||||
// We're at the end of the current word, so move to the next word
|
||||
pos += 1;
|
||||
// Skip any whitespace
|
||||
while pos < chars.len() && Self::get_char_type(chars[pos]) == CharType::Whitespace {
|
||||
pos += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if pos == chars.len() {
|
||||
return pos.saturating_sub(1);
|
||||
// If we've reached the end of the text, return the last position
|
||||
if pos >= chars.len() {
|
||||
return chars.len() - 1;
|
||||
}
|
||||
|
||||
// Get the type of the word we're now on
|
||||
let word_type = Self::get_char_type(chars[pos]);
|
||||
|
||||
// Move to the end of this word
|
||||
while pos < chars.len() - 1 && Self::get_char_type(chars[pos + 1]) == word_type {
|
||||
while pos + 1 < chars.len() && Self::get_char_type(chars[pos + 1]) == word_type {
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user