Commit eee54d95 authored by Phil Krylov's avatar Phil Krylov Committed by Alexandre Julliard

Fixed a RichEdit RTF reader bug which resulted in loss of text.

Eliminated unneeded recursion in ME_InsertTextFromCursor().
parent f6f63a8f
......@@ -325,6 +325,28 @@ void ME_InsertGraphicsFromCursor(ME_TextEditor *editor, int nCursor)
ME_SendSelChange(editor);
}
static void
ME_InternalInsertTextFromCursor(ME_TextEditor *editor, int nCursor,
const WCHAR *str, int len, ME_Style *style,
int flags)
{
ME_DisplayItem *pNewRun = NULL;
ME_Cursor *p = &editor->pCursors[nCursor];
editor->bCaretAtEnd = FALSE;
assert(p->pRun->type == diRun);
ME_AddRefStyle(style);
pNewRun = ME_MakeRun(style, ME_MakeStringN(str, len), flags); /* addrefs style */
ME_InsertRun(editor, ME_CharOfsFromRunOfs(editor, p->pRun, p->nOffset), pNewRun);
ME_DestroyDisplayItem(pNewRun);
ME_ReleaseStyle(style);
}
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
const WCHAR *str, int len, ME_Style *style)
{
......@@ -332,9 +354,6 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
ME_Cursor *p = NULL;
assert(style);
editor->bCaretAtEnd = FALSE;
ME_AddRefStyle(style);
/* FIXME really HERE ? */
if (ME_IsSelection(editor))
......@@ -343,37 +362,33 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
assert(nCursor>=0 && nCursor<editor->nCursors);
if (len == -1)
len = lstrlenW(str);
while (len)
{
pos = str;
/* FIXME this sucks - no respect for unicode (what else can be a line separator in unicode?) */
while(pos-str < len && *pos != '\r' && *pos != '\n' && *pos != '\t')
pos++;
if (pos-str < len && *pos == '\t') { /* handle tabs */
ME_DisplayItem *pNewRun = NULL;
WCHAR tab = '\t';
if (pos!=str)
ME_InsertTextFromCursor(editor, nCursor, str, pos-str, style);
ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
p = &editor->pCursors[nCursor];
assert(style);
assert(p->pRun->type == diRun);
pNewRun = ME_MakeRun(style, ME_MakeStringN(&tab, 1), MERF_TAB); /* addrefs style */
ME_InsertRun(editor, ME_CharOfsFromRunOfs(editor, p->pRun, p->nOffset), pNewRun);
ME_DestroyDisplayItem(pNewRun);
ME_ReleaseStyle(style);
ME_InternalInsertTextFromCursor(editor, nCursor, &tab, 1, style, MERF_TAB);
pos++;
if(pos-str < len) {
ME_InsertTextFromCursor(editor, nCursor, pos, len-(pos-str), style);
if(pos-str <= len) {
len -= pos - str;
str = pos;
continue;
}
return;
}
if (pos-str < len) { /* handle EOLs */
ME_DisplayItem *tp, *end_run;
ME_Paragraph *para;
ME_Style *tmp_style;
if (pos!=str)
ME_InsertTextFromCursor(editor, nCursor, str, pos-str, style);
ME_InternalInsertTextFromCursor(editor, nCursor, str, pos-str, style, 0);
p = &editor->pCursors[nCursor];
tp = ME_FindItemBack(p->pRun, diParagraph);
para = &tp->member.para;
......@@ -394,24 +409,14 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor,
pos++;
if(pos-str < len && *pos =='\n')
pos++;
if(pos-str < len) {
ME_InsertTextFromCursor(editor, nCursor, pos, len-(pos-str), style);
if(pos-str <= len) {
len -= pos - str;
str = pos;
continue;
}
ME_ReleaseStyle(style);
return;
}
p = &editor->pCursors[nCursor];
if (style) {
ME_DisplayItem *pNewRun = NULL;
assert(p->pRun->type == diRun);
pNewRun = ME_MakeRun(style, ME_MakeStringN(str, len), 0); /* addrefs style */
ME_InsertRun(editor, ME_CharOfsFromRunOfs(editor, p->pRun, p->nOffset), pNewRun);
ME_DestroyDisplayItem(pNewRun);
ME_ReleaseStyle(style);
return;
} else {
assert(0);
ME_InternalInsertTextFromCursor(editor, nCursor, str, len, style, 0);
len = 0;
}
}
......
......@@ -2739,10 +2739,9 @@ RTFPutUnicodeString(RTF_Info *info, WCHAR *string, int length)
int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
info->dwOutputCount += fit;
if (fit == sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount)
RTFFlushUnicodeOutputBuffer(info);
else
info->dwOutputCount += fit;
length -= fit;
string += fit;
}
......
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