From 14ee6886299b462a80c0e9bdb99977983236dd89 Mon Sep 17 00:00:00 2001 From: paxcut <53811119+paxcut@users.noreply.github.com> Date: Sat, 9 Aug 2025 03:03:08 -0700 Subject: [PATCH] fix: fixes for issues #2388 and #2389. (#2392) Tab insertion was not being recorded for undoing and the shift-backspace shortcut did not exist. This PR addresses both issues directly. --- .../imgui/ColorTextEditor/source/TextEditor.cpp | 7 +++++++ plugins/builtin/romfs/lang/en_US.json | 1 + .../builtin/source/content/views/view_pattern_editor.cpp | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp b/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp index bf37e7908..2b96f08f4 100644 --- a/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp +++ b/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp @@ -1559,16 +1559,23 @@ namespace hex::ui { line.insert(line.begin() + charIndex, spaces.begin(), spaces.end()); line.m_colorized = false; setCursorPosition(getCharacterCoordinates(coord.m_line, charIndex + spacesToInsert)); + u.m_added = spaces; + u.m_addedSelection.m_end = setCoordinates(m_state.m_cursorPosition); } else { auto spacesToRemove = (charIndex % m_tabSize); if (spacesToRemove == 0) spacesToRemove = m_tabSize; spacesToRemove = std::min(spacesToRemove, (int32_t) line.size()); + auto spacesRemoved = 0; for (int32_t j = 0; j < spacesToRemove; j++) { if (*(line.begin() + (charIndex - 1)) == ' ') { line.erase(line.begin() + (charIndex - 1)); charIndex -= 1; + spacesRemoved++; } } + std::string spaces(spacesRemoved, ' '); + u.m_removed = spaces; + u.m_removedSelection = Selection(Coordinates(coord.m_line, charIndex), Coordinates(coord.m_line, charIndex + spacesRemoved)); line.m_colorized = false; setCursorPosition(getCharacterCoordinates(coord.m_line, std::max(0, charIndex))); } diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index b0cfd7387..5ccd714aa 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -1025,6 +1025,7 @@ "hex.builtin.view.pattern_editor.shortcut.toggle_insert": "Toggle Write Over", "hex.builtin.view.pattern_editor.shortcut.delete": "Delete One Character at the Cursor Position", "hex.builtin.view.pattern_editor.shortcut.backspace": "Delete One Character to the Left of Cursor", + "hex.builtin.view.pattern_editor.shortcut.backspace_shifted": "Delete One Character to the Left of Cursor", "hex.builtin.view.pattern_editor.shortcut.select_all": "Select Entire File", "hex.builtin.view.pattern_editor.menu.edit.select_all": "Select All", "hex.builtin.view.pattern_editor.shortcut.select_left": "Extend Selection One Character to the Left of the Cursor", diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 262bcde63..b105a8bfe 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -2491,6 +2491,11 @@ namespace hex::plugin::builtin { m_textEditor.get(ImHexApi::Provider::get()).backspace(); }); + ShortcutManager::addShortcut(this, SHIFT + Keys::Backspace + AllowWhileTyping, "hex.builtin.view.pattern_editor.shortcut.backspace_shifted", [this] { + if (m_focusedSubWindowName.contains(textEditorView)) + m_textEditor.get(ImHexApi::Provider::get()).backspace(); + }); + ShortcutManager::addShortcut(this, Keys::Insert + AllowWhileTyping, "hex.builtin.view.pattern_editor.shortcut.toggle_insert", [this] { if (m_focusedSubWindowName.contains(textEditorView)) m_textEditor.get(ImHexApi::Provider::get()).setOverwrite(!m_textEditor.get(ImHexApi::Provider::get()).isOverwrite());