@@ -616,222 +616,215 @@ void ResultDock::applyTheme()
616
616
if (!_hSci)
617
617
return ;
618
618
619
- // Helper: send message to the Scintilla dock
620
- auto S = [this ](UINT m, WPARAM w = 0 , LPARAM l = 0 ) -> LRESULT
621
- { return ::SendMessage (_hSci, m, w, l); };
619
+ // Helper lambda for Scintilla calls
620
+ auto S = [this ](UINT m, WPARAM w = 0 , LPARAM l = 0 ) -> LRESULT {
621
+ return ::SendMessage (_hSci, m, w, l);
622
+ };
622
623
623
- // 0. Retrieve base editor colors from Notepad++
624
+ // Determine if dark mode is active
624
625
const bool dark = ::SendMessage (nppData._nppHandle , NPPM_ISDARKMODEENABLED, 0 , 0 ) != 0 ;
626
+ const DockThemeColors& theme = currentColors (dark);
625
627
626
- COLORREF editorBg = (COLORREF)::SendMessage (nppData._nppHandle , NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR, 0 , 0 );
627
- COLORREF editorFg = (COLORREF)::SendMessage (nppData._nppHandle , NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR, 0 , 0 );
628
+ // Base editor colors from Notepad++
629
+ const COLORREF editorBg = (COLORREF)::SendMessage (nppData._nppHandle , NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR, 0 , 0 );
630
+ const COLORREF editorFg = (COLORREF)::SendMessage (nppData._nppHandle , NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR, 0 , 0 );
628
631
629
- // 1. Reset styles and set global font
630
- S (SCI_STYLESETBACK, STYLE_DEFAULT, editorBg);
632
+ // Reset styles and set default font
631
633
S (SCI_STYLESETFORE, STYLE_DEFAULT, editorFg);
634
+ S (SCI_STYLESETBACK, STYLE_DEFAULT, editorBg);
632
635
S (SCI_STYLECLEARALL);
633
636
S (SCI_STYLESETFONT, STYLE_DEFAULT, (LPARAM)" Consolas" );
634
637
S (SCI_STYLESETSIZE, STYLE_DEFAULT, 10 );
635
638
636
- // 2. Configure margins (0=line number, 1=symbol, 2=fold)
637
- COLORREF marginBg = dark ? RGB (0 , 0 , 0 ) : editorBg;
638
- COLORREF marginFg = dark ? RGB (200 , 200 , 200 ) : RGB (80 , 80 , 80 );
639
+ // Margin colors
640
+ const COLORREF marginBg = dark ? RGB (0 , 0 , 0 ) : editorBg;
641
+ const COLORREF marginFg = dark ? RGB (200 , 200 , 200 ) : RGB (80 , 80 , 80 );
639
642
640
643
for (int m = 0 ; m <= 2 ; ++m)
641
644
S (SCI_SETMARGINBACKN, m, marginBg);
642
645
643
646
S (SCI_STYLESETBACK, STYLE_LINENUMBER, marginBg);
644
647
S (SCI_STYLESETFORE, STYLE_LINENUMBER, marginFg);
645
-
646
648
S (SCI_SETFOLDMARGINCOLOUR, TRUE , marginBg);
647
649
S (SCI_SETFOLDMARGINHICOLOUR, TRUE , marginBg);
648
650
649
- // 3. Selection colors
650
- COLORREF selBg = dark ? RGB (96 , 96 , 96 ) : RGB (0xE0 , 0xE0 , 0xE0 );
651
- COLORREF selFg = dark ? RGB (255 , 255 , 255 ) : editorFg;
651
+ // Selection colors
652
+ const COLORREF selBg = dark ? RGB (96 , 96 , 96 ) : RGB (224 , 224 , 224 );
653
+ const COLORREF selFg = dark ? RGB (255 , 255 , 255 ) : editorFg;
652
654
653
655
S (SCI_SETSELFORE, TRUE , selFg);
654
656
S (SCI_SETSELBACK, TRUE , selBg);
655
657
S (SCI_SETSELALPHA, 256 , 0 );
656
-
657
658
S (SCI_SETELEMENTCOLOUR, SC_ELEMENT_SELECTION_INACTIVE_BACK, argb (0xFF , selBg));
658
659
S (SCI_SETELEMENTCOLOUR, SC_ELEMENT_SELECTION_INACTIVE_TEXT, argb (0xFF , selFg));
659
-
660
660
S (SCI_SETADDITIONALSELFORE, selFg);
661
661
S (SCI_SETADDITIONALSELBACK, selBg);
662
662
S (SCI_SETADDITIONALSELALPHA, 256 , 0 );
663
663
664
- // 4. Fold marker colors
665
- const COLORREF markerGlyph = dark ? RDColors::FoldGlyphDark : RDColors::FoldGlyphLight;
666
-
667
- for (int id : {SC_MARKNUM_FOLDER, SC_MARKNUM_FOLDEREND, SC_MARKNUM_FOLDEROPEN,
668
- SC_MARKNUM_FOLDEROPENMID, SC_MARKNUM_FOLDERSUB,
669
- SC_MARKNUM_FOLDERMIDTAIL, SC_MARKNUM_FOLDERTAIL})
670
- {
671
- S (SCI_MARKERSETBACK, id, markerGlyph);
664
+ // Fold markers
665
+ for (int id : {
666
+ SC_MARKNUM_FOLDER,
667
+ SC_MARKNUM_FOLDEREND,
668
+ SC_MARKNUM_FOLDEROPEN,
669
+ SC_MARKNUM_FOLDEROPENMID,
670
+ SC_MARKNUM_FOLDERSUB,
671
+ SC_MARKNUM_FOLDERMIDTAIL,
672
+ SC_MARKNUM_FOLDERTAIL
673
+ }) {
674
+ S (SCI_MARKERSETBACK, id, theme.foldGlyph );
672
675
S (SCI_MARKERSETFORE, id, marginBg);
673
- S (SCI_MARKERSETBACKSELECTED, id, dark ? RDColors::FoldHiDark : RDColors::FoldHiLight );
676
+ S (SCI_MARKERSETBACKSELECTED, id, theme. foldHighlight );
674
677
}
675
678
676
- // 5. Caret line indicator (indicator 0)
679
+ // Caret line
677
680
S (SCI_INDICSETSTYLE, 0 , INDIC_ROUNDBOX);
678
681
S (SCI_INDICSETFORE, 0 , selBg);
679
- S (SCI_INDICSETALPHA, 0 , dark ? RDColors::CaretLineAlphaDark : RDColors::CaretLineAlphaLight );
682
+ S (SCI_INDICSETALPHA, 0 , theme. caretLineAlpha );
680
683
S (SCI_INDICSETUNDER, 0 , TRUE );
681
-
682
684
S (SCI_SETCARETLINEVISIBLE, TRUE , 0 );
683
- S (SCI_SETCARETLINEBACK, dark ? selBg : RDColors::CaretLineBackLight, 0 );
684
- S (SCI_SETCARETLINEBACKALPHA, dark ? RDColors::CaretLineAlphaDark : RDColors::CaretLineAlphaLight);
685
-
686
- // 6. Custom indicators and styles
687
- COLORREF hitLineBg = dark ? RDColors::LineBgDark : RDColors::LineBgLight;
688
- COLORREF lineNrFg = dark ? RDColors::LineNrDark : RDColors::LineNrLight;
689
- COLORREF matchFg = dark ? RDColors::MatchDark : RDColors::MatchLight;
690
- COLORREF matchBg = RDColors::MatchBgLight;
691
- COLORREF headerBg = dark ? RDColors::HeaderBgDark : RDColors::HeaderBgLight;
692
- COLORREF filePathFg = dark ? RDColors::FilePathFgDark : RDColors::FilePathFgLight;
693
-
694
- // 6-a Hit line background
685
+ S (SCI_SETCARETLINEBACK, theme.caretLineBg , 0 );
686
+ S (SCI_SETCARETLINEBACKALPHA, theme.caretLineAlpha );
687
+
688
+ // Line background indicator
695
689
S (SCI_INDICSETSTYLE, INDIC_LINE_BACKGROUND, INDIC_STRAIGHTBOX);
696
- S (SCI_INDICSETFORE, INDIC_LINE_BACKGROUND, hitLineBg );
690
+ S (SCI_INDICSETFORE, INDIC_LINE_BACKGROUND, theme. lineBg );
697
691
S (SCI_INDICSETALPHA, INDIC_LINE_BACKGROUND, 100 );
698
692
S (SCI_INDICSETUNDER, INDIC_LINE_BACKGROUND, TRUE );
699
693
700
- // 6-b Line number color
694
+ // Line number indicator
701
695
S (SCI_INDICSETSTYLE, INDIC_LINENUMBER_FORE, INDIC_TEXTFORE);
702
- S (SCI_INDICSETFORE, INDIC_LINENUMBER_FORE, lineNrFg );
696
+ S (SCI_INDICSETFORE, INDIC_LINENUMBER_FORE, theme. lineNr );
703
697
704
- // 6-c Match indicators
705
- S (SCI_INDICSETSTYLE, INDIC_MATCH_BG, INDIC_FULLBOX);
706
- S (SCI_INDICSETFORE, INDIC_MATCH_BG, matchBg);
707
- S (SCI_INDICSETALPHA, INDIC_MATCH_BG, dark ? 0 : 255 );
708
- S (SCI_INDICSETUNDER, INDIC_MATCH_BG, TRUE );
698
+ // Match background and foreground indicators
699
+ if (dark) {
700
+ // Dark Mode: Nur Textfarbe (kein Hintergrund)
701
+ S (SCI_INDICSETSTYLE, INDIC_MATCH_BG, INDIC_HIDDEN);
702
+ }
703
+ else {
704
+ // Light Mode: Gelber Hintergrund sichtbar
705
+ COLORREF matchBg = RGB (255 , 255 , 160 ); // hellgelb
706
+ S (SCI_INDICSETSTYLE, INDIC_MATCH_BG, INDIC_STRAIGHTBOX);
707
+ S (SCI_INDICSETFORE, INDIC_MATCH_BG, matchBg);
708
+ S (SCI_INDICSETALPHA, INDIC_MATCH_BG, 100 );
709
+ S (SCI_INDICSETUNDER, INDIC_MATCH_BG, TRUE );
710
+ }
709
711
712
+ // Rote Match-Farbe
710
713
S (SCI_INDICSETSTYLE, INDIC_MATCH_FORE, INDIC_TEXTFORE);
711
- S (SCI_INDICSETFORE, INDIC_MATCH_FORE, matchFg);
714
+ S (SCI_INDICSETFORE, INDIC_MATCH_FORE, theme.matchFg ); // z. B. RGB(255, 0, 0)
715
+ S (SCI_INDICSETUNDER, INDIC_MATCH_FORE, TRUE );
712
716
713
- // 6-d Header line style
714
- S (SCI_STYLESETFORE, STYLE_HEADER, RDColors::HeaderFg );
715
- S (SCI_STYLESETBACK, STYLE_HEADER, headerBg);
717
+ // Header style
718
+ S (SCI_STYLESETFORE, STYLE_HEADER, theme. headerFg );
719
+ S (SCI_STYLESETBACK, STYLE_HEADER, theme. headerBg );
716
720
S (SCI_STYLESETBOLD, STYLE_HEADER, TRUE );
717
721
S (SCI_STYLESETEOLFILLED, STYLE_HEADER, TRUE );
718
722
719
- // 6-e File path style
720
- S (SCI_STYLESETFORE, STYLE_FILEPATH, filePathFg);
721
- S (SCI_STYLESETBACK, STYLE_FILEPATH, - 1 );
723
+ // File path style
724
+ S (SCI_STYLESETFORE, STYLE_FILEPATH, theme. filePathFg );
725
+ S (SCI_STYLESETBACK, STYLE_FILEPATH, editorBg); // statt -1 für sauberen Hintergrund
722
726
S (SCI_STYLESETBOLD, STYLE_FILEPATH, TRUE );
723
727
S (SCI_STYLESETITALIC, STYLE_FILEPATH, TRUE );
724
728
S (SCI_STYLESETEOLFILLED, STYLE_FILEPATH, TRUE );
725
729
}
726
730
727
-
728
731
void ResultDock::applyStyling () const
729
732
{
730
- if (!_hSci) return ;
733
+ if (!_hSci)
734
+ return ;
731
735
732
- auto S = [this ](UINT m, WPARAM w = 0 , LPARAM l = 0 )
736
+ auto S = [this ](UINT m, WPARAM w = 0 , LPARAM l = 0 ) -> LRESULT
733
737
{ return ::SendMessage (_hSci, m, w, l); };
734
738
735
-
736
- // 0) Clear all previous styling indicators
737
- for (int ind : { INDIC_LINE_BACKGROUND,
738
- INDIC_LINENUMBER_FORE,
739
- INDIC_MATCH_FORE,
740
- INDIC_MATCH_BG}) // Note: Header/FilePath indicators are no longer needed here
741
- {
742
- S (SCI_SETINDICATORCURRENT, ind);
739
+ // Step 1: Clear previous styling indicators
740
+ const std::vector<int > indicatorsToClear = { INDIC_LINE_BACKGROUND, INDIC_LINENUMBER_FORE, INDIC_MATCH_FORE, INDIC_MATCH_BG };
741
+ for (int indicator : indicatorsToClear) {
742
+ S (SCI_SETINDICATORCURRENT, indicator);
743
743
S (SCI_INDICATORCLEARRANGE, 0 , S (SCI_GETLENGTH));
744
744
}
745
745
746
-
747
-
748
- // 1) Apply base style for each line (Header, File Path, or Default)
749
- // This sets the font (bold/regular) and base colors.
746
+ // Step 2: Apply base style for each line (Header, File Path, Default)
750
747
S (SCI_STARTSTYLING, 0 , 0 );
751
748
752
749
const int lineCount = static_cast <int >(S (SCI_GETLINECOUNT));
753
- for (int ln = 0 ; ln < lineCount; ++ln)
754
- {
755
- const Sci_Position lineStartPos = S (SCI_POSITIONFROMLINE, ln, 0 );
756
- const int lineRawLen = static_cast <int >(S (SCI_LINELENGTH, ln, 0 ));
750
+ for (int line = 0 ; line < lineCount; ++line) {
751
+ const Sci_Position lineStart = S (SCI_POSITIONFROMLINE, line, 0 );
752
+ const int lineLength = static_cast <int >(S (SCI_LINELENGTH, line, 0 ));
757
753
758
- // Determine the style for the current line
759
- int lineStyle = STYLE_DEFAULT;
760
- if (lineRawLen > 0 )
761
- {
762
- std::string buf (lineRawLen, ' \0 ' );
763
- S (SCI_GETLINE, ln, (LPARAM)buf.data ());
754
+ int style = STYLE_DEFAULT;
755
+ if (lineLength > 0 ) {
756
+ std::string buffer (lineLength, ' \0 ' );
757
+ S (SCI_GETLINE, line, reinterpret_cast <LPARAM>(buffer.data ()));
764
758
765
- size_t lead = buf.find_first_not_of (' ' );
766
- if (lead == std::string::npos) lead = 0 ; // line is all spaces
759
+ size_t firstChar = buffer.find_first_not_of (' ' );
760
+ if (firstChar == std::string::npos)
761
+ firstChar = 0 ;
767
762
768
- std::string_view trimmed (buf .data () + lead, buf .size () - lead );
763
+ std::string_view trimmedLine (buffer .data () + firstChar, buffer .size () - firstChar );
769
764
770
- if (trimmed.rfind (" Search " , 0 ) == 0 )
771
- {
772
- lineStyle = STYLE_HEADER;
765
+ if (trimmedLine.rfind (" Search " , 0 ) == 0 ) {
766
+ style = STYLE_HEADER;
773
767
}
774
- // A file path has exactly 4 leading spaces and is not empty.
775
- else if (lead == 4 && !trimmed.empty ())
776
- {
777
- lineStyle = STYLE_FILEPATH;
768
+ else if (firstChar == 4 && !trimmedLine.empty ()) {
769
+ style = STYLE_FILEPATH;
778
770
}
779
771
}
780
772
781
- // Apply styling for the line content
782
- if (lineRawLen > 0 ) {
783
- S (SCI_SETSTYLING, lineRawLen, lineStyle );
773
+ // Apply determined style to line content
774
+ if (lineLength > 0 ) {
775
+ S (SCI_SETSTYLING, lineLength, style );
784
776
}
785
777
786
- // Apply default style to the EOL characters (\r\n)
787
- const Sci_Position lineEndPos = S (SCI_GETLINEENDPOSITION, ln , 0 );
788
- const int eolLen = static_cast <int >(lineEndPos - (lineStartPos + lineRawLen ));
789
- if (eolLen > 0 ) {
790
- S (SCI_SETSTYLING, eolLen , STYLE_DEFAULT);
778
+ // Apply default style to EOL characters
779
+ const Sci_Position lineEnd = S (SCI_GETLINEENDPOSITION, line , 0 );
780
+ const int eolLength = static_cast <int >(lineEnd - (lineStart + lineLength ));
781
+ if (eolLength > 0 ) {
782
+ S (SCI_SETSTYLING, eolLength , STYLE_DEFAULT);
791
783
}
792
784
}
793
785
794
- // 2) Apply overlay indicators for hit details.
795
- // These are drawn on top of the base styles set above.
786
+ // Step 3: Overlay indicators for hits
796
787
797
- // 2-a) Full-line background for each hit
788
+ // 3a. Background for hit lines
798
789
S (SCI_SETINDICATORCURRENT, INDIC_LINE_BACKGROUND);
799
- for (const auto & h : _hits)
800
- {
801
- if (h.displayLineStart < 0 ) continue ; // Skip merged hits
802
- int ln = (int )S (SCI_LINEFROMPOSITION, h.displayLineStart , 0 );
803
- Sci_Position start = S (SCI_POSITIONFROMLINE, ln, 0 );
804
- Sci_Position len = S (SCI_LINELENGTH, ln, 0 );
805
- if (len > 0 )
806
- S (SCI_INDICATORFILLRANGE, start, len);
790
+ for (const auto & hit : _hits) {
791
+ if (hit.displayLineStart < 0 )
792
+ continue ;
793
+
794
+ int line = static_cast <int >(S (SCI_LINEFROMPOSITION, hit.displayLineStart , 0 ));
795
+ Sci_Position startPos = S (SCI_POSITIONFROMLINE, line, 0 );
796
+ Sci_Position length = S (SCI_LINELENGTH, line, 0 );
797
+
798
+ if (length > 0 )
799
+ S (SCI_INDICATORFILLRANGE, startPos, length);
807
800
}
808
801
809
- // 2-b) Line-number digits
802
+ // 3b. Line-number digits
810
803
S (SCI_SETINDICATORCURRENT, INDIC_LINENUMBER_FORE);
811
- for (const auto & h : _hits) {
812
- if (h.displayLineStart >= 0 ) // Ensure hit is valid
813
- S (SCI_INDICATORFILLRANGE,
814
- h.displayLineStart + h.numberStart ,
815
- h.numberLen );
804
+ for (const auto & hit : _hits) {
805
+ if (hit.displayLineStart >= 0 )
806
+ S (SCI_INDICATORFILLRANGE, hit.displayLineStart + hit.numberStart , hit.numberLen );
816
807
}
817
808
818
- // 2-c) Match substrings (background and foreground)
809
+ // 3c. Match substrings (background and foreground)
819
810
S (SCI_SETINDICATORCURRENT, INDIC_MATCH_BG);
820
- for (const auto & h : _hits) {
821
- if (h.displayLineStart < 0 ) continue ;
822
- for (size_t i = 0 ; i < h.matchStarts .size (); ++i)
823
- S (SCI_INDICATORFILLRANGE,
824
- h.displayLineStart + h.matchStarts [i],
825
- h.matchLens [i]);
811
+ for (const auto & hit : _hits) {
812
+ if (hit.displayLineStart < 0 )
813
+ continue ;
814
+
815
+ for (size_t i = 0 ; i < hit.matchStarts .size (); ++i) {
816
+ S (SCI_INDICATORFILLRANGE, hit.displayLineStart + hit.matchStarts [i], hit.matchLens [i]);
817
+ }
826
818
}
827
819
828
820
S (SCI_SETINDICATORCURRENT, INDIC_MATCH_FORE);
829
- for (const auto & h : _hits) {
830
- if (h.displayLineStart < 0 ) continue ;
831
- for (size_t i = 0 ; i < h.matchStarts .size (); ++i)
832
- S (SCI_INDICATORFILLRANGE,
833
- h.displayLineStart + h.matchStarts [i],
834
- h.matchLens [i]);
821
+ for (const auto & hit : _hits) {
822
+ if (hit.displayLineStart < 0 )
823
+ continue ;
824
+
825
+ for (size_t i = 0 ; i < hit.matchStarts .size (); ++i) {
826
+ S (SCI_INDICATORFILLRANGE, hit.displayLineStart + hit.matchStarts [i], hit.matchLens [i]);
827
+ }
835
828
}
836
829
}
837
830
0 commit comments