use super::types::CopyModeState;
use crate::smart_selection::is_word_char;
impl CopyModeState {
pub fn move_word_forward(&mut self, line_text: &str, word_chars: &str) {
let count = self.effective_count();
let chars: Vec<char> = line_text.chars().collect();
let mut col = self.cursor_col;
for _ in 0..count {
if col >= chars.len() {
break;
}
while col < chars.len() && is_word_char(chars[col], word_chars) {
col += 1;
}
while col < chars.len() && !is_word_char(chars[col], word_chars) {
col += 1;
}
}
self.cursor_col = col.min(self.cols.saturating_sub(1));
}
pub fn move_word_backward(&mut self, line_text: &str, word_chars: &str) {
let count = self.effective_count();
let chars: Vec<char> = line_text.chars().collect();
let mut col = self.cursor_col;
for _ in 0..count {
if col == 0 {
break;
}
col = col.saturating_sub(1);
while col > 0 && !is_word_char(chars[col], word_chars) {
col -= 1;
}
while col > 0 && is_word_char(chars[col - 1], word_chars) {
col -= 1;
}
}
self.cursor_col = col;
}
pub fn move_word_end(&mut self, line_text: &str, word_chars: &str) {
let count = self.effective_count();
let chars: Vec<char> = line_text.chars().collect();
let mut col = self.cursor_col;
for _ in 0..count {
if col >= chars.len().saturating_sub(1) {
break;
}
col += 1;
while col < chars.len() && !is_word_char(chars[col], word_chars) {
col += 1;
}
while col < chars.len().saturating_sub(1) && is_word_char(chars[col + 1], word_chars) {
col += 1;
}
}
self.cursor_col = col.min(self.cols.saturating_sub(1));
}
pub fn move_big_word_forward(&mut self, line_text: &str) {
let count = self.effective_count();
let chars: Vec<char> = line_text.chars().collect();
let mut col = self.cursor_col;
for _ in 0..count {
while col < chars.len() && !chars[col].is_whitespace() {
col += 1;
}
while col < chars.len() && chars[col].is_whitespace() {
col += 1;
}
}
self.cursor_col = col.min(self.cols.saturating_sub(1));
}
pub fn move_big_word_backward(&mut self, line_text: &str) {
let count = self.effective_count();
let chars: Vec<char> = line_text.chars().collect();
let mut col = self.cursor_col;
for _ in 0..count {
if col == 0 {
break;
}
col = col.saturating_sub(1);
while col > 0 && chars[col].is_whitespace() {
col -= 1;
}
while col > 0 && !chars[col - 1].is_whitespace() {
col -= 1;
}
}
self.cursor_col = col;
}
pub fn move_big_word_end(&mut self, line_text: &str) {
let count = self.effective_count();
let chars: Vec<char> = line_text.chars().collect();
let mut col = self.cursor_col;
for _ in 0..count {
if col >= chars.len().saturating_sub(1) {
break;
}
col += 1;
while col < chars.len() && chars[col].is_whitespace() {
col += 1;
}
while col < chars.len().saturating_sub(1) && !chars[col + 1].is_whitespace() {
col += 1;
}
}
self.cursor_col = col.min(self.cols.saturating_sub(1));
}
}