From: André Pönitz Date: Wed, 7 Apr 2004 08:07:26 +0000 (+0000) Subject: fix table crash; X-Git-Tag: 1.6.10~15347 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=6c9b23105c2753c91870f50f517edc7ffb8890e5;p=features.git fix table crash; selection by mouse git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8617 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 63721950ec..8f3c60cd1a 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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(); diff --git a/src/cursor.C b/src/cursor.C index c213a1a9e8..6e91d9d9c2 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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()) { diff --git a/src/cursor.h b/src/cursor.h index c8a63b7de4..d59e4312bb 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -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(); // diff --git a/src/cursor_slice.C b/src/cursor_slice.C index a537aee3aa..2f8bb87857 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -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(); diff --git a/src/dociterator.C b/src/dociterator.C index 264df01127..d884598300 100644 --- a/src/dociterator.C +++ b/src/dociterator.C @@ -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()]; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 2aeadc4710..063d329c0e 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -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(); } diff --git a/src/lyxfunc.C b/src/lyxfunc.C index a73ecde36a..0d1e7a2340 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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, ' '); diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 4be4d74974..8711f62420 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -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: diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 0a9fd56874..43c81668e0 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -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); } diff --git a/src/paragraph.C b/src/paragraph.C index 274fe07963..804e3221bd 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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); } diff --git a/src/text2.C b/src/text2.C index 0be76d5ad1..1e1e0a9e4f 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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); diff --git a/src/text3.C b/src/text3.C index c6ee35aadf..e4631d8bdc 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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; }