Skip to content

Commit 49d8a89

Browse files
committed
Merge
2 parents 9e7def7 + 36f2da3 commit 49d8a89

12 files changed

+211
-75
lines changed

demo_imgui/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct ZepContainer : public IZepComponent
115115
{
116116
ZepBuffer* pBuffer = spEditor->GetBuffer("shader.vert");
117117
pBuffer->SetText(shader.c_str());
118+
118119
}
119120
}
120121

src/buffer.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#include <cctype>
22
#include <cstdint>
33
#include <cstdlib>
4+
#include <algorithm>
5+
#include <regex>
46

57
#include "buffer.h"
68
#include "mcommon/file/file.h"
79
#include "mcommon/string/stringutils.h"
810

9-
#include <algorithm>
10-
#include <regex>
11-
1211
#include "mcommon/logger.h"
1312

1413
namespace
@@ -856,4 +855,33 @@ void ZepBuffer::SetTheme(std::shared_ptr<ZepTheme> spTheme)
856855
m_spOverrideTheme = spTheme;
857856
}
858857

858+
BufferRange ZepBuffer::GetSelection() const
859+
{
860+
return m_selection;
861+
}
862+
863+
void ZepBuffer::SetSelection(const BufferRange& selection)
864+
{
865+
m_selection = selection;
866+
if (m_selection.first > m_selection.second)
867+
{
868+
std::swap(m_selection.first, m_selection.second);
869+
}
870+
}
871+
872+
void ZepBuffer::AddRangeMarker(const RangeMarker& marker)
873+
{
874+
m_rangeMarkers.emplace_back(marker);
875+
}
876+
877+
void ZepBuffer::ClearRangeMarkers()
878+
{
879+
m_rangeMarkers.clear();
880+
}
881+
882+
const tRangeMarkers& ZepBuffer::GetRangeMarkers() const
883+
{
884+
return m_rangeMarkers;
885+
}
886+
859887
} // namespace Zep

src/buffer.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#pragma once
22

3-
#include "editor.h"
43
#include <mcommon/file/file.h>
4+
#include "editor.h"
5+
#include "theme.h"
56

67
#include <set>
78
#include <shared_mutex>
@@ -15,6 +16,7 @@ namespace Zep
1516

1617
class ZepSyntax;
1718
class ZepTheme;
19+
enum class ThemeColor;
1820

1921
enum class SearchDirection
2022
{
@@ -57,8 +59,18 @@ enum class LineLocation
5759
using BufferLocation = long;
5860
using BufferRange = std::pair<BufferLocation, BufferLocation>;
5961

60-
const long InvalidOffset = -1;
62+
struct RangeMarker
63+
{
64+
long bufferLine = -1;
65+
BufferRange range;
66+
ThemeColor color;
67+
std::string name;
68+
std::string description;
69+
};
6170

71+
using tRangeMarkers = std::vector<RangeMarker>;
72+
73+
const long InvalidOffset = -1;
6274
extern const char* Msg_Buffer;
6375

6476
// A really big cursor move; which will likely clamp
@@ -165,6 +177,13 @@ class ZepBuffer : public ZepComponent
165177
ZepTheme& GetTheme() const;
166178
void SetTheme(std::shared_ptr<ZepTheme> spTheme);
167179

180+
void SetSelection(const BufferRange& sel);
181+
BufferRange GetSelection() const;
182+
183+
void AddRangeMarker(const RangeMarker& marker);
184+
void ClearRangeMarkers();
185+
const tRangeMarkers& GetRangeMarkers() const;
186+
168187
private:
169188
// Internal
170189
GapBuffer<utf8>::const_iterator SearchWord(uint32_t searchType, GapBuffer<utf8>::const_iterator itrBegin, GapBuffer<utf8>::const_iterator itrEnd, SearchDirection dir) const;
@@ -184,6 +203,9 @@ class ZepBuffer : public ZepComponent
184203
uint32_t m_fileFlags = 0;
185204
fs::path m_filePath;
186205
std::shared_ptr<ZepTheme> m_spOverrideTheme;
206+
207+
BufferRange m_selection;
208+
tRangeMarkers m_rangeMarkers;
187209
};
188210

189211
// Notification payload

src/editor.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,39 @@ void ZepEditor::ResetCursorTimer()
175175
timer_restart(m_cursorTimer);
176176
}
177177

178+
void ZepEditor::NextTabWindow()
179+
{
180+
auto itr = std::find(m_tabWindows.begin(), m_tabWindows.end(), m_pActiveTabWindow);
181+
if (itr != m_tabWindows.end())
182+
itr++;
183+
184+
if (itr == m_tabWindows.end())
185+
{
186+
itr = m_tabWindows.begin();
187+
}
188+
m_pActiveTabWindow = *itr;
189+
}
190+
191+
void ZepEditor::PreviousTabWindow()
192+
{
193+
auto itr = std::find(m_tabWindows.begin(), m_tabWindows.end(), m_pActiveTabWindow);
194+
if (itr == m_tabWindows.end())
195+
{
196+
return;
197+
}
198+
199+
if (itr == m_tabWindows.begin())
200+
{
201+
itr = m_tabWindows.end() - 1;
202+
}
203+
else
204+
{
205+
itr--;
206+
}
207+
208+
m_pActiveTabWindow = *itr;
209+
}
210+
178211
void ZepEditor::SetCurrentTabWindow(ZepTabWindow* pTabWindow)
179212
{
180213
m_pActiveTabWindow = pTabWindow;

src/editor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class ZepEditor
187187

188188
// Tab windows
189189
using tTabWindows = std::vector<ZepTabWindow*>;
190+
void NextTabWindow();
191+
void PreviousTabWindow();
190192
void SetCurrentTabWindow(ZepTabWindow* pTabWindow);
191193
ZepTabWindow* GetActiveTabWindow() const;
192194
ZepTabWindow* AddTabWindow();

src/mode_standard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ void ZepMode_Standard::AddKeyPress(uint32_t key, uint32_t modifierKeys)
390390

391391
if (m_currentMode == EditorMode::Visual)
392392
{
393-
GetCurrentWindow()->SetSelectionRange(m_visualBegin, m_visualEnd);
393+
buffer.SetSelection(BufferRange{m_visualBegin, m_visualEnd});
394394
}
395395
}
396396

