mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
TextEditor: The delete key should work even when there's no selection.
This commit is contained in:
parent
be4533717a
commit
ed2303e2d8
Notes:
sideshowbarker
2024-07-19 14:59:09 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ed2303e2d8f
@ -78,7 +78,7 @@ int main(int argc, char** argv)
|
||||
});
|
||||
|
||||
auto delete_action = GAction::create("Delete", { 0, Key_Delete }, GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/16x16/delete.rgb", { 16, 16 }), [&] (const GAction&) {
|
||||
text_editor->delete_selection();
|
||||
text_editor->do_delete();
|
||||
});
|
||||
|
||||
auto menubar = make<GMenuBar>();
|
||||
|
@ -382,6 +382,18 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
||||
}
|
||||
|
||||
if (event.key() == KeyCode::Key_Delete) {
|
||||
do_delete();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.ctrl() && !event.alt() && !event.text().is_empty())
|
||||
insert_at_cursor_or_replace_selection(event.text());
|
||||
|
||||
return GWidget::keydown_event(event);
|
||||
}
|
||||
|
||||
void GTextEditor::do_delete()
|
||||
{
|
||||
if (has_selection()) {
|
||||
delete_selection();
|
||||
return;
|
||||
@ -404,13 +416,6 @@ void GTextEditor::keydown_event(GKeyEvent& event)
|
||||
set_cursor(m_cursor.line(), previous_length);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.ctrl() && !event.alt() && !event.text().is_empty())
|
||||
insert_at_cursor_or_replace_selection(event.text());
|
||||
|
||||
return GWidget::keydown_event(event);
|
||||
}
|
||||
|
||||
void GTextEditor::insert_at_cursor(const String& text)
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
void cut();
|
||||
void copy();
|
||||
void paste();
|
||||
void delete_selection();
|
||||
void do_delete();
|
||||
|
||||
Function<void(GTextEditor&)> on_return_pressed;
|
||||
Function<void(GTextEditor&)> on_escape_pressed;
|
||||
@ -150,6 +150,7 @@ private:
|
||||
Rect ruler_content_rect(int line) const;
|
||||
void toggle_selection_if_needed_for_event(const GKeyEvent&);
|
||||
void insert_at_cursor_or_replace_selection(const String&);
|
||||
void delete_selection();
|
||||
|
||||
Type m_type { MultiLine };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user