]> git.lyx.org Git - features.git/commitdiff
fix table crash;
authorAndré Pönitz <poenitz@gmx.net>
Wed, 7 Apr 2004 08:07:26 +0000 (08:07 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 7 Apr 2004 08:07:26 +0000 (08:07 +0000)
selection by mouse

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8617 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/BufferView_pimpl.C
src/cursor.C
src/cursor.h
src/cursor_slice.C
src/dociterator.C
src/insets/insettabular.C
src/lyxfunc.C
src/mathed/math_hullinset.C
src/mathed/math_nestinset.C
src/paragraph.C
src/text2.C
src/text3.C

index 63721950ec527afcff3ac94ba68db038e7f8c6ec..8f3c60cd1a219c78108b9d248db78a18251652f6 100644 (file)
@@ -861,7 +861,6 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
        //lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
        LCursor cur(*bv_);
        cur.push(bv_->buffer()->inset());
-       cur.resetAnchor();
        cur.selection() = bv_->cursor().selection();
 
        // Doesn't go through lyxfunc, so we need to update
@@ -873,14 +872,17 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
 
        screen().hideCursor();
 
-       // either the inset under the cursor or the
+       // Either the inset under the cursor or the
        // surrounding LyXText will handle this event.
 
-       // built temporary path to inset
+       // Build temporary cursor.
        InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
        lyxerr << "hit inset at tip: " << inset << endl;
        lyxerr << "created temp cursor:\n" << cur << endl;
 
+       // Put anchor at the same position.
+       cur.resetAnchor();
+
        // Try to dispatch to an non-editable inset near this position
        // via the temp cursor. If the inset wishes to change the real
        // cursor it has to do so explicitly by using
@@ -889,16 +891,11 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
        if (inset)
                inset->dispatch(cur, cmd);
 
-       // Now dispatch to the real cursor. Any change to the cursor
-       // is immediate.
+       // Now dispatch to the temporary cursor. If the real cursor should
+       // be modified, the inset's dispatch has to do so explicitly. 
        if (!res.dispatched())
                res = cur.dispatch(cmd);
 
-       // If the request was dispatched the temp cursor should have been
-       // in a way to be used as new 'real' cursor.
-       if (res.dispatched())
-               bv_->cursor() = cur;
-
        // Redraw if requested or necessary.
        if (res.update())
                update();
index c213a1a9e8cb45a970241341c10f813d898763df..6e91d9d9c27fb770b5080201289244e5f302c290 100644 (file)
@@ -316,15 +316,27 @@ bool LCursor::posRight()
 
 CursorSlice & LCursor::anchor()
 {
+       if (anchor_.size() < size()) {
+               lyxerr << "anchor_.size() < cursor_.size() "
+                       "should not happen when accessing the anchor" << endl;
+               BOOST_ASSERT(false);
+       }
        BOOST_ASSERT(!anchor_.empty());
-       return anchor_.back();
+       // this size is cursor_.size()
+       return anchor_[size() - 1];
 }
 
 
 CursorSlice const & LCursor::anchor() const
 {
+       if (anchor_.size() < size()) {
+               lyxerr << "anchor_.size() < cursor_.size() "
+                       "should not happen when accessing the anchor" << endl;
+               BOOST_ASSERT(false);
+       }
+       // this size is cursor_.size()
        BOOST_ASSERT(!anchor_.empty());
-       return anchor_.back();
+       return anchor_[size() - 1];
 }
 
 
@@ -364,6 +376,7 @@ void LCursor::setSelection()
 {
        selection() = true;
        // a selection with no contents is not a selection
+#warning doesnt look ok
        if (par() == anchor().par() && pos() == anchor().pos())
                selection() = false;
 }
@@ -496,13 +509,6 @@ string LCursor::grabAndEraseSelection()
 }
 
 
