]> git.lyx.org Git - features.git/commitdiff
revert last commits. I've detected problems with it (i.e. it is not complete as is)
authorAlfredo Braunstein <abraunst@lyx.org>
Fri, 2 Apr 2004 22:43:14 +0000 (22:43 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Fri, 2 Apr 2004 22:43:14 +0000 (22:43 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8593 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/BufferView_pimpl.C
src/ChangeLog
src/cursor.C
src/cursor.h
src/frontends/screen.C
src/lyxfunc.C
src/text3.C

index fff8a99f2b9a81cc3195bd80d591e9c102c1844e..e1176d8f3277fd1a3e7b6cd47f00f56fbf18414e 100644 (file)
@@ -379,10 +379,23 @@ void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
                par[i].inset().edit(cursor(), true);
 
        cursor().setCursor(makeDocIterator(par, pos), false);
-       par[0].text()->redoParagraph(par[0].par());
 }
 
 
+/*
+if the fitCursor call refers to some point in never-explored-land, then we
+don't have y information in insets there, then we cannot even do an update
+to get it (because we need the y infomation for setting top_y first). So
+this is solved in putSelectionAt with:
+
+- setting top_y to the y of the outerPar (that has good info)
+- calling update
+- calling cursor().updatePos()
+- then call fitCursor()
+
+Ab.
+*/
+
 void BufferView::putSelectionAt(DocIterator const & cur,
                                int length, bool backwards)
 {
@@ -390,7 +403,15 @@ void BufferView::putSelectionAt(DocIterator const & cur,
 
        cursor().clearSelection();
 
+       LyXText & text = *cur[0].text();
        setCursor(par, cur.pos());
+       
+       // hack for the chicken and egg problem
+       top_y(text.getPar(par.outerPar()).y);
+
+       update();
+       //text.setCursor(cursor(), cur.par(), cur.pos());
+       cursor().updatePos();
 
        if (length) {
                if (backwards) {
@@ -403,6 +424,7 @@ void BufferView::putSelectionAt(DocIterator const & cur,
        }
 
        fitCursor();
+       update();
 }
 
 
index c0d5b6ac62d90466d0cef82dda805e1f1ec54487..20fefddfd6cf62f7d6ffa6d2e62227d1acfb155a 100644 (file)
@@ -358,12 +358,8 @@ void BufferView::Pimpl::setBuffer(Buffer * b)
 
 bool BufferView::Pimpl::fitCursor()
 {
-       // this is enough to get the right y cursor info for fitCursor
-       cursor_[0].text()->redoParagraph(cursor_[0].par());
-
        if (!screen().fitCursor(bv_))
                return false;
-
        updateScrollbar();
        return true;
 }
@@ -392,6 +388,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
 
        text->init(bv_);
        update();
+       bv_->cursor().updatePos();
        fitCursor();
 
        switchKeyMap();
@@ -895,12 +892,14 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
 
        // If the request was dispatched the temp cursor should have been 
        // in a way to be used as new 'real' cursor.
-       if (res.dispatched()) {
+       if (res.dispatched())
                bv_->cursor() = cur;
-               // Redraw if requested or necessary.
-               if (fitCursor() || res.update())
-                       update();
-       }
+
+       // Redraw if requested or necessary.
+       if (res.update())
+               update();
+       if (fitCursor())
+               update();
 
        // see workAreaKeyPress
        cursor_timeout.restart();
index 53144b562d0425422014d2af255004fa6eae24b5..399e48c7ab8d54c82bb59b2b80ddba9a960dde2b 100644 (file)
@@ -1,22 +1,4 @@
 
-2004-04-03  Alfredo Braunstein  <abraunst@lyx.org>
-
-       * BufferView_pimpl.C (fitCursor): oversight
-       
-2004-04-03  Alfredo Braunstein  <abraunst@lyx.org>
-
-       * cursor.[Ch] (LCursor): remove cached_y_ and updatePos 
-       (getDim) remove outdated comment
-
-       * BufferView_pimpl.C (fitCursor): call redoParagraph on the outer
-       cursor paragraph to obtain good cursor y info
-       (workAreaDispatch): remove unneeded update call
-
-       * BufferView.C (setCursor): call redoParagraph, as some insets
-       could have been opened
-       (putSelectionAt): remove the double update and all that cleverness
-       (simplified and transfered to fitCursor where it belongs).
-
 2004-04-01  Alfredo Braunstein  <abraunst@lyx.org>
 
        * text3.C (getStatus): add LFUN_BEGINNINGBUF
index d731738c865e9ae2ee8737eb0ec2155f6e02a712..5b27a79b7c26de15db9ab183132cc33d33f14055 100644 (file)
@@ -84,7 +84,8 @@ void region(CursorSlice const & i1, CursorSlice const & i2,
 
 
 LCursor::LCursor(BufferView & bv)
-       : DocIterator(), bv_(&bv), anchor_(), x_target_(-1),
+       : DocIterator(), bv_(&bv),
+         anchor_(), cached_y_(0), x_target_(-1),
          selection_(false), mark_(false)
 {}
 
@@ -94,6 +95,7 @@ void LCursor::reset(InsetBase & inset)
        clear();
        push_back(CursorSlice(inset));
        anchor_ = DocIterator(inset);
+       cached_y_ = 0;
        clearTargetX();
        selection_ = false;
        mark_ = false;
@@ -234,6 +236,15 @@ int LCursor::currentMode()
 }
 
 
+void LCursor::updatePos()
+{
+       BOOST_ASSERT(!empty());
+       if (size() > 1)
+               cached_y_ = bv().top_y() + back().inset().yo();
+               //cached_y_ = back().inset().yo();
+}
+
+
 void LCursor::getDim(int & asc, int & des) const
 {
        if (inMathed()) {
@@ -259,6 +270,16 @@ void LCursor::getPos(int & x, int & y) const
        y = 0;
        if (!empty())
                inset().getCursorPos(back(), x, y);
+       // getCursorPos gives _screen_ coordinates. We need to add
+       // top_y to get document coordinates. This is hidden in cached_y_.
+       //y += cached_y_ - inset().yo();
+       // The rest is non-obvious. The reason we have to have these
+       // extra computation is that the getCursorPos() calls rely
+       // on the inset's own knowledge of its screen position.
+       // If we scroll up or down in a big enough increment,
+       // inset->draw() is not called: this doesn't update
+       // inset.yo_, so getCursor() returns an old value.
+       // Ugly as you like.
 }
 
 
index a3b0b3e75f0ede5f68b40842d71c0f06e483c842..ad3cf1fbb84ff1f1ec6d11b39cc69413214edab1 100644 (file)
@@ -149,6 +149,8 @@ public:
        CursorSlice & anchor();
        /// access to selection anchor
        CursorSlice const & anchor() const;
+       /// cache the absolute coordinate from the top inset
+       void updatePos();
        /// sets anchor to cursor position
        void resetAnchor(); 
        /// access to owning BufferView
@@ -185,6 +187,8 @@ public:
        DispatchResult disp_;
 
 private:
+       ///
+       int cached_y_;
        /**
         * The target x position of the cursor. This is used for when
         * we have text like :
index 3317e00f9d8f920daffb80fab295a0512feb5442..93f30487b88fb6d6dda9f29aacfa36ac44f1f905 100644 (file)
@@ -214,7 +214,7 @@ bool LyXScreen::fitCursor(BufferView * bv)
        bv->cursor().getPos(x, y);
        bv->cursor().getDim(asc, desc);
        //lyxerr << "LyXScreen::fitCursor: x: " << x << " y: " << y
-       //      << "  top_y: " << top_y << endl;
+       //      << "  top_y: " << top_y << endl;
        
        bool const big_row = h / 4 < asc + desc && asc + desc < h;
 
index da82260329412d2ab1bbdf1fc696d87726b666ab..550b627fe36e52f3ea21f3050d2a624bc33db691 100644 (file)
@@ -1362,6 +1362,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                if (view()->available()) {
                        view()->fitCursor();
                        view()->update();
+                       view()->cursor().updatePos();
                        // if we executed a mutating lfun, mark the buffer as dirty
                        if (getStatus(cmd).enabled()
                                        && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
index 99c28c9f4d50a1f7455c0d5a3317e140633efe28..8fcea9ed27a541bfa7c6b431b6258f37929ec515 100644 (file)
@@ -1136,6 +1136,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                finishUndo();
                cur.x_target() = cursorX(cur.top());
 
+               if (bv->fitCursor())
+                       selection_possible = false;
+
                // Insert primary selection with middle mouse
                // if there is a local selection in the current buffer,
                // insert this