Compare commits
4 Commits
2f638c731a
...
44bf7c68ff
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44bf7c68ff | ||
|
|
4221aa8fb7 | ||
|
|
509db7af46 | ||
|
|
5c46844747 |
@@ -1,8 +1,8 @@
|
||||
- What precise workflow do I need for me to be viable to use this?
|
||||
- From a user (novice) point of view, how does it look like?
|
||||
|
||||
- Open with seek string (open at pattern) filename:32 filename:/^Window$/
|
||||
- build console window
|
||||
- Use WorkDir (raname to Workspace?) to shorten file names
|
||||
- Show what process/coroutines are running and allow to kill (active process buffer?)
|
||||
- Database idea: use special buffers to store information
|
||||
- Editing the buffer doesn't seem to be the slow part rather, accessing the data and putting it into the buffer (potentially hitting many different memory locations) I have a crazy idea to use buffers in order to store the names in a serialized format
|
||||
@@ -19,10 +19,11 @@ Commands TODO:
|
||||
|
||||
- CONSIDER AUTOMATING: CheckpointBeforeGoto
|
||||
- GotoBackward how to handle that in case we want to automate and create on every move?
|
||||
- Add jump checkpoints
|
||||
- Make sure the timing window works forward and backward in undo and jump
|
||||
|
||||
|
||||
backlog
|
||||
ISSUE Ctrl+Alt+Down (DuplicateLine) doesn't work on ubuntu
|
||||
FEATURE Search whole words, case sensitive etc.
|
||||
FEATURE Select all searched occurences
|
||||
FEATURE commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
typedef void OSErrorReport(const char *, ...);
|
||||
|
||||
#if OS_POSIX
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -54,13 +56,19 @@ void RegisterCrashHandler(void) {
|
||||
struct sigaction sa;
|
||||
sa.sa_sigaction = CrashHandler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
sa.sa_flags = SA_SIGINFO | SA_NODEFER | SA_RESETHAND; // Important flags!
|
||||
|
||||
sigaction(SIGSEGV, &sa, NULL);
|
||||
sigaction(SIGABRT, &sa, NULL);
|
||||
sigaction(SIGBUS, &sa, NULL);
|
||||
sigaction(SIGILL, &sa, NULL);
|
||||
sigaction(SIGFPE, &sa, NULL);
|
||||
|
||||
sigaction(SIGSEGV, &sa, NULL); // Segmentation fault
|
||||
sigaction(SIGABRT, &sa, NULL); // Abort
|
||||
sigaction(SIGBUS, &sa, NULL); // Bus error
|
||||
sigaction(SIGILL, &sa, NULL); // Illegal instruction
|
||||
sigaction(SIGFPE, &sa, NULL); // Floating point exception
|
||||
sigaction(SIGTRAP, &sa, NULL); // Breakpoint/trap
|
||||
sigaction(SIGSYS, &sa, NULL); // Bad system call
|
||||
sigaction(SIGXCPU, &sa, NULL); // CPU time limit exceeded
|
||||
sigaction(SIGXFSZ, &sa, NULL); // File size limit exceeded
|
||||
sigaction(SIGTERM, &sa, NULL); // Termination request (optional)
|
||||
}
|
||||
|
||||
API void InitOS(void (*error_proc)(const char *, ...)) {
|
||||
|
||||
@@ -103,6 +103,10 @@ API Int GetMin(Caret caret) {
|
||||
return result;
|
||||
}
|
||||
|
||||
API Int GetSize(Caret caret) {
|
||||
return GetSize(caret.range);
|
||||
}
|
||||
|
||||
API Caret MakeCaret(Int pos) {
|
||||
Caret result = {};
|
||||
result.range.min = result.range.max = pos;
|
||||
@@ -874,12 +878,13 @@ API void AddEdit(Array<Edit> *e, Range range, String16 string) {
|
||||
// multicursor + history
|
||||
///////////////////////////////
|
||||
|
||||
void SaveHistoryBeforeMergeCursor(Buffer *buffer, Array<HistoryEntry> *stack, Array<Caret> &carets) {
|
||||
if (buffer->no_history) return;
|
||||
HistoryEntry *SaveHistoryBeforeMergeCursor(Buffer *buffer, Array<HistoryEntry> *stack, Array<Caret> &carets) {
|
||||
if (buffer->no_history) return NULL;
|
||||
HistoryEntry entry = {};
|
||||
entry.time = GetTimeSeconds();
|
||||
entry.carets = TightCopy(GetSystemAllocator(), carets);
|
||||
Add(stack, entry);
|
||||
return GetLast(*stack);
|
||||
}
|
||||
|
||||
void SaveHistoryBeforeApplyEdits(Buffer *buffer, Array<HistoryEntry> *stack, Array<Edit> &edits) {
|
||||
@@ -924,7 +929,8 @@ API void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
|
||||
HistoryEntry entry = Pop(&buffer->redo_stack);
|
||||
|
||||
SaveHistoryBeforeMergeCursor(buffer, &buffer->undo_stack, *carets);
|
||||
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->undo_stack, *carets);
|
||||
e->time = entry.time;
|
||||
SaveHistoryBeforeApplyEdits(buffer, &buffer->undo_stack, entry.edits);
|
||||
ApplyEditsMultiCursor(buffer, entry.edits);
|
||||
|
||||
@@ -934,6 +940,13 @@ API void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
For(entry.edits) Dealloc(sys_allocator, it.string.data);
|
||||
Dealloc(&entry.edits);
|
||||
|
||||
if (buffer->redo_stack.len > 0) {
|
||||
HistoryEntry *next = GetLast(buffer->redo_stack);
|
||||
if (next->time - entry.time <= ConfigUndoMergeTimeWindow) {
|
||||
RedoEdit(buffer, carets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
@@ -942,8 +955,8 @@ API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
if (buffer->undo_stack.len <= 0) return;
|
||||
|
||||
HistoryEntry entry = Pop(&buffer->undo_stack);
|
||||
|
||||
SaveHistoryBeforeMergeCursor(buffer, &buffer->redo_stack, *carets);
|
||||
HistoryEntry *e = SaveHistoryBeforeMergeCursor(buffer, &buffer->redo_stack, *carets);
|
||||
e->time = entry.time;
|
||||
SaveHistoryBeforeApplyEdits(buffer, &buffer->redo_stack, entry.edits);
|
||||
ApplyEditsMultiCursor(buffer, entry.edits);
|
||||
|
||||
@@ -956,7 +969,7 @@ API void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
|
||||
if (buffer->undo_stack.len > 0) {
|
||||
HistoryEntry *next = GetLast(buffer->undo_stack);
|
||||
if (entry.time - next->time <= ConfigUndoMergeTimeout) {
|
||||
if (entry.time - next->time <= ConfigUndoMergeTimeWindow) {
|
||||
UndoEdit(buffer, carets);
|
||||
}
|
||||
}
|
||||
@@ -1505,8 +1518,8 @@ Buffer *BufferOpenFile(String path) {
|
||||
if (!FileExists(path)) {
|
||||
buffer = CreateBuffer(sys_allocator, path);
|
||||
} else if (IsDir(path)) {
|
||||
ReportWarningf("failed to open, it's a directory: %S", path);
|
||||
return GetBuffer(NullBufferID);
|
||||
buffer = CreateBuffer(sys_allocator, path);
|
||||
buffer->is_dir = true;
|
||||
} else {
|
||||
String string = ReadFile(scratch, path);
|
||||
buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096);
|
||||
|
||||
@@ -43,6 +43,7 @@ struct Buffer {
|
||||
unsigned dont_try_to_save_in_bulk_ops : 1;
|
||||
unsigned close : 1;
|
||||
unsigned special : 1;
|
||||
unsigned is_dir : 1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -19,27 +19,23 @@ BSet GetConsoleSet() {
|
||||
return result;
|
||||
}
|
||||
|
||||
String GetCurrentFilename() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
return main.buffer->name;
|
||||
}
|
||||
|
||||
String GetDir(Buffer *buffer) {
|
||||
String name = ChopLastSlash(buffer->name);
|
||||
return name;
|
||||
if (buffer->is_dir) {
|
||||
return buffer->name;
|
||||
} else {
|
||||
return ChopLastSlash(buffer->name);
|
||||
}
|
||||
}
|
||||
|
||||
String GetMainDir() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
String name = ChopLastSlash(main.buffer->name);
|
||||
return name;
|
||||
return GetDir(main.buffer);
|
||||
}
|
||||
|
||||
void JumpGarbageBuffer(BSet *set, String buffer_name = "") {
|
||||
CheckpointBeforeGoto(set->window);
|
||||
if (buffer_name.len == 0) {
|
||||
String current_dir = ChopLastSlash(set->buffer->name);
|
||||
buffer_name = GetUniqueBufferName(current_dir, "temp");
|
||||
buffer_name = GetUniqueBufferName(GetDir(set->buffer), "temp");
|
||||
}
|
||||
set->view = WindowOpenBufferView(set->window, buffer_name);
|
||||
set->buffer = GetBuffer(set->view->active_buffer);
|
||||
@@ -618,10 +614,13 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
|
||||
ActiveWindowID = set.window->id;
|
||||
}
|
||||
if (IsDir(o.path)) {
|
||||
JumpGarbageBuffer(&set, GetUniqueBufferName(o.path, "temp", ".dirlisting"));
|
||||
Appendf(set.view, "..\n");
|
||||
CheckpointBeforeGoto(set.window);
|
||||
View *view = WindowOpenBufferView(set.window, o.path);
|
||||
Buffer *buffer = GetBuffer(view->active_buffer);
|
||||
ResetBuffer(buffer);
|
||||
RawAppendf(buffer, "..\n");
|
||||
for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) {
|
||||
Appendf(set.view, "%S\n", it.filename);
|
||||
RawAppendf(buffer, "%S\n", it.filename);
|
||||
}
|
||||
} else {
|
||||
CheckpointBeforeGoto(set.window);
|
||||
@@ -852,14 +851,11 @@ void Command_GotoBackward() {
|
||||
void Command_GotoForward() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
GotoForward(main.window);
|
||||
} RegisterCommand(Command_GotoForward, "mousex2");
|
||||
} RegisterCommand(Command_GotoForward, "alt-shift-q | mousex2");
|
||||
|
||||
void Command_OpenUpFolder() {
|
||||
BSet main = GetBSet(LastActiveLayoutWindowID);
|
||||
String name = ChopLastSlash(main.buffer->name);
|
||||
if (EndsWith(main.buffer->name, "dirlisting")) {
|
||||
name = ChopLastSlash(name);
|
||||
}
|
||||
Open(name);
|
||||
} RegisterCommand(Command_OpenUpFolder, "ctrl-period");
|
||||
|
||||
|
||||
@@ -157,5 +157,7 @@ RegisterVariable(Int, ConfigFontSize, 15);
|
||||
RegisterVariable(Int, ConfigFontFilter, 0);
|
||||
RegisterVariable(String, ConfigFont, "/home/krz/text_editor/package/CascadiaMono.ttf");
|
||||
RegisterVariable(String, ConfigVCVarsall, "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvars64.bat");
|
||||
RegisterVariable(Float, ConfigUndoMergeTimeout, 0.3);
|
||||
RegisterVariable(Float, ConfigUndoMergeTimeWindow, 0.3);
|
||||
RegisterVariable(Float, ConfigJumpHistoryMergeTimeWindow, 0.3);
|
||||
RegisterVariable(Int, ConfigJumpHistorySize, 512);
|
||||
RegisterVariable(String, ConfigInternetBrowser, "firefox");
|
||||
|
||||
34
src/text_editor/scratch.cpp
Normal file
34
src/text_editor/scratch.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
|
||||
void RunRingBufferTest() {
|
||||
// Scratch scratch;
|
||||
// RingBuffer<int> buff = {};
|
||||
// Init(scratch, &buff, 4);
|
||||
|
||||
// for (int i = 0; i < 4; i += 1) {
|
||||
// Add(&buff, i);
|
||||
// }
|
||||
// for (int i = 0; i < 4; i += 1) {
|
||||
// Assert(buff.data[i] == i);
|
||||
// }
|
||||
|
||||
// Add(&buff, 4);
|
||||
// Assert(buff.data[0] == 4);
|
||||
// Add(&buff, 5);
|
||||
// Assert(buff.data[1] == 5);
|
||||
// Assert(buff.data[2] == 2);
|
||||
|
||||
// Assert(Pop(&buff) == 5);
|
||||
// Assert(Pop(&buff) == 4);
|
||||
// Assert(Pop(&buff) == 3);
|
||||
// Assert(Pop(&buff) == 2);
|
||||
// Assert(Pop(&buff) == 0);
|
||||
// Assert(Pop(&buff) == 0);
|
||||
// Assert(Pop(&buff) == 0);
|
||||
// Assert(Pop(&buff) == 0);
|
||||
// Assert(Pop(&buff) == 0);
|
||||
|
||||
// // Assert(Pop(&buff) == 2);
|
||||
|
||||
|
||||
} RegisterFunction(&TestFunctions, RunRingBufferTest);
|
||||
@@ -39,10 +39,10 @@
|
||||
#include "commands.cpp"
|
||||
#include "commands_clipboard.cpp"
|
||||
|
||||
#include "scratch.cpp"
|
||||
#include "draw.cpp"
|
||||
#include "test/tests.cpp"
|
||||
|
||||
|
||||
#if OS_WASM
|
||||
EM_JS(void, JS_SetMouseCursor, (const char *cursor_str), {
|
||||
document.getElementById("canvas").style.cursor = UTF8ToString(cursor_str);
|
||||
@@ -526,6 +526,12 @@ void Update(Event event) {
|
||||
{
|
||||
ProfileScope(WindowEndOfFrameVisibilityAndLastActive);
|
||||
For (Windows) {
|
||||
if (it->goto_history.len > ConfigJumpHistorySize) {
|
||||
RemoveByIndex(&it->goto_history, 0);
|
||||
}
|
||||
if (it->goto_redo.len > ConfigJumpHistorySize) {
|
||||
RemoveByIndex(&it->goto_redo, 0);
|
||||
}
|
||||
if (it->sync_visibility_with_focus) {
|
||||
if (it->id == ActiveWindowID) {
|
||||
it->visible = true;
|
||||
@@ -642,6 +648,7 @@ extern char **environ;
|
||||
int main(int argc, char **argv)
|
||||
#endif
|
||||
{
|
||||
InitOS((OSErrorReport *)printf);
|
||||
#if _WIN32
|
||||
int argc = __argc;
|
||||
char **argv = __argv;
|
||||
|
||||
@@ -147,9 +147,6 @@ struct Register_Function {
|
||||
struct Register_Command { Register_Command(Array<CommandData> *fucs, Function *function, String name, String binding) { if (StartsWith(name, "Command_")) name = Skip(name, 8); Add(fucs, {name, binding, function}); } };
|
||||
#define RegisterCommand(name, binding) Register_Command RC__##name(&CommandFunctions, name, #name, binding)
|
||||
|
||||
struct Register_Hook { Register_Hook(Array<PFunctionData> *functions, PFunction *function, String name) { if (StartsWith(name, "Hook_")) name = Skip(name, 5); Add(functions, {name, function}); } };
|
||||
#define RegisterHook(functions, name) Register_Hook RC__##name(functions, (PFunction *)name, #name)
|
||||
|
||||
const int DIR_RIGHT = 0;
|
||||
const int DIR_LEFT = 1;
|
||||
const int DIR_DOWN = 2;
|
||||
|
||||
@@ -249,7 +249,7 @@ void CheckpointBeforeGoto(Window *window) {
|
||||
GotoCrumb GetCrumb(Array<GotoCrumb> *cr) {
|
||||
for (; cr->len;) {
|
||||
GotoCrumb c = Pop(cr);
|
||||
View *view = GetView(c.view_id);
|
||||
View *view = FindView(c.view_id, NULL);
|
||||
if (view) {
|
||||
return c;
|
||||
}
|
||||
@@ -271,15 +271,15 @@ void GotoBackward(Window *window) {
|
||||
|
||||
if (window->goto_history.len) {
|
||||
GotoCrumb *next = GetLast(window->goto_history);
|
||||
if (c.time - next->time <= ConfigUndoMergeTimeout) {
|
||||
if (c.view_id == next->view_id && c.time - next->time <= ConfigJumpHistoryMergeTimeWindow) {
|
||||
GotoBackward(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GotoForward(Window *window) {
|
||||
if (window->goto_redo.len <= 0) return;
|
||||
if (window->jump_history == false) return;
|
||||
if (window->goto_redo.len <= 0) return;
|
||||
BSet set = GetBSet(window);
|
||||
Add(&window->goto_history, {set.view->id, set.view->carets[0], GetTimeSeconds()});
|
||||
|
||||
@@ -291,7 +291,7 @@ void GotoForward(Window *window) {
|
||||
|
||||
if (window->goto_redo.len) {
|
||||
GotoCrumb *next = GetLast(window->goto_redo);
|
||||
if (c.time - next->time <= ConfigUndoMergeTimeout) {
|
||||
if (c.view_id == next->view_id && next->time - c.time <= ConfigJumpHistoryMergeTimeWindow) {
|
||||
GotoForward(window);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ void Command_ShowBufferList() {
|
||||
ActiveWindowID = command_bar.window->id;
|
||||
ResetBuffer(command_bar.buffer);
|
||||
For (Buffers) {
|
||||
if (it->special) {
|
||||
if (it->special || it->garbage) {
|
||||
continue;
|
||||
}
|
||||
RawAppendf(command_bar.buffer, "\n%S", it->name);
|
||||
|
||||
@@ -6,6 +6,7 @@ void DebugWindowInit() {
|
||||
window->visible = false;
|
||||
window->z = 2;
|
||||
window->layout = false;
|
||||
window->jump_history = false;
|
||||
|
||||
Buffer *buffer = CreateBuffer(SysAllocator, GetUniqueBufferName(WorkDir, "debug"));
|
||||
DebugBufferID = buffer->id;
|
||||
|
||||
@@ -15,6 +15,7 @@ void SearchWindowInit() {
|
||||
window->layout = false;
|
||||
window->visible = false;
|
||||
window->lose_visibility_on_escape = true;
|
||||
window->jump_history = false;
|
||||
}
|
||||
|
||||
void SearchWindowLayout(Rect2I *rect, Int wx, Int wy) {
|
||||
@@ -33,10 +34,19 @@ void SearchWindowLayout(Rect2I *rect, Int wx, Int wy) {
|
||||
}
|
||||
|
||||
void Command_Search() {
|
||||
BSet main = GetBSet(ActiveWindowID);
|
||||
String16 string = {};
|
||||
if (main.view->carets.len == 1 && GetSize(main.view->carets[0]) > 0) {
|
||||
string = GetString(main.buffer, main.view->carets[0].range);
|
||||
}
|
||||
BSet set = GetBSet(SearchWindowID);
|
||||
set.window->visible = true;
|
||||
ActiveWindowID = SearchWindowID;
|
||||
SelectEntireBuffer(set.view);
|
||||
if (string.len > 0) {
|
||||
Replace(set.view, string);
|
||||
SelectEntireBuffer(set.view);
|
||||
}
|
||||
} RegisterCommand(Command_Search, "ctrl-f");
|
||||
|
||||
void SearchWindowFindNext(bool forward = true) {
|
||||
|
||||
Reference in New Issue
Block a user