Skip to content

Commit 7255540

Browse files
committed
Don't scroll past the edges and reset scroll position in certain cases
1 parent d118e73 commit 7255540

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

kitty/keys.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ on_key_input(int key, int scancode, int action, int mods, const char* text, int
176176
}
177177
if (screen->scrolled_by && action == GLFW_PRESS && !is_modifier_key(key)) {
178178
screen_history_scroll(screen, SCROLL_FULL, false); // scroll back to bottom
179+
pixel_scroll(screen, 0);
179180
}
180181
bool ok_to_send = action == GLFW_PRESS || action == GLFW_REPEAT || screen->modes.mEXTENDED_KEYBOARD;
181182
if (ok_to_send) {

kitty/mouse.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ drag_scroll(Window *w, OSWindow *frame) {
187187
Screen *screen = w->render_data.screen;
188188
if (screen->linebuf == screen->main_linebuf) {
189189
screen_history_scroll(screen, SCROLL_LINE, upwards);
190+
pixel_scroll(screen, 0);
190191
update_drag(false, w, false, 0);
191192
frame->last_mouse_activity_at = monotonic();
192193
if (mouse_cursor_shape != ARROW) {
@@ -620,11 +621,27 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags) {
620621
if (s == 0 && yoffset != 0) s = yoffset > 0 ? 1 : -1;
621622
}
622623
bool upwards = s > 0;
624+
int pixels = global_state.callback_os_window->pending_scroll_pixels;
625+
//printf("asdf %f\n", pixels);
623626
if (screen->linebuf == screen->main_linebuf) {
624627
screen_history_scroll(screen, abs(s), upwards);
625-
printf("asdf %f\n", global_state.callback_os_window->pending_scroll_pixels);
626-
pixel_scroll(screen, global_state.callback_os_window->pending_scroll_pixels);
628+
if (screen->scrolled_by != 0) {
629+
if (screen->scrolled_by != screen->historybuf->count) {
630+
pixel_scroll(screen, pixels);
631+
} else {
632+
if (pixels < 0) pixel_scroll(screen, pixels);
633+
else pixel_scroll(screen, 0);
634+
}
635+
} else {
636+
if (screen->scrolled_by != screen->historybuf->count) {
637+
if (pixels > 0) pixel_scroll(screen, pixels);
638+
else pixel_scroll(screen, 0);
639+
} else {
640+
pixel_scroll(screen, 0);
641+
}
642+
}
627643
} else {
644+
pixel_scroll(screen, 0);
628645
if (screen->modes.mouse_tracking_mode) {
629646
int sz = encode_mouse_event(w, upwards ? GLFW_MOUSE_BUTTON_4 : GLFW_MOUSE_BUTTON_5, PRESS, 0);
630647
if (sz > 0) {

kitty/screen.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ screen_toggle_screen_buffer(Screen *self) {
590590
self->grman = self->main_grman;
591591
}
592592
screen_history_scroll(self, SCROLL_FULL, false);
593+
pixel_scroll(self, 0);
593594
self->is_dirty = true;
594595
self->selection = EMPTY_SELECTION;
595596
}
@@ -2030,6 +2031,7 @@ static PyObject*
20302031
scroll(Screen *self, PyObject *args) {
20312032
int amt, upwards;
20322033
if (!PyArg_ParseTuple(args, "ip", &amt, &upwards)) return NULL;
2034+
pixel_scroll(self, 0);
20332035
if (screen_history_scroll(self, amt, upwards)) { Py_RETURN_TRUE; }
20342036
Py_RETURN_FALSE;
20352037
}

0 commit comments

Comments
 (0)