@@ -634,10 +634,6 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
634
634
635
635
auto const cell = m_document->get (byte_position);
636
636
637
- bool const selection_inbetween_start_end = byte_position >= m_selection_start && byte_position < m_selection_end;
638
- bool const selection_inbetween_end_start = byte_position >= m_selection_end && byte_position < m_selection_start;
639
- bool const highlight_flag = selection_inbetween_start_end || selection_inbetween_end_start;
640
-
641
637
Gfx::IntRect hex_display_rect_high_nibble {
642
638
frame_thickness () + offset_margin_width () + j * cell_width () + 2 * m_padding,
643
639
frame_thickness () + m_padding + i * line_height (),
@@ -663,27 +659,39 @@ void HexEditor::paint_event(GUI::PaintEvent& event)
663
659
auto high_nibble = line.substring_from_byte_offset (0 , 1 ).release_value_but_fixme_should_propagate_errors ();
664
660
auto low_nibble = line.substring_from_byte_offset (1 ).release_value_but_fixme_should_propagate_errors ();
665
661
666
- Gfx::Color background_color_hex = palette ().color (background_role ());
667
- Gfx::Color background_color_text = background_color_hex;
668
- Gfx::Color text_color_hex = [&]() -> Gfx::Color {
662
+ bool const selected = min (m_selection_start, m_selection_end) <= byte_position
663
+ && byte_position < max (m_selection_start, m_selection_end);
664
+
665
+ // Styling priorities are as follows, with smaller numbers beating larger ones:
666
+ // 1. Modified bytes
667
+ // 2. The cursor position
668
+ // 3. The selection
669
+ // 4. Null bytes
670
+ // 5. Regular formatting
671
+ auto determine_background_color = [&](EditMode edit_mode) -> Gfx::Color {
672
+ if (selected)
673
+ return cell.modified ? palette ().selection ().inverted () : palette ().selection ();
674
+ if (byte_position == m_position && m_edit_mode != edit_mode)
675
+ return palette ().inactive_selection ();
676
+ return palette ().color (background_role ());
677
+ };
678
+ auto determine_text_color = [&](EditMode edit_mode) -> Gfx::Color {
669
679
if (cell.modified )
670
680
return Color::Red;
681
+ if (selected)
682
+ return palette ().selection_text ();
683
+ if (byte_position == m_position)
684
+ return (m_edit_mode == edit_mode) ? palette ().color (foreground_role ()) : palette ().inactive_selection_text ();
671
685
if (cell.value == 0x00 )
672
686
return palette ().color (ColorRole::PlaceholderText);
673
687
return palette ().color (foreground_role ());
674
- }();
675
- Gfx::Color text_color_text = text_color_hex;
688
+ };
689
+ Gfx::Color background_color_hex = determine_background_color (EditMode::Hex);
690
+ Gfx::Color background_color_text = determine_background_color (EditMode::Text);
691
+ Gfx::Color text_color_hex = determine_text_color (EditMode::Hex);
692
+ Gfx::Color text_color_text = determine_text_color (EditMode::Text);
676
693
auto & font = cell.modified ? this ->font ().bold_variant () : this ->font ();
677
694
678
- if (highlight_flag) {
679
- background_color_hex = background_color_text = cell.modified ? palette ().selection ().inverted () : palette ().selection ();
680
- text_color_hex = text_color_text = cell.modified ? text_color_hex : palette ().selection_text ();
681
- } else if (byte_position == m_position) {
682
- background_color_hex = (m_edit_mode == EditMode::Hex) ? background_color_hex : palette ().inactive_selection ();
683
- text_color_hex = (m_edit_mode == EditMode::Hex) ? text_color_text : palette ().inactive_selection_text ();
684
- background_color_text = (m_edit_mode == EditMode::Text) ? background_color_text : palette ().inactive_selection ();
685
- text_color_text = (m_edit_mode == EditMode::Text) ? text_color_text : palette ().inactive_selection_text ();
686
- }
687
695
painter.fill_rect (background_rect, background_color_hex);
688
696
689
697
Gfx::IntRect text_display_rect {
0 commit comments