Compare commits

...

2 Commits

7 changed files with 122 additions and 49 deletions

View File

@@ -1,6 +1,10 @@
- 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?
- Search
- alt + w: word search
- alt + c: case sensitive
- Open with seek string (open at pattern) filename:32 filename:/^Window$/
- build console window
- Show what process/coroutines are running and allow to kill (active process buffer?)
@@ -21,7 +25,6 @@ backlog
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
FEATURE Kill buffer command (it should be marked for deletion and deleted at the end of frame!)
FEATURE Some decl/function indexing in fuzzy format
ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky
FEATURE dump text editor state to file, restore state

View File

@@ -221,7 +221,7 @@ void ReportErrorf(const char *fmt, ...) {
View *view = GetView(NullViewID);
if (view) {
Appendf(view, "%S\n", string);
ActiveWindowID = NullWindowID;
NextActiveWindowID = NullWindowID;
}
}
@@ -432,7 +432,7 @@ View *ExecHidden(String buffer_name, String cmd, String working_dir) {
BSet Exec(String cmd, String working_dir, bool set_active = true) {
BSet main = GetBSet(LastActiveLayoutWindowID);
if (set_active) {
ActiveWindowID = main.window->id;
NextActiveWindowID = main.window->id;
}
JumpGarbageBuffer(&main);
Exec(main.view->id, true, cmd, working_dir);
@@ -441,7 +441,7 @@ BSet Exec(String cmd, String working_dir, bool set_active = true) {
BSet ExecBuild(String cmd) {
BSet main = GetBSet(LastActiveLayoutWindowID);
ActiveWindowID = main.window->id;
NextActiveWindowID = main.window->id;
View *view = WindowOpenBufferView(main.window, BuildBuffer->name);
ResetBuffer(BuildBuffer);
Exec(view->id, true, cmd, WorkDir);
@@ -608,7 +608,7 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
ResolvedOpen o = ResolveOpen(scratch, path, meta);
if (o.kind == OpenKind_Goto) {
if (set_active) {
ActiveWindowID = set.window->id;
NextActiveWindowID = set.window->id;
}
if (IsDir(o.path)) {
View *view = WindowOpenBufferView(set.window, o.path);
@@ -630,7 +630,7 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
UpdateScroll(set.window, true);
} else if (o.kind == OpenKind_Exec) {
if (set_active) {
ActiveWindowID = set.window->id;
NextActiveWindowID = set.window->id;
}
JumpGarbageBuffer(&set);
Exec(set.view->id, true, o.path, GetMainDir());
@@ -674,7 +674,7 @@ void Command_SaveAll() {
void Command_Reopen() {
BSet main = GetBSet(LastActiveLayoutWindowID);
ReopenBuffer(main.buffer);
ActiveWindowID = main.window->id;
NextActiveWindowID = main.window->id;
} RegisterCommand(Command_Reopen, "");
void Command_New() {
@@ -892,10 +892,9 @@ void Command_MakeFontSmaller() {
void Command_Open() {
BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) {
CommandWindowOpen(active);
} else {
Open(FetchLoadWord(active.view));
return;
}
Open(FetchLoadWord(active.view));
} RegisterCommand(Command_Open, "ctrl-q");
void Command_KillSelectedLines() {
@@ -999,7 +998,7 @@ void Command_SelectLeft() {
} RegisterCommand(Command_SelectLeft, "shift-left");
void Command_FocusLeftWindow() {
ActiveWindowID = SwitchWindow(DIR_LEFT)->id;
NextActiveWindowID = SwitchWindow(DIR_LEFT)->id;
} RegisterCommand(Command_FocusLeftWindow, "alt-left");
void Command_MoveLeft() {
@@ -1023,7 +1022,7 @@ void Command_SelectRight() {
} RegisterCommand(Command_SelectRight, "shift-right");
void Command_FocusRightWindow() {
ActiveWindowID = SwitchWindow(DIR_RIGHT)->id;
NextActiveWindowID = SwitchWindow(DIR_RIGHT)->id;
} RegisterCommand(Command_FocusRightWindow, "alt-right");
void Command_MoveRight() {
@@ -1115,14 +1114,11 @@ void Command_InsertNewLineDown() {
} RegisterCommand(Command_InsertNewLineDown, "ctrl-enter");
void Command_NewLine() {
BSet active = GetBSet(ActiveWindowID);
if (active.window->id == CommandWindowID) {
CommandWindowOpen(active);
} else if (active.window->id == SearchWindowID) {
SearchWindowFindNext(true);
} else {
IdentedNewLine(active.view);
if (ActiveWindowID == CommandWindowID || ActiveWindowID == SearchWindowID) {
return;
}
BSet active = GetBSet(ActiveWindowID);
IdentedNewLine(active.view);
} RegisterCommand(Command_NewLine, "enter");
void Command_CreateCaretOnNextFind() {
@@ -1134,13 +1130,13 @@ void Command_CreateCaretOnNextFind() {
} RegisterCommand(Command_CreateCaretOnNextFind, "ctrl-d");
void Command_FocusWindow1() {
ActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id;
NextActiveWindowID = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID))->id;
} RegisterCommand(Command_FocusWindow1, "ctrl-1");
void Command_FocusWindow2() {
Window *first = GetOverlappingWindow({0,0}, GetWindow(ActiveWindowID));
Vec2I p = GetSideOfWindow(first, DIR_RIGHT);
ActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id;
NextActiveWindowID = GetOverlappingWindow(p, GetWindow(ActiveWindowID))->id;
} RegisterCommand(Command_FocusWindow2, "ctrl-2");
void Command_FocusWindow3() {
@@ -1150,7 +1146,7 @@ void Command_FocusWindow3() {
if (second) {
Window *third = GetOverlappingWindow(GetSideOfWindow(second, DIR_RIGHT));
if (third) {
ActiveWindowID = third->id;
NextActiveWindowID = third->id;
}
}
}
@@ -1169,15 +1165,12 @@ void Command_ClearCarets() {
if (active.window->layout) {
//
} else {
ActiveWindowID = LastActiveLayoutWindowID;
NextActiveWindowID = LastActiveLayoutWindowID;
}
}
For (Windows) {
if (it->lose_visibility_on_escape && it->visible) {
if (ActiveWindowID == it->id) {
ActiveWindowID = LastActiveLayoutWindowID;
}
it->visible = false;
}
}

View File

@@ -32,6 +32,7 @@ WindowID SearchWindowID;
ViewID SearchViewID;
BufferID SearchBufferID;
WindowID NextActiveWindowID;
WindowID ActiveWindowID;
WindowID LastActiveLayoutWindowID;
WindowID ScrollbarSelected = {-1};

View File

@@ -275,7 +275,7 @@ void OnCommand(Event event) {
}
bool mouse_in_document = AreOverlapping(mouse, it->document_rect);
if (mouse_in_document) {
ActiveWindowID = it->id;
NextActiveWindowID = ActiveWindowID = it->id;
break;
}
}
@@ -525,6 +525,12 @@ void Update(Event event) {
UpdateProcesses();
CoUpdate(&event);
For(IterateInReverse(&order)) {
if (!it->visible) continue;
View *view = GetView(it->active_view);
UpdateScroll(it, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll);
}
// We update it here despite the name to make it sure that all the possible changes are
// included albeit with delayed response. If we did this at the beginning of the frame
// and the DebugWindowUpdated we wouldnt get to know that in the OnCommand.
@@ -533,7 +539,7 @@ void Update(Event event) {
}
{
ProfileScope(WindowEndOfFrameVisibilityAndLastActive);
ProfileScope(UpdateWindows);
For (Windows) {
if (it->jump_history) {
View *view = GetView(it->active_view);
@@ -556,7 +562,7 @@ void Update(Event event) {
}
if (it->sync_visibility_with_focus) {
if (it->id == ActiveWindowID) {
if (it->id == NextActiveWindowID) {
it->visible = true;
} else {
it->visible = false;
@@ -564,22 +570,20 @@ void Update(Event event) {
}
}
Window *window = GetWindow(ActiveWindowID);
if (ActiveWindowID.id != LastActiveLayoutWindowID.id) {
ActiveWindowID = NextActiveWindowID;
Window *window = GetWindow(ActiveWindowID, NULL);
if (window == NULL || window->visible == false) {
ActiveWindowID = NextActiveWindowID = LastActiveLayoutWindowID;
window = GetWindow(ActiveWindowID);
}
if (ActiveWindowID != LastActiveLayoutWindowID) {
if (window->layout) {
LastActiveLayoutWindowID = ActiveWindowID;
}
}
}
For(IterateInReverse(&order)) {
if (!it->visible) continue;
View *view = GetView(it->active_view);
UpdateScroll(it, !AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && view->update_scroll);
}
GarbageCollect();
}

View File

@@ -159,6 +159,24 @@ Caret FindNext(Buffer *buffer, String16 needle, Caret caret) {
return result;
}
Array<Caret> FindAll(Allocator allocator, Buffer *buffer, String16 needle) {
Array<Caret> result = {allocator};
String16 string = GetString(buffer);
String16 start = string;
for (;;) {
Int index = 0;
if (Seek(string, needle, &index)) {
Int back = index + (Int)(string.data - start.data);
Int front = back + needle.len;
Add(&result, MakeCaret(front, back));
string = Skip(string, index + needle.len);
} else {
break;
}
}
return result;
}
void SelectRange(View *view, Caret caret) {
view->carets.len = 1;
view->carets[0] = caret;

View File

@@ -111,7 +111,7 @@ void CommandWindowUpdate() {
void Command_ShowCommands() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowCommands) {
ActiveWindowID = LastActiveLayoutWindowID;
NextActiveWindowID = LastActiveLayoutWindowID;
return;
}
ProfileFunction();
@@ -119,7 +119,7 @@ void Command_ShowCommands() {
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
command_bar.window->eval_command = true;
ActiveWindowID = command_bar.window->id;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For(CommandFunctions) {
RawAppendf(command_bar.buffer, "\n%S", it.name);
@@ -130,7 +130,7 @@ void Command_ShowCommands() {
void Command_ShowDebugBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowDebugBufferList) {
ActiveWindowID = LastActiveLayoutWindowID;
NextActiveWindowID = LastActiveLayoutWindowID;
return;
}
ProfileFunction();
@@ -138,7 +138,7 @@ void Command_ShowDebugBufferList() {
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
command_bar.window->eval_command = false;
ActiveWindowID = command_bar.window->id;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
RawAppendf(command_bar.buffer, "\n%S", it->name);
@@ -149,7 +149,7 @@ void Command_ShowDebugBufferList() {
void Command_ShowBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowBufferList) {
ActiveWindowID = LastActiveLayoutWindowID;
NextActiveWindowID = LastActiveLayoutWindowID;
return;
}
ProfileFunction();
@@ -157,7 +157,7 @@ void Command_ShowBufferList() {
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
command_bar.window->eval_command = false;
ActiveWindowID = command_bar.window->id;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
if (it->special || it->garbage || it->is_dir) {
@@ -184,7 +184,7 @@ void EvalCommand(String16 command) {
EvalCommand(ToString(scratch, command));
}
void CommandWindowOpen(BSet active) {
void OpenCommand(BSet active) {
ProfileFunction();
Range range = active.view->carets[0].range;
String16 string = FetchLoadWord(active.view);
@@ -202,9 +202,17 @@ void CommandWindowOpen(BSet active) {
}
if (active.window->eval_command) {
BSet main = GetBSet(LastActiveLayoutWindowID);
ActiveWindowID = main.window->id;
NextActiveWindowID = main.window->id;
EvalCommand(string);
} else {
Open(string);
}
}
void Command_OpenCommand() {
if (ActiveWindowID != CommandWindowID) {
return;
}
BSet active = GetBSet(ActiveWindowID);
OpenCommand(active);
} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");

View File

@@ -41,7 +41,7 @@ void Command_Search() {
}
BSet set = GetBSet(SearchWindowID);
set.window->visible = true;
ActiveWindowID = SearchWindowID;
NextActiveWindowID = SearchWindowID;
SelectEntireBuffer(set.view);
if (string.len > 0) {
Replace(set.view, string);
@@ -57,13 +57,59 @@ void SearchWindowFindNext(bool forward = true) {
main.window->search_bar_anchor = main.view->carets[0];
}
void Command_SearchNextInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNextInSearch, "enter");
void Command_SearchPrevInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrevInSearch, "shift-enter");
void Command_SearchNext() {
SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNext, "f3");
void Command_SearchPrev() {
SearchWindowFindNext(false);
} RegisterCommand(Command_SearchPrev, "shift-f3 | shift-enter");
} RegisterCommand(Command_SearchPrev, "shift-f3");
void SearchAll() {
Scratch scratch;
BSet main = GetBSet(LastActiveLayoutWindowID);
BSet set = GetBSet(SearchWindowID);
String16 needle = GetString(set.buffer, GetRange(set.buffer));
Array<Caret> all = FindAll(scratch, main.buffer, needle);
if (all.len > 0) {
main.view->carets.len = 0;
For (all) {
Add(&main.view->carets, it);
}
MergeCarets(main.buffer, &main.view->carets);
}
}
void Command_SearchAll() {
SearchAll();
BSet set = GetBSet(SearchWindowID);
set.window->visible = false;
} RegisterCommand(Command_SearchAll, "alt-f3");
void Command_SearchAllInSearch() {
if (ActiveWindowID != SearchWindowID) {
return;
}
SearchAll();
BSet set = GetBSet(SearchWindowID);
set.window->visible = false;
} RegisterCommand(Command_SearchAllInSearch, "alt-enter");
void SearchWindowUpdate() {
BSet active = GetBSet(ActiveWindowID);