From 28edd8ddaed980cf5a592fe78a83fcfd83c6baca Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Fri, 19 Feb 2016 12:28:42 +0200
Subject: [PATCH] fixup! WInput: use the new mouse API.
---
lib/widget/input.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/widget/input.c b/lib/widget/input.c
index 3c07537..c4f0384 100644
a
|
b
|
input_destroy (WInput * in) |
908 | 908 | |
909 | 909 | /* --------------------------------------------------------------------------------------------- */ |
910 | 910 | |
911 | | static void |
912 | | input_update_point (WInput * in, int pos) |
| 911 | /** |
| 912 | * Calculates the buffer index (aka "point") corresponding to some screen coordinate. |
| 913 | */ |
| 914 | static int |
| 915 | input_screen_to_point (WInput * in, int x) |
913 | 916 | { |
914 | | pos += in->term_first_shown; |
| 917 | x += in->term_first_shown; |
915 | 918 | |
916 | | if (pos < str_term_width1 (in->buffer)) |
917 | | in->point = str_column_to_pos (in->buffer, pos); |
| 919 | if (x < 0) |
| 920 | return 0; |
| 921 | else if (x < str_term_width1 (in->buffer)) |
| 922 | return str_column_to_pos (in->buffer, x); |
918 | 923 | else |
919 | | in->point = str_length (in->buffer); |
| 924 | return str_length (in->buffer); |
920 | 925 | } |
921 | 926 | |
922 | 927 | /* --------------------------------------------------------------------------------------------- */ |
… |
… |
input_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) |
933 | 938 | case MSG_MOUSE_DOWN: |
934 | 939 | dlg_select_widget (w); |
935 | 940 | in->first = FALSE; |
936 | | input_mark_cmd (in, FALSE); |
937 | 941 | |
938 | 942 | if (event->x >= w->cols - HISTORY_BUTTON_WIDTH && should_show_history_button (in)) |
939 | 943 | do_show_hist (in); |
940 | 944 | else |
941 | 945 | { |
942 | | input_update_point (in, event->x); |
| 946 | input_mark_cmd (in, FALSE); |
| 947 | input_set_point (in, input_screen_to_point (in, event->x)); |
943 | 948 | /* save point for the possible following MSG_MOUSE_DRAG action */ |
944 | 949 | prev_point = in->point; |
945 | 950 | } |
946 | | input_update (in, TRUE); |
947 | 951 | break; |
948 | 952 | |
949 | 953 | case MSG_MOUSE_DRAG: |
950 | | /* start point: set marker using point before first GPM_DRAG action */ |
| 954 | /* start point: set marker using point before first MSG_MOUSE_DRAG action */ |
951 | 955 | if (in->mark < 0) |
952 | 956 | in->mark = prev_point; |
953 | 957 | |
954 | | input_update_point (in, event->x); |
955 | | input_update (in, TRUE); |
| 958 | input_set_point (in, input_screen_to_point (in, event->x)); |
956 | 959 | break; |
957 | 960 | |
958 | 961 | default: |