mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +00:00
LibGUI: Add Ctrl-W to insert mode
In Vim's insert mode, Ctrl-W deletes the word before the cursor, like Ctrl-Backspace. Unlike Ctrl-Backspace, if only whitespace exists between the end of the word and the cursor, the word will be deleted with the whitespace. To do so, this commit introduces two methods: delete_previous_word() for TextEditor and first_word_before() for TextDocument, where the former depends on the latter. delete_previous_word() is then called in VimEditingEngine.
This commit is contained in:
parent
8f01a8b741
commit
808e5e813f
5 changed files with 52 additions and 0 deletions
|
@ -674,6 +674,39 @@ TextPosition TextDocument::first_word_break_after(const TextPosition& position)
|
|||
return target;
|
||||
}
|
||||
|
||||
TextPosition TextDocument::first_word_before(const TextPosition& position, bool start_at_column_before) const
|
||||
{
|
||||
if (position.column() == 0) {
|
||||
if (position.line() == 0) {
|
||||
return TextPosition(0, 0);
|
||||
}
|
||||
auto previous_line = this->line(position.line() - 1);
|
||||
return TextPosition(position.line() - 1, previous_line.length());
|
||||
}
|
||||
|
||||
auto target = position;
|
||||
auto line = this->line(target.line());
|
||||
if (target.column() == line.length())
|
||||
start_at_column_before = 1;
|
||||
|
||||
auto nonblank_passed = !is_ascii_blank(line.code_points()[target.column() - start_at_column_before]);
|
||||
while (target.column() > 0) {
|
||||
auto prev_code_point = line.code_points()[target.column() - 1];
|
||||
nonblank_passed |= !is_ascii_blank(prev_code_point);
|
||||
|
||||
if (nonblank_passed && is_ascii_blank(prev_code_point)) {
|
||||
break;
|
||||
} else if (is_ascii_punctuation(prev_code_point)) {
|
||||
target.set_column(target.column() - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
target.set_column(target.column() - 1);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
void TextDocument::undo()
|
||||
{
|
||||
if (!can_undo())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue