Skip to content

Commit cbea731

Browse files
committed
Stop undo bleeding into other edit windows
1 parent e84dd31 commit cbea731

File tree

11 files changed

+60
-30
lines changed

11 files changed

+60
-30
lines changed

TODO.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Bugs
22

3-
43
ALL:
54
Undo shouldn't affect other buffers; need to understand how that even happens.
6-
Tabs don't work well, especially when there isn't room for them
75
Tweak the blend fade out. Understand the ImGui strange behavior
86
insert a bad character near the top of the primitives demo before the macros, and the scene goes.
97

include/zep/buffer.h

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <functional>
44
#include <set>
5+
#include <stack>
56

67
#include "zep/mcommon/logger.h"
78
#include "zep/mcommon/signals.h"
@@ -19,6 +20,7 @@ namespace Zep
1920
class ZepSyntax;
2021
class ZepTheme;
2122
class ZepMode;
23+
class ZepCommand;
2224
enum class ThemeColor;
2325

2426
enum class Direction
@@ -279,6 +281,9 @@ class ZepBuffer : public ZepComponent
279281
Zep::signal<void(ZepBuffer& buffer, const GlyphIterator&, const std::string&)> sigPreInsert;
280282
Zep::signal<void(ZepBuffer& buffer, const GlyphIterator&, const GlyphIterator&)> sigPreDelete;
281283

284+
std::stack<std::shared_ptr<ZepCommand>>& GetUndoStack();
285+
std::stack<std::shared_ptr<ZepCommand>>& GetRedoStack();
286+
282287
private:
283288
void MarkUpdate();
284289

@@ -310,6 +315,9 @@ class ZepBuffer : public ZepComponent
310315
// Modes
311316
std::shared_ptr<ZepMode> m_spMode;
312317
fnKeyNotifier m_postKeyNotifier;
318+
319+
std::stack<std::shared_ptr<ZepCommand>> m_undoStack;
320+
std::stack<std::shared_ptr<ZepCommand>> m_redoStack;
313321
};
314322

315323
// Notification payload

include/zep/mode.h

-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ class ZepMode : public ZepComponent
228228
virtual void ClearSelection();
229229

230230
protected:
231-
std::stack<std::shared_ptr<ZepCommand>> m_undoStack;
232-
std::stack<std::shared_ptr<ZepCommand>> m_redoStack;
233231
EditorMode m_currentMode = EditorMode::Normal;
234232
bool m_lineWise = false;
235233
GlyphIterator m_visualBegin;

include/zep/theme.h

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class ZepTheme
8484
virtual const NVec4f& GetColor(ThemeColor themeColor) const;
8585
virtual NVec4f GetComplement(const NVec4f& col, const NVec4f& adjust = NVec4f(0.0f)) const;
8686
virtual ThemeColor GetUniqueColor(uint32_t id) const;
87+
virtual void SetColor(ThemeColor themeColor, const NVec4f& col);
8788

8889
void SetThemeType(ThemeType type);
8990
ThemeType GetThemeType() const;

prebuild.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if not exist "vcpkg\vcpkg.exe" (
1717
echo Installing libraries for the demo...
1818
cd vcpkg
1919
echo Installing Libraries
20-
vcpkg install imgui[freetype,sdl2-binding,opengl3-binding] tinyfiledialogs gl3w freetype sdl2 --triplet x64-windows-static-md --recurse
20+
vcpkg install imgui[freetype,sdl2-binding,opengl3-binding] clipp tinyfiledialogs gl3w freetype sdl2 --triplet x64-windows-static-md --recurse
2121
cd %~dp0
2222

2323
echo %Time%

prebuild.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ "$(uname)" == "Darwin" ]; then
1414
fi
1515

1616
cd vcpkg
17-
./vcpkg install imgui[freetype,sdl2-binding,opengl3-binding] tinyfiledialogs gl3w freetype sdl2 --triplet ${triplet[0]} --recurse
17+
./vcpkg install imgui[freetype,sdl2-binding,opengl3-binding] clipp tinyfiledialogs gl3w freetype sdl2 --triplet ${triplet[0]} --recurse
1818
if [ "$(uname)" != "Darwin" ]; then
1919
./vcpkg install glib --triplet ${triplet[0]} --recurse
2020
fi

src/buffer.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1766,5 +1766,15 @@ const std::string& ZepBuffer::GetName() const
17661766
}
17671767
return m_strName;
17681768
}
1769+
1770+
std::stack<std::shared_ptr<ZepCommand>>& ZepBuffer::GetUndoStack()
1771+
{
1772+
return m_undoStack;
1773+
}
1774+
1775+
std::stack<std::shared_ptr<ZepCommand>>& ZepBuffer::GetRedoStack()
1776+
{
1777+
return m_redoStack;
1778+
}
17691779

