commit 6c74e94995714f9ccd77231afdd6c0a8bd86cbe5
parent a0fe99742a657cdc5fa6e742409806ddf6ea2d61
Author: Michael Savage <mikejsavage@gmail.com>
Date: Sun, 3 May 2020 12:51:43 +0300
Don't start selecting until you move the mouse
Diffstat:
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/textbox.cc b/src/textbox.cc
@@ -120,6 +120,7 @@ void textbox_mouse_down( TextBox * tb, int window_x, int window_y ) {
int col = x / fw;
tb->selecting = true;
+ tb->selecting_and_mouse_moved = false;
tb->selection_start_col = col;
tb->selection_start_row = row;
tb->selection_end_col = col;
@@ -145,11 +146,18 @@ void textbox_mouse_move( TextBox * tb, int window_x, int window_y ) {
tb->selection_end_row = row;
tb->dirty = true;
}
+ else if( !tb->selecting_and_mouse_moved ) {
+ tb->dirty = true;
+ }
+
+ tb->selecting_and_mouse_moved = true;
}
void textbox_mouse_up( TextBox * tb, int window_x, int window_y ) {
- if( !tb->selecting )
+ if( !tb->selecting || !tb->selecting_and_mouse_moved ) {
+ tb->selecting = false;
return;
+ }
int fw, fh;
ui_get_font_size( &fw, &fh );
@@ -338,7 +346,7 @@ void textbox_draw( TextBox * tb ) {
bool bold_fg = bold;
bool bold_bg = false;
- if( tb->selecting ) {
+ if( tb->selecting && tb->selecting_and_mouse_moved ) {
if( inside_selection( col, rows_drawn + line_rows - row - 1, tb->selection_start_col, tb->selection_start_row, tb->selection_end_col, tb->selection_end_row ) ) {
swap( fg, bg );
swap( bold_fg, bold_bg );
diff --git a/src/textbox.h b/src/textbox.h
@@ -26,6 +26,7 @@ struct TextBox {
size_t scroll_offset;
bool selecting;
+ bool selecting_and_mouse_moved;
int selection_start_col, selection_start_row;
int selection_end_col, selection_end_row;