Skip to content

Commit 9a6a935

Browse files
committed
Lots of small fixes
Navigation between split panes and closing them. Fixed delete in insert mode; not sure how I missed that one. Fixed some errors pointed out by code analysis. Added a crude :e command to load a file; but not implemented properly yet. You can now :vsplit, :split, :close.
1 parent 489850a commit 9a6a935

23 files changed

+332
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ bld/
2424
[Bb]in/
2525
[Oo]bj/
2626

27+
git_stats
2728
# Visual Studio 2015 cache/options directory
2829
.vs/
2930
# Uncomment if you have tasks that create the project's static files in wwwroot

demo_imgui/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ int main(int argc, char** argv)
234234
cfg.PixelSnapH = true;
235235
io.Fonts->AddFontFromFileTTF((std::string(SDL_GetBasePath()) + "ProggyClean.ttf").c_str(), 16.0f, &cfg );
236236
*/
237-
bool show_demo_window = true;
237+
bool show_demo_window = false;
238238
bool show_another_window = false;
239239
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
240240

src/buffer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace Zep
5454
const char* Msg_Buffer = "Buffer";
5555
ZepBuffer::ZepBuffer(ZepEditor& editor, const std::string& strName)
5656
: ZepComponent(editor)
57-
, m_threadPool()
5857
, m_strName(strName)
5958
{
6059
SetText("");
@@ -606,7 +605,10 @@ void ZepBuffer::SetText(const std::string& text)
606605
m_dirty = 0;
607606
}
608607

609-
// TODO: These can be cleaner
608+
// TODO: This can be cleaner
609+
// The function needs to find the point on the line which bufferLocation is on.
610+
// It needs to account for empty lines or the last line, zero terminated.
611+
// It shouldn't walk away to another line!
610612
BufferLocation ZepBuffer::GetLinePos(BufferLocation bufferLocation, LineLocation lineLocation) const
611613
{
612614
if (lineLocation == LineLocation::None)
@@ -618,7 +620,7 @@ BufferLocation ZepBuffer::GetLinePos(BufferLocation bufferLocation, LineLocation
618620
if (m_gapBuffer.empty())
619621
return bufferLocation;
620622

621-
// If we are on the CR, move back 1
623+
// If we are on the CR, move back 1, unless the \n is all that is on the line
622624
if (m_gapBuffer[bufferLocation] == '\n')
623625
{
624626
bufferLocation--;

src/buffer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ class ZepBuffer : public ZepComponent
172172
void ProcessInput(const std::string& str);
173173

174174
private:
175-
bool m_dirty; // Is the text modified?
175+
bool m_dirty = false; // Is the text modified?
176176
bool m_readOnly = false; // Is the text read only?
177177
bool m_viewOnly = false; // Is the text not editable, only view?
178178
GapBuffer<utf8> m_gapBuffer; // Storage for the text - a gap buffer for efficiency
179179
std::vector<long> m_lineEnds; // End of each line
180180
ThreadPool m_threadPool;
181-
uint32_t m_flags;
181+
uint32_t m_flags = 0;
182182
std::shared_ptr<ZepSyntax> m_spSyntax;
183183
std::string m_strName;
184-
uint32_t m_fileFlags;
184+
uint32_t m_fileFlags = 0;
185185
fs::path m_filePath;
186186
std::shared_ptr<ZepTheme> m_spOverrideTheme;
187187
};

src/commands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ZepCommand_Insert : public ZepCommand
8181
BufferLocation m_startOffset;
8282
std::string m_strInsert;
8383

84-
BufferLocation m_endOffsetInserted;
84+
BufferLocation m_endOffsetInserted = -1;
8585
};
8686

8787
} // namespace Zep

src/display.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class ZepTabWindow;
1111
struct SelectRegion
1212
{
1313
// For vertical select, we will have a list of spans...
14-
BufferLocation start;
15-
BufferLocation end;
16-
bool visible;
17-
bool vertical; // Not yet supported
14+
BufferLocation start = 0;
15+
BufferLocation end = 0;
16+
bool visible = true;
17+
bool vertical = false; // Not yet supported
1818
};
1919

2020
// Display interface

src/mcommon/FileWatcher/FileWatcherWin32.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ WatchStruct* CreateWatch(LPCTSTR szDirectory, bool recursive, DWORD mNotifyFilte
136136
WatchStruct* pWatch;
137137
size_t ptrsize = sizeof(*pWatch);
138138
pWatch = static_cast<WatchStruct*>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptrsize));
139+
if (!pWatch)
140+
return nullptr;
139141