17701780
} // namespace Zep

src/editor.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,7 @@ void ZepEditor::Display()
12071207
if (GetConfig().style == EditorStyle::Normal)
12081208
{
12091209
// A line along the bottom of the tab region
1210-
m_pDisplay->DrawRectFilled(
1211-
NRectf(NVec2f(m_tabRegion->rect.Left(), m_tabRegion->rect.Bottom() - DPI_Y(1)), NVec2f(m_tabRegion->rect.Right(), m_tabRegion->rect.Bottom())), GetTheme().GetColor(ThemeColor::TabInactive));
1210+
//m_pDisplay->DrawRectFilled(NRectf(NVec2f(m_tabRegion->rect.Left(), m_tabRegion->rect.Bottom() - DPI_Y(1)), NVec2f(m_tabRegion->rect.Right(), m_tabRegion->rect.Bottom())), GetTheme().GetColor(ThemeColor::TabInactive));
12121211
}
12131212

12141213
// Figure out the active region
@@ -1231,7 +1230,7 @@ void ZepEditor::Display()
12311230
virtualSize = m_tabRegion->children.back()->rect.Right();
12321231
}
12331232

1234-
const auto selectHeight = int(DPI_Y(tabSelectLine));
1233+
const auto selectHeight = DPI_Y(tabSelectLine);
12351234

12361235
// Clamp it
12371236
m_tabOffsetX = std::min(m_tabOffsetX, 0.0f);
@@ -1312,7 +1311,6 @@ void ZepEditor::Display()
13121311
m_pDisplay->DrawChars(uiFont, rc.topLeftPx + DPI_VEC2(NVec2f(textBorder, textBorder)), textCol, (const uint8_t*)text.c_str());
13131312

13141313
auto drawTabLine = [&](auto yPos, auto col, auto height) {
1315-
m_pDisplay->DrawRectFilled(NRectf(rc.Left(), yPos, rc.Width(), height / 2), ModifyBackgroundColor(NVec4f(0.0f, 0.0f, 0.0f, 1.0f)));
13161314
m_pDisplay->DrawRectFilled(NRectf(rc.Left(), yPos + height / 2, rc.Width(), height / 2), ModifyBackgroundColor(col));
13171315
};
13181316

src/mode.cpp

+26-18
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,15 @@ void ZepMode::AddCommand(std::shared_ptr<ZepCommand> spCmd)
564564
return;
565565
}
566566

567+
auto& undoStack = m_pCurrentWindow->GetBuffer().GetUndoStack();
568+
auto& redoStack = m_pCurrentWindow->GetBuffer().GetRedoStack();
569+
567570
spCmd->Redo();
568-
m_undoStack.push(spCmd);
571+
undoStack.push(spCmd);
569572

570573
// Can't redo anything beyond this point
571574
std::stack<std::shared_ptr<ZepCommand>> empty;
572-
m_redoStack.swap(empty);
575+
redoStack.swap(empty);
573576

574577
if (spCmd->GetCursorAfter().Valid())
575578
{
@@ -584,27 +587,30 @@ void ZepMode::Redo()
584587
return;
585588
}
586589

587-
if (m_redoStack.empty())
590+
auto& undoStack = m_pCurrentWindow->GetBuffer().GetUndoStack();
591+
auto& redoStack = m_pCurrentWindow->GetBuffer().GetRedoStack();
592+
593+
if (redoStack.empty())
588594
return;
589595

590-
if (std::dynamic_pointer_cast<ZepCommand_GroupMarker>(m_redoStack.top()) != nullptr)
596+
if (std::dynamic_pointer_cast<ZepCommand_GroupMarker>(redoStack.top()) != nullptr)
591597
{
592-
m_undoStack.push(m_redoStack.top());
593-
m_redoStack.pop();
598+
undoStack.push(redoStack.top());
599+
redoStack.pop();
594600
}
595601

