Skip to content

Commit

Permalink
Fix hidden results of long lines for "Find All ..." commands
Browse files Browse the repository at this point in the history
Fix some the results of "Find all in..." commands of long lines not being displayed, when the long lines are cut (its length > 2048).
All the results displayed in the cut long lines will be kept as the current behaviour. Additionally, each result beyond the cut long line (2048) will be displayed as default mode (ie. each entry will be displayed, so user can double click on the entry line for reaching the result).

Related: notepad-plus-plus#12014

Fix notepad-plus-plus#12023, close notepad-plus-plus#14520
  • Loading branch information
donho committed Dec 26, 2023
1 parent d1b3fe6 commit 78d0e7e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion PowerEditor/installer/nativeLang/english.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ You can define several column markers by using white space to separate the diffe
<Item id="6903" name="Find dialog remains open after search that outputs to results window"/>
<Item id="6904" name="Confirm Replace All in All Opened Documents"/>
<Item id="6905" name="Replace: Don't move to the following occurrence"/>
<Item id="6906" name="Search Result window: show only one entry per found line"/>
<Item id="6906" name="Search Result window: show only one entry per found line if possible"/>
<Item id="6907" name="When Find Dialog is Invoked"/>
<Item id="6908" name="Fill Find Field with Selected Text"/>
<Item id="6909" name="Select Word Under Caret when Nothing Selected"/>
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/installer/nativeLang/english_customizable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ You can define several column markers by using white space to separate the diffe
<Item id="6903" name="Find dialog remains open after search that outputs to results window"/>
<Item id="6904" name="Confirm Replace All in All Opened Documents"/>
<Item id="6905" name="Replace: Don't move to the following occurrence"/>
<Item id="6906" name="Search Result window: show only one entry per found line"/>
<Item id="6906" name="Search Result window: show only one entry per found line if possible"/>
<Item id="6907" name="When Find Dialog is Invoked"/>
<Item id="6908" name="Fill Find Field with Selected Text"/>
<Item id="6909" name="Select Word Under Caret when Nothing Selected"/>
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/installer/nativeLang/french.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ Vous pouvez définir plusieurs marqueurs de colonne en utilisant un espace pour
<Item id="6903" name="La boîte de dialogue &quot;Rechercher&quot; reste ouverte après la recherche qui affiche la fenêtre de résultats"/>
<Item id="6904" name="Confirmer &quot;Remplacer dans tous les documents ouverts&quot;"/>
<Item id="6905" name="&quot;Remplacer&quot; : ne pas passer à l'occurrence suivante"/>
<Item id="6906" name="Résultats de recherche : afficher une seule entrée par ligne trouvée"/>
<Item id="6906" name="Résultats de recherche : afficher une seule entrée par ligne trouvée si possible"/>
<Item id="6907" name="Quand la boîte de dialogue &quot;Rechercher&quot; est invoquée"/>
<Item id="6908" name="Remplir le champ de recherche avec le texte sélectionné"/>
<Item id="6909" name="Sélectionner le mot sous le curseur si rien n'est sélectionné"/>
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/installer/nativeLang/taiwaneseMandarin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@
<Item id="6903" name="搜尋結果輸出到結果視窗後,尋找與取代對話方塊繼續保持打開狀態"/>
<Item id="6904" name="確認「在所有開啟的文件中取代」"/>
<Item id="6905" name="替換:不要移動到下一個匹配項"/>
<Item id="6906" name="搜尋結果視窗:每個找到的行只顯示一個條目"/>
<Item id="6906" name="搜尋結果視窗:在可能的情況下每個找到的行只顯示一個條目"/>
<Item id="6907" name="當尋找對話方塊被觸發引出時"/>
<Item id="6908" name="用選取詞填充尋找與取代對話方塊中的尋找內容"/>
<Item id="6909" name="在沒有任何選取時,選取游標下的字串"/>
Expand Down
22 changes: 15 additions & 7 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,11 @@ bool Finder::notify(SCNotification *notification)
if (end > lineEndAbsPos)
end = lineEndAbsPos;

