Module: wine
Branch: master
Commit: b0f177b61913b9fac1cf8952582d77576705bad1
URL: http://source.winehq.org/git/wine.git/?a=commit;h=b0f177b61913b9fac1cf89525…
Author: Huw Davies <huw(a)codeweavers.com>
Date: Tue Dec 10 11:19:08 2013 +0000
riched20: Ensure the cursors are correctly ordered in the case of a zero (logical) length selection bridging two runs.
---
dlls/riched20/caret.c | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c
index 33ea532..1225c03 100644
--- a/dlls/riched20/caret.c
+++ b/dlls/riched20/caret.c
@@ -56,7 +56,19 @@ int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
int ME_GetSelection(ME_TextEditor *editor, ME_Cursor **from, ME_Cursor **to)
{
- if (ME_GetCursorOfs(&editor->pCursors[0]) < ME_GetCursorOfs(&editor->pCursors[1]))
+ int from_ofs = ME_GetCursorOfs( &editor->pCursors[0] );
+ int to_ofs = ME_GetCursorOfs( &editor->pCursors[1] );
+ BOOL swap = (from_ofs > to_ofs);
+
+ if (from_ofs == to_ofs)
+ {
+ /* If cursor[0] is at the beginning of a run and cursor[1] at the end
+ of the prev run then we need to swap. */
+ if (editor->pCursors[0].nOffset < editor->pCursors[1].nOffset)
+ swap = TRUE;
+ }
+
+ if (!swap)
{
*from = &editor->pCursors[0];
*to = &editor->pCursors[1];