Skip to content

Commit c0a2226

Browse files
authored
feat: Allow adding breakpoints in pattern editor by clicking on line numbers (#2161)
Now that line numbers are not part of the line of code clicking them makes the text editor lose focus. This PR changes that by allowing the user to toggle breakpoints by clicking the field where the line number is located. Not only will the text editor retain focus when breakpoints are set, but if other parts of ImHex had focus, then it will be transferred to the text editor's current cursor position when the line number field is clicked. It is also possible to keep the focus where it was and only retain the focus if the text editor was focused when the break point is set. The change is very trivial so if that is preferred I can easily switch it.
1 parent 6531739 commit c0a2226

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void TextEditor::SetFocus() {
871871
ResetCursorBlinkTime();
872872
EnsureCursorVisible();
873873
if (!this->mReadOnly) {
874-
ImGui::SetKeyboardFocusHere(-1);
874+
ImGui::SetKeyboardFocusHere(0);
875875
mUpdateFocus = false;
876876
}
877877
}
@@ -976,6 +976,15 @@ void TextEditor::RenderText(const char *aTitle, const ImVec2 &lineNumbersStartPo
976976
space += " ";
977977
}
978978
std::string lineNoStr = space + std::to_string((int)(lineNo + 1));
979+
ImGui::SetCursorScreenPos(ImVec2(lineNumbersStartPos.x, lineStartScreenPos.y));
980+
if (ImGui::InvisibleButton(lineNoStr.c_str(),ImVec2(mLineNumberFieldWidth,mCharAdvance.y))) {
981+
if (mBreakpoints.contains(lineNo + 1))
982+
mBreakpoints.erase(lineNo + 1);
983+
else
984+
mBreakpoints.insert(lineNo + 1);
985+
mBreakPointsChanged = true;
986+
JumpToCoords(mState.mCursorPosition);
987+
}
979988
TextUnformattedColoredAt(ImVec2(mLeftMargin + lineNoStartScreenPos.x, lineStartScreenPos.y), mPalette[(int) PaletteIndex::LineNumber], lineNoStr.c_str());
980989
}
981990

0 commit comments

Comments
 (0)