summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xiup/src/win/iupwin_text.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/iup/src/win/iupwin_text.c b/iup/src/win/iupwin_text.c
index c0e7115..bb325b4 100755
--- a/iup/src/win/iupwin_text.c
+++ b/iup/src/win/iupwin_text.c
@@ -1177,6 +1177,8 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag)
char *selection, *units;
PARAFORMAT2 paraformat;
CHARFORMAT2 charformat;
+ CHARRANGE oldRange;
+ DWORD line0, line1;
/* one twip is 1/1440 inch */
/* twip = (pixel*1440)/(pixel/inch) */
@@ -1194,12 +1196,14 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag)
convert2twips = val;
}
+ /* saves current selection / scroll position before doing anything */
+ line0 = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0);
+ SendMessage(hWnd, EM_EXGETSEL, 0, LPARAM(&oldrange));
selection = iupAttribGet(formattag, "SELECTION");
if (selection)
{
/* In Windows, the format message use the current selection */
winTextSetSelectionAttrib(ih, selection);
- iupAttribSetStr(ih, "SELECTION", NULL);
}
else
{
@@ -1208,7 +1212,6 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag)
{
/* In Windows, the format message use the current selection */
winTextSetSelectionPosAttrib(ih, selectionpos);
- iupAttribSetStr(ih, "SELECTIONPOS", NULL);
}
}
@@ -1223,9 +1226,10 @@ void iupdrvTextAddFormatTag(Ihandle* ih, Ihandle* formattag)
if (charformat.dwMask != 0)
SendMessage(ih->handle, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&charformat);
- /* reset the selection, if changed here */
- if (selection)
- winTextSetSelectionAttrib(ih, NULL);
+ /* restores selection / scroll position */
+ SendMessage(ih->handle, EX_EXSETSEL, 0, LPARAL(&oldRange));
+ line1 = SendMessage(ih->handle, EM_GETFIRSTVISIBLELINE, 0, 0);
+ SendMessage(ih->handle, EX_LINESCROLL, 0, Line0 - Line1);
}
static int winTextSetRemoveFormattingAttrib(Ihandle* ih, const char* value)