static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) { ME_DisplayItem *p = ME_FindItemFwd(editor->pBuffer->pFirst, diStartRow); if (editor->vert_si.nPos < p->member.row.nHeight) { pCursor->pRun = ME_FindItemFwd(editor->pBuffer->pFirst, diRun); pCursor->nOffset = 0; editor->bCaretAtEnd = FALSE; /* Native clears seems to clear this x value on page up at the top * of the text, but not on page down at the end of the text. * Doesn't make sense, but we try to be bug for bug compatible. */ editor->nUDArrowX = -1; } else { ME_DisplayItem *pRun = pCursor->pRun; ME_DisplayItem *pLast; int x, y, ys, yd, yp, yprev; int yOldScrollPos = editor->vert_si.nPos; x = ME_GetXForArrow(editor, pCursor); if (!pCursor->nOffset && editor->bCaretAtEnd) pRun = ME_FindItemBack(pRun, diRun); p = ME_FindItemBack(pRun, diStartRowOrParagraph); assert(p->type == diStartRow); yp = ME_FindItemBack(p, diParagraph)->member.para.pt.y; yprev = ys = y = yp + p->member.row.pt.y; ME_ScrollUp(editor, editor->sizeWindow.cy); /* Only move the cursor by the amount scrolled. */ yd = y + editor->vert_si.nPos - yOldScrollPos; pLast = p; do { p = ME_FindItemBack(p, diStartRowOrParagraph); if (!p) break; if (p->type == diParagraph) { /* crossing paragraphs */ if (p->member.para.prev_para == NULL) break; yp = p->member.para.prev_para->member.para.pt.y; continue; } y = yp + p->member.row.pt.y; if (y < yd) break; pLast = p; yprev = y; } while(1); pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, &editor->bCaretAtEnd); } assert(pCursor->pRun); assert(pCursor->pRun->type == diRun); }
static void ME_ArrowPageUp(ME_TextEditor *editor, ME_Cursor *pCursor) { ME_DisplayItem *pRun = pCursor->pRun; ME_DisplayItem *pLast, *p; int x, y, ys, yd, yp, yprev; ME_Cursor tmp_curs = *pCursor; x = ME_GetXForArrow(editor, pCursor); if (!pCursor->nOffset && editor->bCaretAtEnd) pRun = ME_FindItemBack(pRun, diRun); p = ME_FindItemBack(pRun, diStartRowOrParagraph); assert(p->type == diStartRow); yp = ME_FindItemBack(p, diParagraph)->member.para.nYPos; yprev = ys = y = yp + p->member.row.nYPos; yd = y - editor->sizeWindow.cy; pLast = p; do { p = ME_FindItemBack(p, diStartRowOrParagraph); if (!p) break; if (p->type == diParagraph) { /* crossing paragraphs */ if (p->member.para.prev_para == NULL) break; yp = p->member.para.prev_para->member.para.nYPos; continue; } y = yp + p->member.row.nYPos; if (y < yd) break; pLast = p; yprev = y; } while(1); pCursor->pRun = ME_FindRunInRow(editor, pLast, x, &pCursor->nOffset, &editor->bCaretAtEnd); ME_UpdateSelection(editor, &tmp_curs); if (yprev < editor->sizeWindow.cy) { ME_EnsureVisible(editor, ME_FindItemFwd(editor->pBuffer->pFirst, diRun)); ME_Repaint(editor); } else { ME_ScrollUp(editor, ys-yprev); } assert(pCursor->pRun); assert(pCursor->pRun->type == diRun); }