2 * RichEdit - Caret and selection functions.
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2005 by Phil Krylov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 WINE_DEFAULT_DEBUG_CHANNEL(richedit
);
28 ME_MoveCursorChars(ME_TextEditor
*editor
, ME_Cursor
*pCursor
, int nRelOfs
);
30 void ME_GetSelection(ME_TextEditor
*editor
, int *from
, int *to
)
32 *from
= ME_GetCursorOfs(editor
, 0);
33 *to
= ME_GetCursorOfs(editor
, 1);
43 int ME_GetTextLength(ME_TextEditor
*editor
)
45 return ME_CharOfsFromRunOfs(editor
, ME_FindItemBack(editor
->pBuffer
->pLast
, diRun
), 0);
49 int ME_GetTextLengthEx(ME_TextEditor
*editor
, const GETTEXTLENGTHEX
*how
)
53 if (how
->flags
& GTL_PRECISE
&& how
->flags
& GTL_CLOSE
)
55 if (how
->flags
& GTL_NUMCHARS
&& how
->flags
& GTL_NUMBYTES
)
58 length
= ME_GetTextLength(editor
);
60 if ((GetWindowLongW(editor
->hWnd
, GWL_STYLE
) & ES_MULTILINE
)
61 && (how
->flags
& GTL_USECRLF
)
62 && !editor
->bEmulateVersion10
) /* Ignore GTL_USECRLF flag in 1.0 emulation */
63 length
+= editor
->nParagraphs
- 1;
65 if (how
->flags
& GTL_NUMBYTES
)
69 if (how
->codepage
== 1200)
71 if (how
->flags
& GTL_PRECISE
)
72 FIXME("GTL_PRECISE flag unsupported. Using GTL_CLOSE\n");
73 if (GetCPInfo(how
->codepage
, &cpinfo
))
74 return length
* cpinfo
.MaxCharSize
;
75 ERR("Invalid codepage %u\n", how
->codepage
);
82 int ME_SetSelection(ME_TextEditor
*editor
, int from
, int to
)
85 const int len
= ME_GetTextLength(editor
);
87 /* all negative values are effectively the same */
94 if (from
== 0 && to
== -1)
96 editor
->pCursors
[1].pRun
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diRun
);
97 editor
->pCursors
[1].nOffset
= 0;
98 editor
->pCursors
[0].pRun
= ME_FindItemBack(editor
->pBuffer
->pLast
, diRun
);
99 editor
->pCursors
[0].nOffset
= 0;
100 ME_InvalidateSelection(editor
);
101 ME_ClearTempStyle(editor
);
105 /* if both values are equal and also out of bound, that means to */
106 /* put the selection at the end of the text */
107 if ((from
== to
) && (to
< 0 || to
> len
))
113 /* if from is negative and to is positive then selection is */
114 /* deselected and caret moved to end of the current selection */
118 ME_GetSelection(editor
, &start
, &end
);
119 editor
->pCursors
[1] = editor
->pCursors
[0];
121 ME_ClearTempStyle(editor
);
125 /* adjust to if it's a negative value */
129 /* flip from and to if they are reversed */
137 /* after fiddling with the values, we find from > len && to > len */
140 /* special case with to too big */
147 editor
->pCursors
[1].pRun
= editor
->pCursors
[0].pRun
= ME_FindItemBack(editor
->pBuffer
->pLast
, diRun
);
148 editor
->pCursors
[1].nOffset
= editor
->pCursors
[0].nOffset
= 0;
149 ME_InvalidateSelection(editor
);
150 ME_ClearTempStyle(editor
);
154 ME_RunOfsFromCharOfs(editor
, from
, &editor
->pCursors
[1].pRun
, &editor
->pCursors
[1].nOffset
);
155 ME_RunOfsFromCharOfs(editor
, to
, &editor
->pCursors
[0].pRun
, &editor
->pCursors
[0].nOffset
);
161 ME_GetCursorCoordinates(ME_TextEditor
*editor
, ME_Cursor
*pCursor
,
162 int *x
, int *y
, int *height
)
164 ME_DisplayItem
*pCursorRun
= pCursor
->pRun
;
165 ME_DisplayItem
*pSizeRun
= pCursor
->pRun
;
167 assert(height
&& x
&& y
);
168 assert(!(ME_GetParagraph(pCursorRun
)->member
.para
.nFlags
& MEPF_REWRAP
));
169 assert(pCursor
->pRun
);
170 assert(pCursor
->pRun
->type
== diRun
);
172 if (pCursorRun
->type
== diRun
) {
173 ME_DisplayItem
*row
= ME_FindItemBack(pCursorRun
, diStartRowOrParagraph
);
176 HDC hDC
= GetDC(editor
->hWnd
);
178 ME_DisplayItem
*run
= pCursorRun
;
179 ME_DisplayItem
*para
= NULL
;
182 ME_InitContext(&c
, editor
, hDC
);
184 if (!pCursor
->nOffset
)
186 ME_DisplayItem
*prev
= ME_FindItemBack(pCursorRun
, diRunOrParagraph
);
188 if (prev
->type
== diRun
)
191 assert(row
->type
== diStartRow
); /* paragraph -> run without start row ?*/
192 para
= ME_FindItemBack(row
, diParagraph
);
194 assert(para
->type
== diParagraph
);
195 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
&&
196 run
== ME_FindItemFwd(row
, diRun
))
198 ME_DisplayItem
*tmp
= ME_FindItemBack(row
, diRunOrParagraph
);
200 if (tmp
->type
== diRun
)
202 row
= ME_FindItemBack(tmp
, diStartRow
);
203 pSizeRun
= run
= tmp
;
205 assert(run
->type
== diRun
);
206 sz
= ME_GetRunSize(&c
, ¶
->member
.para
,
207 &run
->member
.run
, ME_StrLen(run
->member
.run
.strText
),
208 row
->member
.row
.nLMargin
);
211 if (pCursor
->nOffset
) {
212 sz
= ME_GetRunSize(&c
, ¶
->member
.para
, &run
->member
.run
, pCursor
->nOffset
,
213 row
->member
.row
.nLMargin
);
216 *height
= pSizeRun
->member
.run
.nAscent
+ pSizeRun
->member
.run
.nDescent
;
217 *x
= run
->member
.run
.pt
.x
+ sz
.cx
;
218 *y
= para
->member
.para
.nYPos
+ row
->member
.row
.nBaseline
+ run
->member
.run
.pt
.y
- pSizeRun
->member
.run
.nAscent
- ME_GetYScrollPos(editor
);
219 ME_DestroyContext(&c
, editor
->hWnd
);
223 *height
= 10; /* FIXME use global font */
230 ME_MoveCaret(ME_TextEditor
*editor
)
234 if (ME_WrapMarkedParagraphs(editor
))
235 ME_UpdateScrollBar(editor
);
236 ME_GetCursorCoordinates(editor
, &editor
->pCursors
[0], &x
, &y
, &height
);
237 if(editor
->bHaveFocus
)
241 GetClientRect(editor
->hWnd
, &rect
);
242 x
= min(x
, rect
.right
-2);
243 CreateCaret(editor
->hWnd
, NULL
, 0, height
);
249 void ME_ShowCaret(ME_TextEditor
*ed
)
256 void ME_HideCaret(ME_TextEditor
*ed
)
265 void ME_InternalDeleteText(ME_TextEditor
*editor
, int nOfs
,
274 ME_CursorFromCharOfs(editor
, nOfs
, &c
);
275 run
= &c
.pRun
->member
.run
;
276 if (run
->nFlags
& MERF_ENDPARA
) {
277 int eollen
= run
->nCR
+ run
->nLF
;
279 if (!ME_FindItemFwd(c
.pRun
, diParagraph
))
283 ME_JoinParagraphs(editor
, ME_GetParagraph(c
.pRun
));
284 /* ME_SkipAndPropagateCharOffset(p->pRun, shift); */
285 ME_CheckCharOffsets(editor
);
286 nChars
-= (eollen
< nChars
) ? eollen
: nChars
;
292 int nIntendedChars
= nChars
;
293 int nCharsToDelete
= nChars
;
297 ME_FindItemBack(c
.pRun
, diParagraph
)->member
.para
.nFlags
|= MEPF_REWRAP
;
300 ME_StrRelPos(run
->strText
, loc
, &nChars
);
301 /* nChars is the number of characters that should be deleted from the
302 FOLLOWING runs (these AFTER cursor.pRun)
303 nCharsToDelete is a number of chars to delete from THIS run */
304 nCharsToDelete
-= nChars
;
305 shift
-= nCharsToDelete
;
306 TRACE("Deleting %d (intended %d-remaning %d) chars at %d in '%s' (%d)\n",
307 nCharsToDelete
, nIntendedChars
, nChars
, c
.nOffset
,
308 debugstr_w(run
->strText
->szData
), run
->strText
->nLen
);
310 if (!c
.nOffset
&& ME_StrVLen(run
->strText
) == nCharsToDelete
)
312 /* undo = reinsert whole run */
313 /* nOfs is a character offset (from the start of the document
314 to the current (deleted) run */
315 ME_UndoItem
*pUndo
= ME_AddUndoItem(editor
, diUndoInsertRun
, c
.pRun
);
317 pUndo
->di
.member
.run
.nCharOfs
= nOfs
;
321 /* undo = reinsert partial run */
322 ME_UndoItem
*pUndo
= ME_AddUndoItem(editor
, diUndoInsertRun
, c
.pRun
);
324 ME_DestroyString(pUndo
->di
.member
.run
.strText
);
325 pUndo
->di
.member
.run
.nCharOfs
= nOfs
;
326 pUndo
->di
.member
.run
.strText
= ME_MakeStringN(run
->strText
->szData
+c
.nOffset
, nCharsToDelete
);
329 TRACE("Post deletion string: %s (%d)\n", debugstr_w(run
->strText
->szData
), run
->strText
->nLen
);
330 TRACE("Shift value: %d\n", shift
);
331 ME_StrDeleteV(run
->strText
, c
.nOffset
, nCharsToDelete
);
333 /* update cursors (including c) */
334 for (i
=-1; i
<editor
->nCursors
; i
++) {
335 ME_Cursor
*pThisCur
= editor
->pCursors
+ i
;
336 if (i
== -1) pThisCur
= &c
;
337 if (pThisCur
->pRun
== cursor
.pRun
) {
338 if (pThisCur
->nOffset
> cursor
.nOffset
) {
339 if (pThisCur
->nOffset
-cursor
.nOffset
< nCharsToDelete
)
340 pThisCur
->nOffset
= cursor
.nOffset
;
342 pThisCur
->nOffset
-= nCharsToDelete
;
343 assert(pThisCur
->nOffset
>= 0);
344 assert(pThisCur
->nOffset
<= ME_StrVLen(run
->strText
));
346 if (pThisCur
->nOffset
== ME_StrVLen(run
->strText
))
348 pThisCur
->pRun
= ME_FindItemFwd(pThisCur
->pRun
, diRunOrParagraphOrEnd
);
349 assert(pThisCur
->pRun
->type
== diRun
);
350 pThisCur
->nOffset
= 0;
355 /* c = updated data now */
357 if (c
.pRun
== cursor
.pRun
)
358 ME_SkipAndPropagateCharOffset(c
.pRun
, shift
);
360 ME_PropagateCharOffset(c
.pRun
, shift
);
362 if (!ME_StrVLen(cursor
.pRun
->member
.run
.strText
))
364 TRACE("Removing useless run\n");
365 ME_Remove(cursor
.pRun
);
366 ME_DestroyDisplayItem(cursor
.pRun
);
371 ME_CheckCharOffsets(editor);
378 void ME_DeleteTextAtCursor(ME_TextEditor
*editor
, int nCursor
,
381 assert(nCursor
>=0 && nCursor
<editor
->nCursors
);
382 /* text operations set modified state */
383 editor
->nModifyStep
= 1;
384 ME_InternalDeleteText(editor
, ME_GetCursorOfs(editor
, nCursor
), nChars
);
387 static ME_DisplayItem
*
388 ME_InternalInsertTextFromCursor(ME_TextEditor
*editor
, int nCursor
,
389 const WCHAR
*str
, int len
, ME_Style
*style
,
392 ME_Cursor
*p
= &editor
->pCursors
[nCursor
];
394 editor
->bCaretAtEnd
= FALSE
;
396 assert(p
->pRun
->type
== diRun
);
398 return ME_InsertRunAtCursor(editor
, p
, style
, str
, len
, flags
);
402 void ME_InsertOLEFromCursor(ME_TextEditor
*editor
, const REOBJECT
* reo
, int nCursor
)
404 ME_Style
*pStyle
= ME_GetInsertStyle(editor
, nCursor
);
409 if (ME_IsSelection(editor
))
410 ME_DeleteSelection(editor
);
412 di
= ME_InternalInsertTextFromCursor(editor
, nCursor
, &space
, 1, pStyle
,
414 di
->member
.run
.ole_obj
= ALLOC_OBJ(*reo
);
415 ME_CopyReObject(di
->member
.run
.ole_obj
, reo
);
416 ME_SendSelChange(editor
);
420 void ME_InsertEndRowFromCursor(ME_TextEditor
*editor
, int nCursor
)
422 ME_Style
*pStyle
= ME_GetInsertStyle(editor
, nCursor
);
427 if (ME_IsSelection(editor
))
428 ME_DeleteSelection(editor
);
430 di
= ME_InternalInsertTextFromCursor(editor
, nCursor
, &space
, 1, pStyle
,
432 ME_SendSelChange(editor
);
436 ME_InsertTableCellFromCursor(ME_TextEditor
*editor
, int nCursor
)
439 ME_DisplayItem
*p
, *run
;
440 ME_Style
*pStyle
= ME_GetInsertStyle(editor
, nCursor
);
442 p
= ME_InternalInsertTextFromCursor(editor
, nCursor
, &tab
, 1, pStyle
,
445 while ((run
= ME_FindItemBack(run
, diRunOrParagraph
))->type
== diRun
)
447 if (run
->member
.run
.nFlags
& MERF_CELL
)
449 assert(run
->member
.run
.pCell
->next
);
450 p
->member
.run
.pCell
= run
->member
.run
.pCell
->next
;
454 assert(run
->type
== diParagraph
);
455 assert(run
->member
.para
.bTable
);
456 assert(run
->member
.para
.pCells
);
457 p
->member
.run
.pCell
= run
->member
.para
.pCells
;
461 void ME_InsertTextFromCursor(ME_TextEditor
*editor
, int nCursor
,
462 const WCHAR
*str
, int len
, ME_Style
*style
)
468 /* FIXME really HERE ? */
469 if (ME_IsSelection(editor
))
470 ME_DeleteSelection(editor
);
472 /* FIXME: is this too slow? */
473 /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */
474 oldLen
= ME_GetTextLength(editor
);
476 /* text operations set modified state */
477 editor
->nModifyStep
= 1;
481 assert(nCursor
>=0 && nCursor
<editor
->nCursors
);
485 /* grow the text limit to fit our text */
486 if(editor
->nTextLimit
< oldLen
+len
)
487 editor
->nTextLimit
= oldLen
+ len
;
492 /* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */
493 while(pos
-str
< len
&& *pos
!= '\r' && *pos
!= '\n' && *pos
!= '\t')
495 if (pos
-str
< len
&& *pos
== '\t') { /* handle tabs */
499 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, pos
-str
, style
, 0);
501 ME_InternalInsertTextFromCursor(editor
, nCursor
, &tab
, 1, style
, MERF_TAB
);
510 /* handle special \r\r\n sequence (richedit 2.x and higher only) */
511 if (!editor
->bEmulateVersion10
&& pos
-str
< len
-2 && pos
[0] == '\r' && pos
[1] == '\r' && pos
[2] == '\n') {
515 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, pos
-str
, style
, 0);
517 ME_InternalInsertTextFromCursor(editor
, nCursor
, &space
, 1, style
, 0);
526 if (pos
-str
< len
) { /* handle EOLs */
527 ME_DisplayItem
*tp
, *end_run
;
532 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, pos
-str
, style
, 0);
533 p
= &editor
->pCursors
[nCursor
];
535 ME_SplitRunSimple(editor
, p
->pRun
, p
->nOffset
);
536 p
= &editor
->pCursors
[nCursor
];
538 tmp_style
= ME_GetInsertStyle(editor
, nCursor
);
539 /* ME_SplitParagraph increases style refcount */
541 /* Encode and fill number of CR and LF according to emulation mode */
542 if (editor
->bEmulateVersion10
) {
545 /* We have to find out how many consecutive \r are there, and if there
546 is a \n terminating the run of \r's. */
547 numCR
= 0; numLF
= 0;
549 while (tpos
-str
< len
&& *tpos
== '\r') {
553 if (tpos
-str
>= len
) {
554 /* Reached end of text without finding anything but '\r' */
558 numCR
= 1; numLF
= 0;
559 } else if (*tpos
== '\n') {
560 /* The entire run of \r's plus the one \n is one single line break */
564 /* Found some other content past the run of \r's */
566 numCR
= 1; numLF
= 0;
569 if(pos
-str
< len
&& *pos
=='\r')
571 if(pos
-str
< len
&& *pos
=='\n')
573 numCR
= 1; numLF
= 0;
575 tp
= ME_SplitParagraph(editor
, p
->pRun
, p
->pRun
->member
.run
.style
, numCR
, numLF
);
576 p
->pRun
= ME_FindItemFwd(tp
, diRun
);
577 end_run
= ME_FindItemBack(tp
, diRun
);
578 ME_ReleaseStyle(end_run
->member
.run
.style
);
579 end_run
->member
.run
.style
= tmp_style
;
588 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, len
, style
, 0);
595 ME_MoveCursorChars(ME_TextEditor
*editor
, ME_Cursor
*pCursor
, int nRelOfs
)
597 ME_DisplayItem
*pRun
= pCursor
->pRun
;
601 if (!pCursor
->nOffset
)
604 pRun
= ME_FindItemBack(pRun
, diRunOrParagraph
);
611 if (pRun
->member
.para
.prev_para
->type
== diTextStart
)
613 pRun
= ME_FindItemBack(pRun
, diRunOrParagraph
);
614 /* every paragraph ought to have at least one run */
615 assert(pRun
&& pRun
->type
== diRun
);
616 assert(pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
619 assert(pRun
->type
!= diRun
&& pRun
->type
!= diParagraph
);
622 } while (RUN_IS_HIDDEN(&pRun
->member
.run
));
623 pCursor
->pRun
= pRun
;
624 if (pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
625 pCursor
->nOffset
= 0;
627 pCursor
->nOffset
= pRun
->member
.run
.strText
->nLen
;
630 if (pCursor
->nOffset
)
631 pCursor
->nOffset
= ME_StrRelPos2(pCursor
->pRun
->member
.run
.strText
, pCursor
->nOffset
, nRelOfs
);
636 if (!(pRun
->member
.run
.nFlags
& MERF_ENDPARA
))
638 int new_ofs
= ME_StrRelPos2(pRun
->member
.run
.strText
, pCursor
->nOffset
, nRelOfs
);
640 if (new_ofs
< pRun
->member
.run
.strText
->nLen
)
642 pCursor
->nOffset
= new_ofs
;
647 pRun
= ME_FindItemFwd(pRun
, diRun
);
648 } while (pRun
&& RUN_IS_HIDDEN(&pRun
->member
.run
));
651 pCursor
->pRun
= pRun
;
652 pCursor
->nOffset
= 0;
661 ME_MoveCursorWords(ME_TextEditor
*editor
, ME_Cursor
*cursor
, int nRelOfs
)
663 ME_DisplayItem
*pRun
= cursor
->pRun
, *pOtherRun
;
664 int nOffset
= cursor
->nOffset
;
668 /* Backward movement */
671 nOffset
= ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
672 nOffset
, WB_MOVEWORDLEFT
);
675 pOtherRun
= ME_FindItemBack(pRun
, diRunOrParagraph
);
676 if (pOtherRun
->type
== diRun
)
678 if (ME_CallWordBreakProc(editor
, pOtherRun
->member
.run
.strText
,
679 pOtherRun
->member
.run
.strText
->nLen
- 1,
681 && !(pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
682 && !(cursor
->pRun
== pRun
&& cursor
->nOffset
== 0)
683 && !ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
, 0,
687 nOffset
= pOtherRun
->member
.run
.strText
->nLen
;
689 else if (pOtherRun
->type
== diParagraph
)
691 if (cursor
->pRun
== pRun
&& cursor
->nOffset
== 0)
693 /* Paragraph breaks are treated as separate words */
694 if (pOtherRun
->member
.para
.prev_para
->type
== diTextStart
)
696 pRun
= ME_FindItemBack(pOtherRun
, diRunOrParagraph
);
704 /* Forward movement */
705 BOOL last_delim
= FALSE
;
709 if (last_delim
&& !ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
710 nOffset
, WB_ISDELIMITER
))
712 nOffset
= ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
713 nOffset
, WB_MOVEWORDRIGHT
);
714 if (nOffset
< pRun
->member
.run
.strText
->nLen
)
716 pOtherRun
= ME_FindItemFwd(pRun
, diRunOrParagraphOrEnd
);
717 if (pOtherRun
->type
== diRun
)
719 last_delim
= ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
720 nOffset
- 1, WB_ISDELIMITER
);
724 else if (pOtherRun
->type
== diParagraph
)
726 if (cursor
->pRun
== pRun
)
727 pRun
= ME_FindItemFwd(pOtherRun
, diRun
);
733 if (cursor
->pRun
== pRun
)
741 cursor
->nOffset
= nOffset
;
747 ME_SelectByType(ME_TextEditor
*editor
, ME_SelectionType selectionType
)
749 /* pCursor[0] will be the start of the selection
750 * pCursor[1] is the other end of the selection range
751 * pCursor[2] and [3] are the selection anchors that are backed up
752 * so they are kept when the selection changes for drag selection.
755 editor
->nSelectionType
= selectionType
;
756 switch(selectionType
)
761 ME_MoveCursorWords(editor
, &editor
->pCursors
[1], +1);
762 editor
->pCursors
[0] = editor
->pCursors
[1];
763 ME_MoveCursorWords(editor
, &editor
->pCursors
[0], -1);
768 ME_DisplayItem
*pItem
;
769 ME_DIType fwdSearchType
, backSearchType
;
770 if (selectionType
== stParagraph
) {
771 backSearchType
= diParagraph
;
772 fwdSearchType
= diParagraphOrEnd
;
774 backSearchType
= diStartRow
;
775 fwdSearchType
= diStartRowOrParagraphOrEnd
;
777 pItem
= ME_FindItemBack(editor
->pCursors
[0].pRun
, backSearchType
);
778 editor
->pCursors
[0].pRun
= ME_FindItemFwd(pItem
, diRun
);
779 editor
->pCursors
[0].nOffset
= 0;
781 pItem
= ME_FindItemFwd(editor
->pCursors
[0].pRun
, fwdSearchType
);
783 if (pItem
->type
== diTextEnd
)
784 editor
->pCursors
[1].pRun
= ME_FindItemBack(pItem
, diRun
);
786 editor
->pCursors
[1].pRun
= ME_FindItemFwd(pItem
, diRun
);
787 editor
->pCursors
[1].nOffset
= 0;
792 /* Store the anchor positions for extending the selection. */
793 editor
->pCursors
[2] = editor
->pCursors
[0];
794 editor
->pCursors
[3] = editor
->pCursors
[1];
798 int ME_GetCursorOfs(ME_TextEditor
*editor
, int nCursor
)
800 ME_Cursor
*pCursor
= &editor
->pCursors
[nCursor
];
801 return ME_GetParagraph(pCursor
->pRun
)->member
.para
.nCharOfs
802 + pCursor
->pRun
->member
.run
.nCharOfs
+ pCursor
->nOffset
;
805 static void ME_FindPixelPos(ME_TextEditor
*editor
, int x
, int y
, ME_Cursor
*result
, BOOL
*is_eol
)
807 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
->member
.para
.next_para
;
808 ME_DisplayItem
*last
= NULL
;
815 for (; p
!= editor
->pBuffer
->pLast
; p
= p
->member
.para
.next_para
)
817 assert(p
->type
== diParagraph
);
818 if (y
< p
->member
.para
.nYPos
+ p
->member
.para
.nHeight
)
820 y
-= p
->member
.para
.nYPos
;
821 p
= ME_FindItemFwd(p
, diStartRow
);
826 for (; p
!= editor
->pBuffer
->pLast
; )
829 assert(p
->type
== diStartRow
);
830 if (y
< p
->member
.row
.nYPos
+ p
->member
.row
.nHeight
)
832 p
= ME_FindItemFwd(p
, diRun
);
835 pp
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
836 if (pp
->type
!= diStartRow
)
838 p
= ME_FindItemFwd(p
, diRun
);
843 if (p
== editor
->pBuffer
->pLast
)
845 /* The position is below the last paragraph, so the last row will be used
846 * rather than the end of the text, so the x position will be used to
847 * determine the offset closest to the pixel position. */
848 p
= ME_FindItemBack(p
, diStartRow
);
850 p
= ME_FindItemFwd(p
, diRun
);
854 p
= editor
->pBuffer
->pLast
;
857 for (; p
!= editor
->pBuffer
->pLast
; p
= p
->next
)
862 rx
= x
- p
->member
.run
.pt
.x
;
863 if (rx
< p
->member
.run
.nWidth
)
866 assert(p
->type
== diRun
);
867 if ((p
->member
.run
.nFlags
& MERF_ENDPARA
) || rx
< 0)
870 result
->nOffset
= ME_CharFromPointCursor(editor
, rx
, &p
->member
.run
);
871 if (editor
->pCursors
[0].nOffset
== p
->member
.run
.strText
->nLen
&& rx
)
873 result
->pRun
= ME_FindItemFwd(editor
->pCursors
[0].pRun
, diRun
);
880 p
= ME_FindItemFwd(p
, diRun
);
881 if (is_eol
) *is_eol
= 1;
882 rx
= 0; /* FIXME not sure */
886 rx
= 0; /* FIXME not sure */
893 result
->pRun
= ME_FindItemBack(p
, diRun
);
895 assert(result
->pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
900 ME_CharFromPos(ME_TextEditor
*editor
, int x
, int y
)
905 GetClientRect(editor
->hWnd
, &rc
);
906 if (x
< 0 || y
< 0 || x
>= rc
.right
|| y
>= rc
.bottom
)
908 y
+= ME_GetYScrollPos(editor
);
909 ME_FindPixelPos(editor
, x
, y
, &cursor
, NULL
);
910 return (ME_GetParagraph(cursor
.pRun
)->member
.para
.nCharOfs
911 + cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
);
914 /* Extends the selection with a word, line, or paragraph selection type.
916 * The selection is anchored by editor->pCursors[2-3] such that the text
917 * between the anchors will remain selected, and one end will be extended.
919 * editor->pCursors[0] should have the position to extend the selection to
920 * before this function is called.
922 * Nothing will be done if editor->nSelectionType equals stPosition.
924 static void ME_ExtendAnchorSelection(ME_TextEditor
*editor
)
926 ME_Cursor tmp_cursor
;
927 int curOfs
, anchorStartOfs
, anchorEndOfs
;
928 if (editor
->nSelectionType
== stPosition
)
930 curOfs
= ME_GetCursorOfs(editor
, 0);
931 anchorStartOfs
= ME_GetCursorOfs(editor
, 2);
932 anchorEndOfs
= ME_GetCursorOfs(editor
, 3);
934 tmp_cursor
= editor
->pCursors
[0];
935 editor
->pCursors
[0] = editor
->pCursors
[2];
936 editor
->pCursors
[1] = editor
->pCursors
[3];
937 if (curOfs
< anchorStartOfs
)
939 /* Extend the left side of selection */
940 editor
->pCursors
[0] = tmp_cursor
;
941 if (editor
->nSelectionType
== stWord
)
942 ME_MoveCursorWords(editor
, &editor
->pCursors
[0], -1);
945 ME_DisplayItem
*pItem
;
946 ME_DIType searchType
= ((editor
->nSelectionType
== stLine
) ?
947 diStartRowOrParagraph
:diParagraph
);
948 pItem
= ME_FindItemBack(editor
->pCursors
[0].pRun
, searchType
);
949 editor
->pCursors
[0].pRun
= ME_FindItemFwd(pItem
, diRun
);
950 editor
->pCursors
[0].nOffset
= 0;
953 else if (curOfs
>= anchorEndOfs
)
955 /* Extend the right side of selection */
956 editor
->pCursors
[1] = tmp_cursor
;
957 if (editor
->nSelectionType
== stWord
)
958 ME_MoveCursorWords(editor
, &editor
->pCursors
[1], +1);
961 ME_DisplayItem
*pItem
;
962 ME_DIType searchType
= ((editor
->nSelectionType
== stLine
) ?
963 diStartRowOrParagraphOrEnd
:diParagraphOrEnd
);
964 pItem
= ME_FindItemFwd(editor
->pCursors
[1].pRun
, searchType
);
965 if (pItem
->type
== diTextEnd
)
966 editor
->pCursors
[1].pRun
= ME_FindItemBack(pItem
, diRun
);
968 editor
->pCursors
[1].pRun
= ME_FindItemFwd(pItem
, diRun
);
969 editor
->pCursors
[1].nOffset
= 0;
974 void ME_LButtonDown(ME_TextEditor
*editor
, int x
, int y
, int clickNum
)
976 ME_Cursor tmp_cursor
;
977 int is_selection
= 0;
980 editor
->nUDArrowX
= -1;
982 y
+= ME_GetYScrollPos(editor
);
984 tmp_cursor
= editor
->pCursors
[0];
985 is_selection
= ME_IsSelection(editor
);
986 is_shift
= GetKeyState(VK_SHIFT
) < 0;
988 ME_FindPixelPos(editor
, x
, y
, &editor
->pCursors
[0], &editor
->bCaretAtEnd
);
990 if (x
>= editor
->selofs
|| is_shift
)
994 editor
->pCursors
[1] = editor
->pCursors
[0];
995 if (x
>= editor
->selofs
)
996 ME_SelectByType(editor
, stWord
);
998 ME_SelectByType(editor
, stParagraph
);
1002 editor
->nSelectionType
= stPosition
;
1003 editor
->pCursors
[1] = editor
->pCursors
[0];
1005 else if (!is_selection
)
1007 editor
->nSelectionType
= stPosition
;
1008 editor
->pCursors
[1] = tmp_cursor
;
1010 else if (editor
->nSelectionType
!= stPosition
)
1012 ME_ExtendAnchorSelection(editor
);
1018 ME_SelectByType(editor
, stLine
);
1020 ME_SelectByType(editor
, stParagraph
);
1023 ME_InvalidateSelection(editor
);
1024 HideCaret(editor
->hWnd
);
1025 ME_MoveCaret(editor
);
1026 ShowCaret(editor
->hWnd
);
1027 ME_ClearTempStyle(editor
);
1028 ME_SendSelChange(editor
);
1031 void ME_MouseMove(ME_TextEditor
*editor
, int x
, int y
)
1033 ME_Cursor tmp_cursor
;
1035 y
+= ME_GetYScrollPos(editor
);
1037 tmp_cursor
= editor
->pCursors
[0];
1038 /* FIXME: do something with the return value of ME_FindPixelPos */
1039 ME_FindPixelPos(editor
, x
, y
, &tmp_cursor
, &editor
->bCaretAtEnd
);
1041 ME_InvalidateSelection(editor
);
1042 editor
->pCursors
[0] = tmp_cursor
;
1043 ME_ExtendAnchorSelection(editor
);
1045 if (editor
->nSelectionType
!= stPosition
&&
1046 memcmp(&editor
->pCursors
[1], &editor
->pCursors
[3], sizeof(ME_Cursor
)))
1048 /* The scroll the cursor towards the other end, since it was the one
1049 * extended by ME_ExtendAnchorSelection
1051 ME_Cursor tmpCursor
= editor
->pCursors
[0];
1052 editor
->pCursors
[0] = editor
->pCursors
[1];
1053 editor
->pCursors
[1] = tmpCursor
;
1054 SendMessageW(editor
->hWnd
, EM_SCROLLCARET
, 0, 0);
1055 editor
->pCursors
[1] = editor
->pCursors
[0];
1056 editor
->pCursors
[0] = tmpCursor
;
1058 SendMessageW(editor
->hWnd
, EM_SCROLLCARET
, 0, 0);
1061 HideCaret(editor
->hWnd
);
1062 ME_MoveCaret(editor
);
1063 ME_InvalidateSelection(editor
);
1064 ShowCaret(editor
->hWnd
);
1065 ME_SendSelChange(editor
);
1068 static ME_DisplayItem
*ME_FindRunInRow(ME_TextEditor
*editor
, ME_DisplayItem
*pRow
,
1069 int x
, int *pOffset
, int *pbCaretAtEnd
)
1071 ME_DisplayItem
*pNext
, *pLastRun
;
1072 pNext
= ME_FindItemFwd(pRow
, diRunOrStartRow
);
1073 assert(pNext
->type
== diRun
);
1075 if (pbCaretAtEnd
) *pbCaretAtEnd
= FALSE
;
1076 if (pOffset
) *pOffset
= 0;
1078 int run_x
= pNext
->member
.run
.pt
.x
;
1079 int width
= pNext
->member
.run
.nWidth
;
1084 if (x
>= run_x
&& x
< run_x
+width
)
1086 int ch
= ME_CharFromPointCursor(editor
, x
-run_x
, &pNext
->member
.run
);
1087 ME_String
*s
= pNext
->member
.run
.strText
;
1095 pNext
= ME_FindItemFwd(pNext
, diRunOrStartRow
);
1096 } while(pNext
&& pNext
->type
== diRun
);
1098 if ((pLastRun
->member
.run
.nFlags
& MERF_ENDPARA
) == 0)
1100 pNext
= ME_FindItemFwd(pNext
, diRun
);
1101 if (pbCaretAtEnd
) *pbCaretAtEnd
= TRUE
;
1108 static int ME_GetXForArrow(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1110 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1113 if (editor
->nUDArrowX
!= -1)
1114 x
= editor
->nUDArrowX
;
1116 if (editor
->bCaretAtEnd
)
1118 pRun
= ME_FindItemBack(pRun
, diRun
);
1120 x
= pRun
->member
.run
.pt
.x
+ pRun
->member
.run
.nWidth
;
1123 x
= pRun
->member
.run
.pt
.x
;
1124 x
+= ME_PointFromChar(editor
, &pRun
->member
.run
, pCursor
->nOffset
);
1126 editor
->nUDArrowX
= x
;
1133 ME_MoveCursorLines(ME_TextEditor
*editor
, ME_Cursor
*pCursor
, int nRelOfs
)
1135 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1136 ME_DisplayItem
*pItem
;
1137 int x
= ME_GetXForArrow(editor
, pCursor
);
1139 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
)
1140 pRun
= ME_FindItemBack(pRun
, diRun
);
1145 /* start of this row */
1146 pItem
= ME_FindItemBack(pRun
, diStartRow
);
1148 /* start of the previous row */
1149 pItem
= ME_FindItemBack(pItem
, diStartRow
);
1153 /* start of the next row */
1154 pItem
= ME_FindItemFwd(pRun
, diStartRow
);
1155 /* FIXME If diParagraph is before diStartRow, wrap the next paragraph?
1160 /* row not found - ignore */
1163 pCursor
->pRun
= ME_FindRunInRow(editor
, pItem
, x
, &pCursor
->nOffset
, &editor
->bCaretAtEnd
);
1164 assert(pCursor
->pRun
);
1165 assert(pCursor
->pRun
->type
== diRun
);
1169 static void ME_ArrowPageUp(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1171 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1172 ME_DisplayItem
*pLast
, *p
;
1173 int x
, y
, ys
, yd
, yp
, yprev
;
1174 ME_Cursor tmp_curs
= *pCursor
;
1176 x
= ME_GetXForArrow(editor
, pCursor
);
1177 if (!pCursor
->nOffset
&& editor
->bCaretAtEnd
)
1178 pRun
= ME_FindItemBack(pRun
, diRun
);
1180 p
= ME_FindItemBack(pRun
, diStartRowOrParagraph
);
1181 assert(p
->type
== diStartRow
);
1182 yp
= ME_FindItemBack(p
, diParagraph
)->member
.para
.nYPos
;
1183 yprev
= ys
= y
= yp
+ p
->member
.row
.nYPos
;
1184 yd
= y
- editor
->sizeWindow
.cy
;
1188 p
= ME_FindItemBack(p
, diStartRowOrParagraph
);
1191 if (p
->type
== diParagraph
) { /* crossing paragraphs */
1192 if (p
->member
.para
.prev_para
== NULL
)
1194 yp
= p
->member
.para
.prev_para
->member
.para
.nYPos
;
1197 y
= yp
+ p
->member
.row
.nYPos
;
1204 pCursor
->pRun
= ME_FindRunInRow(editor
, pLast
, x
, &pCursor
->nOffset
, &editor
->bCaretAtEnd
);
1205 ME_UpdateSelection(editor
, &tmp_curs
);
1206 if (yprev
< editor
->sizeWindow
.cy
)
1208 ME_EnsureVisible(editor
, ME_FindItemFwd(editor
->pBuffer
->pFirst
, diRun
));
1213 ME_ScrollUp(editor
, ys
-yprev
);
1215 assert(pCursor
->pRun
);
1216 assert(pCursor
->pRun
->type
== diRun
);
1219 /* FIXME: in the original RICHEDIT, PageDown always scrolls by the same amount
1220 of pixels, even if it makes the scroll bar position exceed its normal maximum.
1221 In such a situation, clicking the scrollbar restores its position back to the
1222 normal range (ie. sets it to (doclength-screenheight)). */
1224 static void ME_ArrowPageDown(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1226 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1227 ME_DisplayItem
*pLast
, *p
;
1228 int x
, y
, ys
, yd
, yp
, yprev
;
1229 ME_Cursor tmp_curs
= *pCursor
;
1231 x
= ME_GetXForArrow(editor
, pCursor
);
1232 if (!pCursor
->nOffset
&& editor
->bCaretAtEnd
)
1233 pRun
= ME_FindItemBack(pRun
, diRun
);
1235 p
= ME_FindItemBack(pRun
, diStartRowOrParagraph
);
1236 assert(p
->type
== diStartRow
);
1237 yp
= ME_FindItemBack(p
, diParagraph
)->member
.para
.nYPos
;
1238 yprev
= ys
= y
= yp
+ p
->member
.row
.nYPos
;
1239 yd
= y
+ editor
->sizeWindow
.cy
;
1243 p
= ME_FindItemFwd(p
, diStartRowOrParagraph
);
1246 if (p
->type
== diParagraph
) {
1247 yp
= p
->member
.para
.nYPos
;
1250 y
= yp
+ p
->member
.row
.nYPos
;
1257 pCursor
->pRun
= ME_FindRunInRow(editor
, pLast
, x
, &pCursor
->nOffset
, &editor
->bCaretAtEnd
);
1258 ME_UpdateSelection(editor
, &tmp_curs
);
1259 if (yprev
>= editor
->nTotalLength
-editor
->sizeWindow
.cy
)
1261 ME_EnsureVisible(editor
, ME_FindItemBack(editor
->pBuffer
->pLast
, diRun
));
1266 ME_ScrollUp(editor
,ys
-yprev
);
1268 assert(pCursor
->pRun
);
1269 assert(pCursor
->pRun
->type
== diRun
);
1272 static void ME_ArrowHome(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1274 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diStartRow
);
1275 ME_WrapMarkedParagraphs(editor
);
1277 ME_DisplayItem
*pRun
;
1278 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
) {
1279 pRow
= ME_FindItemBack(pRow
, diStartRow
);
1283 pRun
= ME_FindItemFwd(pRow
, diRun
);
1285 pCursor
->pRun
= pRun
;
1286 pCursor
->nOffset
= 0;
1289 editor
->bCaretAtEnd
= FALSE
;
1292 static void ME_ArrowCtrlHome(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1294 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diTextStart
);
1296 ME_DisplayItem
*pRun
= ME_FindItemFwd(pRow
, diRun
);
1298 pCursor
->pRun
= pRun
;
1299 pCursor
->nOffset
= 0;
1304 static void ME_ArrowEnd(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1306 ME_DisplayItem
*pRow
;
1308 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
)
1311 pRow
= ME_FindItemFwd(pCursor
->pRun
, diStartRowOrParagraphOrEnd
);
1313 if (pRow
->type
== diStartRow
) {
1314 /* FIXME WTF was I thinking about here ? */
1315 ME_DisplayItem
*pRun
= ME_FindItemFwd(pRow
, diRun
);
1317 pCursor
->pRun
= pRun
;
1318 pCursor
->nOffset
= 0;
1319 editor
->bCaretAtEnd
= 1;
1322 pCursor
->pRun
= ME_FindItemBack(pRow
, diRun
);
1323 assert(pCursor
->pRun
&& pCursor
->pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
1324 pCursor
->nOffset
= 0;
1325 editor
->bCaretAtEnd
= FALSE
;
1328 static void ME_ArrowCtrlEnd(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1330 ME_DisplayItem
*p
= ME_FindItemFwd(pCursor
->pRun
, diTextEnd
);
1332 p
= ME_FindItemBack(p
, diRun
);
1334 assert(p
->member
.run
.nFlags
& MERF_ENDPARA
);
1336 pCursor
->nOffset
= 0;
1337 editor
->bCaretAtEnd
= FALSE
;
1340 BOOL
ME_IsSelection(ME_TextEditor
*editor
)
1342 return memcmp(&editor
->pCursors
[0], &editor
->pCursors
[1], sizeof(ME_Cursor
))!=0;
1345 static int ME_GetSelCursor(ME_TextEditor
*editor
, int dir
)
1347 int cdir
= ME_GetCursorOfs(editor
, 0) - ME_GetCursorOfs(editor
, 1);
1355 BOOL
ME_UpdateSelection(ME_TextEditor
*editor
, const ME_Cursor
*pTempCursor
)
1357 ME_Cursor old_anchor
= editor
->pCursors
[1];
1359 if (GetKeyState(VK_SHIFT
)>=0) /* cancelling selection */
1361 /* any selection was present ? if so, it's no more, repaint ! */
1362 editor
->pCursors
[1] = editor
->pCursors
[0];
1363 if (memcmp(pTempCursor
, &old_anchor
, sizeof(ME_Cursor
))) {
1370 if (!memcmp(pTempCursor
, &editor
->pCursors
[1], sizeof(ME_Cursor
))) /* starting selection */
1372 editor
->pCursors
[1] = *pTempCursor
;
1381 void ME_DeleteSelection(ME_TextEditor
*editor
)
1384 ME_GetSelection(editor
, &from
, &to
);
1385 ME_DeleteTextAtCursor(editor
, ME_GetSelCursor(editor
,-1), to
-from
);
1388 ME_Style
*ME_GetSelectionInsertStyle(ME_TextEditor
*editor
)
1390 return ME_GetInsertStyle(editor
, 0);
1393 void ME_SendSelChange(ME_TextEditor
*editor
)
1397 if (!(editor
->nEventMask
& ENM_SELCHANGE
))
1400 sc
.nmhdr
.hwndFrom
= editor
->hWnd
;
1401 sc
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
1402 sc
.nmhdr
.code
= EN_SELCHANGE
;
1403 SendMessageW(editor
->hWnd
, EM_EXGETSEL
, 0, (LPARAM
)&sc
.chrg
);
1404 sc
.seltyp
= SEL_EMPTY
;
1405 if (sc
.chrg
.cpMin
!= sc
.chrg
.cpMax
)
1406 sc
.seltyp
|= SEL_TEXT
;
1407 if (sc
.chrg
.cpMin
< sc
.chrg
.cpMax
+1) /* wth were RICHEDIT authors thinking ? */
1408 sc
.seltyp
|= SEL_MULTICHAR
;
1409 TRACE("cpMin=%d cpMax=%d seltyp=%d (%s %s)\n",
1410 sc
.chrg
.cpMin
, sc
.chrg
.cpMax
, sc
.seltyp
,
1411 (sc
.seltyp
& SEL_TEXT
) ? "SEL_TEXT" : "",
1412 (sc
.seltyp
& SEL_MULTICHAR
) ? "SEL_MULTICHAR" : "");
1413 if (sc
.chrg
.cpMin
!= editor
->notified_cr
.cpMin
|| sc
.chrg
.cpMax
!= editor
->notified_cr
.cpMax
)
1415 ME_ClearTempStyle(editor
);
1417 editor
->notified_cr
= sc
.chrg
;
1418 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, sc
.nmhdr
.idFrom
, (LPARAM
)&sc
);
1423 ME_ArrowKey(ME_TextEditor
*editor
, int nVKey
, BOOL extend
, BOOL ctrl
)
1426 ME_Cursor
*p
= &editor
->pCursors
[nCursor
];
1427 ME_Cursor tmp_curs
= *p
;
1428 BOOL success
= FALSE
;
1430 ME_CheckCharOffsets(editor
);
1433 editor
->bCaretAtEnd
= 0;
1435 success
= ME_MoveCursorWords(editor
, &tmp_curs
, -1);
1437 success
= ME_MoveCursorChars(editor
, &tmp_curs
, -1);
1440 editor
->bCaretAtEnd
= 0;
1442 success
= ME_MoveCursorWords(editor
, &tmp_curs
, +1);
1444 success
= ME_MoveCursorChars(editor
, &tmp_curs
, +1);
1447 ME_MoveCursorLines(editor
, &tmp_curs
, -1);
1450 ME_MoveCursorLines(editor
, &tmp_curs
, +1);
1453 ME_ArrowPageUp(editor
, &tmp_curs
);
1456 ME_ArrowPageDown(editor
, &tmp_curs
);
1460 ME_ArrowCtrlHome(editor
, &tmp_curs
);
1462 ME_ArrowHome(editor
, &tmp_curs
);
1463 editor
->bCaretAtEnd
= 0;
1468 ME_ArrowCtrlEnd(editor
, &tmp_curs
);
1470 ME_ArrowEnd(editor
, &tmp_curs
);
1475 editor
->pCursors
[1] = tmp_curs
;
1478 ME_InvalidateSelection(editor
);
1480 HideCaret(editor
->hWnd
);
1481 ME_EnsureVisible(editor
, tmp_curs
.pRun
);
1482 ME_ShowCaret(editor
);
1483 ME_SendSelChange(editor
);