From 84a186ebf67db5a15af59d2d6516bb8f24a13c00 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Sun, 16 Nov 2008 18:03:52 +0000 Subject: [PATCH] Make sure the selection painting is updated after LFUN_UP or LFUN_DOWN. See http://thread.gmane.org/gmane.editors.lyx.devel/113428 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27567 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Cursor.cpp | 33 ++++++++++++++++++++++++--------- src/Cursor.h | 2 ++ src/Text3.cpp | 18 +++++++++++++----- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 76ec4c5860..89c1cc768d 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -1702,6 +1702,28 @@ bool Cursor::upDownInMath(bool up) } +bool Cursor::atFirstOrLastRow(bool up) +{ + TextMetrics const & tm = bv_->textMetrics(text()); + ParagraphMetrics const & pm = tm.parMetrics(pit()); + + int row; + if (pos() && boundary()) + row = pm.pos2row(pos() - 1); + else + row = pm.pos2row(pos()); + + if (up) { + if (pit() == 0 && row == 0) + return true; + } else { + if (pit() + 1 >= int(text()->paragraphs().size()) && + row + 1 >= int(pm.rows().size())) + return true; + } + return false; +} + bool Cursor::upDownInText(bool up, bool & updateNeeded) { LASSERT(text(), /**/); @@ -1755,15 +1777,8 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded) else row = pm.pos2row(pos()); - // are we not at the start or end? - if (up) { - if (pit() == 0 && row == 0) - return false; - } else { - if (pit() + 1 >= int(text()->paragraphs().size()) && - row + 1 >= int(pm.rows().size())) - return false; - } + if (atFirstOrLastRow(up)) + return false; // with and without selection are handled differently if (!selection()) { diff --git a/src/Cursor.h b/src/Cursor.h index 178d4fed33..4fc4ef937a 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -359,6 +359,8 @@ public: /// move the cursor up by sending an internal LFUN_DOWN, /// return true if fullscreen update is needed bool down(); + /// whether the cursor is either at the first or last row + bool atFirstOrLastRow(bool up); /// move up/down in a text inset, called for LFUN_UP/DOWN, /// return true if successful, updateNeeded set to true if fullscreen /// update is needed, otherwise it's not touched diff --git a/src/Text3.cpp b/src/Text3.cpp index 517fcd28cf..615f09235d 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -640,16 +640,24 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) // stop/start the selection bool select = cmd.action == LFUN_DOWN_SELECT || cmd.action == LFUN_UP_SELECT; - cur.selHandle(select); // move cursor up/down bool up = cmd.action == LFUN_UP_SELECT || cmd.action == LFUN_UP; - bool const successful = cur.upDownInText(up, needsUpdate); - if (successful) { - // redraw if you leave mathed (for the decorations) + bool const atFirstOrLastRow = cur.atFirstOrLastRow(up); + + if (!atFirstOrLastRow) { + needsUpdate |= cur.selHandle(select); + cur.selHandle(select); + cur.upDownInText(up, needsUpdate); needsUpdate |= cur.beforeDispatchCursor().inMathed(); - } else + } else { + // if the cursor cannot be moved up or down do not remove + // the selection right now, but wait for the next dispatch. + if (select) + needsUpdate |= cur.selHandle(select); + cur.upDownInText(up, needsUpdate); cur.undispatched(); + } break; } -- 2.39.2