_scintView.execute(SCI_SETSEL, begin, end);
_scintView.execute(SCI_SCROLLRANGE, begin, end);
if (begin < end)
{
_scintView.execute(SCI_SETSEL, begin, end);
_scintView.execute(SCI_SCROLLRANGE, begin, end);
}

}
break;
Expand Down Expand Up @@ -4817,30 +4820,35 @@ const char* Finder::foundLine(FoundInfo fi, SearchResultMarkingLine miLine, cons
headerStr += foundline;
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
const char* text2AddUtf8 = wmc.wchar2char(headerStr.c_str(), SC_CP_UTF8, &miLine._segmentPostions[0].first, &miLine._segmentPostions[0].second); // certainly utf8 here
size_t text2AddUtf8Len = strlen(text2AddUtf8);

if (isRepeatedLine) // if current line is the repeated line of previous one, and settings make per found line show once in the result even there are several found occurences in the same line
// if current line is the repeated line of previous one, and settings make per found line show ONCE in the result even there are several found occurences in the same line, for:
if ((isRepeatedLine &&
((text2AddUtf8Len < SC_SEARCHRESULT_LINEBUFFERMAXLENGTH) || // 1. All displayed whole lines, in which it contains all the occurrences.
((text2AddUtf8Len >= SC_SEARCHRESULT_LINEBUFFERMAXLENGTH && miLine._segmentPostions[0].second < SC_SEARCHRESULT_LINEBUFFERMAXLENGTH))))) // 2. or the cut lines but the segments are displayed. For the segments displayed beyond displayed (non-cut part), go to default mode.
{
// Add start and end markers into the previous line's info for colourizing
_pMainMarkings->back()._segmentPostions.push_back(std::pair<intptr_t, intptr_t>(miLine._segmentPostions[0].first, miLine._segmentPostions[0].second));
_pMainFoundInfos->back()._ranges.push_back(fi._ranges.back());

return "";
}
else // default mode: allow same found line has several entries in search result if the searched occurrence is matched several times in the same line
{
_pMainFoundInfos->push_back(fi);

size_t len = strlen(text2AddUtf8);
if (len >= SC_SEARCHRESULT_LINEBUFFERMAXLENGTH)

if (text2AddUtf8Len >= SC_SEARCHRESULT_LINEBUFFERMAXLENGTH)
{
const char* endOfLongLine = " ...\r\n"; // perfectly Utf8-encoded already
size_t lenEndOfLongLine = strlen(endOfLongLine);
size_t cut = SC_SEARCHRESULT_LINEBUFFERMAXLENGTH - lenEndOfLongLine - 1;

while ((cut > 0) && (!Utf8::isValid(&text2AddUtf8[cut], (int)(len - cut))))
while ((cut > 0) && (!Utf8::isValid(&text2AddUtf8[cut], (int)(text2AddUtf8Len - cut))))
cut--;

memcpy((void*)&text2AddUtf8[cut], endOfLongLine, lenEndOfLongLine + 1);
len = cut + lenEndOfLongLine;
text2AddUtf8Len = cut + lenEndOfLongLine;
}

_pMainMarkings->push_back(miLine);
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/WinControls/Preference/preference.rc
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ BEGIN
CONTROL "Find dialog remains open after search that outputs to results window", IDC_CHECK_FINDDLG_ALWAYS_VISIBLE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 89, 350, 10
CONTROL "Confirm Replace All in All Opened Documents", IDC_CHECK_CONFIRMREPLOPENDOCS, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 104, 350, 10
CONTROL "Replace: Don't move to the following occurrence", IDC_CHECK_REPLACEANDSTOP, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 119, 350, 10
CONTROL "Search Result window: show only one entry per found line", IDC_CHECK_SHOWONCEPERFOUNDLINE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 134, 350, 10
CONTROL "Search Result window: show only one entry per found line if possible", IDC_CHECK_SHOWONCEPERFOUNDLINE, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 134, 350, 10
END


Expand Down

0 comments on commit 78d0e7e

Please sign in to comment.