596-
while (!m_redoStack.empty())
602+
while (!redoStack.empty())
597603
{
598-
auto& spCommand = m_redoStack.top();
604+
auto& spCommand = redoStack.top();
599605
spCommand->Redo();
600606

601607
if (spCommand->GetCursorAfter().Valid())
602608
{
603609
GetCurrentWindow()->SetBufferCursor(spCommand->GetCursorAfter());
604610
}
605611

606-
m_undoStack.push(spCommand);
607-
m_redoStack.pop();
612+
undoStack.push(spCommand);
613+
redoStack.pop();
608614

609615
if (std::dynamic_pointer_cast<ZepCommand_GroupMarker>(spCommand) != nullptr)
610616
{
@@ -620,27 +626,29 @@ void ZepMode::Undo()
620626
return;
621627
}
622628

623-
if (m_undoStack.empty())
629+
auto& undoStack = m_pCurrentWindow->GetBuffer().GetUndoStack();
630+
auto& redoStack = m_pCurrentWindow->GetBuffer().GetRedoStack();
631+
if (undoStack.empty())
624632
return;
625633

626-
if (std::dynamic_pointer_cast<ZepCommand_GroupMarker>(m_undoStack.top()) != nullptr)
634+
if (std::dynamic_pointer_cast<ZepCommand_GroupMarker>(undoStack.top()) != nullptr)
627635
{
628-
m_redoStack.push(m_undoStack.top());
629-
m_undoStack.pop();
636+
redoStack.push(undoStack.top());
637+
undoStack.pop();
630638
}
631639

632-
while (!m_undoStack.empty())
640+
while (!undoStack.empty())
633641
{
634-
auto& spCommand = m_undoStack.top();
642+
auto& spCommand = undoStack.top();
635643
spCommand->Undo();
636644

637645
if (spCommand->GetCursorBefore().Valid())
638646
{
639647
GetCurrentWindow()->SetBufferCursor(spCommand->GetCursorBefore());
640648
}
641649

642-
m_redoStack.push(spCommand);
643-
m_undoStack.pop();
650+
redoStack.push(spCommand);
651+
undoStack.pop();
644652

645653
if (std::dynamic_pointer_cast<ZepCommand_GroupMarker>(spCommand) != nullptr)
646654
{

src/theme.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ ThemeColor ZepTheme::GetUniqueColor(uint32_t index) const
121121
return ThemeColor((uint32_t)ThemeColor::UniqueColor0 + (uint32_t)(index % (uint32_t)ThemeColor::UniqueColorLast));
122122
}
123123

124+
void ZepTheme::SetColor(ThemeColor themeColor, const NVec4f& col)
125+
{
126+
m_colors[themeColor] = col;
127+
}
128+
124129
const NVec4f& ZepTheme::GetColor(ThemeColor themeColor) const
125130
{
126131
if (themeColor >= ThemeColor::UniqueColor0)

src/window.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1625,26 +1625,30 @@ void ZepWindow::DisplayMarkerHints()
16251625
const auto lastIndex = m_windowLines[m_visibleLineIndices.y]->lineByteRange.second;
16261626
const auto lineHeight = m_windowLines[m_visibleLineIndices.x]->FullLineHeightPx();
16271627
const float indicatorWidth = 10.0f;
1628+
auto& theme = m_pBuffer->GetTheme();
1629+
auto& display = GetEditor().GetDisplay();
1630+
auto& font = display.GetFont(ZepTextType::Text);
16281631

16291632
m_pBuffer->ForEachMarker(RangeMarkerType::Mark, Direction::Forward, m_pBuffer->Begin(), m_pBuffer->End(), [&](const std::shared_ptr<RangeMarker>& marker) {
16301633
if (!(marker->displayType & RangeMarkerDisplayType::Background))
16311634
{
16321635
return true;
16331636
}
16341637

1638+
auto indicatorWidth = font.GetTextSize((const uint8_t*)"More...").x;
16351639
if (marker->GetRange().second > lastIndex)
16361640
{
16371641
const auto lineInfo = m_windowLines[m_visibleLineIndices.y];
1638-
auto& display = GetEditor().GetDisplay();
16391642
auto rc = NRectf(m_textRegion->rect.Right() - indicatorWidth, m_textRegion->rect.Bottom() - lineHeight, indicatorWidth, lineHeight);
16401643
display.DrawRectFilled(rc, ModifyBackgroundColor(marker->GetBackgroundColor()));
1644+
display.DrawChars(font, rc.topLeftPx, theme.GetColor(marker->GetTextColor()), (const uint8_t*)"More...");
16411645
}
16421646
else if (marker->GetRange().first < firstIndex)
16431647
{
16441648
const auto lineInfo = m_windowLines[m_visibleLineIndices.x];
1645-
auto& display = GetEditor().GetDisplay();
16461649
auto rc = NRectf(m_textRegion->rect.Right() - indicatorWidth, m_textRegion->rect.Top(), indicatorWidth, lineHeight);
16471650
display.DrawRectFilled(rc, ModifyBackgroundColor(marker->GetBackgroundColor()));
1651+
display.DrawChars(font, rc.topLeftPx, theme.GetColor(marker->GetTextColor()), (const uint8_t*)"More...");
16481652
}
16491653

16501654
return true;

0 commit comments

Comments
 (0)