Scrolling even when window inactive
This commit is contained in:
@@ -162,10 +162,9 @@ void Command_EvalLua(View *view) {
|
|||||||
Command_EvalLua(view, string);
|
Command_EvalLua(view, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleActiveWindowBindings(Window *window) {
|
void HandleActiveWindowBindings(Window *window, bool *update_scroll) {
|
||||||
View &view = *GetActiveView(window);
|
View &view = *GetActiveView(window);
|
||||||
Buffer *buffer = GetBuffer(view.buffer_id);
|
Buffer *buffer = GetBuffer(view.buffer_id);
|
||||||
Caret main_caret_on_begin_frame = view.carets[0];
|
|
||||||
if (CtrlPress(KEY_F2)) {
|
if (CtrlPress(KEY_F2)) {
|
||||||
LoadBigLine(buffer);
|
LoadBigLine(buffer);
|
||||||
} else if (Press(KEY_F2)) {
|
} else if (Press(KEY_F2)) {
|
||||||
@@ -294,10 +293,9 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
Command_Replace(&view, L"");
|
Command_Replace(&view, L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dont_update_scroll = false;
|
|
||||||
if (CtrlPress(KEY_A)) {
|
if (CtrlPress(KEY_A)) {
|
||||||
Command_SelectEntireBuffer(&view);
|
Command_SelectEntireBuffer(&view);
|
||||||
dont_update_scroll = true;
|
*update_scroll = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShiftPress(KEY_PAGE_UP)) {
|
if (ShiftPress(KEY_PAGE_UP)) {
|
||||||
@@ -509,10 +507,21 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void HandleWindowBindings(Window *window) {
|
||||||
|
ProfileFunction();
|
||||||
|
View *view = GetActiveView(window);
|
||||||
|
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||||
|
bool update_scroll = true;
|
||||||
|
|
||||||
|
if (IsActive(window)) {
|
||||||
|
HandleActiveWindowBindings(window, &update_scroll);
|
||||||
|
}
|
||||||
|
|
||||||
// Scrolling with caret
|
// Scrolling with caret
|
||||||
if (!AreEqual(main_caret_on_begin_frame, view.carets[0]) && !dont_update_scroll) {
|
if (!AreEqual(view->main_caret_on_begin_frame, view->carets[0]) && update_scroll) {
|
||||||
Caret c = view.carets[0];
|
Caret c = view->carets[0];
|
||||||
Int front = GetFront(c);
|
Int front = GetFront(c);
|
||||||
XY xy = PosToXY(*buffer, front);
|
XY xy = PosToXY(*buffer, front);
|
||||||
|
|
||||||
@@ -524,43 +533,34 @@ void HandleActiveWindowBindings(Window *window) {
|
|||||||
if (xy.line >= visible.max.y - 2) {
|
if (xy.line >= visible.max.y - 2) {
|
||||||
Int set_view_at_line = xy.line - (visible_cells.y - 1);
|
Int set_view_at_line = xy.line - (visible_cells.y - 1);
|
||||||
Int cut_off_y = Max((Int)0, visible_size.y - rect_size.y);
|
Int cut_off_y = Max((Int)0, visible_size.y - rect_size.y);
|
||||||
view.scroll.y = (set_view_at_line * FontLineSpacing) + cut_off_y;
|
view->scroll.y = (set_view_at_line * FontLineSpacing) + cut_off_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xy.line < visible.min.y + 1) {
|
if (xy.line < visible.min.y + 1) {
|
||||||
view.scroll.y = xy.line * FontLineSpacing;
|
view->scroll.y = xy.line * FontLineSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xy.col >= visible.max.x - 1) {
|
if (xy.col >= visible.max.x - 1) {
|
||||||
Int set_view_at_line = xy.col - (visible_cells.x - 1);
|
Int set_view_at_line = xy.col - (visible_cells.x - 1);
|
||||||
Int cut_off_x = Max((Int)0, visible_size.x - rect_size.x);
|
Int cut_off_x = Max((Int)0, visible_size.x - rect_size.x);
|
||||||
view.scroll.x = (set_view_at_line * FontCharSpacing) + cut_off_x;
|
view->scroll.x = (set_view_at_line * FontCharSpacing) + cut_off_x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xy.col <= visible.min.x) {
|
if (xy.col <= visible.min.x) {
|
||||||
view.scroll.x = xy.col * FontCharSpacing;
|
view->scroll.x = xy.col * FontCharSpacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void HandleWindowBindings(Window *window) {
|
|
||||||
ProfileFunction();
|
|
||||||
View &view = *GetActiveView(window);
|
|
||||||
Buffer *buffer = GetBuffer(view.buffer_id);
|
|
||||||
bool is_active = IsActive(window);
|
|
||||||
|
|
||||||
if (is_active) HandleActiveWindowBindings(window);
|
|
||||||
|
|
||||||
// Clip scroll
|
// Clip scroll
|
||||||
{
|
{
|
||||||
ProfileScope(clip_scroll);
|
ProfileScope(clip_scroll);
|
||||||
Int last_line = LastLine(*buffer);
|
Int last_line = LastLine(*buffer);
|
||||||
view.scroll.y = Clamp(view.scroll.y, (Int)0, Max((Int)0, (last_line - 1) * FontLineSpacing));
|
view->scroll.y = Clamp(view->scroll.y, (Int)0, Max((Int)0, (last_line - 1) * FontLineSpacing));
|
||||||
|
|
||||||
// @note:
|
// @note:
|
||||||
// GetCharCountOfLongestLine is a bottleneck, there is probably an algorithm for
|
// GetCharCountOfLongestLine is a bottleneck, there is probably an algorithm for
|
||||||
// calculating this value incrementally but do we even need X scrollbar or x clipping?
|
// calculating this value incrementally but do we even need X scrollbar or x clipping?
|
||||||
view.scroll.x = ClampBottom(view.scroll.x, (Int)0);
|
view->scroll.x = ClampBottom(view->scroll.x, (Int)0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,6 +575,8 @@ void ChangeActiveWindowAndScroll(Array<Int> &order) {
|
|||||||
if (!window->visible) continue;
|
if (!window->visible) continue;
|
||||||
|
|
||||||
View *view = GetActiveView(window);
|
View *view = GetActiveView(window);
|
||||||
|
view->main_caret_on_begin_frame = view->carets[0];
|
||||||
|
|
||||||
Vec2 mouse = GetMousePosition();
|
Vec2 mouse = GetMousePosition();
|
||||||
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
|
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window->total_rect));
|
||||||
if (mouse_in_window) {
|
if (mouse_in_window) {
|
||||||
@@ -600,27 +602,21 @@ void ReplaceInfobarData() {
|
|||||||
View *view = GetView(window->active_view);
|
View *view = GetView(window->active_view);
|
||||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
Buffer *buffer = GetBuffer(view->buffer_id);
|
||||||
|
|
||||||
XY xy = {};
|
Window *last_window = GetWindow(GetLastActiveWindow());
|
||||||
String name = {};
|
View *last_view = GetActiveView(last_window);
|
||||||
{
|
Buffer *last_buffer = GetBuffer(last_view->buffer_id);
|
||||||
Window *window = GetWindow(GetLastActiveWindow());
|
|
||||||
View *view = GetActiveView(window);
|
|
||||||
Buffer *buffer = GetBuffer(view->buffer_id);
|
|
||||||
Scratch scratch;
|
Scratch scratch;
|
||||||
Caret caret = view->carets[0];
|
Caret caret = last_view->carets[0];
|
||||||
xy = PosToXY(*buffer, GetFront(caret));
|
XY xy = PosToXY(*last_buffer, GetFront(caret));
|
||||||
name = buffer->name;
|
String name = last_buffer->name;
|
||||||
}
|
|
||||||
|
|
||||||
Scratch scratch;
|
|
||||||
String16 buffer_string = GetString(*buffer);
|
String16 buffer_string = GetString(*buffer);
|
||||||
|
|
||||||
Range replace_range = {0, buffer->len};
|
Range replace_range = {0, buffer->len};
|
||||||
if (!Seek(buffer_string, L"|", &replace_range.max)) {
|
if (!Seek(buffer_string, L"|", &replace_range.max)) {
|
||||||
ReplaceText(buffer, GetEndAsRange(*buffer), L"|");
|
ReplaceText(buffer, GetEndAsRange(*buffer), L"|");
|
||||||
}
|
}
|
||||||
|
|
||||||
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name));
|
String s = Format(scratch, "line: %5lld col: %5lld name: %.*s wid: %d vid: %d bid: %d", (long long)xy.line + 1ll, (long long)xy.col + 1ll, FmtString(name), (int)last_window->id.id, (int)last_view->id.id, (int)last_buffer->id.id);
|
||||||
String16 string = ToString16(scratch, s);
|
String16 string = ToString16(scratch, s);
|
||||||
ReplaceText(buffer, replace_range, string);
|
ReplaceText(buffer, replace_range, string);
|
||||||
Command_SelectRangeOneCursor(view, {});
|
Command_SelectRangeOneCursor(view, {});
|
||||||
|
|||||||
@@ -43,7 +43,10 @@ struct View {
|
|||||||
BufferID buffer_id;
|
BufferID buffer_id;
|
||||||
Vec2I scroll;
|
Vec2I scroll;
|
||||||
Array<Caret> carets;
|
Array<Caret> carets;
|
||||||
|
|
||||||
|
// window | view
|
||||||
Range selection_anchor;
|
Range selection_anchor;
|
||||||
|
Caret main_caret_on_begin_frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Window {
|
struct Window {
|
||||||
|
|||||||
Reference in New Issue
Block a user