4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: 'hlsearch' highlighting sometimes disappears when inserting text
12 in PHP code with syntax highlighting. (Marcel Svitalsky)
13 Solution: Don't use pointers to remember where a match was found, use an
14 index. The pointers may become invalid when searching in other
19 *** ../vim-6.3.042/src/screen.c Sun Dec 5 14:57:15 2004
20 --- src/screen.c Tue Dec 7 13:09:09 2004
23 int attr; /* attributes to be used for a match */
24 int attr_cur; /* attributes currently active in win_line() */
25 linenr_T first_lnum; /* first lnum to search for multi-line pat */
26 ! char_u *startp; /* in win_line() points to char where HL starts */
27 ! char_u *endp; /* in win_line() points to char where HL ends */
30 static match_T search_hl; /* used for 'hlsearch' highlight matching */
32 int attr; /* attributes to be used for a match */
33 int attr_cur; /* attributes currently active in win_line() */
34 linenr_T first_lnum; /* first lnum to search for multi-line pat */
35 ! colnr_T startcol; /* in win_line() points to char where HL starts */
36 ! colnr_T endcol; /* in win_line() points to char where HL ends */
39 static match_T search_hl; /* used for 'hlsearch' highlight matching */
43 /* When a change starts above w_topline and the end is below
44 * w_topline, start redrawing at w_topline.
45 ! * If the end of the change is above w_topline: do like no changes was
46 * made, but redraw the first line to find changes in syntax. */
47 if (mod_top != 0 && mod_top < wp->w_topline)
51 /* When a change starts above w_topline and the end is below
52 * w_topline, start redrawing at w_topline.
53 ! * If the end of the change is above w_topline: do like no change was
54 * made, but redraw the first line to find changes in syntax. */
55 if (mod_top != 0 && mod_top < wp->w_topline)
65 if (shl->rm.regprog != NULL)
71 ! shl->startcol = MAXCOL;
72 ! shl->endcol = MAXCOL;
74 if (shl->rm.regprog != NULL)
78 if (shl->lnum != 0 && shl->lnum <= lnum)
80 if (shl->lnum == lnum)
81 ! shl->startp = line + shl->rm.startpos[0].col;
84 if (lnum == shl->lnum + shl->rm.endpos[0].lnum
85 - shl->rm.startpos[0].lnum)
86 ! shl->endp = line + shl->rm.endpos[0].col;
88 ! shl->endp = line + MAXCOL;
89 /* Highlight one character for an empty match. */
90 ! if (shl->startp == shl->endp)
93 ! if (has_mbyte && *shl->endp != NUL)
94 ! shl->endp += (*mb_ptr2len_check)(shl->endp);
99 ! if (shl->startp < ptr) /* match at leftcol */
101 shl->attr_cur = shl->attr;
102 search_attr = shl->attr;
104 if (shl->lnum != 0 && shl->lnum <= lnum)
106 if (shl->lnum == lnum)
107 ! shl->startcol = shl->rm.startpos[0].col;
110 if (lnum == shl->lnum + shl->rm.endpos[0].lnum
111 - shl->rm.startpos[0].lnum)
112 ! shl->endcol = shl->rm.endpos[0].col;
114 ! shl->endcol = MAXCOL;
115 /* Highlight one character for an empty match. */
116 ! if (shl->startcol == shl->endcol)
119 ! if (has_mbyte && line[shl->endcol] != NUL)
120 ! shl->endcol += (*mb_ptr2len_check)(line + shl->endcol);
125 ! if ((long)shl->startcol < v) /* match at leftcol */
127 shl->attr_cur = shl->attr;
128 search_attr = shl->attr;
131 * Do this first for search_hl, then for match_hl, so that
132 * ":match" overrules 'hlsearch'.
137 while (shl->rm.regprog != NULL)
139 ! if (shl->startp != NULL
140 ! && ptr >= shl->startp
141 ! && ptr < shl->endp)
143 shl->attr_cur = shl->attr;
145 ! else if (ptr == shl->endp)
149 - v = (long)(ptr - line);
150 next_search_hl(wp, shl, lnum, (colnr_T)v);
152 /* Need to get the line again, a multi-line regexp
154 * Do this first for search_hl, then for match_hl, so that
155 * ":match" overrules 'hlsearch'.
157 + v = (long)(ptr - line);
161 while (shl->rm.regprog != NULL)
163 ! if (shl->startcol != MAXCOL
164 ! && v >= (long)shl->startcol
165 ! && v < (long)shl->endcol)
167 shl->attr_cur = shl->attr;
169 ! else if (v == (long)shl->endcol)
173 next_search_hl(wp, shl, lnum, (colnr_T)v);
175 /* Need to get the line again, a multi-line regexp
179 if (shl->lnum == lnum)
181 ! shl->startp = line + shl->rm.startpos[0].col;
182 if (shl->rm.endpos[0].lnum == 0)
183 ! shl->endp = line + shl->rm.endpos[0].col;
185 ! shl->endp = line + MAXCOL;
187 ! if (shl->startp == shl->endp)
189 /* highlight empty match, try again after
194 ! (*mb_ptr2len_check)(shl->endp);
200 /* Loop to check if the match starts at the
203 if (shl->lnum == lnum)
205 ! shl->startcol = shl->rm.startpos[0].col;
206 if (shl->rm.endpos[0].lnum == 0)
207 ! shl->endcol = shl->rm.endpos[0].col;
209 ! shl->endcol = MAXCOL;
211 ! if (shl->startcol == shl->endcol)
213 /* highlight empty match, try again after
217 ! shl->endcol += (*mb_ptr2len_check)(line
224 /* Loop to check if the match starts at the
227 && ((area_attr != 0 && vcol == fromcol)
228 #ifdef FEAT_SEARCH_EXTRA
229 /* highlight 'hlsearch' match at end of line */
230 ! || ptr - 1 == search_hl.startp
231 ! || ptr - 1 == match_hl.startp
236 && ((area_attr != 0 && vcol == fromcol)
237 #ifdef FEAT_SEARCH_EXTRA
238 /* highlight 'hlsearch' match at end of line */
239 ! || (ptr - line) - 1 == (long)search_hl.startcol
240 ! || (ptr - line) - 1 == (long)match_hl.startcol
246 #ifdef FEAT_SEARCH_EXTRA
249 ! if (ptr - 1 == match_hl.startp)
250 char_attr = match_hl.attr;
252 char_attr = search_hl.attr;
254 #ifdef FEAT_SEARCH_EXTRA
257 ! if ((ptr - line) - 1 == (long)match_hl.startcol)
258 char_attr = match_hl.attr;
260 char_attr = search_hl.attr;
261 *** ../vim-6.3.042/src/version.c Mon Dec 6 11:51:12 2004
262 --- src/version.c Tue Dec 7 12:57:14 2004
266 { /* Add new patch number below this line */
272 A)bort, R)etry, P)lease don't bother me again
274 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
275 /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
276 \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
277 \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///