Compare commits
2 Commits
d5d99cddf7
...
bbf97eba2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbf97eba2f | ||
|
|
52390a7aa8 |
21
build.sh
21
build.sh
@@ -1,10 +1,21 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
mkdir build
|
||||
for arg in "$@"; do declare $arg='1'; done
|
||||
if [ ! -v release ]; then debug=1; fi
|
||||
if [ -v debug ]; then echo "[debug build]"; fi
|
||||
if [ -v release ]; then echo "[release build]"; fi
|
||||
if [ -v slow ]; then echo "[slow build]"; fi
|
||||
|
||||
mkdir -p build
|
||||
cd build
|
||||
|
||||
FLAGS="-Wall -Wno-missing-braces -Wno-writable-strings -nostdlib++ -fsanitize=address -fno-exceptions -fdiagnostics-absolute-paths -g -I../src -DDEBUG_BUILD=1"
|
||||
I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad"
|
||||
clang -o te $FLAGS ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace
|
||||
I="-I../src/external/SDL/include -I../src/external/lua/src -I../src/external/glad -I../src"
|
||||
flags="-Wall -Wextra -Werror -Wformat=2 -Wundef -Wshadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-writable-strings \
|
||||
-g -fdiagnostics-absolute-paths \
|
||||
-nostdlib++ -fno-exceptions"
|
||||
|
||||
# -v -Wl,--verbose
|
||||
if [ -v debug ]; then flags="$flags -fsanitize=address,undefined -fno-omit-frame-pointer -DDEBUG_BUILD=1"; fi
|
||||
if [ -v release ]; then flags="$flags -DDEBUG_BUILD=0 -O2"; fi
|
||||
if [ -v slow ]; then flags="$flags -DSLOW_BUILD=1"; fi
|
||||
|
||||
time clang -o te $flags ../src/text_editor/text_editor.cpp $I -lSDL3 -lm -lbacktrace
|
||||
|
||||
@@ -92,6 +92,7 @@ API bool VDecommit(void *p, size_t size) {
|
||||
#endif
|
||||
|
||||
API void *SystemAllocatorProc(void *object, int kind, void *p, size_t size) {
|
||||
Unused(object);
|
||||
void *result = NULL;
|
||||
if (kind == AllocatorKind_Allocate) {
|
||||
result = malloc(size);
|
||||
@@ -125,6 +126,7 @@ thread_local Array<MemoryRecord> MemoryTrackingRecord;
|
||||
|
||||
|
||||
API void *TrackingAllocatorProc(void *object, int kind, void *p, size_t size) {
|
||||
Unused(object);
|
||||
void *result = NULL;
|
||||
|
||||
if (kind == AllocatorKind_Allocate) {
|
||||
@@ -249,6 +251,7 @@ API void PopToPos(VirtualArena *arena, size_t pos) {
|
||||
}
|
||||
|
||||
API void *ArenaAllocatorProc(void *object, int kind, void *p, size_t size) {
|
||||
Unused(p);
|
||||
if (kind == AllocatorKind_Allocate) {
|
||||
return PushSize((VirtualArena *)object, size);
|
||||
} else if (AllocatorKind_Deallocate) {
|
||||
@@ -316,6 +319,7 @@ API void Unwind(BlockArena *arena, U8 *pos) {
|
||||
}
|
||||
|
||||
API void *BlockArenaAllocatorProc(void *object, int kind, void *p, size_t size) {
|
||||
Unused(p);
|
||||
BlockArena *arena = (BlockArena *)object;
|
||||
if (kind == AllocatorKind_Allocate) {
|
||||
return PushSize(arena, size);
|
||||
|
||||
@@ -28,9 +28,13 @@ API Allocator GetTrackingAllocator();
|
||||
|
||||
#define MemoryZero(x, size) memset(x, 0, size)
|
||||
#define MemoryZeroStruct(x) memset(x, 0, sizeof(*x))
|
||||
#define MemoryCopy(dst, src, size) memcpy(dst, src, size)
|
||||
#define MemoryMove(dst, src, size) memmove(dst, src, size)
|
||||
|
||||
static inline void MemoryCopy(void *dst, void *src, size_t size) {
|
||||
if (src == NULL) return;
|
||||
memcpy(dst, src, size);
|
||||
}
|
||||
|
||||
///////////////////
|
||||
// Block Arena
|
||||
///////////////////
|
||||
|
||||
@@ -165,7 +165,7 @@ Slice<T> GetSlice(Slice<T> &arr, int64_t first_index = 0, int64_t one_past_last_
|
||||
}
|
||||
|
||||
// Make arrays resize on every item
|
||||
#define ARRAY_DEBUG BUILD_SLOW
|
||||
#define ARRAY_DEBUG 0
|
||||
#if ARRAY_DEBUG
|
||||
#define ARRAY_IF_DEBUG_ELSE(IF, ELSE) IF
|
||||
#else
|
||||
@@ -211,12 +211,11 @@ void Reserve(Array<T> *arr, int64_t size) {
|
||||
|
||||
T *new_data = AllocArray(arr->allocator, T, size);
|
||||
Assert(new_data);
|
||||
memcpy(new_data, arr->data, arr->len * sizeof(T));
|
||||
Dealloc(arr->allocator, arr->data);
|
||||
|
||||
MemoryCopy(new_data, arr->data, arr->len * sizeof(T));
|
||||
if (arr->data) Dealloc(arr->allocator, arr->data);
|
||||
arr->data = new_data;
|
||||
arr->cap = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -493,16 +492,16 @@ struct ReverseIter {
|
||||
friend bool operator==(const ReverseIter &a, const ReverseIter &b) { return a.data == b.data; };
|
||||
friend bool operator!=(const ReverseIter &a, const ReverseIter &b) { return a.data != b.data; };
|
||||
|
||||
ReverseIter begin() { return ReverseIter{arr->end() - 1, arr}; }
|
||||
ReverseIter end() { return ReverseIter{arr->begin() - 1, arr}; }
|
||||
ReverseIter begin() { return ReverseIter{arr->end() ? arr->end() - 1 : NULL, arr}; }
|
||||
ReverseIter end() { return ReverseIter{arr->begin() ? arr->begin() - 1 : NULL, arr}; }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
ReverseIter<T> IterateInReverse(Array<T> *arr) {
|
||||
return {arr->end() - 1, &arr->slice};
|
||||
return {arr->end() ? arr->end() - 1 : NULL, &arr->slice};
|
||||
}
|
||||
template <class T>
|
||||
ReverseIter<T> IterateInReverse(Slice<T> *slice) {
|
||||
return {slice->end() - 1, slice};
|
||||
return {slice->end ? slice->end() - 1 : NULL, slice};
|
||||
}
|
||||
|
||||
|
||||
@@ -117,8 +117,9 @@ EM_JS(void, JS_Breakpoint, (), {
|
||||
#define MiB(x) (KiB(x) * 1024ull)
|
||||
#define GiB(x) (MiB(x) * 1024ull)
|
||||
#define TiB(x) (GiB(x) * 1024ull)
|
||||
#define Lengthof(x) ((int64_t)((sizeof(x) / sizeof((x)[0]))))
|
||||
#define SLICE_LAST INT64_MAX
|
||||
#define Lengthof(x) ((int64_t)((sizeof(x) / sizeof((x)[0]))))
|
||||
#define Unused(x) (void)(x)
|
||||
|
||||
using U8 = uint8_t;
|
||||
using U16 = uint16_t;
|
||||
@@ -132,6 +133,8 @@ using Int = S64;
|
||||
using UInt = U64;
|
||||
using Float = double;
|
||||
|
||||
#define IntMax INT64_MAX
|
||||
|
||||
template <class T>
|
||||
T Min(T a, T b) {
|
||||
if (a > b) return b;
|
||||
@@ -247,3 +250,14 @@ inline uint64_t GetRandomU64(RandomSeed *state) {
|
||||
#define STRINGIFY(x) STRINGIFY_(x)
|
||||
#define CONCAT_(a, b) a ## b
|
||||
#define CONCAT(a, b) CONCAT_(a, b)
|
||||
|
||||
Int SizeToInt(size_t size) {
|
||||
Assert(size <= (size_t)IntMax);
|
||||
return (Int)size;
|
||||
}
|
||||
|
||||
Int Strlen(const char *string) {
|
||||
size_t size = strlen(string);
|
||||
Int result = SizeToInt(size);
|
||||
return result;
|
||||
}
|
||||
@@ -24,10 +24,12 @@ API void (*Error)(const char *, ...);
|
||||
struct backtrace_state *backtrace_state = NULL;
|
||||
|
||||
void BacktraceOnError(void *data, const char *msg, int errnum) {
|
||||
Unused(data);
|
||||
Error("libbacktrace error: %s (errnum: %d)\n", msg, errnum);
|
||||
}
|
||||
|
||||
int BacktraceOnPrint(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) {
|
||||
Unused(data); Unused(pc);
|
||||
bool printed = false;
|
||||
if (filename != NULL) {
|
||||
char buffer[1024];
|
||||
@@ -46,6 +48,7 @@ int BacktraceOnPrint(void *data, uintptr_t pc, const char *filename, int lineno,
|
||||
}
|
||||
|
||||
void CrashHandler(int signal, siginfo_t* info, void* context) {
|
||||
Unused(signal); Unused(info); Unused(context);
|
||||
backtrace_full(backtrace_state, 2, BacktraceOnPrint, BacktraceOnError, NULL);
|
||||
exit(1);
|
||||
}
|
||||
@@ -102,7 +105,7 @@ API bool WriteFile(String path, String data) {
|
||||
FILE *f = fopen((const char *)null_term.data, "w");
|
||||
if (f) {
|
||||
size_t written = fwrite(data.data, 1, data.len, f);
|
||||
if (written == data.len) {
|
||||
if (SizeToInt(written) == data.len) {
|
||||
result = true;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
@@ -188,7 +188,7 @@ API String Copy(Allocator allocator, String string) {
|
||||
}
|
||||
|
||||
API String Copy(Allocator allocator, char *string) {
|
||||
return Copy(allocator, {string, (int64_t)strlen(string)});
|
||||
return Copy(allocator, {string, Strlen(string)});
|
||||
}
|
||||
|
||||
API void NormalizePathInPlace(String s) {
|
||||
|
||||
@@ -5,9 +5,9 @@ struct String {
|
||||
int64_t len;
|
||||
|
||||
String() = default;
|
||||
String(char *s) : data(s), len(strlen(s)) {}
|
||||
String(char *s) : data(s), len(Strlen(s)) {}
|
||||
String(char *s, int64_t l) : data((char *)s), len(l) {}
|
||||
String(const char *s) : data((char *)s), len(strlen((char *)s)) {}
|
||||
String(const char *s) : data((char *)s), len(Strlen((char *)s)) {}
|
||||
String(const char *s, int64_t l) : data((char *)s), len(l) {}
|
||||
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ API bool IsDigit(char16_t a) {
|
||||
}
|
||||
|
||||
API bool IsHexDigit(char16_t a) {
|
||||
bool result = a >= u'0' && a <= u'9' || a == 'a' || a == 'b' || a == 'c' || a == 'd' || a == 'e' || a == 'f';
|
||||
bool result = (a >= u'0' && a <= u'9') || a == 'a' || a == 'b' || a == 'c' || a == 'd' || a == 'e' || a == 'f';
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
4
src/external/minicoro.h
vendored
4
src/external/minicoro.h
vendored
@@ -429,8 +429,8 @@ MCO_API const char *mco_result_description(mco_result res); /* Get the descripti
|
||||
#else
|
||||
#ifdef thread_local
|
||||
#define MCO_THREAD_LOCAL thread_local
|
||||
#elif __STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__)
|
||||
#define MCO_THREAD_LOCAL _Thread_local
|
||||
// #elif __STDC_VERSION__ >= 201112 && !defined(__STDC_NO_THREADS__)
|
||||
// #define MCO_THREAD_LOCAL _Thread_local
|
||||
#elif defined(_WIN32) && (defined(_MSC_VER) || defined(__ICL) || defined(__DMC__) || defined(__BORLANDC__))
|
||||
#define MCO_THREAD_LOCAL __declspec(thread)
|
||||
#elif defined(__GNUC__) || defined(__SUNPRO_C) || defined(__xlC__)
|
||||
|
||||
@@ -75,6 +75,7 @@ static const char *glsl_fshader_es3 = R"==(#version 300 es
|
||||
|
||||
void ReportWarningf(const char *fmt, ...);
|
||||
void GLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user) {
|
||||
Unused(source); Unused(type); Unused(id); Unused(length); Unused(user);
|
||||
ReportWarningf("OpenGL message: %s", message);
|
||||
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM) {
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "OpenGL error", message, NULL);
|
||||
|
||||
@@ -26,6 +26,7 @@ void Wait(mco_coro *co) {
|
||||
}
|
||||
|
||||
void PlayTestOpen(mco_coro *co) {
|
||||
Unused(co);
|
||||
// Open file, move a little, then open again and verify the caret didn't move
|
||||
// String basic_env_cpp = Format(SysAllocator, "%S/test_env", TestDir);
|
||||
|
||||
|
||||
@@ -64,11 +64,6 @@ API Range GetBufferEndAsRange(Buffer *buffer) {
|
||||
return result;
|
||||
}
|
||||
|
||||
API Range GetBufferBeginAsRange(Buffer *buffer) {
|
||||
Range result = {0, 0};
|
||||
return result;
|
||||
}
|
||||
|
||||
API Range GetRange(Buffer *buffer) {
|
||||
Range result = {0, buffer->len};
|
||||
return result;
|
||||
@@ -467,10 +462,6 @@ API Int GetBufferEnd(Buffer *buffer) {
|
||||
return buffer->len;
|
||||
}
|
||||
|
||||
API Int GetBufferStart(Buffer *buffer) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
API Int GetNextEmptyLineStart(Buffer *buffer, Int pos) {
|
||||
Int result = pos;
|
||||
Int next_line = PosToLine(buffer, pos) + 1;
|
||||
@@ -903,7 +894,7 @@ API void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
ProfileFunction();
|
||||
if (buffer->no_history) return;
|
||||
|
||||
for (int i = 0; buffer->redo_stack.len > 0; i += 1) {
|
||||
for (;buffer->redo_stack.len > 0;) {
|
||||
HistoryEntry entry = Pop(&buffer->redo_stack);
|
||||
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->undo_stack, *carets);
|
||||
e->time = entry.time;
|
||||
@@ -1251,7 +1242,7 @@ void RunBufferTest() {
|
||||
Assert(buffer.data[15] == L'\n');
|
||||
Assert(buffer.data[16] == L't');
|
||||
|
||||
RawReplaceText(&buffer, GetBufferBeginAsRange(&buffer), u"Things as is\nand stuff\n");
|
||||
RawReplaceText(&buffer, {}, u"Things as is\nand stuff\n");
|
||||
Assert(buffer.line_starts.len == 4);
|
||||
Assert(PosToLine(&buffer, 12) == 0);
|
||||
Assert(buffer.data[12] == L'\n');
|
||||
@@ -1266,7 +1257,7 @@ void RunBufferTest() {
|
||||
Assert(PosToLine(&buffer, 39) == 3);
|
||||
Assert(buffer.data[39] == L't');
|
||||
|
||||
RawReplaceText(&buffer, GetBufferBeginAsRange(&buffer), u"a");
|
||||
RawReplaceText(&buffer, {}, u"a");
|
||||
Assert(buffer.line_starts.len == 4);
|
||||
Assert(PosToLine(&buffer, 13) == 0);
|
||||
Assert(PosToLine(&buffer, 14) == 1);
|
||||
@@ -1458,7 +1449,7 @@ Int ConvertUTF8ToUTF16UnixLine(String string, char16_t *buffer, Int buffer_cap)
|
||||
}
|
||||
if (string.data[i] == '\t') {
|
||||
// @WARNING: DONT INCREASE THE SIZE CARELESSLY, WE NEED TO ADJUST BUFFER SIZE
|
||||
for (Int i = 0; i < 4; i += 1) buffer[buffer_len++] = u' ';
|
||||
for (Int ii = 0; ii < 4; ii += 1) buffer[buffer_len++] = u' ';
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,12 @@ void ReportErrorf(const char *fmt, ...) {
|
||||
BREAK();
|
||||
}
|
||||
|
||||
if (LogView) {
|
||||
Appendf(LogView, "%S\n", string);
|
||||
ShowUIMessagef("%S", string);
|
||||
} else {
|
||||
printf("%.*s\n", (int)string.len, string.data);
|
||||
}
|
||||
}
|
||||
|
||||
void ReportConsolef(const char *fmt, ...) {
|
||||
|
||||
@@ -45,7 +45,7 @@ void ClipboardCopy(View *view) {
|
||||
Range line_range = GetLineRange(buffer, line, &eof);
|
||||
it.range = line_range;
|
||||
if (eof) {
|
||||
it.range.min = ClampBottom(0ll, it.range.min - 1);
|
||||
it.range.min = ClampBottom(0ll, it.range.min - 1ll);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,9 +84,9 @@ void ClipboardPaste(View *view) {
|
||||
Array<Edit> edits = BeginEdit(scratch, buffer, view->carets);
|
||||
MergeCarets(buffer, &view->carets);
|
||||
for (int64_t i = 0; i < view->carets.len; i += 1) {
|
||||
String16 string = SavedClipboardCarets[i];
|
||||
String16 saved_string = SavedClipboardCarets[i];
|
||||
Caret &it = view->carets[i];
|
||||
AddEdit(&edits, it.range, string);
|
||||
AddEdit(&edits, it.range, saved_string);
|
||||
}
|
||||
EndEdit(buffer, &edits, &view->carets, EndEdit_KillSelection);
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ void TestParser() {
|
||||
Scratch scratch;
|
||||
{
|
||||
char *cmd = "ctrl-b";
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"};
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + Strlen(cmd), "keybinding"};
|
||||
Trigger *trigger = ParseKeyCatchAll(&base_lex);
|
||||
Assert(trigger->kind == TriggerKind_Key);
|
||||
Assert(trigger->key == SDLK_B);
|
||||
@@ -237,7 +237,7 @@ void TestParser() {
|
||||
|
||||
{
|
||||
char *cmd = "ctrl-b shift-ctrl-a";
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"};
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + Strlen(cmd), "keybinding"};
|
||||
Trigger *trigger = ParseKeyCatchAll(&base_lex);
|
||||
Assert(trigger->kind == TriggerKind_Binary);
|
||||
Assert(trigger->key == ' ');
|
||||
@@ -253,7 +253,7 @@ void TestParser() {
|
||||
|
||||
{
|
||||
char *cmd = "ctrl-b shift-ctrl-a | ctrl-c | ctrl-d";
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + strlen(cmd), "keybinding"};
|
||||
Lexer base_lex = {scratch, cmd, cmd, cmd + Strlen(cmd), "keybinding"};
|
||||
Trigger *trigger = ParseKeyCatchAll(&base_lex);
|
||||
Assert(trigger->kind == TriggerKind_Binary);
|
||||
Assert(trigger->key == '|');
|
||||
|
||||
@@ -212,8 +212,6 @@ void DrawWindow(Window *window, Event &event) {
|
||||
Vec2I mouse = MouseVec2I();
|
||||
bool mouse_in_document = AreOverlapping(mouse, window->document_rect);
|
||||
if (mouse_in_document) {
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
Int p = ScreenSpaceToBufferPosErrorOutOfBounds(window, view, buffer, mouse);
|
||||
if (p != -1) {
|
||||
Range range = EncloseLoadWord(buffer, p);
|
||||
|
||||
@@ -347,18 +347,18 @@ struct { String string; SDL_Keycode value; } SDLKeycodeConversionTable[] = {
|
||||
};
|
||||
|
||||
void FillEventWithBasicData(Event *event) {
|
||||
if (OS_WINDOWS) {
|
||||
#if OS_WINDOWS
|
||||
if (GetKeyState(VK_SHIFT) & 0x8000) event->shift = 1;
|
||||
if (GetKeyState(VK_CONTROL) & 0x8000) event->ctrl = 1;
|
||||
if (GetKeyState(VK_MENU) & 0x8000) event->alt = 1;
|
||||
if (GetKeyState(VK_LWIN) & 0x8000) event->super = 1;
|
||||
} else {
|
||||
#else
|
||||
SDL_Keymod mod = SDL_GetModState();
|
||||
event->shift = (mod & SDL_KMOD_SHIFT) != 0;
|
||||
event->ctrl = (mod & SDL_KMOD_CTRL) != 0;
|
||||
event->alt = (mod & SDL_KMOD_ALT) != 0;
|
||||
event->super = (mod & SDL_KMOD_GUI) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
float xmouse, ymouse;
|
||||
SDL_GetMouseState(&xmouse, &ymouse);
|
||||
@@ -499,10 +499,10 @@ void GetEventsForFrame(Array<Event> *events) {
|
||||
}
|
||||
|
||||
if (events->len == 0) {
|
||||
Event event = {};
|
||||
FillEventWithBasicData(&event);
|
||||
event.kind = EVENT_UPDATE;
|
||||
Add(events, event);
|
||||
Event ev = {};
|
||||
FillEventWithBasicData(&ev);
|
||||
ev.kind = EVENT_UPDATE;
|
||||
Add(events, ev);
|
||||
}
|
||||
|
||||
Assert(events->len);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
float NewFuzzyRate(String16 s, String16 p) {
|
||||
float score = 0;
|
||||
// try to do this: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go
|
||||
return score;
|
||||
}
|
||||
// float NewFuzzyRate(String16 s, String16 p) {
|
||||
// float score = 0;
|
||||
// // try to do this: https://github.com/junegunn/fzf/blob/master/src/algo/algo.go
|
||||
// return score;
|
||||
// }
|
||||
|
||||
float FuzzyRate(String16 s, String16 p) {
|
||||
float score = 0;
|
||||
|
||||
@@ -22,6 +22,7 @@ void InitBuildWindow() {
|
||||
}
|
||||
|
||||
void LayoutBuildWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Unused(wx); Unused(wy);
|
||||
Window *window = GetWindow(BuildWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
|
||||
@@ -12,7 +12,7 @@ void CMD_ShowCommands() {
|
||||
}
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
SelectRange(command_bar.view, Range{});
|
||||
} RegisterCommand(CMD_ShowCommands, "ctrl-shift-p", "List available commands and their documentation inside the command window");
|
||||
|
||||
void CMD_ShowDebugBufferList() {
|
||||
@@ -31,7 +31,7 @@ void CMD_ShowDebugBufferList() {
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
SelectRange(command_bar.view, Range{});
|
||||
} RegisterCommand(CMD_ShowDebugBufferList, "ctrl-shift-alt-p", "Show full list of buffers, including the special ones that normally just clutter list");
|
||||
|
||||
void CMD_ShowBufferList() {
|
||||
@@ -50,10 +50,11 @@ void CMD_ShowBufferList() {
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
}
|
||||
command_bar.view->update_scroll = true;
|
||||
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
|
||||
SelectRange(command_bar.view, Range{});
|
||||
} RegisterCommand(CMD_ShowBufferList, "ctrl-p", "List open buffers inside the command window that you can fuzzy search over");
|
||||
|
||||
void LayoutCommandWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Unused(wy);
|
||||
Window *window = GetWindow(CommandWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
|
||||
@@ -82,7 +82,7 @@ BufferID LoadConfig(String config_path) {
|
||||
|
||||
#define ExpectP(x, ...) \
|
||||
if (!(x)) { \
|
||||
ReportErrorf("Failed to parse '" __FUNCTION__ "' command, " __VA_ARGS__); \
|
||||
ReportErrorf("Failed to parse command " __VA_ARGS__); \
|
||||
return; \
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ void InitDebugWindow() {
|
||||
}
|
||||
|
||||
void LayoutDebugWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Unused(rect);
|
||||
Window *window = GetWindow(DebugWindowID);
|
||||
Rect2 screen_rect = Rect0Size((float)wx, (float)wy);
|
||||
Vec2 size = GetSize(screen_rect);
|
||||
@@ -47,9 +48,7 @@ void UpdateDebugWindow() {
|
||||
return;
|
||||
}
|
||||
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
RawReplaceText(set.buffer, GetRange(set.buffer), u"Active buffers and views:\n");
|
||||
|
||||
For (Views) {
|
||||
Buffer *buffer = GetBuffer(it->active_buffer);
|
||||
RawAppendf(set.buffer, "view->id:%lld, buffer->id:%lld, buffer->name:%S\n", (long long)it->id.id, (long long)buffer->id.id, buffer->name);
|
||||
|
||||
@@ -61,7 +61,7 @@ void OpenDirectoryNavigation(View *view) {
|
||||
// view->update_hook = UpdateDirectoryNavigation;
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
InsertDirectoryNavigation(buffer);
|
||||
SelectRange(view, GetBufferBeginAsRange(buffer));
|
||||
SelectRange(view, Range{});
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
||||
@@ -108,7 +108,6 @@ void CO_Close(mco_coro *co) {
|
||||
|
||||
void CMD_DeleteFile() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
String buffer_name = main.buffer->name;
|
||||
DeleteFile(main.buffer->name);
|
||||
Close(main.buffer->id);
|
||||
} RegisterCommand(CMD_DeleteFile, "", "Close the open buffer and delete it's corresponding file on disk");
|
||||
|
||||
@@ -294,6 +294,7 @@ SPALL_FN bool spall_flush(SpallProfile *ctx) {
|
||||
}
|
||||
|
||||
SPALL_FN bool spall_buffer_init(SpallProfile *ctx, SpallBuffer *wb) {
|
||||
(void)(ctx);
|
||||
// Fails if buffer is not big enough to contain at least one event!
|
||||
if (wb->length < sizeof(SpallBufferHeader) + sizeof(SpallBeginEventMax)) {
|
||||
return false;
|
||||
|
||||
@@ -84,6 +84,7 @@ void InitSearchWindow() {
|
||||
}
|
||||
|
||||
void LayoutSearchWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Unused(wx); Unused(wy);
|
||||
Window *window = GetWindow(SearchWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
|
||||
@@ -18,6 +18,7 @@ void InitStatusWindow() {
|
||||
}
|
||||
|
||||
void LayoutStatusWindow(Rect2I *rect, int16_t wx, int16_t wy) {
|
||||
Unused(wx); Unused(wy);
|
||||
Window *window = GetWindow(StatusWindowID);
|
||||
Rect2I copy_rect = *rect;
|
||||
if (!window->visible) {
|
||||
|
||||
@@ -55,7 +55,7 @@ void CWSLexIdentifiers(Array<StringAndDistance> *out_idents, Buffer *buffer) {
|
||||
Array<StringAndDistance> idents = {CWS.arena};
|
||||
String16 string = GetString(buffer);
|
||||
Lexer2 lexer = BeginLexing(string.data);
|
||||
for (int i = 0;; i += 1) {
|
||||
for (;;) {
|
||||
String16 token = Next(&lexer);
|
||||
if (token.len <= 0) {
|
||||
break;
|
||||
@@ -141,12 +141,9 @@ void WordComplete(mco_coro *co) {
|
||||
goto yield;
|
||||
}
|
||||
}
|
||||
StringAndDistance it = idents[i];
|
||||
String16 ident = Copy16(CWS.arena, it.string);
|
||||
CWS.last_string = ident;
|
||||
Range range = EncloseWord(CWS.buffer, CWS.original_caret_pos);
|
||||
SelectRange(CWS.view, range);
|
||||
Replace(CWS.view, ident);
|
||||
CWS.last_string = Copy16(CWS.arena, idents[i].string);
|
||||
SelectRange(CWS.view, EncloseWord(CWS.buffer, CWS.original_caret_pos));
|
||||
Replace(CWS.view, CWS.last_string);
|
||||
yield:;
|
||||
mco_yield(co);
|
||||
if (CWS.direction == -1 && i > 0 && i == idents.len) {
|
||||
@@ -155,7 +152,7 @@ void WordComplete(mco_coro *co) {
|
||||
i -= 1;
|
||||
}
|
||||
i += CWS.direction;
|
||||
i = Clamp(i, 0ll, idents.len);
|
||||
i = Clamp(i, (Int)0, idents.len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +180,7 @@ void WordComplete(View *view, Int pos) {
|
||||
CWS.original_caret_pos = pos;
|
||||
CWS.prefix_string = Copy16(CWS.arena, prefix);
|
||||
|
||||
mco_desc desc = mco_desc_init(WordComplete, NULL);
|
||||
mco_desc desc = mco_desc_init(WordComplete, 0);
|
||||
mco_result res = mco_create(&CWS.co, &desc);
|
||||
Assert(res == MCO_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -408,9 +408,7 @@ void OnCommand(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
BSet active = GetBSet(ActiveWindowID);
|
||||
|
||||
bool executed = false;
|
||||
For (active.view->commands) {
|
||||
if (it.trigger && MatchEvent(it.trigger, &event)) {
|
||||
@@ -459,8 +457,11 @@ void OnCommand(Event event) {
|
||||
}
|
||||
}
|
||||
|
||||
IF_SLOW_BUILD(AssertRanges(main.view->carets));
|
||||
IF_SLOW_BUILD(AssertRanges(active.view->carets));
|
||||
#if SLOW_BUILD
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
AssertRanges(main.view->carets);
|
||||
AssertRanges(active.view->carets);
|
||||
#endif
|
||||
}
|
||||
|
||||
void EvalCommand(String command) {
|
||||
@@ -845,7 +846,7 @@ void MainLoop() {
|
||||
SDL_GL_SwapWindow(SDLWindow);
|
||||
}
|
||||
|
||||
#if _WIN32
|
||||
#if OS_WINDOWS
|
||||
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
#else
|
||||
extern char **environ;
|
||||
@@ -853,7 +854,7 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
InitScratch();
|
||||
InitOS((OSErrorReport *)printf);
|
||||
InitOS(ReportErrorf);
|
||||
#if OS_WINDOWS
|
||||
int argc = __argc;
|
||||
char **argv = __argv;
|
||||
@@ -912,8 +913,6 @@ int main(int argc, char **argv)
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
|
||||
SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay();
|
||||
const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id);
|
||||
|
||||
// int w8 = (int)(display_mode->w * 0.8);
|
||||
// int h8 = (int)(display_mode->h * 0.8);
|
||||
@@ -923,6 +922,8 @@ int main(int argc, char **argv)
|
||||
int xhalf = 100;
|
||||
int yhalf = 100;
|
||||
#else
|
||||
SDL_DisplayID primary_display_id = SDL_GetPrimaryDisplay();
|
||||
const SDL_DisplayMode *display_mode = SDL_GetCurrentDisplayMode(primary_display_id);
|
||||
int whalf = (int)(display_mode->w * 0.5) - 10;
|
||||
int hhalf = (int)(display_mode->h) - 120;
|
||||
int xhalf = whalf;
|
||||
|
||||
@@ -84,7 +84,6 @@ void DetectUserFileCallback(Window *window, ResolvedOpen *resolved) {
|
||||
|
||||
String16 QueryUserString(mco_coro *co, String ask) {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
Buffer *original_buffer = main.buffer;
|
||||
JumpTempBuffer(&main);
|
||||
NextActiveWindowID = main.window->id;
|
||||
RawAppendf(main.buffer, R"==(
|
||||
|
||||
@@ -618,18 +618,18 @@ void IndentSelectedLines(View *view, bool shift = false) {
|
||||
indent_string.len = IndentSize;
|
||||
if (!shift) {
|
||||
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min}, indent_string);
|
||||
For (saved_xy) {
|
||||
if (it.front.y == i) it.front.x += indent_string.len;
|
||||
if (it.back.y == i) it.back.x += indent_string.len;
|
||||
ForItem (xy, saved_xy) {
|
||||
if (xy.front.y == i) xy.front.x += indent_string.len;
|
||||
if (xy.back.y == i) xy.back.x += indent_string.len;
|
||||
}
|
||||
} else {
|
||||
Int whitespace_len = 0;
|
||||
for (Int i = 0; i < IndentSize && i < string.len && string.data[i] == u' '; i += 1) {
|
||||
for (Int ii = 0; ii < IndentSize && ii < string.len && string.data[ii] == u' '; ii += 1) {
|
||||
whitespace_len += 1;
|
||||
}
|
||||
For (saved_xy) {
|
||||
if (it.front.y == i) it.front.x -= whitespace_len;
|
||||
if (it.back.y == i) it.back.x -= whitespace_len;
|
||||
ForItem (xy, saved_xy) {
|
||||
if (xy.front.y == i) xy.front.x -= whitespace_len;
|
||||
if (xy.back.y == i) xy.back.x -= whitespace_len;
|
||||
}
|
||||
|
||||
AddEdit(&edits, {pos_range_of_line.min, pos_range_of_line.min + whitespace_len}, u"");
|
||||
|
||||
@@ -279,30 +279,29 @@ void GotoNextInList(Window *window, Int line_offset = 1) {
|
||||
bool opened = false;
|
||||
for (Int i = line + line_offset; i >= 0 && i < buffer_goto->line_starts.len; i += line_offset) {
|
||||
Range line_range = GetLineRangeWithoutNL(buffer_goto, i);
|
||||
String16 line = GetString(buffer_goto, line_range);
|
||||
String16 string_line = GetString(buffer_goto, line_range);
|
||||
|
||||
{
|
||||
Int idx = 0;
|
||||
String16 delim = u"||>";
|
||||
if (Seek(line, delim, &idx, SeekFlag_None)) {
|
||||
line = Skip(line, idx + delim.len);
|
||||
if (Seek(string_line, delim, &idx, SeekFlag_None)) {
|
||||
string_line = Skip(string_line, idx + delim.len);
|
||||
}
|
||||
}
|
||||
|
||||
view_goto->carets[0] = MakeCaret(line_range.min);
|
||||
window->goto_list_pos = line_range.min;
|
||||
line = Trim(line);
|
||||
string_line = Trim(string_line);
|
||||
|
||||
MergeCarets(buffer_goto, &view_goto->carets);
|
||||
IF_DEBUG(AssertRanges(view_goto->carets));
|
||||
if (line.len == 0) {
|
||||
if (string_line.len == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Buffer *active_view_buffer = GetBuffer(active_view->active_buffer);
|
||||
Range before_jump_range = active_view->carets[0].range;
|
||||
|
||||
BSet set = Open(line, ResolveOpenMeta_DontError | ResolveOpenMeta_DontExec);
|
||||
BSet set = Open(string_line, ResolveOpenMeta_DontError | ResolveOpenMeta_DontExec);
|
||||
if (set.window == NULL) {
|
||||
continue;
|
||||
}
|
||||
@@ -402,12 +401,12 @@ BSet GetBSet(WindowID window_id) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String GetPrimaryDirectory() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
return GetDirectory(main.buffer);
|
||||
String GetDirectory(Window *window) {
|
||||
BSet set = GetBSet(window->id);
|
||||
return GetDirectory(set.buffer);
|
||||
}
|
||||
|
||||
String GetDirectory(Window *window) {
|
||||
String GetPrimaryDirectory() {
|
||||
BSet main = GetBSet(PrimaryWindowID);
|
||||
return GetDirectory(main.buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user