Skip to content

Commit 5e34509

Browse files
committed
Fix merge
1 parent 7348c77 commit 5e34509

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

src/ex_getln.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,34 @@ cmdline_at_end()
25062506
}
25072507
#endif
25082508

2509+
#if defined(FEAT_GUI_MACVIM)
2510+
/*
2511+
* Return the virtual column number at the current cursor position.
2512+
* This is used by the IM code to obtain the start of the preedit string.
2513+
*/
2514+
colnr_T
2515+
cmdline_getvcol_cursor()
2516+
{
2517+
if (ccline.cmdbuff == NULL || ccline.cmdpos > ccline.cmdlen)
2518+
return MAXCOL;
2519+
2520+
# ifdef FEAT_MBYTE
2521+
if (has_mbyte)
2522+
{
2523+
colnr_T col;
2524+
int i = 0;
2525+
2526+
for (col = 0; i < ccline.cmdpos; ++col)
2527+
i += (*mb_ptr2len)(ccline.cmdbuff + i);
2528+
2529+
return col;
2530+
}
2531+
else
2532+
# endif
2533+
return ccline.cmdpos;
2534+
}
2535+
#endif
2536+
25092537
/*
25102538
* Allocate a new command line buffer.
25112539
* Assigns the new buffer to ccline.cmdbuff and ccline.cmdbufflen.

src/globals.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,16 @@ EXTERN GtkIMContext *xic INIT(= NULL);
876876
# else
877877
EXTERN XIC xic INIT(= NULL);
878878
# endif
879+
# else
880+
/*
881+
* Start and end column of the preedit area in virtual columns from the start
882+
* of the text line. When there is no preedit area they are set to MAXCOL.
883+
* "preedit_end_col" is needed for coloring the preedited string. Drawing the
884+
* color between "preedit_start_col" and curpos did not work, because some XIM
885+
* set the cursor position to the first char of the string.
886+
*/
887+
EXTERN colnr_T preedit_start_col INIT(= MAXCOL);
888+
EXTERN colnr_T preedit_end_col INIT(= MAXCOL);
879889
# endif
880890
# ifdef FEAT_GUI
881891
EXTERN guicolor_T xim_fg_color INIT(= INVALCOLOR);

src/mbyte.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4453,6 +4453,20 @@ iconv_end()
44534453
# if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM) || defined(PROTO)
44544454
static int xim_has_preediting INIT(= FALSE); /* IM current status */
44554455

4456+
# ifdef FEAT_GUI_MACVIM
4457+
/*
4458+
* Set preedit_start_col to the current cursor position.
4459+
*/
4460+
static void
4461+
init_preedit_start_col(void)
4462+
{
4463+
if (State & CMDLINE)
4464+
preedit_start_col = cmdline_getvcol_cursor();
4465+
else if (curwin != NULL)
4466+
getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL);
4467+
}
4468+
# endif
4469+
44564470
static int im_is_active = FALSE; /* IM is enabled for current mode */
44574471
static int preedit_is_active = FALSE;
44584472
static int im_preedit_start = 0; /* start offset in characters */
@@ -4756,6 +4770,14 @@ im_commit_cb(GtkIMContext *context UNUSED,
47564770
if (add_to_input)
47574771
im_add_to_input((char_u *)str, slen);
47584772

4773+
# ifdef FEAT_GUI_MACVIM
4774+
/* Inserting chars while "im_is_active" is set does not cause a change of
4775+
* buffer. When the chars are committed the buffer must be marked as
4776+
* changed. */
4777+
if (!commit_with_preedit)
4778+
preedit_start_col = MAXCOL;
4779+
# endif
4780+
47594781
if (gtk_main_level() > 0)
47604782
gtk_main_quit();
47614783
}
@@ -4799,6 +4821,9 @@ im_preedit_end_macvim()
47994821
im_delete_preedit();
48004822

48014823
/* Indicate that preediting has finished */
4824+
# ifdef FEAT_GUI_MACVIM
4825+
preedit_start_col = MAXCOL;
4826+
# endif
48024827
xim_has_preediting = FALSE;
48034828

48044829
#if 0
@@ -4882,6 +4907,8 @@ im_preedit_changed_macvim(char *preedit_string, int start_index, int cursor_inde
48824907
gtk_im_context_get_preedit_string(context,
48834908
&preedit_string, NULL,
48844909
&cursor_index);
4910+
# else
4911+
im_preedit_start = start_index;
48854912
# endif
48864913

48874914
#ifdef XIM_DEBUG
@@ -4890,8 +4917,38 @@ im_preedit_changed_macvim(char *preedit_string, int start_index, int cursor_inde
48904917

48914918
g_return_if_fail(preedit_string != NULL); /* just in case */
48924919

4920+
# ifdef FEAT_GUI_MACVIM
4921+
/* If preedit_start_col is MAXCOL set it to the current cursor position. */
4922+
if (preedit_start_col == MAXCOL && preedit_string[0] != '\0')
4923+
{
4924+
xim_has_preediting = TRUE;
4925+
4926+
/* Urgh, this breaks if the input buffer isn't empty now */
4927+
init_preedit_start_col();
4928+
}
4929+
else if (cursor_index == 0 && preedit_string[0] == '\0')
4930+
{
4931+
xim_has_preediting = FALSE;
4932+
4933+
/* If at the start position (after typing backspace)
4934+
* preedit_start_col must be reset. */
4935+
preedit_start_col = MAXCOL;
4936+
}
4937+
# endif
4938+
48934939
im_delete_preedit();
48944940

4941+
# ifdef FEAT_GUI_MACVIM
4942+
/*
4943+
* Compute the end of the preediting area: "preedit_end_col".
4944+
* According to the documentation of gtk_im_context_get_preedit_string(),
4945+
* the cursor_pos output argument returns the offset in bytes. This is
4946+
* unfortunately not true -- real life shows the offset is in characters,
4947+
* and the GTK+ source code agrees with me. Will file a bug later.
4948+
*/
4949+
if (preedit_start_col != MAXCOL)
4950+
preedit_end_col = preedit_start_col;
4951+
# endif
48954952
str = (char_u *)preedit_string;
48964953
for (p = str, i = 0; *p != NUL; p += utf_byte2len(*p), ++i)
48974954
{
@@ -4916,6 +4973,10 @@ im_preedit_changed_macvim(char *preedit_string, int start_index, int cursor_inde
49164973
* composing characters are not counted even if p_deco is set. */
49174974
++num_move_back;
49184975
}
4976+
# ifdef FEAT_GUI_MACVIM
4977+
if (preedit_start_col != MAXCOL)
4978+
preedit_end_col += utf_ptr2cells(p);
4979+
# endif
49194980
}
49204981

49214982
if (p > str)
@@ -4991,6 +5052,9 @@ im_shutdown(void)
49915052
# endif
49925053
im_is_active = FALSE;
49935054
im_commit_handler_id = 0;
5055+
# ifdef FEAT_GUI_MACVIM
5056+
preedit_start_col = MAXCOL;
5057+
# endif
49945058
xim_has_preediting = FALSE;
49955059
}
49965060

@@ -5149,6 +5213,9 @@ xim_reset(void)
51495213
}
51505214
# endif
51515215

5216+
# ifdef FEAT_GUI_MACVIM
5217+
preedit_start_col = MAXCOL;
5218+
# endif
51525219
xim_has_preediting = FALSE;
51535220
}
51545221

src/proto/ex_getln.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ char_u *getexline __ARGS((int c, void *cookie, int indent));
99
char_u *getexmodeline __ARGS((int promptc, void *cookie, int indent));
1010
int cmdline_overstrike __ARGS((void));
1111
int cmdline_at_end __ARGS((void));
12+
colnr_T cmdline_getvcol_cursor __ARGS((void));
1213
void free_cmdline_buf __ARGS((void));
1314
void putcmdline __ARGS((int c, int shift));
1415
void unputcmdline __ARGS((void));

src/proto/mbyte.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void im_set_active __ARGS((int active));
7676
void xim_set_focus __ARGS((int focus));
7777
void im_set_position __ARGS((int row, int col));
7878
void xim_set_preedit __ARGS((void));
79+
int im_get_feedback_attr __ARGS((int col));
7980
void xim_init __ARGS((void));
8081
void im_shutdown __ARGS((void));
8182
int im_xim_isvalid_imactivate __ARGS((void));

src/screen.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,6 +2985,10 @@ win_line(wp, lnum, startrow, endrow, nochange)
29852985
#endif
29862986
#define WL_LINE WL_SBR + 1 /* text in the line */
29872987
int draw_state = WL_START; /* what to draw next */
2988+
#if defined(FEAT_GUI_MACVIM)
2989+
int feedback_col = 0;
2990+
int feedback_old_attr = -1;
2991+
#endif
29882992

29892993
#ifdef FEAT_CONCEAL
29902994
int syntax_flags = 0;
@@ -4858,6 +4862,39 @@ win_line(wp, lnum, startrow, endrow, nochange)
48584862
&& !attr_pri)
48594863
char_attr = extra_attr;
48604864

4865+
#if defined(FEAT_GUI_MACVIM)
4866+
if (
4867+
lnum == wp->w_cursor.lnum
4868+
&& (State & INSERT)
4869+
&& im_is_preediting()
4870+
&& draw_state == WL_LINE)
4871+
{
4872+
colnr_T tcol;
4873+
4874+
if (preedit_end_col == MAXCOL)
4875+
getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
4876+
else
4877+
tcol = preedit_end_col;
4878+
if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
4879+
{
4880+
if (feedback_old_attr < 0)
4881+
{
4882+
feedback_col = 0;
4883+
feedback_old_attr = char_attr;
4884+
}
4885+
char_attr = im_get_feedback_attr(feedback_col);
4886+
if (char_attr < 0)
4887+
char_attr = feedback_old_attr;
4888+
feedback_col++;
4889+
}
4890+
else if (feedback_old_attr >= 0)
4891+
{
4892+
char_attr = feedback_old_attr;
4893+
feedback_old_attr = -1;
4894+
feedback_col = 0;
4895+
}
4896+
}
4897+
#endif
48614898
/*
48624899
* Handle the case where we are in column 0 but not on the first
48634900
* character of the line and the user wants us to show us a

0 commit comments

Comments
 (0)