New UI buffer thing

This commit is contained in:
krzosa
2025-12-28 10:29:53 +01:00
parent 00442da5dd
commit 06cb073832
8 changed files with 94 additions and 29 deletions

View File

@@ -3,12 +3,16 @@
Use session 1:
- OpenCommand in command window freezes the app
- Shift + backspace should delete normally
- SDL popups are not working on linux ...
- CloseAll idea: should create a buffer interface with list of buffers, user would be able to select which buffers to save and which not, then button UICloseAll
- Creating files more efficiently
- Dialog popup on save? Or ctrl-shift-s?
- Maybe rename in bar and do :Rename
New UI Session
- Cleanup String16/String with Open and EvalCommands after lua refactor
- Rename GotoBackward and others to Jump
- 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?)

View File

@@ -829,6 +829,52 @@ void Command_CloseAll() {
}
} RegisterCommand(Command_CloseAll, "");
void Command_ForceClose() {
BSet active = GetBSet(ActiveWindowID);
Close(active.buffer->id);
Close(active.view->id);
}
// @todo: make these uneditable?
// @todo: maybe turn this into a coroutine???
String BufferIDea = R"==(
Do you want to save buffer? [C:/Programming/text_editor/build.sh]
:Yes :No
)==";
void Command_TestUIIdea() {
BSet main = GetBSet(LastActiveLayoutWindowID);
JumpGarbageBuffer(&main, "ui");
NextActiveWindowID = main.window->id;
Add(&main.view->hooks, {"Yes", "enter", [](){
BSet active = GetBSet(ActiveWindowID);
Caret a = FindNext(active.buffer, u"[", MakeCaret(0));
Caret b = FindNext(active.buffer, u"]", MakeCaret(0));
if (GetSize(a) == 0 || GetSize(b) == 0) {
ReportWarningf("Failed to save, '[' or ']' not found");
return;
}
Scratch scratch;
String16 string16 = GetString(active.buffer, {a.range.max, b.range.min});
String string = ToString(scratch, string16);
Buffer *buffer = GetBuffer(string, NULL);
if (buffer) {
SaveBuffer(buffer);
} else {
ReportWarningf("Failed to save, buffer not found: %S", string);
}
Close(active.buffer->id);
Close(active.view->id);
}, ParseKey(Perm, "enter", "Command_TestUIIdea_Yes")}); // @todo: fix memory leak
Add(&main.view->hooks, {"No", "escape", Command_ForceClose, ParseKeyCached("escape")});
RawAppend(main.buffer, BufferIDea);
main.view->carets[0] = FindNext(main.buffer, u":Yes", MakeCaret(0));
main.view->carets[0].range.min = main.view->carets[0].range.max;
} RegisterCommand(Command_TestUIIdea, "");
void Command_GotoBackward() {
BSet main = GetBSet(LastActiveLayoutWindowID);
main.window->skip_checkpoint = true;
@@ -1084,7 +1130,7 @@ void Command_DeleteBoundary() {
void Command_DeleteForward() {
BSet active = GetBSet(ActiveWindowID);
Delete(active.view, DIR_RIGHT);
} RegisterCommand(Command_DeleteForward, "delete");
} RegisterCommand(Command_DeleteForward, "shift-delete | delete");
void Command_DeleteForwardBoundary() {
BSet active = GetBSet(ActiveWindowID);

View File

@@ -79,7 +79,7 @@ String Intern(InternTable *table, String string) {
// optimize worst offenders (like event text)
InternTable GlobalInternTable;
Function *LastExecutedCommand;
Function *LastExecutedManualCommand;
Array<CommandData> CommandFunctions;
Array<FunctionData> TestFunctions;
Array<Variable> Variables;

View File

@@ -386,11 +386,24 @@ void OnCommand(Event event) {
BSet main = GetBSet(LastActiveLayoutWindowID);
BSet active = GetBSet(ActiveWindowID);
bool executed = false;
For (active.view->hooks) {
if (it.trigger && MatchEvent(it.trigger, &event)) {
ProfileScopeEx(it.name);
it.function();
LastExecutedManualCommand = it.function;
executed = true;
break;
}
}
if (executed == false) {
For (CommandFunctions) {
if (it.trigger && MatchEvent(it.trigger, &event)) {
ProfileScopeEx(it.name);
it.function();
LastExecutedCommand = it.function;
LastExecutedManualCommand = it.function;
}
}
}
@@ -476,8 +489,7 @@ void GarbageCollect() {
RawAppendf(GCInfoBuffer, "View %d %S\n", (int)it->id.id, buffer->name);
remove_item = true;
Dealloc(&it->carets);
Dealloc(sys_allocator, it);
Dealloc(it);
}
IterRemove(Buffers) {

View File

@@ -8,11 +8,18 @@ API View *CreateView(BufferID active_buffer) {
view->id = AllocViewID(view);
view->active_buffer = active_buffer;
view->carets.allocator = al;
view->hooks.allocator = al;
Add(&view->carets, {0, 0});
Add(&Views, view);
return view;
}
void Dealloc(View *view) {
Dealloc(&view->carets);
Dealloc(&view->hooks);
Dealloc(view->carets.allocator, view);
}
API View *FindView(ViewID view_id, View *default_view) {
For(Views) {
if (it->id == view_id) {

View File

@@ -1,6 +1,10 @@
struct View;
struct ViewID { Int id; View *o; };
typedef void Function();
struct FunctionData { String name; Function *function; };
struct CommandData { String name; String binding; Function *function; struct Trigger *trigger; };
struct View {
ViewID id;
BufferID active_buffer;
@@ -11,6 +15,7 @@ struct View {
Caret main_caret_on_begin_frame;
bool update_scroll;
Array<CommandData> hooks;
String16 prev_search_line;
struct {
unsigned close : 1;

View File

@@ -36,7 +36,6 @@ struct Window {
uint32_t lose_focus_on_escape : 1;
uint32_t lose_visibility_on_escape : 1;
uint32_t jump_history : 1;
uint32_t eval_command : 1;
uint32_t skip_checkpoint : 1;
};
};

View File

@@ -110,7 +110,7 @@ void CommandWindowUpdate() {
}
void Command_ShowCommands() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowCommands) {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowCommands) {
NextActiveWindowID = LastActiveLayoutWindowID;
return;
}
@@ -118,18 +118,20 @@ void Command_ShowCommands() {
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
command_bar.window->eval_command = true;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (CommandFunctions) {
RawAppendf(command_bar.buffer, "\n%S", it.name);
if (it.name == "OpenCommand") {
continue;
}
RawAppendf(command_bar.buffer, "\n:%S", it.name);
}
command_bar.view->update_scroll = true;
SelectRange(command_bar.view, GetBufferBeginAsRange(command_bar.buffer));
} RegisterCommand(Command_ShowCommands, "ctrl-shift-p");
void Command_ShowDebugBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowDebugBufferList) {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowDebugBufferList) {
NextActiveWindowID = LastActiveLayoutWindowID;
return;
}
@@ -137,7 +139,6 @@ void Command_ShowDebugBufferList() {
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
command_bar.window->eval_command = false;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
@@ -148,7 +149,7 @@ void Command_ShowDebugBufferList() {
} RegisterCommand(Command_ShowDebugBufferList, "");
void Command_ShowBufferList() {
if (ActiveWindowID == CommandWindowID && LastExecutedCommand == Command_ShowBufferList) {
if (ActiveWindowID == CommandWindowID && LastExecutedManualCommand == Command_ShowBufferList) {
NextActiveWindowID = LastActiveLayoutWindowID;
return;
}
@@ -156,7 +157,6 @@ void Command_ShowBufferList() {
BSet command_bar = GetBSet(CommandWindowID);
command_bar.window->visible = true;
command_bar.window->eval_command = false;
NextActiveWindowID = command_bar.window->id;
ResetBuffer(command_bar.buffer);
For (Buffers) {
@@ -178,26 +178,18 @@ void OpenCommand(BSet active) {
if (line == 0) {
line = ClampTop(1ll, active.buffer->line_starts.len - 1ll);
}
string = GetLineStringWithoutNL(active.buffer, line);
Int idx = 0;
if (Seek(string, u"||", &idx)) {
string = Skip(string, idx + 3);
}
}
if (active.window->eval_command) {
BSet main = GetBSet(LastActiveLayoutWindowID);
NextActiveWindowID = main.window->id;
EvalCommand(string);
} else {
Open(string);
}
}
void Command_OpenCommand() {
if (ActiveWindowID != CommandWindowID) {
return;
}
BSet active = GetBSet(ActiveWindowID);
BSet main = GetBSet(LastActiveLayoutWindowID);
NextActiveWindowID = main.window->id;
OpenCommand(active);
} RegisterCommand(Command_OpenCommand, "ctrl-q | enter");