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
&& !ME_IsSelection(editor
))
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
)
252 if(ed
->bHaveFocus
&& !ME_IsSelection(ed
))
256 void ME_HideCaret(ME_TextEditor
*ed
)
258 if(!ed
->bHaveFocus
|| ME_IsSelection(ed
))
265 BOOL
ME_InternalDeleteText(ME_TextEditor
*editor
, int nOfs
, int nChars
,
270 int totalChars
= nChars
;
274 ME_ProtectPartialTableDeletion(editor
, nOfs
, &nChars
);
282 ME_CursorFromCharOfs(editor
, nOfs
, &c
);
283 run
= &c
.pRun
->member
.run
;
284 if (run
->nFlags
& MERF_ENDPARA
) {
285 int eollen
= run
->nCR
+ run
->nLF
;
286 BOOL keepFirstParaFormat
;
288 if (!ME_FindItemFwd(c
.pRun
, diParagraph
))
292 keepFirstParaFormat
= (totalChars
== nChars
&& nChars
<= eollen
&&
294 ME_JoinParagraphs(editor
, ME_GetParagraph(c
.pRun
), keepFirstParaFormat
);
295 /* ME_SkipAndPropagateCharOffset(p->pRun, shift); */
296 ME_CheckCharOffsets(editor
);
297 nChars
-= (eollen
< nChars
) ? eollen
: nChars
;
303 int nIntendedChars
= nChars
;
304 int nCharsToDelete
= nChars
;
308 ME_FindItemBack(c
.pRun
, diParagraph
)->member
.para
.nFlags
|= MEPF_REWRAP
;
311 ME_StrRelPos(run
->strText
, loc
, &nChars
);
312 /* nChars is the number of characters that should be deleted from the
313 FOLLOWING runs (these AFTER cursor.pRun)
314 nCharsToDelete is a number of chars to delete from THIS run */
315 nCharsToDelete
-= nChars
;
316 shift
-= nCharsToDelete
;
317 TRACE("Deleting %d (intended %d-remaning %d) chars at %d in '%s' (%d)\n",
318 nCharsToDelete
, nIntendedChars
, nChars
, c
.nOffset
,
319 debugstr_w(run
->strText
->szData
), run
->strText
->nLen
);
321 if (!c
.nOffset
&& ME_StrVLen(run
->strText
) == nCharsToDelete
)
323 /* undo = reinsert whole run */
324 /* nOfs is a character offset (from the start of the document
325 to the current (deleted) run */
326 ME_UndoItem
*pUndo
= ME_AddUndoItem(editor
, diUndoInsertRun
, c
.pRun
);
328 pUndo
->di
.member
.run
.nCharOfs
= nOfs
;
332 /* undo = reinsert partial run */
333 ME_UndoItem
*pUndo
= ME_AddUndoItem(editor
, diUndoInsertRun
, c
.pRun
);
335 ME_DestroyString(pUndo
->di
.member
.run
.strText
);
336 pUndo
->di
.member
.run
.nCharOfs
= nOfs
;
337 pUndo
->di
.member
.run
.strText
= ME_MakeStringN(run
->strText
->szData
+c
.nOffset
, nCharsToDelete
);
340 TRACE("Post deletion string: %s (%d)\n", debugstr_w(run
->strText
->szData
), run
->strText
->nLen
);
341 TRACE("Shift value: %d\n", shift
);
342 ME_StrDeleteV(run
->strText
, c
.nOffset
, nCharsToDelete
);
344 /* update cursors (including c) */
345 for (i
=-1; i
<editor
->nCursors
; i
++) {
346 ME_Cursor
*pThisCur
= editor
->pCursors
+ i
;
347 if (i
== -1) pThisCur
= &c
;
348 if (pThisCur
->pRun
== cursor
.pRun
) {
349 if (pThisCur
->nOffset
> cursor
.nOffset
) {
350 if (pThisCur
->nOffset
-cursor
.nOffset
< nCharsToDelete
)
351 pThisCur
->nOffset
= cursor
.nOffset
;
353 pThisCur
->nOffset
-= nCharsToDelete
;
354 assert(pThisCur
->nOffset
>= 0);
355 assert(pThisCur
->nOffset
<= ME_StrVLen(run
->strText
));
357 if (pThisCur
->nOffset
== ME_StrVLen(run
->strText
))
359 pThisCur
->pRun
= ME_FindItemFwd(pThisCur
->pRun
, diRunOrParagraphOrEnd
);
360 assert(pThisCur
->pRun
->type
== diRun
);
361 pThisCur
->nOffset
= 0;
366 /* c = updated data now */
368 if (c
.pRun
== cursor
.pRun
)
369 ME_SkipAndPropagateCharOffset(c
.pRun
, shift
);
371 ME_PropagateCharOffset(c
.pRun
, shift
);
373 if (!ME_StrVLen(cursor
.pRun
->member
.run
.strText
))
375 TRACE("Removing useless run\n");
376 ME_Remove(cursor
.pRun
);
377 ME_DestroyDisplayItem(cursor
.pRun
);
382 ME_CheckCharOffsets(editor);
390 BOOL
ME_DeleteTextAtCursor(ME_TextEditor
*editor
, int nCursor
, int nChars
)
392 assert(nCursor
>=0 && nCursor
<editor
->nCursors
);
393 /* text operations set modified state */
394 editor
->nModifyStep
= 1;
395 return ME_InternalDeleteText(editor
, ME_GetCursorOfs(editor
, nCursor
), nChars
,
399 static ME_DisplayItem
*
400 ME_InternalInsertTextFromCursor(ME_TextEditor
*editor
, int nCursor
,
401 const WCHAR
*str
, int len
, ME_Style
*style
,
404 ME_Cursor
*p
= &editor
->pCursors
[nCursor
];
406 editor
->bCaretAtEnd
= FALSE
;
408 assert(p
->pRun
->type
== diRun
);
410 return ME_InsertRunAtCursor(editor
, p
, style
, str
, len
, flags
);
414 void ME_InsertOLEFromCursor(ME_TextEditor
*editor
, const REOBJECT
* reo
, int nCursor
)
416 ME_Style
*pStyle
= ME_GetInsertStyle(editor
, nCursor
);
421 if (ME_IsSelection(editor
))
422 ME_DeleteSelection(editor
);
424 di
= ME_InternalInsertTextFromCursor(editor
, nCursor
, &space
, 1, pStyle
,
426 di
->member
.run
.ole_obj
= ALLOC_OBJ(*reo
);
427 ME_CopyReObject(di
->member
.run
.ole_obj
, reo
);
428 ME_SendSelChange(editor
);
432 void ME_InsertEndRowFromCursor(ME_TextEditor
*editor
, int nCursor
)
434 ME_Style
*pStyle
= ME_GetInsertStyle(editor
, nCursor
);
439 if (ME_IsSelection(editor
))
440 ME_DeleteSelection(editor
);
442 di
= ME_InternalInsertTextFromCursor(editor
, nCursor
, &space
, 1, pStyle
,
444 ME_SendSelChange(editor
);
448 void ME_InsertTextFromCursor(ME_TextEditor
*editor
, int nCursor
,
449 const WCHAR
*str
, int len
, ME_Style
*style
)
455 /* FIXME really HERE ? */
456 if (ME_IsSelection(editor
))
457 ME_DeleteSelection(editor
);
459 /* FIXME: is this too slow? */
460 /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */
461 oldLen
= ME_GetTextLength(editor
);
463 /* text operations set modified state */
464 editor
->nModifyStep
= 1;
468 assert(nCursor
>=0 && nCursor
<editor
->nCursors
);
472 /* grow the text limit to fit our text */
473 if(editor
->nTextLimit
< oldLen
+len
)
474 editor
->nTextLimit
= oldLen
+ len
;
479 /* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */
480 while(pos
-str
< len
&& *pos
!= '\r' && *pos
!= '\n' && *pos
!= '\t')
482 if (pos
-str
< len
&& *pos
== '\t') { /* handle tabs */
486 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, pos
-str
, style
, 0);
488 ME_InternalInsertTextFromCursor(editor
, nCursor
, &tab
, 1, style
, MERF_TAB
);
497 /* handle special \r\r\n sequence (richedit 2.x and higher only) */
498 if (!editor
->bEmulateVersion10
&& pos
-str
< len
-2 && pos
[0] == '\r' && pos
[1] == '\r' && pos
[2] == '\n') {
502 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, pos
-str
, style
, 0);
504 ME_InternalInsertTextFromCursor(editor
, nCursor
, &space
, 1, style
, 0);
513 if (pos
-str
< len
) { /* handle EOLs */
514 ME_DisplayItem
*tp
, *end_run
;
519 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, pos
-str
, style
, 0);
520 p
= &editor
->pCursors
[nCursor
];
522 ME_SplitRunSimple(editor
, p
->pRun
, p
->nOffset
);
523 p
= &editor
->pCursors
[nCursor
];
525 tmp_style
= ME_GetInsertStyle(editor
, nCursor
);
526 /* ME_SplitParagraph increases style refcount */
528 /* Encode and fill number of CR and LF according to emulation mode */
529 if (editor
->bEmulateVersion10
) {
532 /* We have to find out how many consecutive \r are there, and if there
533 is a \n terminating the run of \r's. */
534 numCR
= 0; numLF
= 0;
536 while (tpos
-str
< len
&& *tpos
== '\r') {
540 if (tpos
-str
>= len
) {
541 /* Reached end of text without finding anything but '\r' */
545 numCR
= 1; numLF
= 0;
546 } else if (*tpos
== '\n') {
547 /* The entire run of \r's plus the one \n is one single line break */
551 /* Found some other content past the run of \r's */
553 numCR
= 1; numLF
= 0;
556 if(pos
-str
< len
&& *pos
=='\r')
558 if(pos
-str
< len
&& *pos
=='\n')
560 numCR
= 1; numLF
= 0;
562 tp
= ME_SplitParagraph(editor
, p
->pRun
, p
->pRun
->member
.run
.style
, numCR
, numLF
);
563 p
->pRun
= ME_FindItemFwd(tp
, diRun
);
564 end_run
= ME_FindItemBack(tp
, diRun
);
565 ME_ReleaseStyle(end_run
->member
.run
.style
);
566 end_run
->member
.run
.style
= tmp_style
;
575 ME_InternalInsertTextFromCursor(editor
, nCursor
, str
, len
, style
, 0);
582 ME_MoveCursorChars(ME_TextEditor
*editor
, ME_Cursor
*pCursor
, int nRelOfs
)
584 ME_DisplayItem
*pRun
= pCursor
->pRun
;
588 if (!pCursor
->nOffset
)
591 pRun
= ME_FindItemBack(pRun
, diRunOrParagraph
);
598 if (pRun
->member
.para
.prev_para
->type
== diTextStart
)
600 pRun
= ME_FindItemBack(pRun
, diRunOrParagraph
);
601 /* every paragraph ought to have at least one run */
602 assert(pRun
&& pRun
->type
== diRun
);
603 assert(pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
606 assert(pRun
->type
!= diRun
&& pRun
->type
!= diParagraph
);
609 } while (RUN_IS_HIDDEN(&pRun
->member
.run
));
610 pCursor
->pRun
= pRun
;
611 if (pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
612 pCursor
->nOffset
= 0;
614 pCursor
->nOffset
= pRun
->member
.run
.strText
->nLen
;
617 if (pCursor
->nOffset
)
618 pCursor
->nOffset
= ME_StrRelPos2(pCursor
->pRun
->member
.run
.strText
, pCursor
->nOffset
, nRelOfs
);
623 if (!(pRun
->member
.run
.nFlags
& MERF_ENDPARA
))
625 int new_ofs
= ME_StrRelPos2(pRun
->member
.run
.strText
, pCursor
->nOffset
, nRelOfs
);
627 if (new_ofs
< pRun
->member
.run
.strText
->nLen
)
629 pCursor
->nOffset
= new_ofs
;
634 pRun
= ME_FindItemFwd(pRun
, diRun
);
635 } while (pRun
&& RUN_IS_HIDDEN(&pRun
->member
.run
));
638 pCursor
->pRun
= pRun
;
639 pCursor
->nOffset
= 0;
648 ME_MoveCursorWords(ME_TextEditor
*editor
, ME_Cursor
*cursor
, int nRelOfs
)
650 ME_DisplayItem
*pRun
= cursor
->pRun
, *pOtherRun
;
651 int nOffset
= cursor
->nOffset
;
655 /* Backward movement */
658 nOffset
= ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
659 nOffset
, WB_MOVEWORDLEFT
);
662 pOtherRun
= ME_FindItemBack(pRun
, diRunOrParagraph
);
663 if (pOtherRun
->type
== diRun
)
665 if (ME_CallWordBreakProc(editor
, pOtherRun
->member
.run
.strText
,
666 pOtherRun
->member
.run
.strText
->nLen
- 1,
668 && !(pRun
->member
.run
.nFlags
& MERF_ENDPARA
)
669 && !(cursor
->pRun
== pRun
&& cursor
->nOffset
== 0)
670 && !ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
, 0,
674 nOffset
= pOtherRun
->member
.run
.strText
->nLen
;
676 else if (pOtherRun
->type
== diParagraph
)
678 if (cursor
->pRun
== pRun
&& cursor
->nOffset
== 0)
680 /* Paragraph breaks are treated as separate words */
681 if (pOtherRun
->member
.para
.prev_para
->type
== diTextStart
)
683 pRun
= ME_FindItemBack(pOtherRun
, diRunOrParagraph
);
691 /* Forward movement */
692 BOOL last_delim
= FALSE
;
696 if (last_delim
&& !ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
697 nOffset
, WB_ISDELIMITER
))
699 nOffset
= ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
700 nOffset
, WB_MOVEWORDRIGHT
);
701 if (nOffset
< pRun
->member
.run
.strText
->nLen
)
703 pOtherRun
= ME_FindItemFwd(pRun
, diRunOrParagraphOrEnd
);
704 if (pOtherRun
->type
== diRun
)
706 last_delim
= ME_CallWordBreakProc(editor
, pRun
->member
.run
.strText
,
707 nOffset
- 1, WB_ISDELIMITER
);
711 else if (pOtherRun
->type
== diParagraph
)
713 if (cursor
->pRun
== pRun
)
714 pRun
= ME_FindItemFwd(pOtherRun
, diRun
);
720 if (cursor
->pRun
== pRun
)
728 cursor
->nOffset
= nOffset
;
734 ME_SelectByType(ME_TextEditor
*editor
, ME_SelectionType selectionType
)
736 /* pCursor[0] is the end of the selection
737 * pCursor[1] is the start of the selection (or the position selection anchor)
738 * pCursor[2] and [3] are the selection anchors that are backed up
739 * so they are kept when the selection changes for drag selection.
742 editor
->nSelectionType
= selectionType
;
743 switch(selectionType
)
748 ME_MoveCursorWords(editor
, &editor
->pCursors
[0], +1);
749 editor
->pCursors
[1] = editor
->pCursors
[0];
750 ME_MoveCursorWords(editor
, &editor
->pCursors
[1], -1);
755 ME_DisplayItem
*pItem
;
756 ME_DIType fwdSearchType
, backSearchType
;
757 if (selectionType
== stParagraph
) {
758 backSearchType
= diParagraph
;
759 fwdSearchType
= diParagraphOrEnd
;
761 backSearchType
= diStartRow
;
762 fwdSearchType
= diStartRowOrParagraphOrEnd
;
764 pItem
= ME_FindItemFwd(editor
->pCursors
[0].pRun
, fwdSearchType
);
766 if (pItem
->type
== diTextEnd
)
767 editor
->pCursors
[0].pRun
= ME_FindItemBack(pItem
, diRun
);
769 editor
->pCursors
[0].pRun
= ME_FindItemFwd(pItem
, diRun
);
770 editor
->pCursors
[0].nOffset
= 0;
772 pItem
= ME_FindItemBack(pItem
, backSearchType
);
773 editor
->pCursors
[1].pRun
= ME_FindItemFwd(pItem
, diRun
);
774 editor
->pCursors
[1].nOffset
= 0;
778 /* Select everything with cursor anchored from the start of the text */
779 editor
->nSelectionType
= stDocument
;
780 editor
->pCursors
[1].pRun
= ME_FindItemFwd(editor
->pBuffer
->pFirst
, diRun
);
781 editor
->pCursors
[1].nOffset
= 0;
782 editor
->pCursors
[0].pRun
= ME_FindItemBack(editor
->pBuffer
->pLast
, diRun
);
783 editor
->pCursors
[0].nOffset
= 0;
787 /* Store the anchor positions for extending the selection. */
788 editor
->pCursors
[2] = editor
->pCursors
[0];
789 editor
->pCursors
[3] = editor
->pCursors
[1];
792 int ME_GetCursorOfs(ME_TextEditor
*editor
, int nCursor
)
794 ME_Cursor
*pCursor
= &editor
->pCursors
[nCursor
];
795 return ME_GetParagraph(pCursor
->pRun
)->member
.para
.nCharOfs
796 + pCursor
->pRun
->member
.run
.nCharOfs
+ pCursor
->nOffset
;
799 /* Finds the run and offset from the pixel position.
801 * x & y are pixel positions in virtual coordinates into the rich edit control,
802 * so client coordinates must first be adjusted by the scroll position.
804 * returns TRUE if the result was exactly under the cursor, otherwise returns
805 * FALSE, and result is set to the closest position to the coordinates.
807 static BOOL
ME_FindPixelPos(ME_TextEditor
*editor
, int x
, int y
,
808 ME_Cursor
*result
, BOOL
*is_eol
)
810 ME_DisplayItem
*p
= editor
->pBuffer
->pFirst
->member
.para
.next_para
;
811 ME_DisplayItem
*last
= NULL
;
819 for (; p
!= editor
->pBuffer
->pLast
; p
= p
->member
.para
.next_para
)
821 assert(p
->type
== diParagraph
);
822 if (y
< p
->member
.para
.nYPos
+ p
->member
.para
.nHeight
)
824 y
-= p
->member
.para
.nYPos
;
825 p
= ME_FindItemFwd(p
, diStartRow
);
830 for (; p
!= editor
->pBuffer
->pLast
; )
833 assert(p
->type
== diStartRow
);
834 if (y
< p
->member
.row
.nYPos
+ p
->member
.row
.nHeight
)
836 p
= ME_FindItemFwd(p
, diRun
);
839 pp
= ME_FindItemFwd(p
, diStartRowOrParagraphOrEnd
);
840 if (pp
->type
!= diStartRow
)
842 p
= ME_FindItemFwd(p
, diRun
);
847 if (p
== editor
->pBuffer
->pLast
)
849 /* The position is below the last paragraph, so the last row will be used
850 * rather than the end of the text, so the x position will be used to
851 * determine the offset closest to the pixel position. */
853 p
= ME_FindItemBack(p
, diStartRow
);
855 p
= ME_FindItemFwd(p
, diRun
);
859 p
= editor
->pBuffer
->pLast
;
862 for (; p
!= editor
->pBuffer
->pLast
; p
= p
->next
)
867 rx
= x
- p
->member
.run
.pt
.x
;
868 if (rx
< p
->member
.run
.nWidth
)
871 assert(p
->type
== diRun
);
872 if ((p
->member
.run
.nFlags
& MERF_ENDPARA
) || rx
< 0)
875 result
->nOffset
= ME_CharFromPointCursor(editor
, rx
, &p
->member
.run
);
876 if (editor
->pCursors
[0].nOffset
== p
->member
.run
.strText
->nLen
&& rx
)
878 result
->pRun
= ME_FindItemFwd(editor
->pCursors
[0].pRun
, diRun
);
886 p
= ME_FindItemFwd(p
, diRun
);
887 if (is_eol
) *is_eol
= 1;
888 rx
= 0; /* FIXME not sure */
893 rx
= 0; /* FIXME not sure */
900 result
->pRun
= ME_FindItemBack(p
, diRun
);
902 assert(result
->pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
907 /* Returns the character offset closest to the pixel position
909 * x & y are pixel positions in client coordinates.
911 * isExact will be set to TRUE if the run is directly under the pixel
912 * position, FALSE if it not, unless isExact is set to NULL.
914 int ME_CharFromPos(ME_TextEditor
*editor
, int x
, int y
, BOOL
*isExact
)
920 GetClientRect(editor
->hWnd
, &rc
);
921 if (x
< 0 || y
< 0 || x
>= rc
.right
|| y
>= rc
.bottom
) {
922 if (isExact
) *isExact
= FALSE
;
925 y
+= ME_GetYScrollPos(editor
);
926 bResult
= ME_FindPixelPos(editor
, x
, y
, &cursor
, NULL
);
927 if (isExact
) *isExact
= bResult
;
928 return (ME_GetParagraph(cursor
.pRun
)->member
.para
.nCharOfs
929 + cursor
.pRun
->member
.run
.nCharOfs
+ cursor
.nOffset
);
934 /* Extends the selection with a word, line, or paragraph selection type.
936 * The selection is anchored by editor->pCursors[2-3] such that the text
937 * between the anchors will remain selected, and one end will be extended.
939 * editor->pCursors[0] should have the position to extend the selection to
940 * before this function is called.
942 * Nothing will be done if editor->nSelectionType equals stPosition.
944 static void ME_ExtendAnchorSelection(ME_TextEditor
*editor
)
946 ME_Cursor tmp_cursor
;
947 int curOfs
, anchorStartOfs
, anchorEndOfs
;
948 if (editor
->nSelectionType
== stPosition
|| editor
->nSelectionType
== stDocument
)
950 curOfs
= ME_GetCursorOfs(editor
, 0);
951 anchorStartOfs
= ME_GetCursorOfs(editor
, 3);
952 anchorEndOfs
= ME_GetCursorOfs(editor
, 2);
954 tmp_cursor
= editor
->pCursors
[0];
955 editor
->pCursors
[0] = editor
->pCursors
[2];
956 editor
->pCursors
[1] = editor
->pCursors
[3];
957 if (curOfs
< anchorStartOfs
)
959 /* Extend the left side of selection */
960 editor
->pCursors
[1] = tmp_cursor
;
961 if (editor
->nSelectionType
== stWord
)
962 ME_MoveCursorWords(editor
, &editor
->pCursors
[1], -1);
965 ME_DisplayItem
*pItem
;
966 ME_DIType searchType
= ((editor
->nSelectionType
== stLine
) ?
967 diStartRowOrParagraph
:diParagraph
);
968 pItem
= ME_FindItemBack(editor
->pCursors
[1].pRun
, searchType
);
969 editor
->pCursors
[1].pRun
= ME_FindItemFwd(pItem
, diRun
);
970 editor
->pCursors
[1].nOffset
= 0;
973 else if (curOfs
>= anchorEndOfs
)
975 /* Extend the right side of selection */
976 editor
->pCursors
[0] = tmp_cursor
;
977 if (editor
->nSelectionType
== stWord
)
978 ME_MoveCursorWords(editor
, &editor
->pCursors
[0], +1);
981 ME_DisplayItem
*pItem
;
982 ME_DIType searchType
= ((editor
->nSelectionType
== stLine
) ?
983 diStartRowOrParagraphOrEnd
:diParagraphOrEnd
);
984 pItem
= ME_FindItemFwd(editor
->pCursors
[0].pRun
, searchType
);
985 if (pItem
->type
== diTextEnd
)
986 editor
->pCursors
[0].pRun
= ME_FindItemBack(pItem
, diRun
);
988 editor
->pCursors
[0].pRun
= ME_FindItemFwd(pItem
, diRun
);
989 editor
->pCursors
[0].nOffset
= 0;
994 void ME_LButtonDown(ME_TextEditor
*editor
, int x
, int y
, int clickNum
)
996 ME_Cursor tmp_cursor
;
997 int is_selection
= 0;
1000 editor
->nUDArrowX
= -1;
1002 y
+= ME_GetYScrollPos(editor
);
1004 tmp_cursor
= editor
->pCursors
[0];
1005 is_selection
= ME_IsSelection(editor
);
1006 is_shift
= GetKeyState(VK_SHIFT
) < 0;
1008 ME_FindPixelPos(editor
, x
, y
, &editor
->pCursors
[0], &editor
->bCaretAtEnd
);
1010 if (x
>= editor
->selofs
|| is_shift
)
1014 editor
->pCursors
[1] = editor
->pCursors
[0];
1016 if (x
>= editor
->selofs
)
1017 ME_SelectByType(editor
, stWord
);
1019 ME_SelectByType(editor
, stParagraph
);
1020 } else if (clickNum
% 2 == 0) {
1021 ME_SelectByType(editor
, stWord
);
1023 ME_SelectByType(editor
, stParagraph
);
1028 editor
->nSelectionType
= stPosition
;
1029 editor
->pCursors
[1] = editor
->pCursors
[0];
1031 else if (!is_selection
)
1033 editor
->nSelectionType
= stPosition
;
1034 editor
->pCursors
[1] = tmp_cursor
;
1036 else if (editor
->nSelectionType
!= stPosition
)
1038 ME_ExtendAnchorSelection(editor
);
1044 ME_SelectByType(editor
, stLine
);
1045 } else if (clickNum
% 2 == 0 || is_shift
) {
1046 ME_SelectByType(editor
, stParagraph
);
1048 ME_SelectByType(editor
, stDocument
);
1051 ME_InvalidateSelection(editor
);
1052 HideCaret(editor
->hWnd
);
1053 ME_ShowCaret(editor
);
1054 ME_ClearTempStyle(editor
);
1055 ME_SendSelChange(editor
);
1058 void ME_MouseMove(ME_TextEditor
*editor
, int x
, int y
)
1060 ME_Cursor tmp_cursor
;
1062 if (editor
->nSelectionType
== stDocument
)
1064 y
+= ME_GetYScrollPos(editor
);
1066 tmp_cursor
= editor
->pCursors
[0];
1067 /* FIXME: do something with the return value of ME_FindPixelPos */
1068 ME_FindPixelPos(editor
, x
, y
, &tmp_cursor
, &editor
->bCaretAtEnd
);
1070 ME_InvalidateSelection(editor
);
1071 editor
->pCursors
[0] = tmp_cursor
;
1072 ME_ExtendAnchorSelection(editor
);
1074 if (editor
->nSelectionType
!= stPosition
&&
1075 memcmp(&editor
->pCursors
[1], &editor
->pCursors
[3], sizeof(ME_Cursor
)))
1077 /* The scroll the cursor towards the other end, since it was the one
1078 * extended by ME_ExtendAnchorSelection
1080 ME_Cursor tmpCursor
= editor
->pCursors
[0];
1081 editor
->pCursors
[0] = editor
->pCursors
[1];
1082 editor
->pCursors
[1] = tmpCursor
;
1083 SendMessageW(editor
->hWnd
, EM_SCROLLCARET
, 0, 0);
1084 editor
->pCursors
[1] = editor
->pCursors
[0];
1085 editor
->pCursors
[0] = tmpCursor
;
1087 SendMessageW(editor
->hWnd
, EM_SCROLLCARET
, 0, 0);
1090 ME_InvalidateSelection(editor
);
1091 HideCaret(editor
->hWnd
);
1092 ME_ShowCaret(editor
);
1093 ME_SendSelChange(editor
);
1096 static ME_DisplayItem
*ME_FindRunInRow(ME_TextEditor
*editor
, ME_DisplayItem
*pRow
,
1097 int x
, int *pOffset
, int *pbCaretAtEnd
)
1099 ME_DisplayItem
*pNext
, *pLastRun
;
1100 pNext
= ME_FindItemFwd(pRow
, diRunOrStartRow
);
1101 assert(pNext
->type
== diRun
);
1103 if (pbCaretAtEnd
) *pbCaretAtEnd
= FALSE
;
1104 if (pOffset
) *pOffset
= 0;
1106 int run_x
= pNext
->member
.run
.pt
.x
;
1107 int width
= pNext
->member
.run
.nWidth
;
1112 if (x
>= run_x
&& x
< run_x
+width
)
1114 int ch
= ME_CharFromPointCursor(editor
, x
-run_x
, &pNext
->member
.run
);
1115 ME_String
*s
= pNext
->member
.run
.strText
;
1123 pNext
= ME_FindItemFwd(pNext
, diRunOrStartRow
);
1124 } while(pNext
&& pNext
->type
== diRun
);
1126 if ((pLastRun
->member
.run
.nFlags
& MERF_ENDPARA
) == 0)
1128 pNext
= ME_FindItemFwd(pNext
, diRun
);
1129 if (pbCaretAtEnd
) *pbCaretAtEnd
= TRUE
;
1136 static int ME_GetXForArrow(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1138 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1141 if (editor
->nUDArrowX
!= -1)
1142 x
= editor
->nUDArrowX
;
1144 if (editor
->bCaretAtEnd
)
1146 pRun
= ME_FindItemBack(pRun
, diRun
);
1148 x
= pRun
->member
.run
.pt
.x
+ pRun
->member
.run
.nWidth
;
1151 x
= pRun
->member
.run
.pt
.x
;
1152 x
+= ME_PointFromChar(editor
, &pRun
->member
.run
, pCursor
->nOffset
);
1154 editor
->nUDArrowX
= x
;
1161 ME_MoveCursorLines(ME_TextEditor
*editor
, ME_Cursor
*pCursor
, int nRelOfs
)
1163 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1164 ME_DisplayItem
*pItem
;
1165 int x
= ME_GetXForArrow(editor
, pCursor
);
1167 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
)
1168 pRun
= ME_FindItemBack(pRun
, diRun
);
1173 /* start of this row */
1174 pItem
= ME_FindItemBack(pRun
, diStartRow
);
1176 /* start of the previous row */
1177 pItem
= ME_FindItemBack(pItem
, diStartRow
);
1181 /* start of the next row */
1182 pItem
= ME_FindItemFwd(pRun
, diStartRow
);
1183 /* FIXME If diParagraph is before diStartRow, wrap the next paragraph?
1188 /* row not found - ignore */
1191 pCursor
->pRun
= ME_FindRunInRow(editor
, pItem
, x
, &pCursor
->nOffset
, &editor
->bCaretAtEnd
);
1192 assert(pCursor
->pRun
);
1193 assert(pCursor
->pRun
->type
== diRun
);
1197 static void ME_ArrowPageUp(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1199 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1200 ME_DisplayItem
*pLast
, *p
;
1201 int x
, y
, ys
, yd
, yp
, yprev
;
1202 ME_Cursor tmp_curs
= *pCursor
;
1204 x
= ME_GetXForArrow(editor
, pCursor
);
1205 if (!pCursor
->nOffset
&& editor
->bCaretAtEnd
)
1206 pRun
= ME_FindItemBack(pRun
, diRun
);
1208 p
= ME_FindItemBack(pRun
, diStartRowOrParagraph
);
1209 assert(p
->type
== diStartRow
);
1210 yp
= ME_FindItemBack(p
, diParagraph
)->member
.para
.nYPos
;
1211 yprev
= ys
= y
= yp
+ p
->member
.row
.nYPos
;
1212 yd
= y
- editor
->sizeWindow
.cy
;
1216 p
= ME_FindItemBack(p
, diStartRowOrParagraph
);
1219 if (p
->type
== diParagraph
) { /* crossing paragraphs */
1220 if (p
->member
.para
.prev_para
== NULL
)
1222 yp
= p
->member
.para
.prev_para
->member
.para
.nYPos
;
1225 y
= yp
+ p
->member
.row
.nYPos
;
1232 pCursor
->pRun
= ME_FindRunInRow(editor
, pLast
, x
, &pCursor
->nOffset
, &editor
->bCaretAtEnd
);
1233 ME_UpdateSelection(editor
, &tmp_curs
);
1234 if (yprev
< editor
->sizeWindow
.cy
)
1236 ME_EnsureVisible(editor
, ME_FindItemFwd(editor
->pBuffer
->pFirst
, diRun
));
1241 ME_ScrollUp(editor
, ys
-yprev
);
1243 assert(pCursor
->pRun
);
1244 assert(pCursor
->pRun
->type
== diRun
);
1247 /* FIXME: in the original RICHEDIT, PageDown always scrolls by the same amount
1248 of pixels, even if it makes the scroll bar position exceed its normal maximum.
1249 In such a situation, clicking the scrollbar restores its position back to the
1250 normal range (ie. sets it to (doclength-screenheight)). */
1252 static void ME_ArrowPageDown(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1254 ME_DisplayItem
*pRun
= pCursor
->pRun
;
1255 ME_DisplayItem
*pLast
, *p
;
1256 int x
, y
, ys
, yd
, yp
, yprev
;
1257 ME_Cursor tmp_curs
= *pCursor
;
1259 x
= ME_GetXForArrow(editor
, pCursor
);
1260 if (!pCursor
->nOffset
&& editor
->bCaretAtEnd
)
1261 pRun
= ME_FindItemBack(pRun
, diRun
);
1263 p
= ME_FindItemBack(pRun
, diStartRowOrParagraph
);
1264 assert(p
->type
== diStartRow
);
1265 yp
= ME_FindItemBack(p
, diParagraph
)->member
.para
.nYPos
;
1266 yprev
= ys
= y
= yp
+ p
->member
.row
.nYPos
;
1267 yd
= y
+ editor
->sizeWindow
.cy
;
1271 p
= ME_FindItemFwd(p
, diStartRowOrParagraph
);
1274 if (p
->type
== diParagraph
) {
1275 yp
= p
->member
.para
.nYPos
;
1278 y
= yp
+ p
->member
.row
.nYPos
;
1285 pCursor
->pRun
= ME_FindRunInRow(editor
, pLast
, x
, &pCursor
->nOffset
, &editor
->bCaretAtEnd
);
1286 ME_UpdateSelection(editor
, &tmp_curs
);
1287 if (yprev
>= editor
->nTotalLength
-editor
->sizeWindow
.cy
)
1289 ME_EnsureVisible(editor
, ME_FindItemBack(editor
->pBuffer
->pLast
, diRun
));
1294 ME_ScrollUp(editor
,ys
-yprev
);
1296 assert(pCursor
->pRun
);
1297 assert(pCursor
->pRun
->type
== diRun
);
1300 static void ME_ArrowHome(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1302 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diStartRow
);
1303 ME_WrapMarkedParagraphs(editor
);
1305 ME_DisplayItem
*pRun
;
1306 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
) {
1307 pRow
= ME_FindItemBack(pRow
, diStartRow
);
1311 pRun
= ME_FindItemFwd(pRow
, diRun
);
1313 pCursor
->pRun
= pRun
;
1314 pCursor
->nOffset
= 0;
1317 editor
->bCaretAtEnd
= FALSE
;
1320 static void ME_ArrowCtrlHome(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1322 ME_DisplayItem
*pRow
= ME_FindItemBack(pCursor
->pRun
, diTextStart
);
1324 ME_DisplayItem
*pRun
= ME_FindItemFwd(pRow
, diRun
);
1326 pCursor
->pRun
= pRun
;
1327 pCursor
->nOffset
= 0;
1332 static void ME_ArrowEnd(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1334 ME_DisplayItem
*pRow
;
1336 if (editor
->bCaretAtEnd
&& !pCursor
->nOffset
)
1339 pRow
= ME_FindItemFwd(pCursor
->pRun
, diStartRowOrParagraphOrEnd
);
1341 if (pRow
->type
== diStartRow
) {
1342 /* FIXME WTF was I thinking about here ? */
1343 ME_DisplayItem
*pRun
= ME_FindItemFwd(pRow
, diRun
);
1345 pCursor
->pRun
= pRun
;
1346 pCursor
->nOffset
= 0;
1347 editor
->bCaretAtEnd
= 1;
1350 pCursor
->pRun
= ME_FindItemBack(pRow
, diRun
);
1351 assert(pCursor
->pRun
&& pCursor
->pRun
->member
.run
.nFlags
& MERF_ENDPARA
);
1352 pCursor
->nOffset
= 0;
1353 editor
->bCaretAtEnd
= FALSE
;
1356 static void ME_ArrowCtrlEnd(ME_TextEditor
*editor
, ME_Cursor
*pCursor
)
1358 ME_DisplayItem
*p
= ME_FindItemFwd(pCursor
->pRun
, diTextEnd
);
1360 p
= ME_FindItemBack(p
, diRun
);
1362 assert(p
->member
.run
.nFlags
& MERF_ENDPARA
);
1364 pCursor
->nOffset
= 0;
1365 editor
->bCaretAtEnd
= FALSE
;
1368 BOOL
ME_IsSelection(ME_TextEditor
*editor
)
1370 return memcmp(&editor
->pCursors
[0], &editor
->pCursors
[1], sizeof(ME_Cursor
))!=0;
1373 static int ME_GetSelCursor(ME_TextEditor
*editor
, int dir
)
1375 int cdir
= ME_GetCursorOfs(editor
, 0) - ME_GetCursorOfs(editor
, 1);
1383 BOOL
ME_UpdateSelection(ME_TextEditor
*editor
, const ME_Cursor
*pTempCursor
)
1385 ME_Cursor old_anchor
= editor
->pCursors
[1];
1387 if (GetKeyState(VK_SHIFT
)>=0) /* cancelling selection */
1389 /* any selection was present ? if so, it's no more, repaint ! */
1390 editor
->pCursors
[1] = editor
->pCursors
[0];
1391 if (memcmp(pTempCursor
, &old_anchor
, sizeof(ME_Cursor
))) {
1398 if (!memcmp(pTempCursor
, &editor
->pCursors
[1], sizeof(ME_Cursor
))) /* starting selection */
1400 editor
->pCursors
[1] = *pTempCursor
;
1409 void ME_DeleteSelection(ME_TextEditor
*editor
)
1412 ME_GetSelection(editor
, &from
, &to
);
1413 ME_DeleteTextAtCursor(editor
, ME_GetSelCursor(editor
,-1), to
-from
);
1416 ME_Style
*ME_GetSelectionInsertStyle(ME_TextEditor
*editor
)
1418 return ME_GetInsertStyle(editor
, 0);
1421 void ME_SendSelChange(ME_TextEditor
*editor
)
1425 if (!(editor
->nEventMask
& ENM_SELCHANGE
))
1428 sc
.nmhdr
.hwndFrom
= editor
->hWnd
;
1429 sc
.nmhdr
.idFrom
= GetWindowLongW(editor
->hWnd
, GWLP_ID
);
1430 sc
.nmhdr
.code
= EN_SELCHANGE
;
1431 SendMessageW(editor
->hWnd
, EM_EXGETSEL
, 0, (LPARAM
)&sc
.chrg
);
1432 sc
.seltyp
= SEL_EMPTY
;
1433 if (sc
.chrg
.cpMin
!= sc
.chrg
.cpMax
)
1434 sc
.seltyp
|= SEL_TEXT
;
1435 if (sc
.chrg
.cpMin
< sc
.chrg
.cpMax
+1) /* wth were RICHEDIT authors thinking ? */
1436 sc
.seltyp
|= SEL_MULTICHAR
;
1437 TRACE("cpMin=%d cpMax=%d seltyp=%d (%s %s)\n",
1438 sc
.chrg
.cpMin
, sc
.chrg
.cpMax
, sc
.seltyp
,
1439 (sc
.seltyp
& SEL_TEXT
) ? "SEL_TEXT" : "",
1440 (sc
.seltyp
& SEL_MULTICHAR
) ? "SEL_MULTICHAR" : "");
1441 if (sc
.chrg
.cpMin
!= editor
->notified_cr
.cpMin
|| sc
.chrg
.cpMax
!= editor
->notified_cr
.cpMax
)
1443 ME_ClearTempStyle(editor
);
1445 editor
->notified_cr
= sc
.chrg
;
1446 SendMessageW(GetParent(editor
->hWnd
), WM_NOTIFY
, sc
.nmhdr
.idFrom
, (LPARAM
)&sc
);
1451 ME_ArrowKey(ME_TextEditor
*editor
, int nVKey
, BOOL extend
, BOOL ctrl
)
1454 ME_Cursor
*p
= &editor
->pCursors
[nCursor
];
1455 ME_Cursor tmp_curs
= *p
;
1456 BOOL success
= FALSE
;
1458 ME_CheckCharOffsets(editor
);
1461 editor
->bCaretAtEnd
= 0;
1463 success
= ME_MoveCursorWords(editor
, &tmp_curs
, -1);
1465 success
= ME_MoveCursorChars(editor
, &tmp_curs
, -1);
1468 editor
->bCaretAtEnd
= 0;
1470 success
= ME_MoveCursorWords(editor
, &tmp_curs
, +1);
1472 success
= ME_MoveCursorChars(editor
, &tmp_curs
, +1);
1475 ME_MoveCursorLines(editor
, &tmp_curs
, -1);
1478 ME_MoveCursorLines(editor
, &tmp_curs
, +1);
1481 ME_ArrowPageUp(editor
, &tmp_curs
);
1484 ME_ArrowPageDown(editor
, &tmp_curs
);
1488 ME_ArrowCtrlHome(editor
, &tmp_curs
);
1490 ME_ArrowHome(editor
, &tmp_curs
);
1491 editor
->bCaretAtEnd
= 0;
1496 ME_ArrowCtrlEnd(editor
, &tmp_curs
);
1498 ME_ArrowEnd(editor
, &tmp_curs
);
1503 editor
->pCursors
[1] = tmp_curs
;
1506 ME_InvalidateSelection(editor
);
1508 HideCaret(editor
->hWnd
);
1509 ME_EnsureVisible(editor
, tmp_curs
.pRun
);
1510 ME_ShowCaret(editor
);
1511 ME_SendSelChange(editor
);