Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for breakpoints #1923

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/third_party/imgui/ColorTextEditor/include/TextEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class TextEditor
using Keywords = std::unordered_set<std::string> ;
using ErrorMarkers = std::map<Coordinates, std::pair<uint32_t ,std::string>>;
using ErrorHoverBoxes = std::map<Coordinates, std::pair<ImVec2,ImVec2>>;
using Breakpoints = std::unordered_set<int32_t>;
using Breakpoints = std::unordered_set<uint32_t>;
using Palette = std::array<ImU32, (uint32_t)PaletteIndex::Max>;
using Char = uint8_t ;

Expand Down Expand Up @@ -199,6 +199,7 @@ class TextEditor
static void SetPalette(const Palette& aValue);

void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }
Breakpoints &GetBreakpoints() { return mBreakpoints; }
void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }
ImVec2 Underwaves( ImVec2 pos, uint32_t nChars, ImColor color= ImGui::GetStyleColorVec4(ImGuiCol_Text), const ImVec2 &size_arg= ImVec2(0, 0));

Expand All @@ -223,6 +224,8 @@ class TextEditor
bool IsReadOnly() const { return mReadOnly; }
bool IsTextChanged() const { return mTextChanged; }
bool IsCursorPositionChanged() const { return mCursorPositionChanged; }
bool IsBreakpointsChanged() const { return mBreakPointsChanged; }
void ClearBreakpointsChanged() { mBreakPointsChanged = false; }