-void LCursor::selClear()
-{
-       resetAnchor();
-       clearSelection();
-}
-
-
 void LCursor::selCopy()
 {
        if (selection()) {
index c8a63b7de48a1cb1be4a4bdfaa47ec5d2704b049..d59e4312bb9e9f3d30f96dc36f5c96194e8c49e0 100644 (file)
@@ -96,10 +96,6 @@ public:
        void selPaste(size_t n);
        ///
        void selHandle(bool selecting);
-       /// start selection
-       void selStart();
-       /// clear selection
-       void selClear();
        /// clears or deletes selection depending on lyxrc setting
        void selClearOrDel();
        //
index a537aee3aa373a2d9a0d7ca412705c9dc4468dc7..2f8bb87857049218d03575afe23e7443b2ce90aa 100644 (file)
@@ -150,7 +150,7 @@ bool operator<(CursorSlice const & p, CursorSlice const & q)
        if (&p.inset() != &q.inset()) {
                lyxerr << "can't compare cursor and anchor in different insets\n"
                       << "p: " << p << '\n' << "q: " << q << endl;
-               return true;
+               BOOST_ASSERT(false);
        }
        if (p.idx() != q.idx())
                return p.idx() < q.idx();
index 264df011274a88580ff74a1a3171750d53e0fdd7..d884598300b1be9bdcfec31860672cf3c9d1654b 100644 (file)
@@ -103,6 +103,7 @@ MathAtom & DocIterator::prevAtom()
 MathAtom const & DocIterator::nextAtom() const
 {
        BOOST_ASSERT(!empty());
+       lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
        BOOST_ASSERT(pos() < lastpos());
        return cell()[pos()];
 }
@@ -111,6 +112,7 @@ MathAtom const & DocIterator::nextAtom() const
 MathAtom & DocIterator::nextAtom()
 {
        BOOST_ASSERT(!empty());
+       lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl;
        BOOST_ASSERT(pos() < lastpos());
        return cell()[pos()];
 }
index 2aeadc47101d774b8371e247adc76128a73f095d..063d329c0eecb07b475f434dbfc7594e881ca9e0 100644 (file)
@@ -410,6 +410,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
        //lyxerr << "  cur:\n" << cur << endl;
        CursorSlice sl = cur.top();
+       LCursor & bvcur = cur.bv().cursor();
 
        switch (cmd.action) {
 
@@ -420,7 +421,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                cur.selection() = false;
                setPos(cur, cmd.x, cmd.y);
                cur.resetAnchor();
-               cur.bv().cursor().setCursor(cur, false);
+               bvcur = cur;
                //if (cmd.button() == mouse_button::button2)
                //      dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
                //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
@@ -429,13 +430,16 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_MOTION:
                if (cmd.button() != mouse_button::button1)
                        break;
+               // ignore motions deeper nested than the real anchor
+               if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
+                       break;
                setPos(cur, cmd.x, cmd.y);
-               cur.bv().cursor().setCursor(cur, true);
-               //lyxerr << "# InsetTabular::MouseMotion\n" << cur.bv().cursor() << endl;
+               bvcur.setCursor(cur, true);
+               //lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
                break;
 
        case LFUN_MOUSE_RELEASE:
-               //lyxerr << "# InsetTabular::MouseRelease\n" << cur.bv().cursor() << endl;
+               //lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
                if (cmd.button() == mouse_button::button3)
                        InsetTabularMailer(*this).showDialog(&cur.bv());
                break;
@@ -1725,7 +1729,7 @@ void InsetTabular::addPreview(PreviewLoader & loader) const
 
 bool InsetTabular::tablemode(LCursor & cur) const
 {
-       return cur.selBegin().idx() != cur.selEnd().idx();
+       return cur.selection() && cur.selBegin().idx() != cur.selEnd().idx();
 }
 
 
index a73ecde36a3e5de3c3ee3a775ae154094d8d1677..0d1e7a23405d814dfae66cf3567db673b3e2c091 100644 (file)
@@ -511,6 +511,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
                flag.enabled(false);
        }
 
+       //lyxerr << "LyXFunc::getStatus: got: " << flag.enabled() << endl;
        return flag;
 }
 
@@ -1257,13 +1258,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        break;
                }
 
-               case LFUN_BREAKLINE: {
-#ifdef WITH_WARNINGS
-#warning swallow 'Return' if the minibuffer is focused. But how?
-#endif
-                       break;
-               }
-
                case LFUN_ALL_INSETS_TOGGLE: {
                        string action;
                        string const name = split(argument, action, ' ');
index 4be4d7497493e923b1587e81060ad611221381a6..8711f6242010057becf14926c6a86fb1e000c174 100644 (file)
@@ -783,7 +783,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest & func)
 
 void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 {
-       lyxerr << "*** MathHullInset: request: " << cmd << endl;
+       //lyxerr << "*** MathHullInset: request: " << cmd << endl;
        switch (cmd.action) {
 
        case LFUN_BREAKLINE:
index 0a9fd568747933be7fc54c4bb2fbc62c713eb45c..43c81668e00927547b5b731d890669a8e3b3a710 100644 (file)
@@ -571,7 +571,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 
        case LFUN_ESCAPE:
                if (cur.selection())
-                       cur.selClear();
+                       cur.clearSelection();
                else
                        cmd = FuncRequest(LFUN_FINISHED_LEFT);
                break;
@@ -964,7 +964,7 @@ void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
        if (cmd.button() == mouse_button::button2) {
                MathArray ar;
                asArray(cur.bv().getClipboard(), ar);
-               cur.selClear();
+               cur.clearSelection();
                cur.setScreenPos(cmd.x, cmd.y);
                cur.insert(ar);
                cur.bv().update();
@@ -987,9 +987,9 @@ void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
        if (cmd.button() == mouse_button::button1) {
                first_x = cmd.x;
                first_y = cmd.y;
-               cur.selClear();
                //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
                lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
+               cur.resetAnchor();
                cur.bv().cursor() = cur;
        }
 
@@ -1011,10 +1011,6 @@ void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
        first_x = cmd.x;
        first_y = cmd.y;
 
-       if (!cur.selection())
-               cur.selBegin();
-
-       //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
        cur.bv().cursor().setCursor(cur, true);
 }
 
index 274fe07963c77a1b49ded8da442f00ab96b2a731..804e3221bd40a7ab951eba3e34390246b7002ad4 100644 (file)
@@ -1671,14 +1671,14 @@ void Paragraph::cleanChanges()
 
 Change::Type Paragraph::lookupChange(lyx::pos_type pos) const
 {
-       BOOST_ASSERT(!size() || pos < size());
+       BOOST_ASSERT(empty() || pos < size());
        return pimpl_->lookupChange(pos);
 }
 
 
 Change const Paragraph::lookupChangeFull(lyx::pos_type pos) const
 {
-       BOOST_ASSERT(!size() || pos < size());
+       BOOST_ASSERT(empty() || pos < size());
        return pimpl_->lookupChangeFull(pos);
 }
 
index 0be76d5ad164b0429952d0d945738313b63c5d21..1e1e0a9e4fa137eed7e80014c561eb2b80365654 100644 (file)
@@ -417,12 +417,18 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
        DocIterator pos = cur.selectionBegin();
        DocIterator posend = cur.selectionEnd();
 
+       lyxerr << "pos: " << pos << " posend: " << posend << endl;
+
        BufferParams const & params = bv()->buffer()->params();
 
-       for (; pos != posend; pos.forwardChar()) {
-               LyXFont f = getFont(pos.par(), pos.pos());
-               f.update(font, params.language, toggleall);
-               setCharFont(pos.par(), pos.pos(), f);
+       // Don't use forwardChar here as posend might have
+       // pos() == lastpos() and forwardChar would miss it.
+       for (; pos != posend; pos.forwardPos()) {
+               if (pos.pos() != pos.lastpos()) {
+                       LyXFont f = getFont(pos.par(), pos.pos());
+                       f.update(font, params.language, toggleall);
+                       setCharFont(pos.par(), pos.pos(), f);
+               }
        }
 
        redoParagraphs(beg, end + 1);
index c6ee35aadfda4ca7a2e38e071e51a3733bc8b3ef..e4631d8bdc98c804060b905254292c290bfae97a 100644 (file)
@@ -138,7 +138,7 @@ namespace {
 
                if (sel.empty()) {
                        cur.insert(new MathHullInset);
-                       cur.dispatch(FuncRequest(LFUN_RIGHT));
+                       cur.nextInset()->edit(cur, true);
                        cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
                        // don't do that also for LFUN_MATH_MODE unless you want end up with
                        // always changing to mathrm when opening an inlined inset
@@ -1079,6 +1079,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
                        break;
                }
+
+               // ignore motions deeper nested than the real anchor
+               LCursor & bvcur = cur.bv().cursor();
+               if (bvcur.selection() && bvcur.anchor_.size() < cur.size())
+                       break;
+
                CursorSlice old = cur.top();
                setCursorFromCoordinates(cur, cmd.x, cmd.y);
 
@@ -1140,6 +1146,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                finishUndo();
                cur.x_target() = cursorX(cur.top());
 
+               // Set cursor here.
+               bv->cursor() = cur;
+
+               // Don't allow selection after a big jump.
                if (bv->fitCursor())
                        selection_possible = false;
 
@@ -1153,6 +1163,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                                bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION, "paragraph"));
                        selection_possible = false;
                }
+
                break;
        }