On Mon, 2005-11-07 at 12:40 +0100, Jean-Marc Lasgouttes wrote:
> >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes:
> 
> >>  If selectionEnd is resize to go oustside an inset, the pos at top
> >> level has to be incremented, so that the inset is in the selection.
> >> Look at the comment in the anchor() method.
> 
> Martin> OK, point taken. Better patch attached.
> 
> This looks very good. In the furture, it would be even better to
> change LCursor::anchor() (which is not used outside of LCursor) to
> return a full DocIterator, so that we do not have to duplicate the
> code between selXXX and selectionXXX. The former should be just
>    return selectionXXX().top();
> 
> Also, could you update the code in drawSelection (both versions just
> in case) to use directly selectionBegin/End?

Like this?

- Martin

Index: cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor.C,v
retrieving revision 1.138
diff -u -p -r1.138 cursor.C
--- cursor.C	12 Oct 2005 18:44:52 -0000	1.138
+++ cursor.C	7 Nov 2005 12:36:17 -0000
@@ -438,7 +438,9 @@ DocIterator LCursor::selectionBegin() co
 {
 	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() cons
 {
 	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: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.632
diff -u -p -r1.632 text.C
--- text.C	13 Oct 2005 14:48:25 -0000	1.632
+++ text.C	7 Nov 2005 12:36:18 -0000
@@ -1776,12 +1776,8 @@ void LyXText::drawSelection(PainterInfo 
 
 	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
@@ -1849,12 +1845,8 @@ void LyXText::drawSelection(PainterInfo 
                 << "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

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to