Alfredo Braunstein wrote:

> Anyway, I'll still test it for a day or so to avoid bad surprises. ;-)

I'm willing to apply this as it seems to work correctly.

No objections (naming or otherwise)?

Alfredo
Index: BufferView.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v
retrieving revision 1.213
diff -u -r1.213 BufferView.C
--- BufferView.C	1 Dec 2003 13:35:36 -0000	1.213
+++ BufferView.C	12 Dec 2003 14:41:12 -0000
@@ -68,6 +68,12 @@
 }
 
 
+void BufferView::unsetXSel()
+{
+	pimpl_->xsel_cache_.set = false;
+}
+
+
 Buffer * BufferView::buffer() const
 {
 	return pimpl_->buffer_;
Index: BufferView.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v
retrieving revision 1.154
diff -u -r1.154 BufferView.h
--- BufferView.h	28 Nov 2003 15:08:36 -0000	1.154
+++ BufferView.h	12 Dec 2003 14:41:13 -0000
@@ -182,6 +182,9 @@
 	/// return target x position of cursor
 	int x_target() const;
 
+	/// clear the X selection
+	void unsetXSel();
+
 	/// access to cursor
 	LCursor & cursor();
 	/// access to cursor
Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.477
diff -u -r1.477 BufferView_pimpl.C
--- BufferView_pimpl.C	12 Dec 2003 13:39:18 -0000	1.477
+++ BufferView_pimpl.C	12 Dec 2003 14:41:17 -0000
@@ -114,6 +114,8 @@
 	: bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
 	  using_xterm_cursor(false), cursor_(bv)
 {
+	xsel_cache_.set = false;
+
 	workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height));
 	screen_.reset(LyXScreenFactory::create(workarea()));
 
@@ -390,10 +392,10 @@
 
 	par = bv_->text()->cursor.par();
 	pos = bv_->text()->cursor.pos();
-	selstartpar = bv_->text()->selection.start.par();
-	selstartpos = bv_->text()->selection.start.pos();
-	selendpar = bv_->text()->selection.end.par();
-	selendpos = bv_->text()->selection.end.pos();
+	selstartpar = bv_->text()->selStart().par();
+	selstartpos = bv_->text()->selStart().pos();
+	selendpar = bv_->text()->selEnd().par();
+	selendpos = bv_->text()->selEnd().pos();
 	selection = bv_->text()->selection.set();
 	mark_set = bv_->text()->selection.mark();
 	bv_->text()->textwidth_ = bv_->workWidth();
@@ -526,20 +528,22 @@
 
 	LyXText * text = bv_->getLyXText();
 
-	if (text->selection.set() &&
-		(!bv_->text()->xsel_cache.set() ||
-		 text->selection.start != bv_->text()->xsel_cache.start ||
-		 text->selection.end != bv_->text()->xsel_cache.end))
+	if (!text->selection.set()) {
+		xsel_cache_.set = false;
+		return;
+	}
+
+	if (!xsel_cache_.set ||
+	    text->cursor != xsel_cache_.cursor ||
+	    text->selection.cursor != xsel_cache_.selection_cursor)
 	{
-		bv_->text()->xsel_cache = text->selection;
+		xsel_cache_.cursor = text->cursor;
+		xsel_cache_.selection_cursor = text->selection.cursor;
+		xsel_cache_.set = text->selection.set();
 		sel = text->selectionAsString(*bv_->buffer(), false);
-	} else if (!text->selection.set()) {
-		sel = string();
-		bv_->text()->xsel_cache.set(false);
-	}
-	if (!sel.empty()) {
-		workarea().putClipboard(sel);
-	}
+		if (!sel.empty())
+			workarea().putClipboard(sel);
+	} 
 }
 
 
@@ -548,7 +552,7 @@
 	if (available()) {
 		screen().hideCursor();
 		bv_->getLyXText()->clearSelection();
-		bv_->text()->xsel_cache.set(false);
+		xsel_cache_.set = false;
 	}
 }
 
@@ -631,8 +635,8 @@
 	if (!text->selection.set())
 		return Change(Change::UNCHANGED);
 
-	return text->getPar(text->selection.start)
-		->lookupChangeFull(text->selection.start.pos());
+	return text->getPar(text->selStart())
+		->lookupChangeFull(text->selStart().pos());
 }
 
 
Index: BufferView_pimpl.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v
retrieving revision 1.110
diff -u -r1.110 BufferView_pimpl.h
--- BufferView_pimpl.h	10 Nov 2003 18:15:52 -0000	1.110
+++ BufferView_pimpl.h	12 Dec 2003 14:41:17 -0000
@@ -193,7 +193,12 @@
 	void MenuInsertLyXFile(std::string const & filen);
 	/// our workarea
 	WorkArea & workarea() const;
-
+	/// this is used to handle XSelection events in the right manner
+	struct {
+		LyXCursor cursor;
+		LyXCursor selection_cursor;
+		bool set;
+	} xsel_cache_;
 	///
 	LCursor cursor_;
 };
Index: ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1749
diff -u -r1.1749 ChangeLog
--- ChangeLog	12 Dec 2003 13:39:17 -0000	1.1749
+++ ChangeLog	12 Dec 2003 14:41:59 -0000
@@ -1,4 +1,17 @@
-2003-12-12  Alfredo Braunstein  <[EMAIL PROTECTED]>
+2003-12-12  Alfredo Braunstein  <[EMAIL PROTECTED]>
+
+	* textcursor.[Ch] (selStart,selEnd): add new methods 
+	remove selection::start, end, use LyXCursor::operator<
+	* lyxcursor.[Ch] (operator<): add
+	* BufferView_pimpl.[Ch]: add new struct xsel_cache_
+	* BufferView.[Ch] (unsetXSel): add
+	* text2.C (clearSelection): use unsetXSel,adjust
+	* text.C: adjust
+	* text3.C: adjust
+	* rowpainter.C: adjust
+	* bufferview_funcs.C (put_selection_at): adjust
+
+2003-12-12  Alfredo Braunstein  <[EMAIL PROTECTED]>
 
 	* BufferView_pimpl.C: small coord. correction
 
Index: bufferview_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferview_funcs.C,v
retrieving revision 1.128
diff -u -r1.128 bufferview_funcs.C
--- bufferview_funcs.C	10 Dec 2003 09:45:26 -0000	1.128
+++ bufferview_funcs.C	12 Dec 2003 14:42:00 -0000
@@ -301,7 +301,7 @@
 		text->setSelectionRange(length);
 		text->setSelection();
 		if (backwards)
-			text->cursor = text->selection.start;
+			std::swap(text->cursor, text->selection.cursor);
 	}
 
 	bv->fitCursor();
Index: lyxcursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxcursor.C,v
retrieving revision 1.28
diff -u -r1.28 lyxcursor.C
--- lyxcursor.C	26 Nov 2003 10:42:42 -0000	1.28
+++ lyxcursor.C	12 Dec 2003 14:42:00 -0000
@@ -94,3 +94,9 @@
 	return !(a == b);
 }
 
+
+bool operator<(LyXCursor const & a, LyXCursor const & b)
+{
+	return (a.par() < b.par() ||
+		(a.par() == b.par()  && a.pos() < b.pos()));
+}
Index: lyxcursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxcursor.h,v
retrieving revision 1.40
diff -u -r1.40 lyxcursor.h
--- lyxcursor.h	4 Nov 2003 07:43:00 -0000	1.40
+++ lyxcursor.h	12 Dec 2003 14:42:00 -0000
@@ -81,5 +81,7 @@
 bool operator==(LyXCursor const & a, LyXCursor const & b);
 ///
 bool operator!=(LyXCursor const & a, LyXCursor const & b);
+///
+bool operator<(LyXCursor const & a, LyXCursor const & b);
 
 #endif // LYXCURSOR_H
Index: lyxfind.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxfind.C,v
retrieving revision 1.60
diff -u -r1.60 lyxfind.C
--- lyxfind.C	28 Nov 2003 08:55:06 -0000	1.60
+++ lyxfind.C	12 Dec 2003 14:42:01 -0000
@@ -225,7 +225,7 @@
 
 	text->replaceSelectionWithString(replacestr);
 	text->setSelectionRange(replacestr.length());
-	text->cursor = fw ? text->selection.end : text->selection.start;
+	text->cursor = fw ? text->selEnd() : text->selStart();
 
 	bv->buffer()->markDirty();
 	find(bv, searchstr, cs, mw, fw);
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.103
diff -u -r1.103 rowpainter.C
--- rowpainter.C	1 Dec 2003 13:35:41 -0000	1.103
+++ rowpainter.C	12 Dec 2003 14:42:03 -0000
@@ -391,14 +391,14 @@
 	bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
 
 	// the current selection
-	int const startx = text_.selection.start.x();
-	int const endx = text_.selection.end.x();
-	int const starty = text_.selection.start.y();
-	int const endy = text_.selection.end.y();
-	ParagraphList::iterator startpit = text_.getPar(text_.selection.start);
-	ParagraphList::iterator endpit = text_.getPar(text_.selection.end);
-	RowList::iterator startrow = startpit->getRow(text_.selection.start.pos());
-	RowList::iterator endrow = endpit->getRow(text_.selection.end.pos());
+	int const startx = text_.selStart().x();
+	int const endx = text_.selEnd().x();
+	int const starty = text_.selStart().y();
+	int const endy = text_.selEnd().y();
+	ParagraphList::iterator startpit = text_.getPar(text_.selStart());
+	ParagraphList::iterator endpit = text_.getPar(text_.selEnd());
+	RowList::iterator startrow = startpit->getRow(text_.selStart().pos());
+	RowList::iterator endrow = endpit->getRow(text_.selEnd().pos());
 	int const h = row_.height();
 
 	int const row_y = pit_->y + row_.y_offset();
