fix: Fixed ImHex crashing when using ctrl-backspace on empty file. (#2433)

Editor was attempting to delete non-existent chars which is UB. Fixed by
checking before deleting. Also fixed was a problem created by having to
press enter to change the search string which advanced the selection to
the first match. In the next step one would expect that pressing enter
on the replace field would replace the selected item but was replacing
the item found after he first.

This was fixed by always replacing the current selection first. If the
replacement is the same as the searched term then replacing won't
advance the cursor, but if they are different then the current match
will no longer exist so it would search fora new one.
This commit is contained in:
paxcut
2025-09-05 02:28:11 -07:00
committed by GitHub
parent d62b64c27a
commit d8dd287cdf
10 changed files with 122 additions and 89 deletions

View File

@@ -59,6 +59,12 @@ namespace hex::ui {
Coordinates getSelectedColumns();
bool isSingleLine();
bool contains(Coordinates coordinates, int8_t endsInclusive=1);
bool operator==(const Selection &o) const {
return m_start == o.m_start && m_end == o.m_end;
}
bool operator!=(const Selection &o) const {
return m_start != o.m_start || m_end != o.m_end;
}
};
struct EditorState {
@@ -72,7 +78,7 @@ namespace hex::ui {
typedef std::vector<EditorState> Matches;
Matches &getMatches() { return m_matches; }
bool findNext(TextEditor *editor);
u32 findMatch(TextEditor *editor, bool isNex);
u32 findMatch(TextEditor *editor, i32 index);
bool replace(TextEditor *editor, bool right);
bool replaceAll(TextEditor *editor);
std::string &getFindWord() { return m_findWord; }
@@ -687,7 +693,6 @@ namespace hex::ui {
bool m_raiseContextMenu = false;
Coordinates m_focusAtCoords = {};
bool m_updateFocus = false;
bool m_ensureCursorVisible = false;
std::vector<std::string> m_clickableText;