Commit 7c352b96 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Implemented paragraph selection.

parent abefc28f
...@@ -744,11 +744,54 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs) ...@@ -744,11 +744,54 @@ ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
void void
ME_SelectWord(ME_TextEditor *editor) ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType)
{ {
ME_MoveCursorWords(editor, &editor->pCursors[1], +1); /* pCursor[0] will be the start of the selection
editor->pCursors[0] = editor->pCursors[1]; * pCursor[1] is the other end of the selection range
ME_MoveCursorWords(editor, &editor->pCursors[0], -1); * pCursor[2] and [3] are the selection anchors that are backed up
* so they are kept when the selection changes for drag selection.
*/
editor->nSelectionType = selectionType;
switch(selectionType)
{
case stPosition:
break;
case stWord:
ME_MoveCursorWords(editor, &editor->pCursors[1], +1);
editor->pCursors[0] = editor->pCursors[1];
ME_MoveCursorWords(editor, &editor->pCursors[0], -1);
break;
case stLine:
case stParagraph:
{
ME_DisplayItem *pItem;
ME_DIType fwdSearchType, backSearchType;
if (selectionType == stParagraph) {
backSearchType = diParagraph;
fwdSearchType = diParagraphOrEnd;
} else {
backSearchType = diStartRow;
fwdSearchType = diStartRowOrParagraphOrEnd;
}
pItem = ME_FindItemBack(editor->pCursors[0].pRun, backSearchType);
editor->pCursors[0].pRun = ME_FindItemFwd(pItem, diRun);
editor->pCursors[0].nOffset = 0;
pItem = ME_FindItemFwd(editor->pCursors[0].pRun, fwdSearchType);
assert(pItem);
if (pItem->type == diTextEnd)
editor->pCursors[1].pRun = ME_FindItemBack(pItem, diRun);
else
editor->pCursors[1].pRun = ME_FindItemFwd(pItem, diRun);
editor->pCursors[1].nOffset = 0;
break;
}
default: assert(0);
}
/* Store the anchor positions for extending the selection. */
editor->pCursors[2] = editor->pCursors[0];
editor->pCursors[3] = editor->pCursors[1];
} }
...@@ -900,8 +943,9 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor) ...@@ -900,8 +943,9 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor)
else else
{ {
ME_DisplayItem *pItem; ME_DisplayItem *pItem;
pItem = ME_FindItemBack(editor->pCursors[0].pRun, ME_DIType searchType = ((editor->nSelectionType == stLine) ?
diStartRowOrParagraph); diStartRowOrParagraph:diParagraph);
pItem = ME_FindItemBack(editor->pCursors[0].pRun, searchType);
editor->pCursors[0].pRun = ME_FindItemFwd(pItem, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(pItem, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
} }
...@@ -915,8 +959,9 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor) ...@@ -915,8 +959,9 @@ static void ME_ExtendAnchorSelection(ME_TextEditor *editor)
else else
{ {
ME_DisplayItem *pItem; ME_DisplayItem *pItem;
pItem = ME_FindItemFwd(editor->pCursors[1].pRun, ME_DIType searchType = ((editor->nSelectionType == stLine) ?
diStartRowOrParagraphOrEnd); diStartRowOrParagraphOrEnd:diParagraphOrEnd);
pItem = ME_FindItemFwd(editor->pCursors[1].pRun, searchType);
if (pItem->type == diTextEnd) if (pItem->type == diTextEnd)
editor->pCursors[1].pRun = ME_FindItemBack(pItem, diRun); editor->pCursors[1].pRun = ME_FindItemBack(pItem, diRun);
else else
...@@ -930,6 +975,7 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) ...@@ -930,6 +975,7 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
{ {
ME_Cursor tmp_cursor; ME_Cursor tmp_cursor;
int is_selection = 0; int is_selection = 0;
BOOL is_shift;
editor->nUDArrowX = -1; editor->nUDArrowX = -1;
...@@ -937,23 +983,22 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) ...@@ -937,23 +983,22 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
tmp_cursor = editor->pCursors[0]; tmp_cursor = editor->pCursors[0];
is_selection = ME_IsSelection(editor); is_selection = ME_IsSelection(editor);
is_shift = GetKeyState(VK_SHIFT) < 0;
ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd); ME_FindPixelPos(editor, x, y, &editor->pCursors[0], &editor->bCaretAtEnd);
if (x >= editor->selofs || GetKeyState(VK_SHIFT) < 0) if (x >= editor->selofs || is_shift)
{ {
if (clickNum > 1) if (clickNum > 1)
{ {
editor->nSelectionType = stWord;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
ME_SelectWord(editor); if (x >= editor->selofs)
/* Store the anchor positions for extending the selection. */ ME_SelectByType(editor, stWord);
editor->pCursors[2] = editor->pCursors[0]; else
editor->pCursors[3] = editor->pCursors[1]; ME_SelectByType(editor, stParagraph);
} }
else if (GetKeyState(VK_SHIFT)>=0) else if (!is_shift)
{ {
/* Shift is not down */
editor->nSelectionType = stPosition; editor->nSelectionType = stPosition;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
} }
...@@ -969,25 +1014,11 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum) ...@@ -969,25 +1014,11 @@ void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
} }
else else
{ {
ME_DisplayItem *pItem; if (clickNum < 2) {
ME_SelectByType(editor, stLine);
editor->nSelectionType = stLine; } else {
/* Set pCursors[0] to beginning of line */ ME_SelectByType(editor, stParagraph);
/* Set pCursors[1] to end of line */ }
pItem = ME_FindItemFwd(editor->pCursors[0].pRun, diStartRowOrParagraphOrEnd);
assert(pItem);
if (pItem->type == diTextEnd)
editor->pCursors[1].pRun = ME_FindItemBack(pItem, diRun);
else
editor->pCursors[1].pRun = ME_FindItemFwd(pItem, diRun);
editor->pCursors[1].nOffset = 0;
/* pCursor[0] is the position where the cursor will be drawn,
* pCursor[1] is the other end of the selection range
* pCursor[2] and [3] are the selection anchors that are backed up
* so they are kept when the selection changes for drag line selection.
*/
editor->pCursors[2] = editor->pCursors[0];
editor->pCursors[3] = editor->pCursors[1];
} }
ME_InvalidateSelection(editor); ME_InvalidateSelection(editor);
HideCaret(editor->hWnd); HideCaret(editor->hWnd);
......
...@@ -176,7 +176,7 @@ void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod); ...@@ -176,7 +176,7 @@ void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod);
/* caret.c */ /* caret.c */
int ME_SetSelection(ME_TextEditor *editor, int from, int to); int ME_SetSelection(ME_TextEditor *editor, int from, int to);
void ME_SelectWord(ME_TextEditor *editor); void ME_SelectByType(ME_TextEditor *editor, ME_SelectionType selectionType);
void ME_HideCaret(ME_TextEditor *ed); void ME_HideCaret(ME_TextEditor *ed);
void ME_ShowCaret(ME_TextEditor *ed); void ME_ShowCaret(ME_TextEditor *ed);
void ME_MoveCaret(ME_TextEditor *ed); void ME_MoveCaret(ME_TextEditor *ed);
......
...@@ -247,7 +247,8 @@ typedef enum { ...@@ -247,7 +247,8 @@ typedef enum {
typedef enum { typedef enum {
stPosition = 0, stPosition = 0,
stWord, stWord,
stLine stLine,
stParagraph
} ME_SelectionType; } ME_SelectionType;
typedef struct tagME_FontTableItem { typedef struct tagME_FontTableItem {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment