mirror of
https://github.com/RGBCube/serenity
synced 2025-07-19 13:17:39 +00:00
LibGUI: Convert always-valid pointer to reference
The pointer is always assumed to be non-null, so let's change it to a reference.
This commit is contained in:
parent
5910a41adb
commit
2f023acf78
4 changed files with 46 additions and 46 deletions
|
@ -40,9 +40,9 @@ void EditingEngine::detach()
|
||||||
bool EditingEngine::on_key(const KeyEvent& event)
|
bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
{
|
{
|
||||||
if (event.key() == KeyCode::Key_Left) {
|
if (event.key() == KeyCode::Key_Left) {
|
||||||
if (!event.shift() && m_editor->selection()->is_valid()) {
|
if (!event.shift() && m_editor->selection().is_valid()) {
|
||||||
m_editor->set_cursor(m_editor->selection()->normalized().start());
|
m_editor->set_cursor(m_editor->selection().normalized().start());
|
||||||
m_editor->selection()->clear();
|
m_editor->selection().clear();
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
if (!event.ctrl()) {
|
if (!event.ctrl()) {
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
|
@ -52,25 +52,25 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
if (event.ctrl()) {
|
if (event.ctrl()) {
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
move_to_previous_span();
|
move_to_previous_span();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
move_one_left();
|
move_one_left();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key() == KeyCode::Key_Right) {
|
if (event.key() == KeyCode::Key_Right) {
|
||||||
if (!event.shift() && m_editor->selection()->is_valid()) {
|
if (!event.shift() && m_editor->selection().is_valid()) {
|
||||||
m_editor->set_cursor(m_editor->selection()->normalized().end());
|
m_editor->set_cursor(m_editor->selection().normalized().end());
|
||||||
m_editor->selection()->clear();
|
m_editor->selection().clear();
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
if (!event.ctrl()) {
|
if (!event.ctrl()) {
|
||||||
m_editor->update();
|
m_editor->update();
|
||||||
|
@ -80,16 +80,16 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
if (event.ctrl()) {
|
if (event.ctrl()) {
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
move_to_next_span(event);
|
move_to_next_span(event);
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
move_one_right();
|
move_one_right();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -100,8 +100,8 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
}
|
}
|
||||||
move_one_up(event);
|
move_one_up(event);
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -112,8 +112,8 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
}
|
}
|
||||||
move_one_down(event);
|
move_one_down(event);
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -122,15 +122,15 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
if (event.key() == KeyCode::Key_Home) {
|
if (event.key() == KeyCode::Key_Home) {
|
||||||
if (event.ctrl()) {
|
if (event.ctrl()) {
|
||||||
move_to_first_line();
|
move_to_first_line();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
move_to_line_beginning();
|
move_to_line_beginning();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,15 +140,15 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
if (event.key() == KeyCode::Key_End) {
|
if (event.key() == KeyCode::Key_End) {
|
||||||
if (event.ctrl()) {
|
if (event.ctrl()) {
|
||||||
move_to_last_line();
|
move_to_last_line();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
move_to_line_end();
|
move_to_line_end();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,8 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
}
|
}
|
||||||
move_page_up();
|
move_page_up();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -172,8 +172,8 @@ bool EditingEngine::on_key(const KeyEvent& event)
|
||||||
m_editor->update_selection(event.shift());
|
m_editor->update_selection(event.shift());
|
||||||
}
|
}
|
||||||
move_page_down();
|
move_page_down();
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -240,8 +240,8 @@ void EditingEngine::move_to_next_span(const KeyEvent& event)
|
||||||
new_cursor = m_editor->document().first_word_break_after(m_editor->cursor());
|
new_cursor = m_editor->document().first_word_break_after(m_editor->cursor());
|
||||||
}
|
}
|
||||||
m_editor->set_cursor(new_cursor);
|
m_editor->set_cursor(new_cursor);
|
||||||
if (event.shift() && m_editor->selection()->start().is_valid()) {
|
if (event.shift() && m_editor->selection().start().is_valid()) {
|
||||||
m_editor->selection()->set_end(m_editor->cursor());
|
m_editor->selection().set_end(m_editor->cursor());
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,8 +654,8 @@ void EditingEngine::move_selected_lines_up()
|
||||||
m_editor->set_cursor({ first_line - 1, 0 });
|
m_editor->set_cursor({ first_line - 1, 0 });
|
||||||
|
|
||||||
if (m_editor->has_selection()) {
|
if (m_editor->has_selection()) {
|
||||||
m_editor->selection()->set_start({ first_line - 1, 0 });
|
m_editor->selection().set_start({ first_line - 1, 0 });
|
||||||
m_editor->selection()->set_end({ last_line - 1, m_editor->line(last_line - 1).length() });
|
m_editor->selection().set_end({ last_line - 1, m_editor->line(last_line - 1).length() });
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editor->did_change();
|
m_editor->did_change();
|
||||||
|
@ -679,8 +679,8 @@ void EditingEngine::move_selected_lines_down()
|
||||||
m_editor->set_cursor({ first_line + 1, 0 });
|
m_editor->set_cursor({ first_line + 1, 0 });
|
||||||
|
|
||||||
if (m_editor->has_selection()) {
|
if (m_editor->has_selection()) {
|
||||||
m_editor->selection()->set_start({ first_line + 1, 0 });
|
m_editor->selection().set_start({ first_line + 1, 0 });
|
||||||
m_editor->selection()->set_end({ last_line + 1, m_editor->line(last_line + 1).length() });
|
m_editor->selection().set_end({ last_line + 1, m_editor->line(last_line + 1).length() });
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editor->did_change();
|
m_editor->did_change();
|
||||||
|
|
|
@ -990,20 +990,20 @@ void TextEditor::reset_cursor_blink()
|
||||||
|
|
||||||
void TextEditor::update_selection(bool is_selecting)
|
void TextEditor::update_selection(bool is_selecting)
|
||||||
{
|
{
|
||||||
if (is_selecting && !selection()->is_valid()) {
|
if (is_selecting && !selection().is_valid()) {
|
||||||
selection()->set(cursor(), {});
|
selection().set(cursor(), {});
|
||||||
did_update_selection();
|
did_update_selection();
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!is_selecting && selection()->is_valid()) {
|
if (!is_selecting && selection().is_valid()) {
|
||||||
selection()->clear();
|
selection().clear();
|
||||||
did_update_selection();
|
did_update_selection();
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (is_selecting && selection()->start().is_valid()) {
|
if (is_selecting && selection().start().is_valid()) {
|
||||||
selection()->set_end(cursor());
|
selection().set_end(cursor());
|
||||||
did_update_selection();
|
did_update_selection();
|
||||||
update();
|
update();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -193,7 +193,7 @@ public:
|
||||||
|
|
||||||
bool is_in_drag_select() const { return m_in_drag_select; }
|
bool is_in_drag_select() const { return m_in_drag_select; }
|
||||||
|
|
||||||
TextRange* selection() { return &m_selection; };
|
TextRange& selection() { return m_selection; };
|
||||||
void did_update_selection();
|
void did_update_selection();
|
||||||
void did_change(AllowCallback = AllowCallback::Yes);
|
void did_change(AllowCallback = AllowCallback::Yes);
|
||||||
void update_cursor();
|
void update_cursor();
|
||||||
|
|
|
@ -1242,7 +1242,7 @@ void VimEditingEngine::switch_to_visual_mode()
|
||||||
m_editor->reset_cursor_blink();
|
m_editor->reset_cursor_blink();
|
||||||
m_previous_key = {};
|
m_previous_key = {};
|
||||||
m_selection_start_position = m_editor->cursor();
|
m_selection_start_position = m_editor->cursor();
|
||||||
m_editor->selection()->set(m_editor->cursor(), { m_editor->cursor().line(), m_editor->cursor().column() + 1 });
|
m_editor->selection().set(m_editor->cursor(), { m_editor->cursor().line(), m_editor->cursor().column() + 1 });
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
m_motion.reset();
|
m_motion.reset();
|
||||||
}
|
}
|
||||||
|
@ -1260,7 +1260,7 @@ void VimEditingEngine::update_selection_on_cursor_move()
|
||||||
end.set_column(end.column() + 1);
|
end.set_column(end.column() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_editor->selection()->set(start, end);
|
m_editor->selection().set(start, end);
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1276,7 +1276,7 @@ void VimEditingEngine::clamp_cursor_position()
|
||||||
void VimEditingEngine::clear_visual_mode_data()
|
void VimEditingEngine::clear_visual_mode_data()
|
||||||
{
|
{
|
||||||
if (m_editor->has_selection()) {
|
if (m_editor->has_selection()) {
|
||||||
m_editor->selection()->clear();
|
m_editor->selection().clear();
|
||||||
m_editor->did_update_selection();
|
m_editor->did_update_selection();
|
||||||
clamp_cursor_position();
|
clamp_cursor_position();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue