]> git.lyx.org Git - features.git/commitdiff
Fix bug 2115 (crash, selection begin and end different depths)
authorMartin Vermeer <martin.vermeer@hut.fi>
Mon, 7 Nov 2005 15:02:08 +0000 (15:02 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Mon, 7 Nov 2005 15:02:08 +0000 (15:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10594 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/cursor.C
src/text.C

index 1c38fc5a22062d3803e8fbd351ed1f08ca29b834..c495f9774cf58243a1d53f75d4a26b4a7c1e45d1 100644 (file)
@@ -1,3 +1,9 @@
+2005-11-07  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * cursor.C (selectionBegin, selectionEnd):
+       * text.C (drawSelection): Fix bug 2115: assertion when anchor and 
+       cursor at different depths
+
 2005-11-03  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * bufferview_funcs.C (coordOffset): do not call cursorPos
index ff206f532005623129edbbec1758a2ea7194a9f7..61559ffa22e1c07ca478a536a6ea1123bedcdbc3 100644 (file)
@@ -438,7 +438,9 @@ DocIterator LCursor::selectionBegin() const
 {
        if (!selection())
                return *this;
-       return anchor() < top() ? anchor_ : *this;
+       DocIterator di = (anchor() < top() ? anchor_ : *this);
+       di.resize(depth());
+       return di;
 }
 
 
@@ -446,7 +448,12 @@ DocIterator LCursor::selectionEnd() const
 {
        if (!selection())
                return *this;
-       return anchor() > top() ? anchor_ : *this;
+       DocIterator di = (anchor() > top() ? anchor_ : *this);
+       if (di.depth() > depth()) {
+               di.resize(depth());
+               ++di.pos();
+       }
+       return di;
 }
 
 
index 264a732a3c8f08352e554fd1136600028d8a9070..b56b9f4a467c9f7c27199c7ef0ed673c0e7ac933 100644 (file)
@@ -1775,12 +1775,8 @@ void LyXText::drawSelection(PainterInfo & pi, int x , int) const
 
        lyxerr << "draw selection at " << x << endl;
 
-       // is there a better way of getting these two iterators?
-       DocIterator beg = cur;
-       DocIterator end = cur;
-
-       beg.top() = cur.selBegin();
-       end.top() = cur.selEnd();
+       DocIterator beg = cur.selectionBegin();
+       DocIterator end = cur.selectionEnd();
 
        // the selection doesn't touch the visible screen
        if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
@@ -1848,12 +1844,8 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
                 << "draw selection at " << x
                 << endl;
 
-       // is there a better way of getting these two iterators?
-       DocIterator beg = cur;
-       DocIterator end = cur;
-
-       beg.top() = cur.selBegin();
-       end.top() = cur.selEnd();
+       DocIterator beg = cur.selectionBegin();
+       DocIterator end = cur.selectionEnd();
 
        // the selection doesn't touch the visible screen
        if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW