diff --git a/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h b/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h index ec20a4840..3b8ebf7fb 100644 --- a/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h +++ b/lib/third_party/imgui/ColorTextEditor/include/TextEditor.h @@ -244,7 +244,8 @@ public: Coordinates GetCursorPosition() const { return GetActualCursorCoordinates(); } void SetCursorPosition(const Coordinates& aPosition); - + bool RaiseContextMenu() { return mRaiseContextMenu; } + void ClearRaiseContextMenu() { mRaiseContextMenu = false; } inline void SetHandleMouseInputs (bool aValue){ mHandleMouseInputs = aValue;} inline bool IsHandleMouseInputsEnabled() const { return mHandleKeyboardInputs; } @@ -502,6 +503,7 @@ private: float mLastClick; bool mShowCursor; bool mShowLineNumbers; + bool mRaiseContextMenu = false; static const int sCursorBlinkInterval; static const int sCursorBlinkOnTime; diff --git a/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp b/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp index 9eae2a61a..33cbe5236 100644 --- a/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp +++ b/lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp @@ -764,10 +764,11 @@ void TextEditor::HandleMouseInputs() { if (ImGui::IsWindowHovered()) { if (!alt) { - auto click = ImGui::IsMouseClicked(0); - auto doubleClick = ImGui::IsMouseDoubleClicked(0); - auto t = ImGui::GetTime(); - auto tripleClick = click && !doubleClick && (mLastClick != -1.0f && (t - mLastClick) < io.MouseDoubleClickTime); + auto click = ImGui::IsMouseClicked(0); + auto doubleClick = ImGui::IsMouseDoubleClicked(0); + auto rightClick = ImGui::IsMouseClicked(1); + auto t = ImGui::GetTime(); + auto tripleClick = click && !doubleClick && (mLastClick != -1.0f && (t - mLastClick) < io.MouseDoubleClickTime); bool resetBlinking = false; /* Left mouse button triple click @@ -821,6 +822,16 @@ void TextEditor::HandleMouseInputs() { EnsureCursorVisible(); mLastClick = (float)ImGui::GetTime(); + } else if (rightClick) { + auto cursorPosition = ScreenPosToCoordinates(ImGui::GetMousePos()); + + if (!HasSelection() || mState.mSelectionStart > cursorPosition || cursorPosition > mState.mSelectionEnd) { + mState.mCursorPosition = mInteractiveStart = mInteractiveEnd = cursorPosition; + mSelectionMode = SelectionMode::Normal; + SetSelection(mInteractiveStart, mInteractiveEnd, mSelectionMode); + } + ResetCursorBlinkTime(); + mRaiseContextMenu = true; } // Mouse left button dragging (=> update selection) else if (ImGui::IsMouseDragging(0) && ImGui::IsMouseDown(0)) { diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index e74859f84..72d86a7db 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -351,8 +351,9 @@ namespace hex::plugin::builtin { m_textEditorHoverBox = ImRect(windowPosition,windowPosition+textEditorSize); m_consoleHoverBox = ImRect(ImVec2(windowPosition.x,windowPosition.y+textEditorSize.y),windowPosition+availableSize); TextEditor::FindReplaceHandler *findReplaceHandler = m_textEditor.GetFindReplaceHandler(); - if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsMouseHoveringRect(m_textEditorHoverBox.Min,m_textEditorHoverBox.Max) && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { + if (m_textEditor.RaiseContextMenu()) { ImGui::OpenPopup("##pattern_editor_context_menu"); + m_textEditor.ClearRaiseContextMenu(); } if (ImGui::BeginPopup("##pattern_editor_context_menu")) { @@ -364,6 +365,8 @@ namespace hex::plugin::builtin { ImGui::Separator(); + if (!m_textEditor.HasSelection()) + m_textEditor.SelectWordUnderCursor(); const bool hasSelection = m_textEditor.HasSelection(); if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.cut"_lang, Shortcut(CTRLCMD + Keys::X).toString().c_str(), false, hasSelection)) { m_textEditor.Cut(); @@ -386,7 +389,7 @@ namespace hex::plugin::builtin { ImGui::Separator(); // Search and replace entries - if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.find"_lang, Shortcut(CTRLCMD + Keys::F).toString().c_str(),false, m_textEditor.HasSelection())){ + if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.find"_lang, Shortcut(CTRLCMD + Keys::F).toString().c_str())){ m_replaceMode = false; m_openFindReplacePopUp = true; } @@ -398,7 +401,7 @@ namespace hex::plugin::builtin { if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.find_previous"_lang, Shortcut(SHIFT + Keys::F3).toString().c_str(),false,!findReplaceHandler->GetFindWord().empty())) findReplaceHandler->FindMatch(&m_textEditor,false); - if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.replace"_lang, Shortcut(CTRLCMD + Keys::H).toString().c_str(),false,!findReplaceHandler->GetReplaceWord().empty())) { + if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.replace"_lang, Shortcut(CTRLCMD + Keys::H).toString().c_str())) { m_replaceMode = true; m_openFindReplacePopUp = true; } @@ -921,9 +924,12 @@ namespace hex::plugin::builtin { void ViewPatternEditor::drawConsole(ImVec2 size) { auto findReplaceHandler = m_consoleEditor.GetFindReplaceHandler(); - if (ImGui::IsMouseDown(ImGuiMouseButton_Right) && ImGui::IsMouseHoveringRect(m_consoleHoverBox.Min,m_consoleHoverBox.Max) && !ImGui::IsMouseDragging(ImGuiMouseButton_Right)) { + if (m_consoleEditor.RaiseContextMenu()) { ImGui::OpenPopup("##console_context_menu"); + m_consoleEditor.ClearRaiseContextMenu(); } + if (!m_consoleEditor.HasSelection()) + m_consoleEditor.SelectWordUnderCursor(); const bool hasSelection = m_consoleEditor.HasSelection(); if (ImGui::BeginPopup("##console_context_menu")) { if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.copy"_lang, Shortcut(CTRLCMD + Keys::C).toString().c_str(), false, hasSelection)) { @@ -934,7 +940,7 @@ namespace hex::plugin::builtin { } ImGui::Separator(); // Search and replace entries - if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.find"_lang, Shortcut(CTRLCMD + Keys::F).toString().c_str(),false, hasSelection)) { + if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.find"_lang, Shortcut(CTRLCMD + Keys::F).toString().c_str())) { m_openFindReplacePopUp = true; m_replaceMode = false; }