@@ -468,9 +468,9 @@
 		}
 
 		if (((startpit != pit_ && startrow != rit_)
-				|| text_.selection.start.pos() <= pos) &&
+				|| text_.selStart().pos() <= pos) &&
 			((endpit != pit_ && endrow != rit_)
-				|| pos < text_.selection.end.pos())) {
+				|| pos < text_.selEnd().pos())) {
 			// Here we do not use x_ as xo_ was added to x_.
 			pain_.fillRectangle(int(old_tmpx), yo_,
 				int(tmpx - old_tmpx + 1), h, LColor::selection);
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.509
diff -u -r1.509 text.C
--- text.C	10 Dec 2003 09:45:26 -0000	1.509
+++ text.C	12 Dec 2003 14:42:09 -0000
@@ -1129,9 +1129,9 @@
 	if (!selection.set() && cursorPar()->size())
 		return;
 
-	if (selection.start.par() == selection.end.par()) {
-		LyXCursor & startc = selection.start;
-		LyXCursor & endc = selection.end;
+	if (selStart().par() == selEnd().par()) {
+		LyXCursor const & startc = selStart();
+		LyXCursor const & endc = selEnd();
 		recordUndo(Undo::INSERT, this, startc.par());
 		getPar(startc)->acceptChange(startc.pos(), endc.pos());
 		finishUndo();
@@ -1148,9 +1148,9 @@
 	if (!selection.set() && cursorPar()->size())
 		return;
 
-	if (selection.start.par() == selection.end.par()) {
-		LyXCursor & startc = selection.start;
-		LyXCursor & endc = selection.end;
+	if (selStart().par() == selEnd().par()) {
+		LyXCursor const & startc = selStart();
+		LyXCursor const & endc = selEnd();
 		recordUndo(Undo::INSERT, this, startc.par());
 		getPar(startc)->rejectChange(startc.pos(), endc.pos());
 		finishUndo();
@@ -1206,8 +1206,6 @@
 		cursorRight(bv());
 	} else {
 		LyXCursor tmpcursor = cursor;
-		// We can't store the row over a regular setCursor
-		// so we set it to 0 and reset it afterwards.
 		selection.set(true); // to avoid deletion
 		cursorEnd();
 		setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
@@ -1229,8 +1227,8 @@
 	LyXCursor to;
 
 	if (selection.set()) {
-		from = selection.start;
-		to = selection.end;
+		from = selStart();
+		to = selEnd();
 	} else {
 		from = cursor;
 		getWord(from, to, lyx::PARTIAL_WORD);
@@ -1514,10 +1512,10 @@
 		return string();
 
 	// should be const ...
-	ParagraphList::iterator startpit = getPar(selection.start);
-	ParagraphList::iterator endpit = getPar(selection.end);
-	size_t const startpos = selection.start.pos();
-	size_t const endpos = selection.end.pos();
+	ParagraphList::iterator startpit = getPar(selStart());
+	ParagraphList::iterator endpit = getPar(selEnd());
+	size_t const startpos = selStart().pos();
+	size_t const endpos = selEnd().pos();
 
 	if (startpit == endpit)
 		return startpit->asString(buffer, startpos, endpos, label);
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.519
diff -u -r1.519 text2.C
--- text2.C	8 Dec 2003 12:47:18 -0000	1.519
+++ text2.C	12 Dec 2003 14:42:13 -0000
@@ -301,8 +301,6 @@
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::setLayout(string const & layout)
 {
-	setSelection();
-
 	// special handling of new environment insets
 	BufferParams const & params = bv()->buffer()->params();
 	LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
@@ -321,8 +319,8 @@
 		return;
 	}
 
-	ParagraphList::iterator start = getPar(selection.start.par());
-	ParagraphList::iterator end = boost::next(getPar(selection.end.par()));
+	ParagraphList::iterator start = getPar(selStart().par());
+	ParagraphList::iterator end = boost::next(getPar(selEnd().par()));
 	ParagraphList::iterator endpit = setLayout(start, end, layout);
 
 	redoParagraphs(start, endpit);
@@ -342,8 +340,8 @@
 		beg = text.cursorPar();
 		end = boost::next(beg);
 	} else {
-		beg = text.getPar(text.selection.start);
-		end = boost::next(text.getPar(text.selection.end));
+		beg = text.getPar(text.selStart());
+		end = boost::next(text.getPar(text.selEnd()));
 	}
 }
 
@@ -438,14 +436,14 @@
 	}
 
 	// ok we have a selection.
-	recUndo(selection.start.par(), selection.end.par());
+	recUndo(selStart().par(), selEnd().par());
 	freezeUndo();
 
-	ParagraphList::iterator beg = getPar(selection.start.par());
-	ParagraphList::iterator end = getPar(selection.end.par());
+	ParagraphList::iterator beg = getPar(selStart().par());
+	ParagraphList::iterator end = getPar(selEnd().par());
 	
-	PosIterator pos(&paragraphs(), beg, selection.start.pos());
-	PosIterator posend(&paragraphs(), end, selection.end.pos());
+	PosIterator pos(&paragraphs(), beg, selStart().pos());
+	PosIterator posend(&paragraphs(), end, selEnd().pos());
 
 	BufferParams const & params = bv()->buffer()->params();
 
@@ -481,7 +479,7 @@
 
 	// reset this in the bv()!
 	if (bv() && bv()->text())
-		bv()->text()->xsel_cache.set(false);
+		bv()->unsetXSel();
 }
 
 
@@ -561,7 +559,7 @@
 	string idxstring;
 	if (!selection.set())
 		bv()->owner()->message(_("Nothing to index!"));
-	else if (selection.start.par() != selection.end.par())
+	else if (selStart().par() != selEnd().par())
 		bv()->owner()->message(_("Cannot index more than one paragraph!"));
 	else
 		idxstring = selectionAsString(*bv()->buffer(), false);
@@ -588,9 +586,8 @@
 void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
 	string const & labelwidthstring, bool noindent)
 {
-	setSelection();
 	// make sure that the depth behind the selection are restored, too
-	ParagraphList::iterator endpit = boost::next(getPar(selection.end));
+	ParagraphList::iterator endpit = boost::next(getPar(selEnd()));
 	ParagraphList::iterator pars_end = paragraphs().end();
 
 	while (endpit != pars_end && endpit->getDepth())
@@ -599,10 +596,10 @@
 	if (endpit != pars_end)
 		++endpit;
 
-	recUndo(selection.start.par(), parOffset(endpit) - 1);
+	recUndo(selStart().par(), parOffset(endpit) - 1);
 
-	ParagraphList::reverse_iterator pit(getPar(selection.end.par()));
-	ParagraphList::reverse_iterator beg(getPar(selection.start.par()));
+	ParagraphList::reverse_iterator pit(getPar(selEnd().par()));
+	ParagraphList::reverse_iterator beg(getPar(selStart().par()));
 
 	for (++beg; pit != beg; ++pit) {
 		ParagraphParameters & params = pit->params();
@@ -623,7 +620,7 @@
 		params.noindent(noindent);
 	}
 
-	redoParagraphs(getPar(selection.start), endpit);
+	redoParagraphs(getPar(selStart()), endpit);
 	redoCursor();
 }
 
@@ -955,12 +952,12 @@
 	if (!selection.set())
 		return;
 
-	// OK, we have a selection. This is always between selection.start
-	// and selection.end
+	// OK, we have a selection. This is always between selStart()
+	// and selEnd()
 
 	// make sure that the depth behind the selection are restored, too
-	ParagraphList::iterator begpit = getPar(selection.start.par());
-	ParagraphList::iterator endpit = getPar(selection.end.par());
+	ParagraphList::iterator begpit = getPar(selStart().par());
+	ParagraphList::iterator endpit = getPar(selEnd().par());
 	ParagraphList::iterator undopit = boost::next(endpit);
 	ParagraphList::iterator pars_end = paragraphs().end();
 
@@ -969,22 +966,22 @@
 	//because of parindents etc.
 	if (undopit != pars_end)
 		++undopit;
-	recUndo(selection.start.par(), parOffset(undopit) - 1);
+	recUndo(selStart().par(), parOffset(undopit) - 1);
 
-	int endpos = selection.end.pos();
+	int endpos = selEnd().pos();
 
 	BufferParams const & bufparams = bv()->buffer()->params();
 	boost::tie(endpit, endpos) = realcut ?
 		CutAndPaste::cutSelection(bufparams,
 					  paragraphs(),
 					  begpit , endpit,
-					  selection.start.pos(), endpos,
+					  selStart().pos(), endpos,
 					  bufparams.textclass,
 					  doclear)
 		: CutAndPaste::eraseSelection(bufparams,
 					      paragraphs(),
 					      begpit, endpit,
-					      selection.start.pos(), endpos,
+					      selStart().pos(), endpos,
 					      doclear);
 	// sometimes necessary
 	if (doclear)
@@ -1013,19 +1010,20 @@
 	if (!selection.set())
 		return;
 
-	// ok we have a selection. This is always between selection.start
+	// ok we have a selection. This is always between selStart()
 	// and sel_end cursor
 
 	// copy behind a space if there is one
-	while (getPar(selection.start)->size() > selection.start.pos()
-	       && getPar(selection.start)->isLineSeparator(selection.start.pos())
-	       && (selection.start.par() != selection.end.par()
-		   || selection.start.pos() < selection.end.pos()))
-		selection.start.pos(selection.start.pos() + 1);
-
-	CutAndPaste::copySelection(getPar(selection.start.par()),
-				   getPar(selection.end.par()),
-				   selection.start.pos(), selection.end.pos(),
+	while (getPar(selStart())->size() > selStart().pos()
+	       && getPar(selStart())->isLineSeparator(selStart().pos())
+	       && (selStart().par() != selEnd().par()
+		   || selStart().pos() < selEnd().pos()))
+		selStart().pos(selStart().pos() + 1);
+
+	CutAndPaste::copySelection(getPar(selStart().par()),
+				   getPar(selEnd().par()),
+				   selStart().pos(), 
+				   selEnd().pos(),
 				   bv()->buffer()->params().textclass);
 }
 
@@ -1082,22 +1080,17 @@
 	recUndo(cursor.par());
 	freezeUndo();
 
-	if (!selection.set()) { // create a dummy selection
-		selection.end = cursor;
-		selection.start = cursor;
-	}
-
 	// Get font setting before we cut
-	pos_type pos = selection.end.pos();
-	LyXFont const font = getPar(selection.start)
+	pos_type pos = selEnd().pos();
+	LyXFont const font = getPar(selStart())
 		->getFontSettings(bv()->buffer()->params(),
-				  selection.start.pos());
+				  selStart().pos());
 
 	// Insert the new string
 	string::const_iterator cit = str.begin();
 	string::const_iterator end = str.end();
 	for (; cit != end; ++cit) {
-		getPar(selection.end)->insertChar(pos, (*cit), font);
+		getPar(selEnd())->insertChar(pos, (*cit), font);
 		++pos;
 	}
 
