1010
1111#include "vim.h"
1212
13- #if defined(FEAT_BEVAL ) || defined(PROTO )
14-
13+ #if defined(FEAT_BEVAL ) || defined(FEAT_TEXT_PROP ) || defined(PROT )
1514/*
16- * Get the text and position to be evaluated for "beval".
17- * If "getword" is true the returned text is not the whole line but the
18- * relevant word in allocated memory.
19- * Returns OK or FAIL.
15+ * Find text under the mouse position "row" / "col".
16+ * If "getword" is TRUE the returned text in "*textp" is not the whole line but
17+ * the relevant word in allocated memory.
18+ * Return OK if found.
19+ * Return FAIL if not found, no text at the mouse position.
2020 */
2121 int
22- get_beval_info (
23- BalloonEval * beval ,
24- int getword ,
25- win_T * * winp ,
26- linenr_T * lnump ,
27- char_u * * textp ,
28- int * colp )
22+ find_word_under_cursor (
23+ int mouserow ,
24+ int mousecol ,
25+ int getword ,
26+ int flags , // flags for find_ident_at_pos()
27+ win_T * * winp , // can be NULL
28+ linenr_T * lnump , // can be NULL
29+ char_u * * textp ,
30+ int * colp , // column where mouse hovers, can be NULL
31+ int * startcolp ) // column where text starts, can be NULL
2932{
33+ int row = mouserow ;
34+ int col = mousecol ;
35+ int scol ;
3036 win_T * wp ;
31- int row , col ;
3237 char_u * lbuf ;
3338 linenr_T lnum ;
3439
3540 * textp = NULL ;
36- # ifdef FEAT_BEVAL_TERM
37- # ifdef FEAT_GUI
38- if (!gui .in_use )
39- # endif
40- {
41- row = mouse_row ;
42- col = mouse_col ;
43- }
44- # endif
45- # ifdef FEAT_GUI
46- if (gui .in_use )
47- {
48- row = Y_2_ROW (beval -> y );
49- col = X_2_COL (beval -> x );
50- }
51- #endif
5241 wp = mouse_find_win (& row , & col , FAIL_POPUP );
5342 if (wp != NULL && row >= 0 && row < wp -> w_height && col < wp -> w_width )
5443 {
55- /* Found a window and the cursor is in the text. Now find the line
56- * number. */
44+ // Found a window and the cursor is in the text. Now find the line
45+ // number.
5746 if (!mouse_comp_pos (wp , & row , & col , & lnum ))
5847 {
59- /* Not past end of the file. */
48+ // Not past end of the file.
6049 lbuf = ml_get_buf (wp -> w_buffer , lnum , FALSE);
6150 if (col <= win_linetabsize (wp , lbuf , (colnr_T )MAXCOL ))
6251 {
63- /* Not past end of line. */
52+ // Not past end of line.
6453 if (getword )
6554 {
66- /* For Netbeans we get the relevant part of the line
67- * instead of the whole line. */
55+ // For Netbeans we get the relevant part of the line
56+ // instead of the whole line.
6857 int len ;
6958 pos_T * spos = NULL , * epos = NULL ;
7059
@@ -93,9 +82,9 @@ get_beval_info(
9382 ? col <= (int )epos -> col
9483 : lnum < epos -> lnum ))
9584 {
96- /* Visual mode and pointing to the line with the
97- * Visual selection: return selected text, with a
98- * maximum of one line. */
85+ // Visual mode and pointing to the line with the
86+ // Visual selection: return selected text, with a
87+ // maximum of one line.
9988 if (spos -> lnum != epos -> lnum || spos -> col == epos -> col )
10089 return FAIL ;
10190
@@ -109,32 +98,78 @@ get_beval_info(
10998 }
11099 else
111100 {
112- /* Find the word under the cursor. */
101+ // Find the word under the cursor.
113102 ++ emsg_off ;
114- len = find_ident_at_pos (wp , lnum , (colnr_T )col , & lbuf ,
115- FIND_IDENT + FIND_STRING + FIND_EVAL );
103+ len = find_ident_at_pos (wp , lnum , (colnr_T )col ,
104+ & lbuf , & scol , flags );
116105 -- emsg_off ;
117106 if (len == 0 )
118107 return FAIL ;
119108 lbuf = vim_strnsave (lbuf , len );
120109 }
121110 }
122111
123- * winp = wp ;
124- * lnump = lnum ;
112+ if (winp != NULL )
113+ * winp = wp ;
114+ if (lnump != NULL )
115+ * lnump = lnum ;
125116 * textp = lbuf ;
126- * colp = col ;
127- #ifdef FEAT_VARTABS
128- vim_free (beval -> vts );
129- beval -> vts = tabstop_copy (wp -> w_buffer -> b_p_vts_array );
130- if (wp -> w_buffer -> b_p_vts_array != NULL && beval -> vts == NULL )
131- return FAIL ;
132- #endif
133- beval -> ts = wp -> w_buffer -> b_p_ts ;
117+ if (colp != NULL )
118+ * colp = col ;
119+ if (startcolp != NULL )
120+ * startcolp = scol ;
134121 return OK ;
135122 }
136123 }
137124 }
125+ return FAIL ;
126+ }
127+ #endif
128+
129+ #if defined(FEAT_BEVAL ) || defined(PROTO )
130+
131+ /*
132+ * Get the text and position to be evaluated for "beval".
133+ * If "getword" is TRUE the returned text is not the whole line but the
134+ * relevant word in allocated memory.
135+ * Returns OK or FAIL.
136+ */
137+ int
138+ get_beval_info (
139+ BalloonEval * beval ,
140+ int getword ,
141+ win_T * * winp ,
142+ linenr_T * lnump ,
143+ char_u * * textp ,
144+ int * colp )
145+ {
146+ int row = mouse_row ;
147+ int col = mouse_col ;
148+
149+ # ifdef FEAT_GUI
150+ if (gui .in_use )
151+ {
152+ row = Y_2_ROW (beval -> y );
153+ col = X_2_COL (beval -> x );
154+ }
155+ #endif
156+ if (find_word_under_cursor (row , col , getword ,
157+ FIND_IDENT + FIND_STRING + FIND_EVAL ,
158+ winp , lnump , textp , colp , NULL ) == OK )
159+ {
160+ #ifdef FEAT_VARTABS
161+ vim_free (beval -> vts );
162+ beval -> vts = tabstop_copy ((* winp )-> w_buffer -> b_p_vts_array );
163+ if ((* winp )-> w_buffer -> b_p_vts_array != NULL && beval -> vts == NULL )
164+ {
165+ if (getword )
166+ vim_free (* textp );
167+ return FAIL ;
168+ }
169+ #endif
170+ beval -> ts = (* winp )-> w_buffer -> b_p_ts ;
171+ return OK ;
172+ }
138173
139174 return FAIL ;
140175}
@@ -264,11 +299,15 @@ general_beval_cb(BalloonEval *beval, int state UNUSED)
264299
265300 set_vim_var_string (VV_BEVAL_TEXT , NULL , -1 );
266301 if (result != NULL && result [0 ] != NUL )
267- {
268302 post_balloon (beval , result , NULL );
269- recursive = FALSE;
270- return ;
271- }
303+
304+ // The 'balloonexpr' evaluation may show something on the screen
305+ // that requires a screen update.
306+ if (must_redraw )
307+ redraw_after_callback (FALSE);
308+
309+ recursive = FALSE;
310+ return ;
272311 }
273312 }
274313#endif
0 commit comments