GotoForward

This commit is contained in:
Krzosa Karol
2024-08-09 10:36:33 +02:00
parent 19546eea4d
commit 00c1f405c6
7 changed files with 71 additions and 24 deletions

View File

@@ -89,17 +89,40 @@ void ToggleConsole() {
}
}
void CheckpointBeforeGoto() {
Window *window = GetWindow(GetLastActiveWindow());
void CheckpointBeforeGoto(WindowID window_id) {
Window *window = GetWindow(window_id);
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
Add(&GotoCrumbs, {buffer->id, view->carets[0]});
Add(&window->goto_history, {buffer->id, view->carets[0]});
window->goto_redo.len = 0;
}
void GoBackToLastCrumb() {
Window *window = GetWindow(GetLastActiveWindow());
if (GotoCrumbs.len <= 0) return;
GotoCrumb c = Pop(&GotoCrumbs);
void GotoBackward(WindowID window_id) {
Window *window = GetWindow(window_id);
if (window->goto_history.len <= 0) return;
{
Window *window = GetWindow(window_id);
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
Add(&window->goto_redo, {buffer->id, view->carets[0]});
}
GotoCrumb c = Pop(&window->goto_history);
Buffer *buffer = GetBuffer(c.buffer_id);
View *view = WindowOpenBufferView(window, buffer->name);
view->carets[0] = c.caret;
UpdateScroll(window, true);
}
void GotoForward(WindowID window_id) {
Window *window = GetWindow(window_id);
if (window->goto_redo.len <= 0) return;
{
Window *window = GetWindow(window_id);
View *view = GetView(window->active_view);
Buffer *buffer = GetBuffer(view->active_buffer);
Add(&window->goto_history, {buffer->id, view->carets[0]});
}
GotoCrumb c = Pop(&window->goto_redo);
Buffer *buffer = GetBuffer(c.buffer_id);
View *view = WindowOpenBufferView(window, buffer->name);
view->carets[0] = c.caret;
@@ -289,10 +312,12 @@ bool GlobalCommand(Event event) {
if (event.ctrl && event.shift && Mouse(RIGHT)) {
MouseExecWord(event);
} else if (event.alt && event.ctrl && Mouse(RIGHT)) {
GotoForward(GetLastActiveWindow());
} else if (event.ctrl && Mouse(RIGHT)) {
MouseLoadWord(event);
} else if (event.alt && Mouse(RIGHT)) {
GoBackToLastCrumb();
GotoBackward(GetLastActiveWindow());
} else if (Mouse(RIGHT)) {
Vec2I mouse = MouseVec2I();
Window *window = GetActiveWindow();

View File

@@ -896,6 +896,8 @@ void WindowCommand(Event event, Window *window, View *view) {
String16 string = GetString(*buffer, range);
Command_EvalLua(view, string);
} else if (CtrlAlt(SDLK_Q)) {
GotoForward(GetLastActiveWindow());
} else if (Ctrl(SDLK_Q)) {
Caret caret = view->carets[0];
Range range = caret.range;
@@ -904,7 +906,7 @@ void WindowCommand(Event event, Window *window, View *view) {
Open(string);
} else if (Alt(SDLK_Q)) {
GoBackToLastCrumb();
GotoBackward(GetLastActiveWindow());
}
}

View File

@@ -37,7 +37,7 @@ String GetUniqueBufferName(Allocator allocator, String working_dir, String p
void ExecInNewBuffer(String cmd, String working_dir) {
Scratch scratch;
CheckpointBeforeGoto();
CheckpointBeforeGoto(GetLastActiveWindow());
String buffer_name = GetUniqueBufferName(scratch, working_dir, "+CMD");
Window *window = GetWindow(GetLastActiveWindow());
View *view = WindowOpenBufferView(window, buffer_name);
@@ -66,8 +66,9 @@ void Open(String path) {
String col_string = FieldString(LuaState, "col");
Int col = strtoll(col_string.data, NULL, 10);
CheckpointBeforeGoto();
Window *window = GetWindow(GetLastActiveWindow());
WindowID window_id = GetLastActiveWindow();
CheckpointBeforeGoto(window_id);
Window *window = GetWindow(window_id);
View *view = WindowOpenBufferView(window, file_path);
Buffer *buffer = GetBuffer(view->active_buffer);
if (line != -1 && col != -1) {
@@ -192,6 +193,21 @@ int LuaGetCurrentBufferDir(lua_State *L) {
return 1;
}
void OpenFilesHereRecursive(Window *window, String path) {
Scratch scratch;
}
int LuaOpenFilesHere(lua_State *L) {
Window *window = GetWindow(GetLastActiveWindow());
Scratch scratch;
for (FileIter it = IterateFiles(scratch, GetCurrentBufferDir()); IsValid(it); Advance(&it)) {
WindowOpenBufferView(window, it.absolute_path);
}
return 0;
}
static void HookLuaForceExit(lua_State *L, lua_Debug *debug) {
SDL_PumpEvents();
int numkeys = 0;
@@ -213,6 +229,7 @@ luaL_Reg LuaFunctions[] = {
{ "Kill", LuaKill},
{ "NewC", LuaNewCmd},
{ "AppendC", LuaAppendCmd},
{ "OpenFilesHere", LuaOpenFilesHere},
{ NULL, NULL},
};

View File

@@ -24,10 +24,9 @@ BufferID SearchBufferID;
// Remember that WindowCommand works on window handed it down from HandleEvent
// just because we don't have NextActiveWindow doesn't mean that we work on new
// window all of a sudden in that function call!
WindowID ActiveWindow;
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
Array<GotoCrumb> GotoCrumbs;
Int CaretChangeID;
WindowID ActiveWindow;
Array<WindowID> WindowSwitchHistory; // @todo: probably better as a circular buffer
Int CaretChangeID;
WindowID ScrollbarSelected = {-1};
WindowID DocumentSelected = {-1};
@@ -267,7 +266,7 @@ Buffer *BufferOpenFile(String path) {
path = GetAbsolutePath(scratch, path);
path = Intern(&GlobalInternTable, path);
String string = ReadFile(scratch, path);
buffer = CreateBuffer(sys_allocator, path, string.len * 4);
buffer = CreateBuffer(sys_allocator, path, string.len * 4 + 4096);
buffer->len = ConvertUTF8ToUTF16UnixLine(string, buffer->str, buffer->cap);
UpdateLines(buffer, {}, String16{(wchar_t *)buffer->data, buffer->len});
}

View File

@@ -14,6 +14,6 @@ alt mright - go back
ctrl mright - load word
shift mright -
alt shift mright -
alt ctrl mright -
alt ctrl mright - go forward
ctrl shift mright - exec word
mmiddle -

View File

@@ -57,6 +57,11 @@ struct View {
};
};
struct GotoCrumb {
BufferID buffer_id;
Caret caret;
};
struct Window {
WindowID id;
ViewID active_view;
@@ -69,6 +74,9 @@ struct Window {
Rect2I line_numbers_rect;
Rect2I document_rect;
Array<GotoCrumb> goto_history;
Array<GotoCrumb> goto_redo;
double mouse_scroller_offset;
int z;
@@ -94,11 +102,6 @@ struct Scroller {
Int line_count;
};
struct GotoCrumb {
BufferID buffer_id;
Caret caret;
};
// @WARNING: be careful about using this, should only be used for debugging
// the problem with this is that we want events to be reproducible.
// We eat as many events as we can in a frame, we abstract the frame and so on.

View File

@@ -1,3 +1,4 @@
- jump history forward
- Remove pointers and use ViewIDs (enable array debug while doing this)
- try using git grep for search for now, combine with fuzzy search buffer
- lua maybe try heuristic matching paths from left?
@@ -32,6 +33,7 @@
Windows
- better teminology then 'active' 'last active' 'current'
- switch to previous view (ctrl + tab)
- shift + ctrl + click should open a new window and then with alt it probably should kill it
- layout using a tree!!
@@ -48,7 +50,6 @@ backlog
- drop text into window
- page up and down should also scroll and leave you in exactly same scroll
- I think the way sublime text and we display line highlights is confusing with multiple cursors (line highlight can be confused with selection)
- ctrl + delete maybe should stop on new line but it keeps on going, sublime is much more careful with deleting
- text_editor --record events.txt text_editor --playback events.txt
- make the editor replayable, store events and then replay, be careful about globals
- maybe open should return multiple options if there are many more? (like in sublime if many symbols you get a window and you choose and it automatically jumps you to the symbol in the background)