From 48366502d759ae8a40f843581526a91ed43bca60 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 20 Feb 2004 11:00:41 +0000 Subject: [PATCH] fix tabular crashs git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8451 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 13 +++++++++++++ src/cursor.C | 9 +++++++++ src/cursor.h | 2 +- src/cursor_slice.C | 3 +++ src/insets/insettabular.C | 4 ++++ src/lyxfunc.C | 18 ------------------ src/paragraph.C | 5 ++++- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index fa3fe6e807..f318697064 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -981,6 +981,15 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) switch (cmd.action) { + case LFUN_ESCAPE: { + if (bv_->cursor().depth() > 1) { + bv_->cursor().pop(); + // Tell the paragraph dialog that we changed paragraph + dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); + } + break; + } + case LFUN_UNDO: if (available()) { cur.message(_("Undo")); @@ -1118,6 +1127,10 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) cur.errorMessage(N_("Unknown function!")); break; + case LFUN_CENTER: + bv_->center(); + break; + default: return false; } diff --git a/src/cursor.C b/src/cursor.C index 50d630ec85..df64bb4eda 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -80,6 +80,9 @@ void LCursor::reset() DispatchResult LCursor::dispatch(FuncRequest const & cmd0) { lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl; + BOOST_ASSERT(pos() <= lastpos()); + BOOST_ASSERT(idx() <= lastidx()); + BOOST_ASSERT(par() <= lastpar()); FuncRequest cmd = cmd0; disp_.update(true); disp_.val(NONE); @@ -529,6 +532,12 @@ LCursor::row_type LCursor::lastcrow() const } +LCursor::idx_type LCursor::lastidx() const +{ + return current_ ? current().lastidx() : 0; +} + + size_t LCursor::nargs() const { // assume 1x1 grid for 'plain text' diff --git a/src/cursor.h b/src/cursor.h index b860827eb4..91e169f5f1 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -160,7 +160,7 @@ public: /// return the cell of the inset this cursor is in idx_type & idx() { return current().idx(); } /// return the last possible cell in this inset - idx_type lastidx() const { return current().lastidx(); } + idx_type lastidx() const; /// return the paragraph this cursor is in par_type par() const { return current().par(); } /// return the paragraph this cursor is in diff --git a/src/cursor_slice.C b/src/cursor_slice.C index 20a0331c8c..c7eb6673fb 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -43,18 +43,21 @@ CursorSlice::CursorSlice(InsetBase * p) size_t CursorSlice::nargs() const { + BOOST_ASSERT(inset_); return inset_->nargs(); } size_t CursorSlice::nrows() const { + BOOST_ASSERT(inset_); return inset_->nrows(); } size_t CursorSlice::ncols() const { + BOOST_ASSERT(inset_); return inset_->ncols(); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 4046479f08..62d0f14bb9 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -491,6 +491,8 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd) if (sl == cur.current()) if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) { cur.idx() = tabular.getCellBelow(cur.idx()); + cur.par() = 0; + cur.pos() = 0; resetPos(cur); } if (sl == cur.current()) @@ -503,6 +505,8 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd) if (sl == cur.current()) if (tabular.row_of_cell(cur.idx()) != 0) { cur.idx() = tabular.getCellAbove(cur.idx()); + cur.par() = cur.lastpar(); + cur.pos() = cur.lastpos(); resetPos(cur); } if (sl == cur.current()) diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 370560c4c2..048a5ae563 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -841,15 +841,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) switch (action) { - case LFUN_ESCAPE: { - if (!view()->available()) - break; - view()->cursor().pop(); - // Tell the paragraph dialog that we changed paragraph - dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); - break; - } - case LFUN_WORDFINDFORWARD: case LFUN_WORDFINDBACKWARD: { static string last_search; @@ -901,10 +892,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) !owner->buffer()->isReadonly()); break; - case LFUN_CENTER: // this is center and redraw. - view()->center(); - break; - // --- Menus ----------------------------------------------- case LFUN_MENUNEW: menuNew(argument, false); @@ -1068,11 +1055,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) open(argument); break; - case LFUN_LAYOUT_TABULAR: - if (InsetTabular * tab = view()->cursor().innerInsetTabular()) - tab->openLayoutDialog(view()); - break; - case LFUN_DROP_LAYOUTS_CHOICE: owner->getToolbar().openLayoutList(); break; diff --git a/src/paragraph.C b/src/paragraph.C index 29db569c79..b46a5a2384 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -328,7 +328,10 @@ InsetBase const * Paragraph::getInset(pos_type pos) const LyXFont const Paragraph::getFontSettings(BufferParams const & bparams, pos_type pos) const { - BOOST_ASSERT(pos <= size()); + if (pos > size()) { + lyxerr << " pos: " << pos << " size: " << size() << endl; + BOOST_ASSERT(pos <= size()); + } Pimpl::FontList::const_iterator cit = pimpl_->fontlist.begin(); Pimpl::FontList::const_iterator end = pimpl_->fontlist.end(); -- 2.39.5