No history buffer, Active window stack
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
void SaveHistoryBeforeMergeCursor(Buffer *buffer, Array<HistoryEntry> *stack, Array<Caret> &carets) {
|
||||
if (buffer->no_history) return;
|
||||
HistoryEntry *entry = Alloc(stack);
|
||||
entry->carets = TightCopy(GetSystemAllocator(), carets);
|
||||
}
|
||||
|
||||
void SaveHistoryBeforeApplyEdits(Buffer *buffer, Array<HistoryEntry> *stack, Array<Edit> &edits) {
|
||||
ProfileFunction();
|
||||
if (buffer->no_history) return;
|
||||
HistoryEntry *entry = GetLast(*stack);
|
||||
Allocator sys_allocator = GetSystemAllocator();
|
||||
entry->edits = TightCopy(sys_allocator, edits);
|
||||
@@ -39,6 +41,7 @@ void SaveHistoryBeforeApplyEdits(Buffer *buffer, Array<HistoryEntry> *stack, Arr
|
||||
|
||||
void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
ProfileFunction();
|
||||
if (buffer->no_history) return;
|
||||
if (buffer->redo_stack.len <= 0) return;
|
||||
|
||||
HistoryEntry entry = Pop(&buffer->redo_stack);
|
||||
@@ -57,6 +60,7 @@ void RedoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
|
||||
void UndoEdit(Buffer *buffer, Array<Caret> *carets) {
|
||||
ProfileFunction();
|
||||
if (buffer->no_history) return;
|
||||
if (buffer->undo_stack.len <= 0) return;
|
||||
|
||||
HistoryEntry entry = Pop(&buffer->undo_stack);
|
||||
@@ -102,14 +106,16 @@ void AfterEdit(Buffer *buffer, Array<Edit> *edits, Array<Caret> *carets) {
|
||||
ProfileFunction();
|
||||
Assert(buffer->debug_edit_phase == 2);
|
||||
buffer->debug_edit_phase -= 2;
|
||||
HistoryEntry *entry = GetLast(buffer->undo_stack);
|
||||
|
||||
#if BUFFER_DEBUG
|
||||
if (buffer->no_history == false) {
|
||||
HistoryEntry *entry = GetLast(buffer->undo_stack);
|
||||
Assert(entry->carets.len);
|
||||
Assert(entry->edits.len);
|
||||
for (Int i = 0; i < edits->len - 1; i += 1) {
|
||||
Assert(edits->data[i].range.min <= edits->data[i + 1].range.min);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
@@ -224,7 +224,7 @@ void HandleGlobalCommands() {
|
||||
}
|
||||
if (CtrlPress(KEY_P)) {
|
||||
if (command_window->visible) {
|
||||
SetActiveWindow(LastActiveWindow);
|
||||
SetActiveWindow(GetLastActiveWindow());
|
||||
} else {
|
||||
SetActiveWindow(command_window->id);
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ void HandleActiveWindowBindings(Window *window) {
|
||||
String16 string = GetString(*buffer, range);
|
||||
String16 eval_result = EvalString(scratch, string);
|
||||
|
||||
if (Ctrl()) {
|
||||
if (Ctrl() && eval_result.len) {
|
||||
Command_SelectEntireBuffer(&view);
|
||||
Command_Replace(&view, eval_result);
|
||||
Command_SelectRange(&view, {});
|
||||
@@ -395,11 +395,11 @@ void HandleActiveWindowBindings(Window *window) {
|
||||
if (window->id.id == CommandWindowID.id) {
|
||||
Window *command_window = GetWindow(CommandWindowID);
|
||||
command_window->visible = !command_window->visible;
|
||||
ActiveWindow = LastActiveWindow;
|
||||
ActiveWindow = GetLastActiveWindow();
|
||||
}
|
||||
|
||||
{
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
Window *window = GetWindow(GetLastActiveWindow());
|
||||
View *view = GetView(window->active_view);
|
||||
SetActiveWindow(window->id);
|
||||
Command_Replace(view, eval_result);
|
||||
@@ -574,13 +574,15 @@ void ChangeActiveWindowAndScroll(Array<Int> &order) {
|
||||
|
||||
void ReplaceInfobarData() {
|
||||
Window *window = GetWindow(InfoBarWindowID);
|
||||
if (IsActive(window)) return;
|
||||
|
||||
View *view = GetView(window->active_view);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
|
||||
XY xy = {};
|
||||
String name = {};
|
||||
{
|
||||
Window *window = GetActiveWindow();
|
||||
Window *window = GetWindow(GetLastActiveWindow());
|
||||
View *view = GetActiveView(window);
|
||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||
Scratch scratch;
|
||||
@@ -591,8 +593,8 @@ void ReplaceInfobarData() {
|
||||
|
||||
Scratch scratch;
|
||||
String error = {};
|
||||
if (InfoBarErrorMessage.len) error = Format(scratch, "| error: %.*s", FmtString(InfoBarErrorMessage));
|
||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), FmtString(error));
|
||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name));
|
||||
String16 string = ToString16(scratch, s);
|
||||
ReplaceText(buffer, {0, buffer->len}, string);
|
||||
Command_SelectRange(view, {});
|
||||
}
|
||||
@@ -3,7 +3,7 @@ String16 LuaCommandResult = {};
|
||||
|
||||
int LuaOpenFile(lua_State *L) {
|
||||
const char *text = luaL_checkstring(L, 1);
|
||||
Window *window = GetWindow(LastActiveWindow);
|
||||
Window *window = GetWindow(GetLastActiveWindow());
|
||||
View *view = ViewOpenFile(window, text);
|
||||
SetActiveWindow(window->id);
|
||||
return 0; // number of results
|
||||
@@ -71,13 +71,6 @@ void InitLua() {
|
||||
lua_setglobal(LuaState, "list_windows");
|
||||
}
|
||||
|
||||
// @todo: also log to buffer or something
|
||||
void SetInfoBarErrorMessage(String string) {
|
||||
Allocator sys = GetSystemAllocator();
|
||||
if (InfoBarErrorMessage.data) Dealloc(sys, &InfoBarErrorMessage.data);
|
||||
if (string.len) InfoBarErrorMessage = Copy(sys, string);
|
||||
}
|
||||
|
||||
String16 EvalString(Allocator allocator, String16 string16) {
|
||||
Scratch scratch((Arena *)allocator.object);
|
||||
String string = ToString(scratch, string16);
|
||||
|
||||
@@ -50,11 +50,21 @@ View *CreateView(BufferID buffer_id) {
|
||||
return w;
|
||||
}
|
||||
|
||||
void SetActiveWindow(WindowID window) {
|
||||
if (LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
||||
if (ActiveWindow.id != CommandWindowID.id) {
|
||||
LastActiveWindow = ActiveWindow;
|
||||
inline bool IsSpecial(WindowID window) {
|
||||
bool result = window.id == CommandWindowID.id || window.id == InfoBarWindowID.id;
|
||||
return result;
|
||||
}
|
||||
|
||||
WindowID GetLastActiveWindow() {
|
||||
For(IterateInReverse(&WindowSwitchHistory)) {
|
||||
if (!IsSpecial(it)) return it;
|
||||
}
|
||||
return NullWindowID;
|
||||
}
|
||||
|
||||
void SetActiveWindow(WindowID window) {
|
||||
if (window.id != ActiveWindow.id && LastFrameIDWhenSwitchedActiveWindow != FrameID) {
|
||||
Add(&WindowSwitchHistory, window);
|
||||
ActiveWindow = window;
|
||||
LastFrameIDWhenSwitchedActiveWindow = FrameID;
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ int main(void) {
|
||||
w->draw_scrollbar = false;
|
||||
w->draw_line_numbers = false;
|
||||
Buffer *b = CreateBuffer(sys_allocator, "*infobar*");
|
||||
b->no_history = true;
|
||||
View *v = CreateView(b->id);
|
||||
AddView(w, v->id);
|
||||
InfoBarWindowID = w->id;
|
||||
|
||||
@@ -35,6 +35,7 @@ struct Buffer {
|
||||
Array<HistoryEntry> undo_stack;
|
||||
Array<HistoryEntry> redo_stack;
|
||||
int debug_edit_phase;
|
||||
bool no_history;
|
||||
};
|
||||
|
||||
struct View {
|
||||
@@ -91,7 +92,6 @@ WindowID InfoBarWindowID = {0};
|
||||
Array<Buffer> Buffers = {};
|
||||
Array<View> Views = {};
|
||||
Array<Window> Windows = {};
|
||||
WindowID ActiveWindow = {};
|
||||
|
||||
float MenuFontSize;
|
||||
Font MenuFont;
|
||||
@@ -105,9 +105,9 @@ Int FontCharSpacing;
|
||||
Int FrameID;
|
||||
Int LastFrameIDWhenScrolled;
|
||||
|
||||
WindowID LastActiveWindow;
|
||||
Int LastFrameIDWhenSwitchedActiveWindow;
|
||||
String InfoBarErrorMessage;
|
||||
Array<WindowID> WindowSwitchHistory;
|
||||
WindowID ActiveWindow = {};
|
||||
|
||||
String16 EvalString(Allocator allocator, String16 string16);
|
||||
Rect2I GetVisibleCells(Window &window);
|
||||
|
||||
Reference in New Issue
Block a user