@@ -1749,8 +1742,6 @@
 			// correct all cursors held by the LyXText
 			fixCursorAfterDelete(cursor, old_cursor);
 			fixCursorAfterDelete(selection.cursor, old_cursor);
-			fixCursorAfterDelete(selection.start, old_cursor);
-			fixCursorAfterDelete(selection.end, old_cursor);
 			return false;
 		}
 	}
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.194
diff -u -r1.194 text3.C
--- text3.C	12 Dec 2003 10:05:20 -0000	1.194
+++ text3.C	12 Dec 2003 14:42:16 -0000
@@ -999,6 +999,8 @@
 	case LFUN_BEGINNINGBUFSEL:
 		if (in_inset_)
 			return DispatchResult(false);
+		if (!selection.set())
+			selection.cursor = cursor;
 		cursorTop();
 		finishChange(bv, true);
 		break;
@@ -1006,6 +1008,8 @@
 	case LFUN_ENDBUFSEL:
 		if (in_inset_)
 			return DispatchResult(false);
+		if (!selection.set())
+			selection.cursor = cursor;
 		cursorBottom();
 		finishChange(bv, true);
 		break;
@@ -1076,10 +1080,10 @@
 		bool change_layout = (current_layout != layout);
 
 		if (!change_layout && selection.set() &&
-			selection.start.par() != selection.end.par())
+			selStart().par() != selEnd().par())
 		{
-			ParagraphList::iterator spit = getPar(selection.start);
-			ParagraphList::iterator epit = boost::next(getPar(selection.end));
+			ParagraphList::iterator spit = getPar(selStart());
+			ParagraphList::iterator epit = boost::next(getPar(selEnd()));
 			while (spit != epit) {
 				if (spit->layout()->name() != current_layout) {
 					change_layout = true;
Index: textcursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/textcursor.C,v
retrieving revision 1.11
diff -u -r1.11 textcursor.C
--- textcursor.C	26 Nov 2003 09:48:21 -0000	1.11
+++ textcursor.C	12 Dec 2003 14:42:17 -0000
@@ -11,40 +11,44 @@
 #include <config.h>
 
 #include "textcursor.h"
-#include "paragraph.h"
-#include "ParagraphList_fwd.h"
-#include "debug.h"
 
-#include <string>
 
-using std::string;
+LyXCursor const & TextCursor::selStart() const
+{
+	if (!selection.set())
+		return cursor;
+	return selection.cursor < cursor ? selection.cursor : cursor;
+}
 
 
-void TextCursor::setSelection()
+LyXCursor const & TextCursor::selEnd() const
 {
-	selection.set(true);
+	if (!selection.set())
+		return cursor;
+	return selection.cursor < cursor ? cursor : selection.cursor;
+}
 
-	if (selection.cursor.par() == cursor.par())
-		if (selection.cursor.pos() < cursor.pos()) {
-			selection.end = cursor;
-			selection.start = selection.cursor;
-		} else {
-			selection.end = selection.cursor;
-			selection.start = cursor;
-		}
-	else if (selection.cursor.par() < cursor.par() ||
-		 (selection.cursor.par() == cursor.par()
-		  && selection.cursor.pos() < cursor.pos())) {
-		selection.end = cursor;
-		selection.start = selection.cursor;
-	} else {
-		selection.end = selection.cursor;
-		selection.start = cursor;
-	}
 
+LyXCursor & TextCursor::selStart()
+{
+	TextCursor const & t = *this;
+	return const_cast<LyXCursor &>(t.selStart());
+}
+
+
+LyXCursor & TextCursor::selEnd()
+{
+	TextCursor const & t = *this;
+	return const_cast<LyXCursor &>(t.selEnd());
+}
+
+
+void TextCursor::setSelection()
+{
+	selection.set(true);
 	// a selection with no contents is not a selection
-	if (selection.start.par() == selection.end.par() &&
-	    selection.start.pos() == selection.end.pos())
+	if (cursor.par() == selection.cursor.par() &&
+	    cursor.pos() == selection.cursor.pos())
 	{
 		selection.set(false);
 	}
@@ -55,8 +59,6 @@
 {
 	selection.set(false);
 	selection.mark(false);
-	selection.end    = cursor;
-	selection.start  = cursor;
 	selection.cursor = cursor;
 }
 
Index: textcursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/textcursor.h,v
retrieving revision 1.12
diff -u -r1.12 textcursor.h
--- textcursor.h	9 Oct 2003 10:52:10 -0000	1.12
+++ textcursor.h	12 Dec 2003 14:42:17 -0000
@@ -50,10 +50,7 @@
 	void mark(bool m) {
 		mark_ = m;
 	}
-	LyXCursor cursor; // temporary cursor to hold a cursor position
-				// until setSelection is called!
-	LyXCursor start;  // start of a REAL selection
-	LyXCursor end;    // end of a REAL selection
+	LyXCursor cursor; // the other end of the selection
 private:
 	bool set_; // former selection
 	bool mark_; // former mark_set
@@ -70,8 +67,11 @@
 	LyXCursor cursor;
 
 	Selection selection;
-	// this is used to handle XSelection events in the right manner
-	Selection xsel_cache;
+
+	LyXCursor const & selStart() const;
+	LyXCursor const & selEnd() const;
+	LyXCursor & selStart();
+	LyXCursor & selEnd();
 };
 
 #endif
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.561
diff -u -r1.561 insettext.C
--- insets/insettext.C	10 Dec 2003 09:45:31 -0000	1.561
+++ insets/insettext.C	12 Dec 2003 14:42:23 -0000
@@ -546,18 +546,7 @@
 			first->insertChar(first_par_size, ' ');
 		}
 
-#warning probably broken
-		if (text_.selection.set()) {
-			if (text_.selection.start.par() == 1) {
-				text_.selection.start.par(1);
-				text_.selection.start.pos(text_.selection.start.pos() + first_par_size);
-			}
-			if (text_.selection.end.par() == 2) {
-				text_.selection.end.par(1);
-				text_.selection.end.pos(text_.selection.end.pos() + first_par_size);
-			}
-		}
-
+		text_.clearSelection();
 		mergeParagraph(bv->buffer()->params(), paragraphs(), first);
 	}
 }

Reply via email to