mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Rework some of the new case-modifying commands to share more code, and
also to update the autosuggestion and syntax highlighting
This commit is contained in:
parent
cd1c2f74d3
commit
b993dce12f
1 changed files with 25 additions and 25 deletions
50
reader.cpp
50
reader.cpp
|
@ -3792,37 +3792,37 @@ const wchar_t *reader_readline(void)
|
|||
}
|
||||
|
||||
case R_UPCASE_WORD:
|
||||
{
|
||||
size_t pos = data->buff_pos;
|
||||
move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false);
|
||||
for (; pos < data->buff_pos; pos++)
|
||||
data->command_line.at(pos) = towupper(data->command_line.at(pos));
|
||||
reader_repaint();
|
||||
break;
|
||||
}
|
||||
|
||||
case R_DOWNCASE_WORD:
|
||||
{
|
||||
size_t pos = data->buff_pos;
|
||||
move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false);
|
||||
for (; pos < data->buff_pos; pos++)
|
||||
data->command_line.at(pos) = towlower(data->command_line.at(pos));
|
||||
reader_repaint();
|
||||
break;
|
||||
}
|
||||
|
||||
case R_CAPITALIZE_WORD:
|
||||
{
|
||||
size_t pos = data->buff_pos;
|
||||
// For capitalize_word, whether we've capitalized a character so far
|
||||
bool capitalized_first = false;
|
||||
|
||||
// We apply the operation from the current location to the end of the word
|
||||
size_t pos = data->buff_pos;
|
||||
move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false);
|
||||
for (; pos < data->buff_pos; pos++) {
|
||||
if (iswalnum(data->command_line.at(pos)) && !capitalized_first) {
|
||||
data->command_line.at(pos) = towupper(data->command_line.at(pos));
|
||||
capitalized_first = true;
|
||||
} else
|
||||
data->command_line.at(pos) = towlower(data->command_line.at(pos));
|
||||
for (; pos < data->buff_pos; pos++)
|
||||
{
|
||||
wchar_t chr = data->command_line.at(pos);
|
||||
|
||||
// We always change the case; this decides whether we go uppercase (true) or lowercase (false)
|
||||
bool make_uppercase;
|
||||
if (c == R_CAPITALIZE_WORD)
|
||||
make_uppercase = ! capitalized_first && iswalnum(chr);
|
||||
else
|
||||
make_uppercase = (c == R_UPCASE_WORD);
|
||||
|
||||
// Apply the operation and then record what we did
|
||||
if (make_uppercase)
|
||||
chr = towupper(chr);
|
||||
else
|
||||
chr = towlower(chr);
|
||||
|
||||
data->command_line.at(pos) = chr;
|
||||
capitalized_first = capitalized_first || make_uppercase;
|
||||
}
|
||||
data->command_line_changed();
|
||||
reader_super_highlight_me_plenty(data->buff_pos);
|
||||
reader_repaint();
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue