@@ -205,7 +205,7 @@ int n2e_HighlightWord(LPCSTR word)
205
205
lrange = bHighlightAll
206
206
? (bEditSelectionInit && bEditSelectionScope )
207
207
? SciCall_GetLineCount ()
208
- : min (SendMessage ( hwndEdit , SCI_LINESONSCREEN , 0 , 0 ), SciCall_GetLineCount ())
208
+ : min (SciCall_GetLinesOnScreen ( ), SciCall_GetLineCount ())
209
209
: 0 ;
210
210
211
211
ttf .chrg .cpMin = SendMessage (hwndEdit , SCI_POSITIONFROMLINE , lstart , 0 );
@@ -224,7 +224,6 @@ int n2e_HighlightWord(LPCSTR word)
224
224
int search_opt = bEditSelectionWholeWordMode ? SCFIND_WHOLEWORD : SCFIND_MATCHCASE ;
225
225
int wlen = strlen (word );
226
226
int curr_indi = N2E_SELECT_INDICATOR_SINGLE ;
227
- BOOL bPreviousMatchIsVisible = FALSE;
228
227
if (bEditSelectionInit )
229
228
{
230
229
n2e_ClearEditSelections ();
@@ -241,62 +240,45 @@ int n2e_HighlightWord(LPCSTR word)
241
240
}
242
241
strcpy (pEditSelectionOriginalWord , word );
243
242
}
244
- // 2 first words
243
+
244
+ if (bEditSelectionInit )
245
245
{
246
- ttf1 .chrg .cpMin = max (0 , ttf .chrg .cpMin - iMaxSearchDistance );
247
- ttf1 .chrg .cpMax = min (len , ttf .chrg .cpMin + iMaxSearchDistance );
246
+ curr_indi = N2E_SELECT_INDICATOR_EDIT ;
247
+ bEditSelection = TRUE;
248
+ iOriginalSelectionLength = wlen ;
248
249
}
249
- ttf1 .lpstrText = (LPSTR )word ;
250
- res = SendMessage (hwndEdit , SCI_FINDTEXT , search_opt , (LPARAM )& ttf1 );
251
- bPreviousMatchIsVisible = ttf1 .chrgText .cpMin >= ttf .chrg .cpMin && ttf1 .chrgText .cpMin < ttf .chrg .cpMax ;
252
- while (1 )
250
+ else
253
251
{
254
- ttf1 .chrg .cpMin = ttf1 .chrgText .cpMax ;
255
- res = SendMessage (hwndEdit , SCI_FINDTEXT , search_opt , (LPARAM )& ttf1 );
256
- if (-1 != res )
252
+ ttf1 .chrg .cpMin = max (0 , ttf .chrg .cpMin - iMaxSearchDistance );
253
+ ttf1 .chrg .cpMax = min (len , ttf .chrg .cpMin + iMaxSearchDistance );
254
+ ttf1 .lpstrText = (LPSTR )word ;
255
+ SciCall_FindText (search_opt , & ttf1 );
256
+ const BOOL bMatchIsVisible = ttf1 .chrgText .cpMin >= ttf .chrg .cpMin && ttf1 .chrgText .cpMin < ttf .chrg .cpMax ;
257
+ if (bMatchIsVisible )
257
258
{
258
- // current match is visible
259
- if (
260
- ttf1 .chrgText .cpMin >= ttf .chrg .cpMin &&
261
- ttf1 .chrgText .cpMin < ttf .chrg .cpMax
262
- )
263
- {
264
- if (bPreviousMatchIsVisible )
265
- {
266
- if (bEditSelectionInit )
267
- {
268
- curr_indi = N2E_SELECT_INDICATOR_EDIT ;
269
- bEditSelection = TRUE;
270
- iOriginalSelectionLength = wlen ;
271
- }
272
- else
273
- {
274
- curr_indi = N2E_SELECT_INDICATOR_PAGE ;
275
- }
276
- break ;
277
- }
278
- else
279
- {
280
- curr_indi = N2E_SELECT_INDICATOR ;
281
- }
282
- bPreviousMatchIsVisible = TRUE;
283
- }
284
- if (ttf1 .chrgText .cpMin >= ttf .chrg .cpMax && N2E_SELECT_INDICATOR == curr_indi )
259
+ ttf1 .chrg .cpMin = ttf1 .chrgText .cpMax ;
260
+ const BOOL bSecondMatchIsVisible = (SciCall_FindText (search_opt , & ttf1 ) != -1 )
261
+ && (ttf1 .chrgText .cpMin >= ttf .chrg .cpMin && ttf1 .chrgText .cpMin < ttf .chrg .cpMax );
262
+ if (bHighlightAll )
285
263
{
286
- if (bEditSelectionInit )
264
+ if (SciCall_GetLinesOnScreen () < SciCall_GetLineCount () )
287
265
{
288
- bEditSelection = TRUE ;
289
- iOriginalSelectionLength = wlen ;
266
+ ttf1 . chrg . cpMin = SendMessage ( hwndEdit , SCI_GETLINEENDPOSITION , lstart + SciCall_GetLinesOnScreen (), 0 ) + 1 ;
267
+ ttf1 . chrg . cpMax = SendMessage ( hwndEdit , SCI_GETLINEENDPOSITION , SciCall_GetLineCount (), 0 ) + 1 ;
290
268
}
291
- break ;
292
269
}
293
- ttf1 .chrg .cpMin = ttf1 .chrgText .cpMax ;
270
+ curr_indi = (SciCall_FindText (search_opt , & ttf1 ) == -1 )
271
+ ? bSecondMatchIsVisible
272
+ ? N2E_SELECT_INDICATOR_PAGE
273
+ : N2E_SELECT_INDICATOR_SINGLE
274
+ : N2E_SELECT_INDICATOR ;
294
275
}
295
276
else
296
277
{
297
- break ;
278
+ curr_indi = N2E_SELECT_INDICATOR ;
298
279
}
299
280
}
281
+
300
282
SendMessage (hwndEdit , SCI_SETINDICATORCURRENT , curr_indi , 0 );
301
283
if (bEditSelectionInit && !n2e_IsSelectionEditModeOn ())
302
284
{
@@ -437,7 +419,7 @@ void n2e_SelectionHighlightInit()
437
419
}
438
420
439
421
sel_len = trEditSelection .chrg .cpMax - trEditSelection .chrg .cpMin ;
440
- if (sel_len > 0 )
422
+ if (sel_len > 1 )
441
423
{
442
424
trEditSelection .lpstrText = n2e_Alloc (sel_len + 1 );
443
425
SciCall_GetTextRange (0 , & trEditSelection );
@@ -754,6 +736,11 @@ void n2e_SelectionNotificationHandler(const int code, const struct SCNotificatio
754
736
}
755
737
n2e_SelectionUpdate (SUM_UPDATE );
756
738
}
739
+ else if ((scn -> updated & SC_UPDATE_SELECTION )
740
+ && n2e_IsSelectionEditModeOn ())
741
+ {
742
+ n2e_SelectionUpdate (SUM_UPDATE );
743
+ }
757
744
else if ((scn -> updated & (SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL ))
758
745
&& n2e_IsSelectionEditModeOn ()
759
746
&& (iEditSelectionFirstVisibleLine != SciCall_DocLineFromVisible (SciCall_GetFirstVisibleLine ())))
0 commit comments