Fix MoveWordStyle naming convention

This commit is contained in:
Johannes Altmanninger 2023-12-23 09:07:44 +01:00
parent 60777f99b4
commit 2358d4dec8
3 changed files with 41 additions and 55 deletions

View File

@ -202,107 +202,95 @@ fn test_word_motion() {
validate!(
Direction::Left,
MoveWordStyle::move_word_style_punctuation,
MoveWordStyle::Punctuation,
"^echo ^hello_^world.^txt^"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_punctuation,
MoveWordStyle::Punctuation,
"^echo^ hello^_world^.txt^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_punctuation,
MoveWordStyle::Punctuation,
"echo ^foo_^foo_^foo/^/^/^/^/^ ^"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_punctuation,
MoveWordStyle::Punctuation,
"^echo^ foo^_foo^_foo^/^/^/^/^/ ^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^/^foo/^bar/^baz/^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^echo ^--foo ^--bar^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^echo ^hi ^> ^/^dev/^null^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^echo ^/^foo/^bar{^aaa,^bbb,^ccc}^bak/^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^echo ^bak ^///^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^aaa ^@ ^@^aaa^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^aaa ^a ^@^aaa^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^aaa ^@@@ ^@@^aa^"
);
validate!(
Direction::Left,
MoveWordStyle::move_word_style_path_components,
MoveWordStyle::PathComponents,
"^aa^@@ ^aa@@^a^"
);
validate!(Direction::Right, MoveWordStyle::Punctuation, "^a^ bcd^");
validate!(Direction::Right, MoveWordStyle::Punctuation, "a^b^ cde^");
validate!(Direction::Right, MoveWordStyle::Punctuation, "^ab^ cde^");
validate!(
Direction::Right,
MoveWordStyle::move_word_style_punctuation,
"^a^ bcd^"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_punctuation,
"a^b^ cde^"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_punctuation,
"^ab^ cde^"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_punctuation,
MoveWordStyle::Punctuation,
"^ab^&cd^ ^& ^e^ f^&"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_whitespace,
MoveWordStyle::Whitespace,
"^^a-b-c^ d-e-f"
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_whitespace,
MoveWordStyle::Whitespace,
"^a-b-c^\n d-e-f^ "
);
validate!(
Direction::Right,
MoveWordStyle::move_word_style_whitespace,
MoveWordStyle::Whitespace,
"^a-b-c^\n\nd-e-f^ "
);
}

View File

@ -138,9 +138,12 @@ mod tokenizer_ffi {
}
enum MoveWordStyle {
move_word_style_punctuation, // stop at punctuation
move_word_style_path_components, // stops at path components
move_word_style_whitespace, // stops at whitespace
/// stop at punctuation
Punctuation,
/// stops at path components
PathComponents,
/// stops at whitespace
Whitespace,
}
/// Our state machine that implements "one word" movement or erasure.
@ -1188,9 +1191,9 @@ impl MoveWordStateMachine {
pub fn consume_char(&mut self, c: char) -> bool {
match self.style {
MoveWordStyle::move_word_style_punctuation => self.consume_char_punctuation(c),
MoveWordStyle::move_word_style_path_components => self.consume_char_path_components(c),
MoveWordStyle::move_word_style_whitespace => self.consume_char_whitespace(c),
MoveWordStyle::Punctuation => self.consume_char_punctuation(c),
MoveWordStyle::PathComponents => self.consume_char_path_components(c),
MoveWordStyle::Whitespace => self.consume_char_whitespace(c),
_ => panic!(),
}
}

View File

@ -754,9 +754,8 @@ class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
bool can_autosuggest() const;
void autosuggest_completed(autosuggestion_t result);
void update_autosuggestion();
void accept_autosuggestion(
bool full, bool single = false,
move_word_style_t style = move_word_style_t::move_word_style_punctuation);
void accept_autosuggestion(bool full, bool single = false,
move_word_style_t style = move_word_style_t::Punctuation);
void super_highlight_me_plenty();
/// Finish up any outstanding syntax highlighting, before execution.
@ -3729,10 +3728,9 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
case rl::backward_kill_path_component:
case rl::backward_kill_bigword: {
move_word_style_t style =
(c == rl::backward_kill_bigword ? move_word_style_t::move_word_style_whitespace
: c == rl::backward_kill_path_component
? move_word_style_t::move_word_style_path_components
: move_word_style_t::move_word_style_punctuation);
(c == rl::backward_kill_bigword ? move_word_style_t::Whitespace
: c == rl::backward_kill_path_component ? move_word_style_t::PathComponents
: move_word_style_t::Punctuation);
// Is this the same killring item as the last kill?
bool newv = (rls.last_cmd != rl::backward_kill_word &&
rls.last_cmd != rl::backward_kill_path_component &&
@ -3744,8 +3742,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
case rl::kill_bigword: {
// The "bigword" functions differ only in that they move to the next whitespace, not
// punctuation.
auto move_style = (c == rl::kill_word) ? move_word_style_t::move_word_style_punctuation
: move_word_style_t::move_word_style_whitespace;
auto move_style = (c == rl::kill_word) ? move_word_style_t::Punctuation
: move_word_style_t::Whitespace;
move_word(active_edit_line(), MOVE_DIR_RIGHT, true /* erase */, move_style,
rls.last_cmd != c /* same kill item if same movement */);
break;
@ -3762,9 +3760,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
break;
}
auto move_style = (c != rl::backward_bigword)
? move_word_style_t::move_word_style_punctuation
: move_word_style_t::move_word_style_whitespace;
auto move_style = (c != rl::backward_bigword) ? move_word_style_t::Punctuation
: move_word_style_t::Whitespace;
move_word(active_edit_line(), MOVE_DIR_LEFT, false /* do not erase */, move_style,
false);
break;
@ -3781,9 +3778,8 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
break;
}
auto move_style = (c != rl::forward_bigword)
? move_word_style_t::move_word_style_punctuation
: move_word_style_t::move_word_style_whitespace;
auto move_style = (c != rl::forward_bigword) ? move_word_style_t::Punctuation
: move_word_style_t::Whitespace;
editable_line_t *el = active_edit_line();
if (el->position() < el->size()) {
move_word(el, MOVE_DIR_RIGHT, false /* do not erase */, move_style, false);
@ -4006,8 +4002,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
// We apply the operation from the current location to the end of the word.
size_t pos = el->position();
size_t init_pos = pos;
move_word(el, MOVE_DIR_RIGHT, false, move_word_style_t::move_word_style_punctuation,
false);
move_word(el, MOVE_DIR_RIGHT, false, move_word_style_t::Punctuation, false);
wcstring replacement;
for (; pos < el->position(); pos++) {
wchar_t chr = el->text()->at(pos);