Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds movement for start of word, regardless of stop characters #6445

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/src/keyassignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ pub enum CopyModeAssignment {
MoveToStartOfNextLine,
MoveToSelectionOtherEnd,
MoveToSelectionOtherEndHoriz,
MoveBackwardWordStart,
MoveBackwardWord,
MoveForwardWord,
MoveForwardWordEnd,
Expand Down
49 changes: 49 additions & 0 deletions wezterm-gui/src/overlay/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,54 @@ impl CopyRenderable {
}
}

fn move_backward_one_word_start(&mut self) {
let y = if self.cursor.x == 0 && self.cursor.y > 0 {
self.cursor.x = usize::max_value();
self.cursor.y.saturating_sub(1)
} else {
self.cursor.y
};

let (top, lines) = self.delegate.get_lines(y..y + 1);
if let Some(line) = lines.get(0) {
self.cursor.y = top;
if self.cursor.x == usize::max_value() {
self.cursor.x = line.len().saturating_sub(1);
}
let s = line.columns_as_str(0..self.cursor.x.saturating_add(1));

let mut last_was_whitespace = false;

for (idx, word) in s.split_ascii_whitespace().rev().enumerate() {
let width = unicode_column_width(word, None);

if is_whitespace_word(word) {
self.cursor.x = self.cursor.x.saturating_sub(width);
last_was_whitespace = true;
continue;
}
last_was_whitespace = false;

if idx == 0 && width == 1 {
// We were at the start of the initial word
self.cursor.x = self.cursor.x.saturating_sub(width);
continue;
}

self.cursor.x = self.cursor.x.saturating_sub(width.saturating_sub(1));
break;
}

if last_was_whitespace && self.cursor.y > 0 {
// The line begins with whitespace
self.cursor.x = usize::max_value();
self.cursor.y -= 1;
return self.move_backward_one_word_start();
}
}
self.select_to_cursor_pos();
}

fn move_backward_one_word(&mut self) {
let y = if self.cursor.x == 0 && self.cursor.y > 0 {
self.cursor.x = usize::max_value();
Expand Down Expand Up @@ -1260,6 +1308,7 @@ impl Pane for CopyOverlay {
MoveToStartOfNextLine => render.move_to_start_of_next_line(),
MoveToSelectionOtherEnd => render.move_to_selection_other_end(),
MoveToSelectionOtherEndHoriz => render.move_to_selection_other_end_horiz(),
MoveBackwardWordStart => render.move_backward_one_word_start(),
MoveBackwardWord => render.move_backward_one_word(),
MoveForwardWord => render.move_forward_one_word(),
MoveForwardWordEnd => render.move_to_end_of_word(),
Expand Down