src/mode_vim.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ bool ZepMode_Vim::GetCommand(CommandContext& context)
568568
{
569569
auto bufferCursor = GetCurrentWindow()->GetBufferCursor();
570570
auto pWindow = GetCurrentWindow();
571+
auto& buffer = GetCurrentWindow()->GetBuffer();
571572

572573
// Motion
573574
if (context.command == "$")
@@ -585,6 +586,17 @@ bool ZepMode_Vim::GetCommand(CommandContext& context)
585586
GetCurrentWindow()->SetBufferCursor(context.buffer.GetLinePos(bufferCursor, LineLocation::LineFirstGraphChar));
586587
return true;
587588
}
589+
// Moving between tabs
590+
else if (context.command == "H" && (context.modifierKeys & ModifierKey::Shift))
591+
{
592+
GetEditor().PreviousTabWindow();
593+
return true;
594+
}
595+
else if (context.command == "L" && (context.modifierKeys & ModifierKey::Shift))
596+
{
597+
GetEditor().NextTabWindow();
598+
return true;
599+
}
588600
// Moving between splits
589601
else if (context.command == "j" && (context.modifierKeys & ModifierKey::Ctrl))
590602
{
@@ -1218,7 +1230,7 @@ void ZepMode_Vim::UpdateVisualSelection()
12181230
{
12191231
m_visualEnd = GetCurrentWindow()->GetBuffer().LocationFromOffsetByChars(GetCurrentWindow()->GetBufferCursor(), 1);
12201232
}
1221-
GetCurrentWindow()->SetSelectionRange(m_visualBegin, m_visualEnd);
1233+
GetCurrentWindow()->GetBuffer().SetSelection(BufferRange{m_visualBegin, m_visualEnd});
12221234
}
12231235
}
12241236
void ZepMode_Vim::AddKeyPress(uint32_t key, uint32_t modifierKeys)

src/tab_window.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ void ZepTabWindow::CloseActiveWindow()
186186
{
187187
RemoveWindow(m_pActiveWindow);
188188
}
189-
SetDisplayRegion(m_lastRegionRect, true);
189+
190+
if (!m_windows.empty())
191+
{
192+
SetDisplayRegion(m_lastRegionRect, true);
193+
}
190194
}
191195

192196
void ZepTabWindow::RemoveWindow(ZepWindow* pWindow)

src/theme.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "theme.h"
21
#include "editor.h"
32
#include "syntax.h"
3+
#include "theme.h"
44

55
namespace Zep
66
{
@@ -64,6 +64,10 @@ void ZepTheme::SetDarkTheme()
6464
m_colors[ThemeColor::Keyword] = NVec4f(0.1f, 1.0f, 1.0f, 1.0f);
6565
m_colors[ThemeColor::Integer] = NVec4f(0.1f, 1.0f, 1.0f, 1.0f);
6666
m_colors[ThemeColor::Whitespace] = NVec4f(0.15f, .2f, .15f, 1.0f);
67+
68+
m_colors[ThemeColor::Error] = NVec4f(0.65f, .2f, .15f, 1.0f);
69+
m_colors[ThemeColor::Warning] = NVec4f(0.15f, .2f, .65f, 1.0f);
70+
m_colors[ThemeColor::Info] = NVec4f(0.15f, .6f, .15f, 1.0f);
6771
}
6872

6973
void ZepTheme::SetLightTheme()
@@ -92,6 +96,10 @@ void ZepTheme::SetLightTheme()
9296
m_colors[ThemeColor::Keyword] = NVec4f(0.1f, .2f, .3f, 1.0f);
9397
m_colors[ThemeColor::Integer] = NVec4f(0.1f, .3f, .2f, 1.0f);
9498
m_colors[ThemeColor::Whitespace] = NVec4f(0.15f, .2f, .15f, 1.0f);
99+
100+
m_colors[ThemeColor::Error] = NVec4f(0.89f, .2f, .15f, 1.0f);
101+
m_colors[ThemeColor::Warning] = NVec4f(0.15f, .2f, .89f, 1.0f);
102+
m_colors[ThemeColor::Info] = NVec4f(0.15f, .85f, .15f, 1.0f);
95103
}
96104
NVec4f ZepTheme::GetUniqueColor(uint32_t index) const
97105
{

src/theme.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

3-
#include "editor.h"
4-
#include "syntax.h"
3+
#include "math/math.h"
54

65
namespace Zep
76
{
@@ -31,7 +30,10 @@ enum class ThemeColor
3130
Comment,
3231
Whitespace,
3332
HiddenChar,
34-
Parenthesis
33+
Parenthesis,
34+
Error,
35+
Warning,
36+
Info
3537
};
3638

3739
enum class ThemeType

0 commit comments

Comments
 (0)