]> git.lyx.org Git - features.git/commitdiff
Transfer and bug fix LFUN_BUFFER_BEGIN/END_SELECT to BufferView.cpp
authorAbdelrazak Younes <younes@lyx.org>
Thu, 6 Mar 2008 15:39:30 +0000 (15:39 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Thu, 6 Mar 2008 15:39:30 +0000 (15:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23512 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp
src/Cursor.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/TextMetrics.h
src/mathed/InsetMathNest.cpp

index 448d1958574303f0b55505c4fe0211762b01002b..c2b0d588887ff9ed64e3b4a848aa3f37a7053bb5 100644 (file)
@@ -902,14 +902,9 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
        case LFUN_SCREEN_UP:
        case LFUN_SCREEN_DOWN:
        case LFUN_SCROLL:
-               flag.enabled(true);
-               break;
-
-       // FIXME: LFUN_SCREEN_DOWN_SELECT should be removed from
-       // everywhere else before this can enabled:
        case LFUN_SCREEN_UP_SELECT:
        case LFUN_SCREEN_DOWN_SELECT:
-               flag.enabled(false);
+               flag.enabled(true);
                break;
 
        case LFUN_LAYOUT_TABULAR:
@@ -1311,26 +1306,37 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                lfunScroll(cmd);
                break;
 
-       case LFUN_SCREEN_UP_SELECT:
-       case LFUN_SCREEN_DOWN_SELECT: {
-               // Those two are not ready yet for consumption.
-               return false;
-
+       case LFUN_SCREEN_UP_SELECT: {
                cur.selHandle(true);
-               size_t initial_depth = cur.depth();
-               Point const p = getPos(cur, cur.boundary());
-               scroll(cmd.action == LFUN_SCREEN_UP_SELECT? - height_ : height_);
-               // FIXME: We need to verify if the cursor stayed within an inset...
-               //cur.reset(buffer_.inset());
-               d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
+               if (isTopScreen()) {
+                       lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN_SELECT));
+                       cur.finishUndo();
+                       break;
+               }
+               int y = getPos(cur, cur.boundary()).y_;
+               int const ymin = y - height_ + defaultRowHeight();
+               while (y > ymin && cur.up())
+                       y = getPos(cur, cur.boundary()).y_;
+
                cur.finishUndo();
-               while (cur.depth() > initial_depth) {
-                       cur.forwardInset();
+               processUpdateFlags(Update::SinglePar | Update::FitCursor);
+               break;
+       }
+
+       case LFUN_SCREEN_DOWN_SELECT: {
+               cur.selHandle(true);
+               if (isBottomScreen()) {
+                       lyx::dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
+                       cur.finishUndo();
+                       break;
                }
-               // FIXME: we need to do a redraw again because of the selection
-               // But no screen update is needed.
-               d->update_strategy_ = NoScreenUpdate;
-               buffer_.changed();
+               int y = getPos(cur, cur.boundary()).y_;
+               int const ymax = y + height_ - defaultRowHeight();
+               while (y < ymax && cur.down())
+                       y = getPos(cur, cur.boundary()).y_;
+
+               cur.finishUndo();
+               processUpdateFlags(Update::SinglePar | Update::FitCursor);
                break;
        }
 
index 397331f7a686c46fc21067ed47c965035a6b1fe4..d60323c64812d2f7351d0e94a22382384e2b5966 100644 (file)
@@ -1554,7 +1554,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                if (pit() + 1 >= int(text()->paragraphs().size()) &&
                                row + 1 >= int(pm.rows().size()))
                        return false;
-       }       
+       }
 
        // with and without selection are handled differently
        if (!selection()) {
@@ -1587,7 +1587,10 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                                top().pos() = min(tm.x2pos(pit(), row - 1, xo), top().lastpos());
                        } else if (pit() > 0) {
                                --pit();
-                               ParagraphMetrics const & pmcur = bv_->parMetrics(text(), pit());
+                               TextMetrics & tm = bv_->textMetrics(text());
+                               if (!tm.contains(pit()))
+                                       tm.newParMetricsUp();
+                               ParagraphMetrics const & pmcur = tm.parMetrics(pit());
                                top().pos() = min(tm.x2pos(pit(), pmcur.rows().size() - 1, xo), top().lastpos());
                        }
                } else {
@@ -1595,6 +1598,9 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded)
                                top().pos() = min(tm.x2pos(pit(), row + 1, xo), top().lastpos());
                        } else if (pit() + 1 < int(text()->paragraphs().size())) {
                                ++pit();
+                               TextMetrics & tm = bv_->textMetrics(text());
+                               if (!tm.contains(pit()))
+                                       tm.newParMetricsDown();
                                top().pos() = min(tm.x2pos(pit(), 0, xo), top().lastpos());
                        }
                }
index d434eb5aaf25f5029e3e24f53085b7a2013653ba..5926c31eabe801f408d98d9dd185f12dcb61e3f7 100644 (file)
@@ -604,25 +604,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                needsUpdate |= cursorDownParagraph(cur);
                break;
 
