From: Alfredo Braunstein Date: Mon, 21 Mar 2005 18:21:13 +0000 (+0000) Subject: fix crash in table selection X-Git-Tag: 1.6.10~14455 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c605824a66f0780358aa6d56062665e3a2ac556e;p=features.git fix crash in table selection git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9735 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index c7f03ff94c..8596597a06 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,10 @@ + +2005-03-21 Alfredo Braunstein + + * insettabular.[Ch]: rename setPos -> setCursorFromCoordinates and + make it *not* descend into insets (fix a crash). Move the part + needed from editXY to a new function getNearestCell + 2005-02-22 Jean-Marc Lasgouttes * insetinclude.C (InsetInclude): when constructing from another diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 1a351fb2b3..2ab039b1cc 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -426,16 +426,6 @@ void InsetTabular::edit(LCursor & cur, bool left) } -InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const -{ - //lyxerr << "InsetTabular::editXY: " << this << endl; - cur.selection() = false; - cur.push(const_cast(*this)); - return setPos(cur, x, y); - //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx()); -} - - void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) { lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl; @@ -450,7 +440,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button1) { cur.selection() = false; - setPos(cur, cmd.x, cmd.y); + setCursorFromCoordinates(cur, cmd.x, cmd.y); cur.resetAnchor(); bvcur = cur; break; @@ -474,7 +464,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd) if (cmd.button() == mouse_button::button1) { // only accept motions to places not deeper nested than the real anchor if (bvcur.anchor_.hasPart(cur)) { - setPos(cur, cmd.x, cmd.y); + setCursorFromCoordinates(cur, cmd.x, cmd.y); bvcur.setCursor(cur); bvcur.selection() = true; } else @@ -1136,9 +1126,30 @@ int dist(InsetOld const & inset, int x, int y) } //namespace anon -InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const +InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const { - lyxerr << "# InsetTabular::setPos() x=" << x << " y=" << y << endl; + //lyxerr << "InsetTabular::editXY: " << this << endl; + cur.selection() = false; + cur.push(const_cast(*this)); + cur.idx() = getNearestCell(x, y); + resetPos(cur); + return cell(cur.idx())->text_.editXY(cur, x, y); + //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx()); +} + + +void InsetTabular::setCursorFromCoordinates(LCursor & cur, int x, int y) const +{ + //lyxerr << "# InsetTabular::setCursorFromCoordinates()\n" << cur << endl; + cur.idx() = getNearestCell(x, y); + resetPos(cur); + return cell(cur.idx())->text_.setCursorFromCoordinates(cur, x, y); +} + + +InsetTabular::idx_type InsetTabular::getNearestCell(int x, int y) const +{ + lyxerr << "# InsetTabular::getNearestCell() x=" << x << " y=" << y << endl; idx_type idx_min = 0; int dist_min = std::numeric_limits::max(); for (idx_type i = 0; i < nargs(); ++i) { @@ -1150,10 +1161,7 @@ InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const } } } - cur.idx() = idx_min; - //lyxerr << "# InsetTabular::setPos()\n" << cur << endl; - resetPos(cur); - return cell(cur.idx())->text_.editXY(cur, x, y); + return idx_min; } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index b405518834..f3f8ad25ad 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -153,7 +153,7 @@ private: void drawCellLines(Painter &, int x, int y, row_type row, idx_type cell) const; /// - InsetBase * setPos(LCursor & cur, int x, int y) const; + void setCursorFromCoordinates(LCursor & cur, int x, int y) const; /// void moveNextCell(LCursor & cur); @@ -183,6 +183,9 @@ private: /// are we operating on several cells? bool tablemode(LCursor & cur) const; + /// return the cell nearest to x, y + idx_type getNearestCell(int x, int y) const; + /// Buffer const * buffer_; ///