Skip to content

Commit

Permalink
Bracket Colors
Browse files Browse the repository at this point in the history
Add bracketcolors plugin. Color {}, [], () based on nesting order

Closes #1148
  • Loading branch information
aminArlut committed Apr 6, 2023
1 parent 50ae403 commit 48fdf9e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
13 changes: 11 additions & 2 deletions bracketcolors/src/BracketMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@


// -----------------------------------------------------------------------------
void BracketMap::ComputeOrder()
std::set<BracketMap::Index> BracketMap::ComputeOrder()
/*
----------------------------------------------------------------------------- */
{
std::stack<Index> orderStack;
std::set<Index> updatedBrackets;

for (auto &it : mBracketMap) {

Expand Down Expand Up @@ -105,6 +106,14 @@
orderStack.push(endPos);
}

GetOrder(bracket) = orderStack.size() - 1;
Order newOrder = orderStack.size() - 1;
Order currOrder = GetOrder(bracket);
if (newOrder != currOrder) {
updatedBrackets.insert(startIndex);
}

GetOrder(bracket) = newOrder;
}

return updatedBrackets;
}
3 changes: 2 additions & 1 deletion bracketcolors/src/BracketMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <map>
#include <tuple>
#include <set>

#include <glib.h>

Expand All @@ -41,7 +42,7 @@
~BracketMap();

void Update(Index index, Length length);
void ComputeOrder();
std::set<Index> ComputeOrder();

static const gint UNDEFINED = -1;

Expand Down
9 changes: 5 additions & 4 deletions bracketcolors/src/bracketcolors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,9 @@
return madeChange;
}

for (const auto &it : indiciesToRecompute) {
bracketColorsData.recomputeIndicies.insert(it);
}
bracketColorsData.recomputeIndicies.insert(
indiciesToRecompute.begin(), indiciesToRecompute.end()
);

for (const auto &it : indiciesToAdjust) {
bracketMap.mBracketMap.insert(
Expand Down Expand Up @@ -1078,7 +1078,8 @@
}
}

bracketMap.ComputeOrder();
std::set<BracketMap::Index> updatedBrackets = bracketMap.ComputeOrder();
data->redrawIndicies.insert(updatedBrackets.begin(), updatedBrackets.end());
}

position = data->recomputeIndicies.erase(position);
Expand Down

0 comments on commit 48fdf9e

Please sign in to comment.