void SetShowCursor(bool aValue) { mShowCursor = aValue; }
void SetShowLineNumbers(bool aValue) { mShowLineNumbers = aValue; }
Expand Down Expand Up @@ -461,6 +464,7 @@ class TextEditor
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor.
int mLeftMargin;
bool mCursorPositionChanged;
bool mBreakPointsChanged;
int mColorRangeMin, mColorRangeMax;
SelectionMode mSelectionMode;
bool mHandleKeyboardInputs;
Expand Down
40 changes: 27 additions & 13 deletions lib/third_party/imgui/ColorTextEditor/source/TextEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,17 @@ void TextEditor::RemoveLine(int aStart, int aEnd) {
mErrorMarkers = std::move(etmp);

Breakpoints btmp;
for (auto i : mBreakpoints) {
if (i >= aStart && i <= aEnd)
continue;
btmp.insert(i >= aStart ? i - 1 : i);
for (auto breakpoint : mBreakpoints) {
if (breakpoint <= aStart || breakpoint >= aEnd) {
if (breakpoint >= aEnd) {
btmp.insert(breakpoint - 1);
mBreakPointsChanged = true;
} else
btmp.insert(breakpoint);
}
}
mBreakpoints = std::move(btmp);
if (mBreakPointsChanged)
mBreakpoints = std::move(btmp);
if (aStart == 0 && aEnd == (int32_t)mLines.size() - 1)
mLines.erase(mLines.begin() + aStart, mLines.end());
else
Expand All @@ -608,12 +613,15 @@ void TextEditor::RemoveLine(int aIndex) {
mErrorMarkers = std::move(etmp);

Breakpoints btmp;
for (auto i : mBreakpoints) {
if (i == aIndex)
continue;
btmp.insert(i >= aIndex ? i - 1 : i);
for (auto breakpoint : mBreakpoints) {
if (breakpoint > aIndex) {
btmp.insert(breakpoint - 1);
mBreakPointsChanged = true;
}else
btmp.insert(breakpoint);
}
mBreakpoints = std::move(btmp);
if (mBreakPointsChanged)
mBreakpoints = std::move(btmp);

mLines.erase(mLines.begin() + aIndex);
assert(!mLines.empty());
Expand All @@ -630,9 +638,15 @@ TextEditor::Line &TextEditor::InsertLine(int aIndex) {
mErrorMarkers = std::move(etmp);

Breakpoints btmp;
for (auto i : mBreakpoints)
btmp.insert(i >= aIndex ? i + 1 : i);
mBreakpoints = std::move(btmp);
for (auto breakpoint : mBreakpoints) {
if (breakpoint >= aIndex) {
btmp.insert(breakpoint + 1);
mBreakPointsChanged = true;
} else
btmp.insert(breakpoint);
}
if (mBreakPointsChanged)
mBreakpoints = std::move(btmp);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ namespace hex::plugin::builtin {
std::mutex m_logMutex;

PerProvider<TextEditor::Coordinates> m_cursorPosition;
PerProvider<std::unordered_set<u32>> m_breakpoints;
PerProvider<std::optional<pl::core::err::PatternLanguageError>> m_lastEvaluationError;
PerProvider<std::vector<pl::core::err::CompileError>> m_lastCompileError;
PerProvider<const std::vector<std::unique_ptr<pl::core::ast::ASTNode>>*> m_callStack;
Expand Down
29 changes: 20 additions & 9 deletions plugins/builtin/source/content/views/view_pattern_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,16 @@ namespace hex::plugin::builtin {
}
}

if (m_textEditor.IsBreakpointsChanged()) {
m_breakpoints = m_textEditor.GetBreakpoints();
m_textEditor.ClearBreakpointsChanged();
const auto &runtime = ContentRegistry::PatternLanguage::getRuntime();
auto &evaluator = runtime.getInternals().evaluator;
if (evaluator) {
evaluator->setBreakpoints(m_breakpoints);
}
}

if (m_textEditor.IsTextChanged()) {
m_hasUnevaluatedChanges = true;
m_lastEditorChangeTime = std::chrono::steady_clock::now();
Expand Down Expand Up @@ -1245,23 +1255,23 @@ namespace hex::plugin::builtin {

if (ImGui::BeginChild("##debugger", size, true)) {
auto &evaluator = runtime.getInternals().evaluator;
const auto &breakpoints = evaluator->getBreakpoints();
m_breakpoints = m_textEditor.GetBreakpoints();
evaluator->setBreakpoints(m_breakpoints);
const auto line = m_textEditor.GetCursorPosition().mLine + 1;

if (!breakpoints.contains(line)) {
if (!m_breakpoints->contains(line)) {
if (ImGuiExt::IconButton(ICON_VS_DEBUG_BREAKPOINT, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) {
evaluator->addBreakpoint(line);
m_textEditor.SetBreakpoints(breakpoints);
}
ImGuiExt::InfoTooltip("hex.builtin.view.pattern_editor.debugger.add_tooltip"_lang);
} else {
if (ImGuiExt::IconButton(ICON_VS_DEBUG_BREAKPOINT_UNVERIFIED, ImGuiExt::GetCustomColorVec4(ImGuiCustomCol_ToolbarRed))) {
evaluator->removeBreakpoint(line);
m_textEditor.SetBreakpoints(breakpoints);
}
ImGuiExt::InfoTooltip("hex.builtin.view.pattern_editor.debugger.remove_tooltip"_lang);
}

m_breakpoints = evaluator->getBreakpoints();
m_textEditor.SetBreakpoints(m_breakpoints);
ImGui::SameLine();

if (*m_breakpointHit) {
Expand Down Expand Up @@ -2359,15 +2369,16 @@ namespace hex::plugin::builtin {
const auto &runtime = ContentRegistry::PatternLanguage::getRuntime();

auto &evaluator = runtime.getInternals().evaluator;
auto &breakpoints = evaluator->getBreakpoints();
m_breakpoints = m_textEditor.GetBreakpoints();
evaluator->setBreakpoints(m_breakpoints);

if (breakpoints.contains(line)) {
if (m_breakpoints->contains(line)) {
evaluator->removeBreakpoint(line);
} else {
evaluator->addBreakpoint(line);
}

m_textEditor.SetBreakpoints(breakpoints);
m_breakpoints = evaluator->getBreakpoints();
m_textEditor.SetBreakpoints(m_breakpoints);
});

/* Trigger evaluation */
Expand Down
Loading