Fix view centering

This commit is contained in:
Krzosa Karol
2025-12-31 10:34:11 +01:00
parent f8f9e33032
commit 0921054b6e
4 changed files with 16 additions and 6 deletions

View File

@@ -4,8 +4,6 @@
Use session 3:
- Maybe status view, commit changes (like to buffer name or line) on enter?
- Upload sublime settings to git and also install script / update config script
How to go about search/replace, opening code and other considerations
- We can use sed + find to search and replace, the automatic reopen should do the job
@@ -17,7 +15,6 @@ How to go about search/replace, opening code and other considerations
Use session 2
- Need configs I can't change browser or vcvarsall currently, maybe syntax like :Set InternetBrowser "firefox"
- Tutorial
- When jumping should center the view!!!
Debug session:
- Report errorf - use coroutine dialogs
@@ -49,7 +46,6 @@ Commands TODO:
- Special: non editable, hotkeys don't work etc.
backlog
FEATURE commands for scrolling: center, cursor_at_bottom_of_screen, cursor_at_top
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

@@ -204,6 +204,19 @@ void ReportDebugf(const char *fmt, ...) {
RawAppendf(TraceBuffer, "%S\n", string);
}
void Command_CenterView() {
BSet set = GetBSet(LastActiveLayoutWindowID);
Caret c = set.view->carets[0];
Int front = GetFront(c);
XY xy = PosToXY(set.buffer, front);
Vec2I size = GetSize(set.window->document_rect);
Int y = size.y / 2 / set.window->font->line_spacing;
set.view->scroll.x = 0;
if (xy.line > y) {
set.view->scroll.y = (xy.line) * set.window->font->line_spacing - (size.y / 2);
}
} RegisterCommand(Command_CenterView, "");
void MoveCursorByPageSize(Window *window, int direction, bool shift = false) {
Assert(direction == DIR_UP || direction == DIR_DOWN);
BSet set = GetBSet(window);
@@ -589,6 +602,7 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
for (FileIter it = IterateFiles(scratch, o.path); IsValid(it); Advance(&it)) {
RawAppendf(buffer, "%S\n", it.filename);
}
SelectRange(view, GetBufferBeginAsRange(buffer));
} else {
View *view = WindowOpenBufferView(set.window, o.path);
Buffer *buffer = GetBuffer(view->active_buffer);
@@ -598,7 +612,7 @@ BSet Open(Window *window, String path, String meta, bool set_active = true) {
view->carets[0] = MakeCaret(pos);
}
}
UpdateScroll(set.window, true);
Command_CenterView();
} else if (o.kind == OpenKind_Exec) {
if (set_active) {
NextActiveWindowID = set.window->id;

View File

@@ -119,6 +119,7 @@ void SetMouseCursor(Event event) {
}
SetMouseCursor(SDL_SYSTEM_CURSOR_DEFAULT);
}
void UpdateScroll(Window *window, bool update_caret_scrolling) {
ProfileFunction();
BSet set = GetBSet(window);

View File

@@ -149,7 +149,6 @@ void Command_CommandWindowOpen() {
BSet main = GetBSet(LastActiveLayoutWindowID);
NextActiveWindowID = main.window->id;
OpenCommand(active);
SelectRange(main.view, Range{});
}
void CommandWindowLayout(Rect2I *rect, Int wx, Int wy) {