-       case LFUN_SCREEN_UP_SELECT:
-               needsUpdate |= cur.selHandle(true);
-               if (cur.pit() == 0 && cur.textRow().pos() == 0)
-                       cur.undispatched();
-               else {
-                       tm.cursorPrevious(cur);
-               }
-               break;
-
-       case LFUN_SCREEN_DOWN_SELECT:
-               needsUpdate |= cur.selHandle(true);
-               if (cur.pit() == cur.lastpit()
-                         && cur.textRow().endpos() == cur.lastpos())
-                       cur.undispatched();
-               else {
-                       tm.cursorNext(cur);
-               }
-               break;
-
        case LFUN_LINE_BEGIN:
        case LFUN_LINE_BEGIN_SELECT:
                needsUpdate |= cur.selHandle(cmd.action == LFUN_LINE_BEGIN_SELECT);
@@ -2137,8 +2118,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_DOWN_SELECT:
        case LFUN_PARAGRAPH_UP_SELECT:
        case LFUN_PARAGRAPH_DOWN_SELECT:
-       case LFUN_SCREEN_UP_SELECT:
-       case LFUN_SCREEN_DOWN_SELECT:
        case LFUN_LINE_BEGIN_SELECT:
        case LFUN_LINE_END_SELECT:
        case LFUN_WORD_FORWARD_SELECT:
index 078b5907d4690fddcf7235bf6d084341e3dfa278..69b9840c5dbc0cd070057bbd22dc0e6e3d19df27 100644 (file)
@@ -32,7 +32,6 @@
 #include "InsetList.h"
 #include "Layout.h"
 #include "Length.h"
-#include "LyXFunc.h"
 #include "LyXRC.h"
 #include "MetricsInfo.h"
 #include "paragraph_funcs.h"
@@ -1611,73 +1610,6 @@ int TextMetrics::cursorY(CursorSlice const & sl, bool boundary) const
 }
 
 
-void TextMetrics::cursorPrevious(Cursor & cur)
-{
-       if (bv_->isTopScreen()) {
-               lyx::dispatch(FuncRequest(cur.selection()
-                       ? LFUN_BUFFER_BEGIN_SELECT : LFUN_BUFFER_BEGIN));
-               cur.finishUndo();
-               cur.updateFlags(Update::None);
-               return;
-       }
-
-       pos_type cpos = cur.pos();
-       pit_type cpar = cur.pit();
-
-       // Memorize current position.
-       Point p = bv_->getPos(cur, cur.boundary());
-       // Scroll one full page.
-       lyx::dispatch(FuncRequest(LFUN_SCROLL, "page up"));
-       // Try to place the cursor to the same coordinates.
-       setCursorFromCoordinates(cur, p.x_, p.y_);
-       // And move one line up in order to acknowledge in inset movement and/or
-       // selection.
-       cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
-
-       if (cpar == cur.pit() && cpos == cur.pos())
-               // we have a row which is taller than the workarea. The
-               // simplest solution is to move to the previous row instead.
-               cur.dispatch(FuncRequest(cur.selection()? LFUN_UP_SELECT: LFUN_UP));
-
-       cur.finishUndo();
-       cur.updateFlags(Update::Force | Update::FitCursor);
-}
-
-
-void TextMetrics::cursorNext(Cursor & cur)
-{
-       if (bv_->isBottomScreen()) {
-               lyx::dispatch(FuncRequest(cur.selection()
-                       ? LFUN_BUFFER_END_SELECT : LFUN_BUFFER_END));
-               cur.finishUndo();
-               cur.updateFlags(Update::None);
-               return;
-       }
-
-       pos_type cpos = cur.pos();
-       pit_type cpar = cur.pit();
-
-       // Memorize current position.
-       Point p = bv_->getPos(cur, cur.boundary());
-       // Scroll one full page.
-       lyx::dispatch(FuncRequest(LFUN_SCROLL, "page down"));
-       // Try to place the cursor to the same coordinates.
-       setCursorFromCoordinates(cur, p.x_, p.y_);
-       // And move one line down in order to acknowledge in inset movement and/or
-       // selection.
-       cur.dispatch(FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
-
-       if (cpar == cur.pit() && cpos == cur.pos())
-               // we have a row which is taller than the workarea. The
-               // simplest solution is to move to the next row instead.
-               cur.dispatch(
-                       FuncRequest(cur.selection()? LFUN_DOWN_SELECT: LFUN_DOWN));
-
-       cur.finishUndo();
-       cur.updateFlags(Update::Force | Update::FitCursor);
-}
-
-
 // the cursor set functions have a special mechanism. When they
 // realize you left an empty paragraph, they will delete it.
 
index bb9d7bd6c122ccc207390695e4f68bd01a3a3a83..d42759d842eec5d3fe45071aa406611eedf1419d 100644 (file)
@@ -211,10 +211,6 @@ public:
        int cursorY(CursorSlice const & cursor,
                bool boundary) const;
 
-       ///
-       void cursorPrevious(Cursor & cur);
-       ///
-       void cursorNext(Cursor & cur);
        ///
        bool cursorHome(Cursor & cur);
        ///
index a4b42a2d3609abeb746f76542e70417079f869c2..5e7d88f36de2a766e48c12a0eed3958c184932c0 100644 (file)
@@ -665,16 +665,6 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                }
                break;
 
-       case LFUN_SCREEN_UP_SELECT:
-               cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
-               cur.undispatched();
-               break;
-
-       case LFUN_SCREEN_DOWN_SELECT:
-               cmd = FuncRequest(LFUN_FINISHED_FORWARD);
-               cur.undispatched();
-               break;
-
        case LFUN_CELL_FORWARD:
                cur.updateFlags(Update::Decoration | Update::FitCursor);
                cur.inset().idxNext(cur);