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? - 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? - 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$/ - Open with seek string (open at pattern) filename:32 filename:/^Window$/
- build console window - build console window
- Show what process/coroutines are running and allow to kill (active process buffer?) - 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 Search whole words, case sensitive etc.
FEATURE Select all searched occurences FEATURE Select all searched occurences
FEATURE commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top 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 FEATURE Some decl/function indexing in fuzzy format
ISSUE? Fix jump scroll, the query ends up the last line on screen, kind of wacky 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 FEATURE dump text editor state to file, restore state

View File

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

View File

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

View File

@@ -275,7 +275,7 @@ void OnCommand(Event event) {
} }
bool mouse_in_document = AreOverlapping(mouse, it->document_rect); bool mouse_in_document = AreOverlapping(mouse, it->document_rect);
if (mouse_in_document) { if (mouse_in_document) {
ActiveWindowID = it->id; NextActiveWindowID = ActiveWindowID = it->id;
break; break;
} }
} }
@@ -525,6 +525,12 @@ void Update(Event event) {
UpdateProcesses(); UpdateProcesses();
CoUpdate(&event); 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 // 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 // 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. // 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) { For (Windows) {
if (it->jump_history) { if (it->jump_history) {
View *view = GetView(it->active_view); View *view = GetView(it->active_view);
@@ -556,7 +562,7 @@ void Update(Event event) {
} }
if (it->sync_visibility_with_focus) { if (it->sync_visibility_with_focus) {
if (it->id == ActiveWindowID) { if (it->id == NextActiveWindowID) {
it->visible = true; it->visible = true;
} else { } else {
it->visible = false; it->visible = false;
@@ -564,22 +570,20 @@ void Update(Event event) {
} }
} }
Window *window = GetWindow(ActiveWindowID); ActiveWindowID = NextActiveWindowID;
if (ActiveWindowID.id != LastActiveLayoutWindowID.id) { Window *window = GetWindow(ActiveWindowID, NULL);
if (window == NULL || window->visible == false) {
ActiveWindowID = NextActiveWindowID = LastActiveLayoutWindowID;
window = GetWindow(ActiveWindowID);
}
if (ActiveWindowID != LastActiveLayoutWindowID) {
if (window->layout) { if (window->layout) {
LastActiveLayoutWindowID = ActiveWindowID; 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(); GarbageCollect();
} }

View File

@@ -159,6 +159,24 @@ Caret FindNext(Buffer *buffer, String16 needle, Caret caret) {
return result; 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) { void SelectRange(View *view, Caret caret) {
view->carets.len = 1; view->carets.len = 1;
view->carets[0] = caret; view->carets[0] = caret;

View File

@@ -111,7 +111,7 @@ void CommandWindowUpdate() {
void Command_ShowCommands() { void Command_ShowCommands() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowCommands) { if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowCommands) {
ActiveWindowID = LastActiveLayoutWindowID; NextActiveWindowID = LastActiveLayoutWindowID;
return; return;
} }
ProfileFunction(); ProfileFunction();
@@ -119,7 +119,7 @@ void Command_ShowCommands() {
BSet command_bar = GetBSet(CommandWindowID); BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = true; command_bar.window->eval_command = true;
ActiveWindowID = command_bar.window->id; NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer); ResetBuffer(command_bar.buffer);
For(CommandFunctions) { For(CommandFunctions) {
RawAppendf(command_bar.buffer, "\n%S", it.name); RawAppendf(command_bar.buffer, "\n%S", it.name);
@@ -130,7 +130,7 @@ void Command_ShowCommands() {
void Command_ShowDebugBufferList() { void Command_ShowDebugBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowDebugBufferList) { if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowDebugBufferList) {
ActiveWindowID = LastActiveLayoutWindowID; NextActiveWindowID = LastActiveLayoutWindowID;
return; return;
} }
ProfileFunction(); ProfileFunction();
@@ -138,7 +138,7 @@ void Command_ShowDebugBufferList() {
BSet command_bar = GetBSet(CommandWindowID); BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = false; command_bar.window->eval_command = false;
ActiveWindowID = command_bar.window->id; NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer); ResetBuffer(command_bar.buffer);
For (Buffers) { For (Buffers) {
RawAppendf(command_bar.buffer, "\n%S", it->name); RawAppendf(command_bar.buffer, "\n%S", it->name);
@@ -149,7 +149,7 @@ void Command_ShowDebugBufferList() {
void Command_ShowBufferList() { void Command_ShowBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowBufferList) { if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowBufferList) {
ActiveWindowID = LastActiveLayoutWindowID; NextActiveWindowID = LastActiveLayoutWindowID;
return; return;
} }
ProfileFunction(); ProfileFunction();
@@ -157,7 +157,7 @@ void Command_ShowBufferList() {
BSet command_bar = GetBSet(CommandWindowID); BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true; command_bar.window->visible = true;
command_bar.window->eval_command = false; command_bar.window->eval_command = false;
ActiveWindowID = command_bar.window->id; NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer); ResetBuffer(command_bar.buffer);
For (Buffers) { For (Buffers) {
if (it->special || it->garbage || it->is_dir) { if (it->special || it->garbage || it->is_dir) {
@@ -184,7 +184,7 @@ void EvalCommand(String16 command) {
EvalCommand(ToString(scratch, command)); EvalCommand(ToString(scratch, command));
} }
void CommandWindowOpen(BSet active) { void OpenCommand(BSet active) {
ProfileFunction(); ProfileFunction();
Range range = active.view->carets[0].range; Range range = active.view->carets[0].range;
String16 string = FetchLoadWord(active.view); String16 string = FetchLoadWord(active.view);
@@ -202,9 +202,17 @@ void CommandWindowOpen(BSet active) {
} }
if (active.window->eval_command) { if (active.window->eval_command) {
BSet main = GetBSet(LastActiveLayoutWindowID); BSet main = GetBSet(LastActiveLayoutWindowID);
ActiveWindowID = main.window->id; NextActiveWindowID = main.window->id;
EvalCommand(string); EvalCommand(string);
} else { } else {
Open(string); 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); BSet set = GetBSet(SearchWindowID);
set.window->visible = true; set.window->visible = true;
ActiveWindowID = SearchWindowID; NextActiveWindowID = SearchWindowID;
SelectEntireBuffer(set.view); SelectEntireBuffer(set.view);
if (string.len > 0) { if (string.len > 0) {
Replace(set.view, string); Replace(set.view, string);
@@ -57,13 +57,59 @@ void SearchWindowFindNext(bool forward = true) {
main.window->search_bar_anchor = main.view->carets[0]; 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() { void Command_SearchNext() {
SearchWindowFindNext(true); SearchWindowFindNext(true);
} RegisterCommand(Command_SearchNext, "f3"); } RegisterCommand(Command_SearchNext, "f3");
void Command_SearchPrev() { void Command_SearchPrev() {
SearchWindowFindNext(false); 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() { void SearchWindowUpdate() {
BSet active = GetBSet(ActiveWindowID); BSet active = GetBSet(ActiveWindowID);