riched20: Return a run ptr from the run insert function.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2020-10-14 11:17:18 +01:00 committed by Alexandre Julliard
parent 1797d2124a
commit 579618c0d7
4 changed files with 35 additions and 28 deletions

View File

@ -471,7 +471,7 @@ ME_InternalInsertTextFromCursor(ME_TextEditor *editor, int nCursor,
assert(p->pRun->type == diRun); assert(p->pRun->type == diRun);
return ME_InsertRunAtCursor(editor, p, style, str, len, flags); return run_get_di( run_insert( editor, p, style, str, len, flags ) );
} }
static struct re_object* create_re_object(const REOBJECT *reo) static struct re_object* create_re_object(const REOBJECT *reo)

View File

@ -119,8 +119,8 @@ int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN;
/* run.c */ /* run.c */
ME_Run *run_create( ME_Style *s, int nFlags ) DECLSPEC_HIDDEN; ME_Run *run_create( ME_Style *s, int nFlags ) DECLSPEC_HIDDEN;
ME_DisplayItem *ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Run *run_insert( ME_TextEditor *editor, ME_Cursor *cursor,
ME_Style *style, const WCHAR *str, int len, int flags) DECLSPEC_HIDDEN; ME_Style *style, const WCHAR *str, int len, int flags ) DECLSPEC_HIDDEN;
void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN; void ME_CheckCharOffsets(ME_TextEditor *editor) DECLSPEC_HIDDEN;
void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN; void ME_PropagateCharOffset(ME_DisplayItem *p, int shift) DECLSPEC_HIDDEN;
/* this one accounts for 1/2 char tolerance */ /* this one accounts for 1/2 char tolerance */
@ -133,6 +133,7 @@ void run_join( ME_TextEditor *editor, ME_Run *run ) DECLSPEC_HIDDEN;
ME_Run *run_next( ME_Run *run ) DECLSPEC_HIDDEN; ME_Run *run_next( ME_Run *run ) DECLSPEC_HIDDEN;
ME_Run *run_next_all_paras( ME_Run *run ) DECLSPEC_HIDDEN; ME_Run *run_next_all_paras( ME_Run *run ) DECLSPEC_HIDDEN;
ME_Run *run_prev( ME_Run *run ) DECLSPEC_HIDDEN; ME_Run *run_prev( ME_Run *run ) DECLSPEC_HIDDEN;
ME_Run *run_prev_all_paras( ME_Run *run ) DECLSPEC_HIDDEN;
ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN; ME_Run *run_split( ME_TextEditor *editor, ME_Cursor *cursor ) DECLSPEC_HIDDEN;
void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) DECLSPEC_HIDDEN; void ME_UpdateRunFlags(ME_TextEditor *editor, ME_Run *run) DECLSPEC_HIDDEN;
SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen, SIZE ME_GetRunSizeCommon(ME_Context *c, const ME_Paragraph *para, ME_Run *run, int nLen,

View File

@ -57,6 +57,16 @@ ME_Run *run_next_all_paras( ME_Run *run )
return NULL; return NULL;
} }
ME_Run *run_prev_all_paras( ME_Run *run )
{
ME_DisplayItem *item = run_get_di( run ), *dummy = para_get_di( run->para );
if (ME_PrevRun( &dummy, &item, TRUE ))
return &item->member.run;
return NULL;
}
/****************************************************************************** /******************************************************************************
* ME_CanJoinRuns * ME_CanJoinRuns
* *
@ -347,56 +357,53 @@ ME_Run *run_create( ME_Style *s, int flags )
} }
/****************************************************************************** /******************************************************************************
* ME_InsertRunAtCursor * run_insert
* *
* Inserts a new run with given style, flags and content at a given position, * Inserts a new run with given style, flags and content at a given position,
* which is passed as a cursor structure (which consists of a run and * which is passed as a cursor structure (which consists of a run and
* a run-relative character offset). * a run-relative character offset).
*/ */
ME_DisplayItem * ME_Run *run_insert( ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style, const WCHAR *str, int len, int flags )
const WCHAR *str, int len, int flags)
{ {
ME_DisplayItem *insert_before = cursor->pRun, *prev; ME_Run *insert_before = &cursor->pRun->member.run, *run, *prev;
ME_Run *run;
if (cursor->nOffset) if (cursor->nOffset)
{ {
if (cursor->nOffset == cursor->pRun->member.run.len) if (cursor->nOffset == insert_before->len)
{ {
insert_before = ME_FindItemFwd( cursor->pRun, diRun ); insert_before = run_next_all_paras( insert_before );
if (!insert_before) insert_before = cursor->pRun; /* Always insert before the final eop run */ if (!insert_before) insert_before = &cursor->pRun->member.run; /* Always insert before the final eop run */
} }
else else
{ {
run_split( editor, cursor ); run_split( editor, cursor );
insert_before = cursor->pRun; insert_before = &cursor->pRun->member.run;
} }
} }
add_undo_delete_run( editor, insert_before->member.run.para->nCharOfs + add_undo_delete_run( editor, insert_before->para->nCharOfs + insert_before->nCharOfs, len );
insert_before->member.run.nCharOfs, len );
run = run_create( style, flags ); run = run_create( style, flags );
run->nCharOfs = insert_before->member.run.nCharOfs; run->nCharOfs = insert_before->nCharOfs;
run->len = len; run->len = len;
run->para = insert_before->member.run.para; run->para = insert_before->para;
ME_InsertString( run->para->text, run->nCharOfs, str, len ); ME_InsertString( run->para->text, run->nCharOfs, str, len );
ME_InsertBefore( insert_before, run_get_di( run ) ); ME_InsertBefore( run_get_di( insert_before ), run_get_di( run ) );
TRACE("Shift length:%d\n", len); TRACE("Shift length:%d\n", len);
ME_PropagateCharOffset( insert_before, len ); ME_PropagateCharOffset( run_get_di( insert_before ), len );
para_mark_rewrap( editor, insert_before->member.run.para ); para_mark_rewrap( editor, insert_before->para );
/* Move any cursors that were at the end of the previous run to the end of the inserted run */ /* Move any cursors that were at the end of the previous run to the end of the inserted run */
prev = ME_FindItemBack( run_get_di( run ), diRun ); prev = run_prev_all_paras( run );
if (prev) if (prev)
{ {
int i; int i;
for (i = 0; i < editor->nCursors; i++) for (i = 0; i < editor->nCursors; i++)
{ {
if (editor->pCursors[i].pRun == prev && if (editor->pCursors[i].pRun == run_get_di( prev ) &&
editor->pCursors[i].nOffset == prev->member.run.len) editor->pCursors[i].nOffset == prev->len)
{ {
editor->pCursors[i].pRun = run_get_di( run ); editor->pCursors[i].pRun = run_get_di( run );
editor->pCursors[i].nOffset = len; editor->pCursors[i].nOffset = len;
@ -404,7 +411,7 @@ ME_InsertRunAtCursor(ME_TextEditor *editor, ME_Cursor *cursor, ME_Style *style,
} }
} }
return run_get_di( run ); return run;
} }
static BOOL run_is_splittable( const ME_Run *run ) static BOOL run_is_splittable( const ME_Run *run )

View File

@ -357,10 +357,9 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, struct undo_item *undo)
{ {
ME_Cursor tmp; ME_Cursor tmp;
ME_CursorFromCharOfs(editor, undo->u.insert_run.pos, &tmp); ME_CursorFromCharOfs(editor, undo->u.insert_run.pos, &tmp);
ME_InsertRunAtCursor(editor, &tmp, undo->u.insert_run.style, run_insert( editor, &tmp, undo->u.insert_run.style,
undo->u.insert_run.str, undo->u.insert_run.str, undo->u.insert_run.len,
undo->u.insert_run.len, undo->u.insert_run.flags );
undo->u.insert_run.flags);
break; break;
} }
case undo_delete_run: case undo_delete_run: