From: Lars Gullik Bjønnes Date: Fri, 15 Jul 2005 12:56:23 +0000 (+0000) Subject: bug 1825 make sure that we do not return a pos that is not on the row X-Git-Tag: 1.6.10~14125 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8355663e9726b794448ea198fec251a42ff126b1;p=features.git bug 1825 make sure that we do not return a pos that is not on the row git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10206 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/ChangeLog b/src/ChangeLog index 81d2d86d4e..f50c4d3816 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,10 @@ 2005-07-15 + * text.C (setCursorFromCoordinates): add a debug statement + + * text2.C (getColumnNearX): bug 1825 make sure that we don't + return a pos that is not on the row + * output_latex.C (TeXDeeper): get rid of potential dereferencing of past the end iterator diff --git a/src/text.C b/src/text.C index d43486d460..61c3dd8500 100644 --- a/src/text.C +++ b/src/text.C @@ -2304,5 +2304,12 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y) bool bound = false; int xx = x; pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); + + lyxerr[Debug::DEBUG] + << BOOST_CURRENT_FUNCTION + << ": setting cursor pit: " << pit + << " pos: " << pos + << endl; + setCursor(cur, pit, pos, true, bound); } diff --git a/src/text2.C b/src/text2.C index b993d6e6a9..75d4f4f875 100644 --- a/src/text2.C +++ b/src/text2.C @@ -61,6 +61,7 @@ using lyx::pos_type; using std::endl; using std::ostringstream; using std::string; +using std::min; LyXText::LyXText(BufferView * bv) @@ -854,7 +855,11 @@ pos_type LyXText::getColumnNearX(pit_type const pit, } x = int(tmpx) + xo; - return c - row.pos(); + + if (end == par.size()) + return c - row.pos(); + + return min(c - row.pos(), end - 1 - row.pos()); }