HexEditor: Remove blinking of the cursor

This commit is contained in:
tetektoza 2023-12-13 22:42:47 +01:00 committed by Andreas Kling
parent daecf741d4
commit 1ea675a9ec
Notes: sideshowbarker 2024-07-17 18:46:30 +09:00
2 changed files with 2 additions and 25 deletions

View File

@ -42,12 +42,6 @@ HexEditor::HexEditor()
set_background_role(ColorRole::Base);
set_foreground_role(ColorRole::BaseText);
vertical_scrollbar().set_step(line_height());
m_blink_timer = Core::Timer::create_repeating(500, [this]() {
m_cursor_blink_active = !m_cursor_blink_active;
update();
}).release_value_but_fixme_should_propagate_errors();
m_blink_timer->start();
}
ErrorOr<void> HexEditor::open_new_file(size_t size)
@ -120,7 +114,6 @@ void HexEditor::set_position(size_t position)
m_position = position;
m_cursor_at_low_nibble = false;
reset_cursor_blink_state();
scroll_position_into_view(position);
update_status();
}
@ -133,7 +126,6 @@ void HexEditor::set_selection(size_t position, size_t length)
m_cursor_at_low_nibble = false;
m_selection_start = position;
m_selection_end = position + length;
reset_cursor_blink_state();
scroll_position_into_view(position);
update_status();
}
@ -432,7 +424,6 @@ void HexEditor::keydown_event(GUI::KeyEvent& event)
} else
m_selection_start = m_selection_end = m_position = new_position;
m_cursor_at_low_nibble = false;
reset_cursor_blink_state();
scroll_position_into_view(m_position);
update();
update_status();
@ -538,7 +529,6 @@ ErrorOr<void> HexEditor::hex_mode_keydown_event(GUI::KeyEvent& event)
m_cursor_at_low_nibble = false;
}
reset_cursor_blink_state();
update();
update_status();
did_change();
@ -565,7 +555,6 @@ ErrorOr<void> HexEditor::text_mode_keydown_event(GUI::KeyEvent& event)
m_position++;
m_cursor_at_low_nibble = false;
reset_cursor_blink_state();
update();
update_status();
did_change();
@ -686,7 +675,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
painter.draw_text(hex_display_rect, line, Gfx::TextAlignment::TopLeft, text_color);
if (m_edit_mode == EditMode::Hex) {
if (byte_position == m_position && m_cursor_blink_active) {
if (byte_position == m_position) {
Gfx::IntRect cursor_position_rect {
static_cast<int>(hex_display_rect.left() + m_cursor_at_low_nibble * character_width()),
hex_display_rect.top(),
@ -732,7 +721,7 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
painter.draw_text(text_display_rect, character, Gfx::TextAlignment::TopLeft, text_color);
if (m_edit_mode == EditMode::Text) {
if (byte_position == m_position && m_cursor_blink_active) {
if (byte_position == m_position) {
Gfx::IntRect cursor_position_rect {
text_display_rect.left(), text_display_rect.top(), 2, text_display_rect.height()
};
@ -857,12 +846,6 @@ Vector<Match> HexEditor::find_all_strings(size_t min_length)
return matches;
}
void HexEditor::reset_cursor_blink_state()
{
m_cursor_blink_active = true;
m_blink_timer->restart();
}
ErrorOr<void> HexEditor::did_complete_action(size_t position, u8 old_value, u8 new_value)
{
if (old_value == new_value)
@ -892,7 +875,6 @@ bool HexEditor::undo()
return false;
m_undo_stack.undo();
reset_cursor_blink_state();
update();
update_status();
did_change();
@ -905,7 +887,6 @@ bool HexEditor::redo()
return false;
m_undo_stack.redo();
reset_cursor_blink_state();
update();
update_status();
did_change();

View File

@ -86,8 +86,6 @@ private:
size_t m_position { 0 };
bool m_cursor_at_low_nibble { false };
EditMode m_edit_mode { Hex };
RefPtr<Core::Timer> m_blink_timer;
bool m_cursor_blink_active { false };
NonnullOwnPtr<HexDocument> m_document;
GUI::UndoStack m_undo_stack;
@ -110,8 +108,6 @@ private:
void did_change();
ErrorOr<void> did_complete_action(size_t position, u8 old_value, u8 new_value);
ErrorOr<void> did_complete_action(size_t position, ByteBuffer&& old_values, ByteBuffer&& new_values);
void reset_cursor_blink_state();
};
}