Commit ecb6c216 authored by Dylan Smith's avatar Dylan Smith Committed by Alexandre Julliard

richedit: Store paragraph in cursors.

This prevents some needless searching for the start of the paragraph from a run stored in a cursor. Usually a pointer to the paragraph is already available when the cursor is set anyway.
parent 2033312b
...@@ -263,6 +263,7 @@ typedef struct tagME_TextBuffer ...@@ -263,6 +263,7 @@ typedef struct tagME_TextBuffer
typedef struct tagME_Cursor typedef struct tagME_Cursor
{ {
ME_DisplayItem *pPara;
ME_DisplayItem *pRun; ME_DisplayItem *pRun;
int nOffset; int nOffset;
} ME_Cursor; } ME_Cursor;
......
...@@ -137,7 +137,6 @@ void ME_Repaint(ME_TextEditor *editor) ...@@ -137,7 +137,6 @@ void ME_Repaint(ME_TextEditor *editor)
void ME_UpdateRepaint(ME_TextEditor *editor) void ME_UpdateRepaint(ME_TextEditor *editor)
{ {
/* Should be called whenever the contents of the control have changed */ /* Should be called whenever the contents of the control have changed */
ME_Cursor *pCursor;
BOOL wrappedParagraphs; BOOL wrappedParagraphs;
wrappedParagraphs = ME_WrapMarkedParagraphs(editor); wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
...@@ -145,8 +144,7 @@ void ME_UpdateRepaint(ME_TextEditor *editor) ...@@ -145,8 +144,7 @@ void ME_UpdateRepaint(ME_TextEditor *editor)
ME_UpdateScrollBar(editor); ME_UpdateScrollBar(editor);
/* Ensure that the cursor is visible */ /* Ensure that the cursor is visible */
pCursor = &editor->pCursors[0]; ME_EnsureVisible(editor, &editor->pCursors[0]);
ME_EnsureVisible(editor, pCursor);
/* send EN_CHANGE if the event mask asks for it */ /* send EN_CHANGE if the event mask asks for it */
if(editor->nEventMask & ENM_CHANGE) if(editor->nEventMask & ENM_CHANGE)
...@@ -1226,7 +1224,7 @@ void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor) ...@@ -1226,7 +1224,7 @@ void ME_EnsureVisible(ME_TextEditor *editor, ME_Cursor *pCursor)
{ {
ME_Run *pRun = &pCursor->pRun->member.run; ME_Run *pRun = &pCursor->pRun->member.run;
ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow); ME_DisplayItem *pRow = ME_FindItemBack(pCursor->pRun, diStartRow);
ME_DisplayItem *pPara = ME_FindItemBack(pCursor->pRun, diParagraph); ME_DisplayItem *pPara = pCursor->pPara;
int x, y, yheight; int x, y, yheight;
assert(pRow); assert(pRow);
......
...@@ -208,7 +208,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -208,7 +208,7 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
ME_DisplayItem *new_para = ME_MakeDI(diParagraph); ME_DisplayItem *new_para = ME_MakeDI(diParagraph);
ME_DisplayItem *end_run; ME_DisplayItem *end_run;
ME_UndoItem *undo = NULL; ME_UndoItem *undo = NULL;
int ofs; int ofs, i;
ME_DisplayItem *pp; ME_DisplayItem *pp;
int run_flags = MERF_ENDPARA; int run_flags = MERF_ENDPARA;
...@@ -236,14 +236,23 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -236,14 +236,23 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
undo = ME_AddUndoItem(editor, diUndoJoinParagraphs, NULL); undo = ME_AddUndoItem(editor, diUndoJoinParagraphs, NULL);
if (undo) if (undo)
undo->nStart = run_para->member.para.nCharOfs + ofs; undo->nStart = run_para->member.para.nCharOfs + ofs;
/* Update selection cursors to point to the correct paragraph. */
for (i = 0; i < editor->nCursors; i++) {
if (editor->pCursors[i].pPara == run_para &&
run->member.run.nCharOfs <= editor->pCursors[i].pRun->member.run.nCharOfs)
{
editor->pCursors[i].pPara = new_para;
}
}
/* the new paragraph will have a different starting offset, so let's update its runs */ /* the new paragraph will have a different starting offset, so let's update its runs */
pp = run; pp = run;
while(pp->type == diRun) { while(pp->type == diRun) {
pp->member.run.nCharOfs -= ofs; pp->member.run.nCharOfs -= ofs;
pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd); pp = ME_FindItemFwd(pp, diRunOrParagraphOrEnd);
} }
new_para->member.para.nCharOfs = ME_GetParagraph(run)->member.para.nCharOfs+ofs; new_para->member.para.nCharOfs = run_para->member.para.nCharOfs + ofs;
new_para->member.para.nCharOfs += eol_str->nLen; new_para->member.para.nCharOfs += eol_str->nLen;
new_para->member.para.nFlags = MEPF_REWRAP; new_para->member.para.nFlags = MEPF_REWRAP;
...@@ -309,11 +318,11 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run, ...@@ -309,11 +318,11 @@ ME_DisplayItem *ME_SplitParagraph(ME_TextEditor *editor, ME_DisplayItem *run,
/* force rewrap of the */ /* force rewrap of the */
run_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP; run_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
new_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP; new_para->member.para.prev_para->member.para.nFlags |= MEPF_REWRAP;
/* we've added the end run, so we need to modify nCharOfs in the next paragraphs */ /* we've added the end run, so we need to modify nCharOfs in the next paragraphs */
ME_PropagateCharOffset(next_para, eol_str->nLen); ME_PropagateCharOffset(next_para, eol_str->nLen);
editor->nParagraphs++; editor->nParagraphs++;
return new_para; return new_para;
} }
...@@ -330,9 +339,9 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp, ...@@ -330,9 +339,9 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
assert(tp->type == diParagraph); assert(tp->type == diParagraph);
assert(tp->member.para.next_para); assert(tp->member.para.next_para);
assert(tp->member.para.next_para->type == diParagraph); assert(tp->member.para.next_para->type == diParagraph);
pNext = tp->member.para.next_para; pNext = tp->member.para.next_para;
/* Need to locate end-of-paragraph run here, in order to know end_len */ /* Need to locate end-of-paragraph run here, in order to know end_len */
pRun = ME_FindItemBack(pNext, diRunOrParagraph); pRun = ME_FindItemBack(pNext, diRunOrParagraph);
...@@ -397,19 +406,21 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp, ...@@ -397,19 +406,21 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
pTmp = pTmp->next; pTmp = pTmp->next;
} }
} }
shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len; shift = pNext->member.para.nCharOfs - tp->member.para.nCharOfs - end_len;
pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph); pFirstRunInNext = ME_FindItemFwd(pNext, diRunOrParagraph);
assert(pFirstRunInNext->type == diRun); assert(pFirstRunInNext->type == diRun);
/* if some cursor points at end of paragraph, make it point to the first /* Update selection cursors so they don't point to the removed end
run of the next joined paragraph */ * paragraph run, and point to the correct paragraph. */
for (i=0; i<editor->nCursors; i++) { for (i=0; i < editor->nCursors; i++) {
if (editor->pCursors[i].pRun == pRun) { if (editor->pCursors[i].pRun == pRun) {
editor->pCursors[i].pRun = pFirstRunInNext; editor->pCursors[i].pRun = pFirstRunInNext;
editor->pCursors[i].nOffset = 0; editor->pCursors[i].nOffset = 0;
} else if (editor->pCursors[i].pPara == pNext) {
editor->pCursors[i].pPara = tp;
} }
} }
...@@ -421,7 +432,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp, ...@@ -421,7 +432,7 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
TRACE("shifting \"%s\" by %d (previous %d)\n", debugstr_w(pTmp->member.run.strText->szData), shift, pTmp->member.run.nCharOfs); TRACE("shifting \"%s\" by %d (previous %d)\n", debugstr_w(pTmp->member.run.strText->szData), shift, pTmp->member.run.nCharOfs);
pTmp->member.run.nCharOfs += shift; pTmp->member.run.nCharOfs += shift;
} while(1); } while(1);
ME_Remove(pRun); ME_Remove(pRun);
ME_DestroyDisplayItem(pRun); ME_DestroyDisplayItem(pRun);
...@@ -429,16 +440,16 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp, ...@@ -429,16 +440,16 @@ ME_DisplayItem *ME_JoinParagraphs(ME_TextEditor *editor, ME_DisplayItem *tp,
editor->pLastSelStartPara = tp; editor->pLastSelStartPara = tp;
if (editor->pLastSelEndPara == pNext) if (editor->pLastSelEndPara == pNext)
editor->pLastSelEndPara = tp; editor->pLastSelEndPara = tp;
tp->member.para.next_para = pNext->member.para.next_para; tp->member.para.next_para = pNext->member.para.next_para;
pNext->member.para.next_para->member.para.prev_para = tp; pNext->member.para.next_para->member.para.prev_para = tp;
ME_Remove(pNext); ME_Remove(pNext);
ME_DestroyDisplayItem(pNext); ME_DestroyDisplayItem(pNext);
ME_PropagateCharOffset(tp->member.para.next_para, -end_len); ME_PropagateCharOffset(tp->member.para.next_para, -end_len);
ME_CheckCharOffsets(editor); ME_CheckCharOffsets(editor);
editor->nParagraphs--; editor->nParagraphs--;
tp->member.para.nFlags |= MEPF_REWRAP; tp->member.para.nFlags |= MEPF_REWRAP;
return tp; return tp;
...@@ -516,8 +527,8 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte ...@@ -516,8 +527,8 @@ ME_GetSelectionParas(ME_TextEditor *editor, ME_DisplayItem **para, ME_DisplayIte
{ {
ME_Cursor *pEndCursor = &editor->pCursors[1]; ME_Cursor *pEndCursor = &editor->pCursors[1];
*para = ME_GetParagraph(editor->pCursors[0].pRun); *para = editor->pCursors[0].pPara;
*para_end = ME_GetParagraph(editor->pCursors[1].pRun); *para_end = editor->pCursors[1].pPara;
if (*para == *para_end) if (*para == *para_end)
return; return;
......
...@@ -163,7 +163,8 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, ...@@ -163,7 +163,8 @@ int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara,
*/ */
void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor)
{ {
ME_RunOfsFromCharOfs(editor, nCharOfs, NULL, &pCursor->pRun, &pCursor->nOffset); ME_RunOfsFromCharOfs(editor, nCharOfs, &pCursor->pPara,
&pCursor->pRun, &pCursor->nOffset);
} }
/****************************************************************************** /******************************************************************************
...@@ -243,10 +244,10 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p) ...@@ -243,10 +244,10 @@ void ME_JoinRuns(ME_TextEditor *editor, ME_DisplayItem *p)
/****************************************************************************** /******************************************************************************
* ME_SplitRun * ME_SplitRun
* *
* Splits a run into two in a given place. It also updates the screen position * Splits a run into two in a given place. It also updates the screen position
* and size (extent) of the newly generated runs. * and size (extent) of the newly generated runs.
*/ */
ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar) ME_DisplayItem *ME_SplitRun(ME_WrapContext *wc, ME_DisplayItem *item, int nVChar)
{ {
ME_TextEditor *editor = wc->context->editor; ME_TextEditor *editor = wc->context->editor;
...@@ -369,38 +370,38 @@ ME_DisplayItem *ME_InsertRun(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem ...@@ -369,38 +370,38 @@ ME_DisplayItem *ME_InsertRun(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem
/****************************************************************************** /******************************************************************************
* ME_InsertRunAtCursor * ME_InsertRunAtCursor
* *
* 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_DisplayItem *
ME_InsertRunAtCursor(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 *pDI; ME_DisplayItem *pDI;
ME_UndoItem *pUI; ME_UndoItem *pUI;
if (cursor->nOffset) { if (cursor->nOffset) {
/* We're inserting at the middle of the existing run, which means that /* We're inserting at the middle of the existing run, which means that
* that run must be split. It isn't always necessary, but */ * that run must be split. It isn't always necessary, but */
cursor->pRun = ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset); cursor->pRun = ME_SplitRunSimple(editor, cursor->pRun, cursor->nOffset);
cursor->nOffset = 0; cursor->nOffset = 0;
} }
pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL); pUI = ME_AddUndoItem(editor, diUndoDeleteRun, NULL);
if (pUI) { if (pUI) {
pUI->nStart = (ME_GetParagraph(cursor->pRun)->member.para.nCharOfs pUI->nStart = cursor->pPara->member.para.nCharOfs
+ cursor->pRun->member.run.nCharOfs); + cursor->pRun->member.run.nCharOfs;
pUI->nLen = len; pUI->nLen = len;
} }
pDI = ME_MakeRun(style, ME_MakeStringN(str, len), flags); pDI = ME_MakeRun(style, ME_MakeStringN(str, len), flags);
pDI->member.run.nCharOfs = cursor->pRun->member.run.nCharOfs; pDI->member.run.nCharOfs = cursor->pRun->member.run.nCharOfs;
ME_InsertBefore(cursor->pRun, pDI); ME_InsertBefore(cursor->pRun, pDI);
TRACE("Shift length:%d\n", len); TRACE("Shift length:%d\n", len);
ME_PropagateCharOffset(cursor->pRun, len); ME_PropagateCharOffset(cursor->pRun, len);
ME_GetParagraph(cursor->pRun)->member.para.nFlags |= MEPF_REWRAP; cursor->pPara->member.para.nFlags |= MEPF_REWRAP;
return pDI; return pDI;
} }
...@@ -577,10 +578,10 @@ static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style ...@@ -577,10 +578,10 @@ static void ME_GetTextExtent(ME_Context *c, LPCWSTR szText, int nChars, ME_Style
/****************************************************************************** /******************************************************************************
* ME_PointFromChar * ME_PointFromChar
* *
* Returns a run-relative pixel position given a run-relative character * Returns a run-relative pixel position given a run-relative character
* position (character offset) * position (character offset)
*/ */
int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset) int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset)
{ {
SIZE size; SIZE size;
...@@ -776,7 +777,7 @@ void ME_SetCharFormat(ME_TextEditor *editor, int nOfs, int nChars, CHARFORMAT2W ...@@ -776,7 +777,7 @@ void ME_SetCharFormat(ME_TextEditor *editor, int nOfs, int nChars, CHARFORMAT2W
if (tmp2.nOffset) if (tmp2.nOffset)
tmp2.pRun = ME_SplitRunSimple(editor, tmp2.pRun, tmp2.nOffset); tmp2.pRun = ME_SplitRunSimple(editor, tmp2.pRun, tmp2.nOffset);
para = ME_GetParagraph(tmp.pRun); para = tmp.pPara;
para->member.para.nFlags |= MEPF_REWRAP; para->member.para.nFlags |= MEPF_REWRAP;
while(tmp.pRun != tmp2.pRun) while(tmp.pRun != tmp2.pRun)
......
...@@ -70,6 +70,7 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor, ...@@ -70,6 +70,7 @@ static ME_DisplayItem* ME_InsertEndParaFromCursor(ME_TextEditor *editor,
} }
tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags); tp = ME_SplitParagraph(editor, cursor->pRun, pStyle, eol_str, paraFlags);
cursor->pPara = tp;
cursor->pRun = ME_FindItemFwd(tp, diRun); cursor->pRun = ME_FindItemFwd(tp, diRun);
return tp; return tp;
} }
...@@ -89,6 +90,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor, ...@@ -89,6 +90,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
ME_DisplayItem *prev_para, *end_para; ME_DisplayItem *prev_para, *end_para;
ME_Cursor savedCursor = editor->pCursors[0]; ME_Cursor savedCursor = editor->pCursors[0];
ME_DisplayItem *startRowPara; ME_DisplayItem *startRowPara;
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -96,7 +98,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor, ...@@ -96,7 +98,7 @@ ME_DisplayItem* ME_InsertTableRowStartAtParagraph(ME_TextEditor *editor,
editor->pCursors[0] = savedCursor; editor->pCursors[0] = savedCursor;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
end_para = ME_GetParagraph(editor->pCursors[0].pRun)->member.para.next_para; end_para = editor->pCursors[0].pPara->member.para.next_para;
prev_para = startRowPara->member.para.next_para; prev_para = startRowPara->member.para.next_para;
para = prev_para->member.para.next_para; para = prev_para->member.para.next_para;
while (para != end_para) while (para != end_para)
...@@ -276,9 +278,9 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars) ...@@ -276,9 +278,9 @@ void ME_ProtectPartialTableDeletion(ME_TextEditor *editor, int nOfs,int *nChars)
ME_Cursor c, c2; ME_Cursor c, c2;
ME_DisplayItem *this_para, *end_para; ME_DisplayItem *this_para, *end_para;
ME_CursorFromCharOfs(editor, nOfs, &c); ME_CursorFromCharOfs(editor, nOfs, &c);
this_para = ME_GetParagraph(c.pRun); this_para = c.pPara;
ME_CursorFromCharOfs(editor, nOfs + *nChars, &c2); ME_CursorFromCharOfs(editor, nOfs + *nChars, &c2);
end_para = ME_GetParagraph(c2.pRun); end_para = c2.pPara;
if (c2.pRun->member.run.nFlags & MERF_ENDPARA) { if (c2.pRun->member.run.nFlags & MERF_ENDPARA) {
/* End offset might be in the middle of the end paragraph run. /* End offset might be in the middle of the end paragraph run.
* If this is the case, then we need to use the next paragraph as the last * If this is the case, then we need to use the next paragraph as the last
...@@ -399,14 +401,15 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ...@@ -399,14 +401,15 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd; ME_DisplayItem *insertedCell, *para, *cell, *prevTableEnd;
cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell); cell = ME_FindItemFwd(ME_GetTableRowStart(table_row), diCell);
prevTableEnd = ME_GetTableRowEnd(table_row); prevTableEnd = ME_GetTableRowEnd(table_row);
run = prevTableEnd->member.para.next_para; para = prevTableEnd->member.para.next_para;
run = ME_FindItemFwd(run, diRun); run = ME_FindItemFwd(para, diRun);
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
para = ME_InsertTableRowStartFromCursor(editor); para = ME_InsertTableRowStartFromCursor(editor);
insertedCell = ME_FindItemFwd(para, diCell); insertedCell = ME_FindItemFwd(para, diCell);
/* Copy cell properties */ /* Copy cell properties */
insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary; insertedCell->member.cell.nRightBoundary = cell->member.cell.nRightBoundary;
insertedCell->member.cell.border = cell->member.cell.border; insertedCell->member.cell.border = cell->member.cell.border;
while (cell->member.cell.next_cell) { while (cell->member.cell.next_cell) {
...@@ -425,6 +428,7 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor, ...@@ -425,6 +428,7 @@ ME_DisplayItem* ME_AppendTableRow(ME_TextEditor *editor,
run = ME_FindItemBack(table_row->member.para.next_para, diRun); run = ME_FindItemBack(table_row->member.para.next_para, diRun);
pFmt = table_row->member.para.pFmt; pFmt = table_row->member.para.pFmt;
assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE); assert(pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE);
editor->pCursors[0].pPara = table_row;
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -474,6 +478,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -474,6 +478,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
para = ME_AppendTableRow(editor, ME_GetTableRowStart(para)); para = ME_AppendTableRow(editor, ME_GetTableRowStart(para));
/* Put cursor at the start of the new table row */ /* Put cursor at the start of the new table row */
para = para->member.para.next_para; para = para->member.para.next_para;
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -483,10 +488,12 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -483,10 +488,12 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
} }
/* Select cell */ /* Select cell */
editor->pCursors[1].pRun = ME_FindItemFwd(cell, diRun); editor->pCursors[1].pRun = ME_FindItemFwd(cell, diRun);
editor->pCursors[1].pPara = ME_GetParagraph(editor->pCursors[1].pRun);
editor->pCursors[1].nOffset = 0; editor->pCursors[1].nOffset = 0;
assert(editor->pCursors[0].pRun); assert(editor->pCursors[0].pRun);
cell = cell->member.cell.next_cell; cell = cell->member.cell.next_cell;
editor->pCursors[0].pRun = ME_FindItemBack(cell, diRun); editor->pCursors[0].pRun = ME_FindItemBack(cell, diRun);
editor->pCursors[0].pPara = ME_GetParagraph(editor->pCursors[0].pRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
assert(editor->pCursors[1].pRun); assert(editor->pCursors[1].pRun);
} else { /* v1.0 - 3.0 */ } else { /* v1.0 - 3.0 */
...@@ -508,6 +515,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -508,6 +515,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
{ {
run = ME_FindItemFwd(para, diRun); run = ME_FindItemFwd(para, diRun);
assert(run); assert(run);
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = run; editor->pCursors[0].pRun = run;
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
i = 1; i = 1;
...@@ -515,6 +523,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -515,6 +523,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
/* Insert table row */ /* Insert table row */
para = ME_AppendTableRow(editor, para->member.para.prev_para); para = ME_AppendTableRow(editor, para->member.para.prev_para);
/* Put cursor at the start of the new table row */ /* Put cursor at the start of the new table row */
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
...@@ -526,6 +535,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor, ...@@ -526,6 +535,7 @@ static void ME_SelectOrInsertNextCell(ME_TextEditor *editor,
if (i == 0) if (i == 0)
run = ME_FindItemFwd(run, diRun); run = ME_FindItemFwd(run, diRun);
editor->pCursors[i].pRun = run; editor->pCursors[i].pRun = run;
editor->pCursors[i].pPara = ME_GetParagraph(run);
editor->pCursors[i].nOffset = 0; editor->pCursors[i].nOffset = 0;
} }
} }
...@@ -595,12 +605,13 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) ...@@ -595,12 +605,13 @@ void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow)
* without a selection. */ * without a selection. */
void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor) void ME_MoveCursorFromTableRowStartParagraph(ME_TextEditor *editor)
{ {
ME_DisplayItem *para = ME_GetParagraph(editor->pCursors[0].pRun); ME_DisplayItem *para = editor->pCursors[0].pPara;
if (para == ME_GetParagraph(editor->pCursors[1].pRun) && if (para == editor->pCursors[1].pPara &&
para->member.para.nFlags & MEPF_ROWSTART) { para->member.para.nFlags & MEPF_ROWSTART) {
/* The cursors should not be at the hidden start row paragraph without /* The cursors should not be at the hidden start row paragraph without
* a selection, so the cursor is moved into the first cell. */ * a selection, so the cursor is moved into the first cell. */
para = para->member.para.next_para; para = para->member.para.next_para;
editor->pCursors[0].pPara = para;
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun); editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
editor->pCursors[0].nOffset = 0; editor->pCursors[0].nOffset = 0;
editor->pCursors[1] = editor->pCursors[0]; editor->pCursors[1] = editor->pCursors[0];
......
...@@ -316,7 +316,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) ...@@ -316,7 +316,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
ME_Cursor tmp; ME_Cursor tmp;
ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp); ME_CursorFromCharOfs(editor, pUItem->nStart, &tmp);
/* the only thing that's needed is paragraph offset, so no need to split runs */ /* the only thing that's needed is paragraph offset, so no need to split runs */
ME_JoinParagraphs(editor, ME_GetParagraph(tmp.pRun), TRUE); ME_JoinParagraphs(editor, tmp.pPara, TRUE);
break; break;
} }
case diUndoSplitParagraph: case diUndoSplitParagraph:
...@@ -329,7 +329,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem) ...@@ -329,7 +329,7 @@ static void ME_PlayUndoItem(ME_TextEditor *editor, ME_DisplayItem *pItem)
if (tmp.nOffset) if (tmp.nOffset)
tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset); tmp.pRun = ME_SplitRunSimple(editor, tmp.pRun, tmp.nOffset);
assert(pUItem->eol_str); assert(pUItem->eol_str);
this_para = ME_GetParagraph(tmp.pRun); this_para = tmp.pPara;
bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART; bFixRowStart = this_para->member.para.nFlags & MEPF_ROWSTART;
if (bFixRowStart) if (bFixRowStart)
{ {
......
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