140142
pWatch->mDirHandle = CreateFile(szDirectory, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL);
141143

@@ -151,8 +153,14 @@ WatchStruct* CreateWatch(LPCTSTR szDirectory, bool recursive, DWORD mNotifyFilte
151153
}
152154
else
153155
{
154-
CloseHandle(pWatch->mOverlapped.hEvent);
155-
CloseHandle(pWatch->mDirHandle);
156+
if (pWatch->mOverlapped.hEvent != 0)
157+
{
158+
CloseHandle(pWatch->mOverlapped.hEvent);
159+
}
160+
if (pWatch->mDirHandle != 0)
161+
{
162+
CloseHandle(pWatch->mDirHandle);
163+
}
156164
}
157165
}
158166

@@ -252,6 +260,7 @@ void FileWatcherWin32::handleAction(WatchStruct* watch, const String& filename,
252260
fwAction = Actions::Delete;
253261
break;
254262
case FILE_ACTION_MODIFIED:
263+
default:
255264
fwAction = Actions::Modified;
256265
break;
257266
};

src/mcommon/animation/timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum class TimerSample : uint32_t
1515

1616
struct timer
1717
{
18-
int64_t startTime;
18+
int64_t startTime = 0;
1919
};
2020
extern timer globalTimer;
2121

@@ -36,7 +36,7 @@ class TimerBlock
3636
public:
3737
std::string strTimer;
3838
timer blockTimer;
39-
uint64_t elapsed;
39+
uint64_t elapsed = 0;
4040

4141
TimerBlock(const std::string& timer);
4242
~TimerBlock();

src/mcommon/file/archive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct ArchiveSection
3838
// The tables index into the loaded string, which is poked full of 0's to deliniate the data
3939
struct Archive
4040
{
41-
bool saving;
41+
bool saving = false;
4242
uint64_t currentSectionIndex;
4343

4444
// Path of this file

src/mcommon/logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// than out to the console sometimes, and as long as you are building on Windows, you are referencing the necessary
1717
// kernel32.dll....
1818
extern "C" {
19-
__declspec(dllimport) void __stdcall OutputDebugStringA(const char* pszChar);
19+
__declspec(dllimport) void __stdcall OutputDebugStringA(_In_opt_ const char* pszChar);
2020
}
2121
#endif
2222

src/mcommon/math/math.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ struct NRect
346346
{
347347
return bottomRightPx.x - topLeftPx.x;
348348
}
349+
NVec2f Center() const
350+
{
351+
return (bottomRightPx + topLeftPx) * .5f;
352+
}
349353
NVec2f Size() const
350354
{
351355
return bottomRightPx - topLeftPx;

src/mode.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Zep
1010

1111
ZepMode::ZepMode(ZepEditor& editor)
1212
: ZepComponent(editor)
13-
, m_currentMode(EditorMode::Normal)
1413
{
1514
}
1615

src/mode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ class ZepMode : public ZepComponent
8181
protected:
8282
std::stack<std::shared_ptr<ZepCommand>> m_undoStack;
8383
std::stack<std::shared_ptr<ZepCommand>> m_redoStack;
84-
EditorMode m_currentMode;
84+
EditorMode m_currentMode = EditorMode::Normal;
8585
bool m_lineWise = false;
86-
BufferLocation m_insertBegin;
87-
BufferLocation m_visualBegin;
88-
BufferLocation m_visualEnd;
86+
BufferLocation m_insertBegin = 0;
87+
BufferLocation m_visualBegin = 0;
88+
BufferLocation m_visualEnd = 0;
8989
};
9090

9191
} // namespace Zep

src/mode_vim.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,27 @@ bool ZepMode_Vim::GetCommand(CommandContext& context)
422422
GetCurrentWindow()->SetBufferCursor(context.buffer.GetLinePos(bufferCursor, LineLocation::LineFirstGraphChar));
423423
return true;
424424
}
425+
// Moving between splits
426+
else if (context.command == "j" && (context.modifierKeys & ModifierKey::Ctrl))
427+
{
428+
GetCurrentWindow()->GetTabWindow().DoMotion(WindowMotion::Down);
429+
return true;
430+
}
431+
else if (context.command == "k" && (context.modifierKeys & ModifierKey::Ctrl))
432+
{
433+
GetCurrentWindow()->GetTabWindow().DoMotion(WindowMotion::Up);
434+
return true;
435+
}
436+
else if (context.command == "h" && (context.modifierKeys & ModifierKey::Ctrl))
437+
{
438+
GetCurrentWindow()->GetTabWindow().DoMotion(WindowMotion::Left);
439+
return true;
440+
}
441+
else if (context.command == "l" && (context.modifierKeys & ModifierKey::Ctrl))
442+
{
443+
GetCurrentWindow()->GetTabWindow().DoMotion(WindowMotion::Right);
444+
return true;
445+
}
425446
else if (context.command == "j" || context.command == "+" || context.lastKey == ExtKeys::DOWN)
426447
{
427448
GetCurrentWindow()->MoveCursorY(context.count);
@@ -991,18 +1012,34 @@ bool ZepMode_Vim::GetCommand(CommandContext& context)
9911012
pTab->AddWindow(&GetEditor().GetActiveTabWindow()->GetActiveWindow()->GetBuffer(), pTab->GetActiveWindow(), true);
9921013
}
9931014
}
994-
else if (context.command == ":hsplit")
1015+
else if (context.command == ":hsplit" ||
1016+
context.command == ":split")
9951017
{
9961018
auto pTab = GetEditor().GetActiveTabWindow();
9971019
if (pTab)
9981020
{
9991021
pTab->AddWindow(&GetEditor().GetActiveTabWindow()->GetActiveWindow()->GetBuffer(), pTab->GetActiveWindow(), false);
10001022
}
10011023
}
1024+
else if (context.command.find(":e") == 0)
1025+
{
1026+
auto strTok = string_split(context.command, " ");
1027+
if (strTok.size() > 1)
1028+
{
1029+
auto fname = strTok[1];
1030+
auto pBuffer = GetEditor().AddBuffer(fname);
1031+
pBuffer->Load(fname);
1032+
GetEditor().GetActiveTabWindow()->GetActiveWindow()->SetBuffer(pBuffer);
1033+
}
1034+
}
10021035
else if (context.command == ":w")
10031036
{
10041037
GetEditor().SaveBuffer(context.buffer);
10051038
}
1039+
else if (context.command == ":close" || context.command == ":clo")
1040+
{
1041+
GetEditor().GetActiveTabWindow()->CloseActiveWindow();
1042+
}
10061043
else if (context.command[1] == 'q')
10071044
{
10081045
if (context.command == ":q")
@@ -1385,6 +1422,7 @@ void ZepMode_Vim::HandleInsert(uint32_t key)
13851422
// There is more work to do here to support keyboard combos in insert mode
13861423
// (not that I can think of ones that I use!)
13871424
CommandContext context("", *this, key, 0, EditorMode::Insert);
1425+
context.bufferCursor = bufferCursor;
13881426
if (GetCommand(context) && context.commandResult.spCommand)
13891427
{
13901428
AddCommand(context.commandResult.spCommand);

src/mode_vim.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class ZepMode_Vim : public ZepMode
132132

133133
std::string m_currentCommand;
134134
std::string m_lastCommand;
135-
int m_lastCount;
135+
int m_lastCount = 0;
136136
std::string m_lastInsertString;
137137

138138
bool m_pendingEscape = false;

src/splits.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,45 @@ enum Flags
2323

2424
struct Region
2525
{
26+
const char* pszName = nullptr;
2627
uint32_t flags = RegionFlags::Expanding;
2728
float ratio = 1.0f;
2829
NRectf rect;
2930
NVec2f min_size = NVec2f(0.0f, 0.0f);
3031
NVec2f fixed_size = NVec2f(0.0f, 0.0f);
3132
bool vertical = true;
3233

33-
Region* pParent = nullptr;
34+
std::shared_ptr<Region> pParent;
3435
std::vector<std::shared_ptr<Region>> children;
3536
};
3637

3738
inline std::ostream& operator<<(std::ostream& str, const Region& region)
3839
{
39-
str << region.rect;
40+
static int indent = 0;
41+
auto do_indent = [&str](int sz) { for (int i = 0; i < sz; i++) str << " "; };
42+
43+
do_indent(indent);
44+
if (region.pszName)
45+
str << region.pszName << " ";
46+
str << std::hex << &region << " -> ";
47+
48+
str << "RC: " << region.rect << ", pParent: " << std::hex << region.pParent;
49+
if (!region.children.empty())
50+
{
51+
str << std::endl;
52+
for (auto& child : region.children)
53+
{
54+
indent++;
55+
str << *child;
56+
indent--;
57+
}
58+
}
59+
str << std::endl;
60+
4061
return str;
4162
}
4263

4364
void LayoutRegion(Region& region);
4465

66+
4567
} // namespace Zep

0 commit comments

Comments
 (0)