| 871 | } |
| 872 | |
| 873 | void CGameConsole::CInstance::UpdateSearch() |
| 874 | { |
| 875 | if(!m_Searching) |
| 876 | return; |
| 877 | |
| 878 | const char *pSearchText = m_Input.GetString(); |
| 879 | bool SearchChanged = str_utf8_comp_nocase(pSearchText, m_aCurrentSearchString) != 0; |
| 880 | |
| 881 | int SearchLength = m_Input.GetLength(); |
| 882 | str_copy(m_aCurrentSearchString, pSearchText); |
| 883 | |
| 884 | m_vSearchMatches.clear(); |
| 885 | if(pSearchText[0] == '\0') |
| 886 | { |
| 887 | m_CurrentMatchIndex = -1; |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | if(SearchChanged) |
| 892 | { |
| 893 | m_CurrentMatchIndex = -1; |
| 894 | m_HasSelection = false; |
| 895 | } |
| 896 | |
| 897 | ITextRender *pTextRender = m_pGameConsole->Ui()->TextRender(); |
| 898 | const int LineWidth = m_pGameConsole->Ui()->Screen()->w - 10.0f; |
| 899 | |
| 900 | CBacklogEntry *pEntry = m_Backlog.Last(); |
| 901 | int EntryLine = 0, LineToScrollStart = 0, LineToScrollEnd = 0; |
| 902 | |
| 903 | for(; pEntry; EntryLine += pEntry->m_LineCount, pEntry = m_Backlog.Prev(pEntry)) |
| 904 | { |
| 905 | const char *pSearchPos = str_utf8_find_nocase(pEntry->m_aText, pSearchText); |
| 906 | if(!pSearchPos) |
| 907 | continue; |
| 908 | |
| 909 | int EntryLineCount = pEntry->m_LineCount; |
| 910 | |
| 911 | // Find all occurrences of the search string and save their positions |
| 912 | while(pSearchPos) |
| 913 | { |
| 914 | int Pos = pSearchPos - pEntry->m_aText; |
| 915 | |
| 916 | if(EntryLineCount == 1) |
| 917 | { |
| 918 | m_vSearchMatches.emplace_back(Pos, EntryLine, EntryLine, EntryLine); |
| 919 | if(EntryLine > LineToScrollStart) |
| 920 | { |
| 921 | LineToScrollStart = EntryLine; |
| 922 | LineToScrollEnd = EntryLine; |
| 923 | } |
| 924 | } |
| 925 | else |
| 926 | { |
| 927 | // A match can span multiple lines in case of a multiline entry, so we need to know which line the match starts at |
| 928 | // and which line it ends at in order to put it in viewport properly |
| 929 | STextSizeProperties Props; |
| 930 | int LineCount; |
no test coverage detected