mudgangster

Tiny, scriptable MUD client
Log | Files | Refs | README

commit c2ebebf65776bd74bdacd97d18de328709f34b34
parent fc03b528f85e86e937e46897242f5868b199d7d5
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun,  3 May 2020 16:23:28 +0300

Freeze scrolling when selecting text

Diffstat:
Msrc/textbox.cc | 10++++++++--
Msrc/textbox.h | 1+
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/textbox.cc b/src/textbox.cc @@ -64,9 +64,11 @@ void textbox_add( TextBox * tb, const char * str, size_t len, Colour fg, Colour } void textbox_newline( TextBox * tb ) { + bool freeze = tb->scroll_offset > 0 || tb->selecting; + if( tb->num_lines < tb->max_lines ) { tb->num_lines++; - if( tb->scroll_offset > 0 ) + if( freeze ) tb->scroll_offset++; else tb->dirty = true; @@ -74,7 +76,7 @@ void textbox_newline( TextBox * tb ) { } tb->head++; - if( tb->scroll_offset > 0 ) + if( freeze ) tb->scroll_offset = min( tb->scroll_offset + 1, tb->num_lines - 1 ); tb->dirty = true; @@ -122,6 +124,7 @@ void textbox_mouse_down( TextBox * tb, int window_x, int window_y ) { tb->selecting = true; tb->selecting_and_mouse_moved = false; + tb->scroll_down_after_selecting = tb->scroll_offset == 0; tb->selection_start_col = col; tb->selection_start_row = row; tb->selection_end_col = col; @@ -257,6 +260,9 @@ void textbox_mouse_up( TextBox * tb, int window_x, int window_y ) { tb->selecting = false; tb->dirty = true; + + if( tb->scroll_down_after_selecting ) + tb->scroll_offset = 0; } void textbox_set_pos( TextBox * tb, int x, int y ) { diff --git a/src/textbox.h b/src/textbox.h @@ -27,6 +27,7 @@ struct TextBox { bool selecting; bool selecting_and_mouse_moved; + bool scroll_down_after_selecting; int selection_start_col, selection_start_row; int selection_end_col, selection_end_row;