+ makes setFont do not use cursors (still crashes over insets though)

Ok to go in?

Regards, Alfredo
? bfri.C
? textcursor.C-save
? textcursor.h-save
Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.499
diff -u -p -u -r1.499 text.C
--- text.C	25 Nov 2003 11:17:23 -0000	1.499
+++ text.C	26 Nov 2003 17:56:41 -0000
@@ -1281,7 +1281,7 @@ void LyXText::Delete()
 	LyXCursor old_cursor = cursor;
 
 	// just move to the right
-	cursorRight(bv());
+	cursorRight(true);
 
 	// if you had success make a backspace
 	if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.513
diff -u -p -u -r1.513 text2.C
--- text2.C	26 Nov 2003 09:48:19 -0000	1.513
+++ text2.C	26 Nov 2003 17:56:43 -0000
@@ -349,14 +349,7 @@ LyXText::setLayout(LyXCursor & cur, LyXC
 // set layout over selection and make a total rebreak of those paragraphs
 void LyXText::setLayout(string const & layout)
 {
-	LyXCursor tmpcursor = cursor;  // store the current cursor
-
-	// if there is no selection just set the layout
-	// of the current paragraph
-	if (!selection.set()) {
-		selection.start = cursor;  // dummy selection
-		selection.end = cursor;
-	}
+	setSelection();
 
 	// special handling of new environment insets
 	BufferParams const & params = bv()->buffer()->params();
@@ -371,8 +364,7 @@ void LyXText::setLayout(string const & l
 		if (bv()->insertInset(inset)) {
 			//inset->edit(bv());
 			//bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
-		}
-		else
+		} else
 			delete inset;
 		return;
 	}
@@ -380,16 +372,8 @@ void LyXText::setLayout(string const & l
 	ParagraphList::iterator endpit = setLayout(cursor, selection.start,
 						   selection.end, layout);
 	redoParagraphs(getPar(selection.start), endpit);
-
-	// we have to reset the selection, because the
-	// geometry could have changed
-	setCursor(selection.start.par(), selection.start.pos(), false);
-	selection.cursor = cursor;
-	setCursor(selection.end.par(), selection.end.pos(), false);
 	updateCounters();
-	clearSelection();
-	setSelection();
-	setCursor(tmpcursor.par(), tmpcursor.pos(), true);
+	redoCursor();
 }
 
 
@@ -499,39 +483,28 @@ void LyXText::setFont(LyXFont const & fo
 		return;
 	}
 
-	LyXCursor tmpcursor = cursor; // store the current cursor
-
-	// ok we have a selection. This is always between sel_start_cursor
-	// and sel_end cursor
-
+	// ok we have a selection.
 	recUndo(selection.start.par(), selection.end.par());
 	freezeUndo();
-	cursor = selection.start;
-	while (cursor.par() != selection.end.par() ||
-	       cursor.pos() < selection.end.pos())
-	{
-		if (cursor.pos() < cursorPar()->size()) {
-			// an open footnote should behave like a closed one
-			setCharFont(cursorPar(), cursor.pos(), font, toggleall);
-			cursor.pos(cursor.pos() + 1);
+	ParagraphList::iterator end = getPar(selection.end.par());
+	ParagraphList::iterator beg = getPar(selection.start.par());
+	lyx::pos_type endpos = selection.end.pos();
+
+	ParagraphList::iterator pit = beg;
+	lyx::pos_type pos = selection.start.pos();
+	while (pit != end || pos < endpos) {
+		if (pos < pit->size()) {
+			setCharFont(pit, pos, font, toggleall);
+			++pos;
 		} else {
-			cursor.pos(0);
-			cursor.par(cursor.par() + 1);
+			pos = 0;
+			++pit;
 		}
 	}
 	unFreezeUndo();
 
-	redoParagraph(getPar(selection.start));
-
-	// we have to reset the selection, because the
-	// geometry could have changed, but we keep
-	// it for user convenience
-	setCursor(selection.start.par(), selection.start.pos());
-	selection.cursor = cursor;
-	setCursor(selection.end.par(), selection.end.pos());
-	setSelection();
-	setCursor(tmpcursor.par(), tmpcursor.pos(), true,
-		  tmpcursor.boundary());
+	redoParagraphs(beg, end);
+	redoCursor();
 }
 
 
@@ -665,12 +638,7 @@ void LyXText::setParagraph(VSpace const 
 			   string const & labelwidthstring,
 			   bool noindent)
 {
-	LyXCursor tmpcursor = cursor;
-	if (!selection.set()) {
-		selection.start = cursor;
-		selection.end = cursor;
-	}
-
+	setSelection();
 	// make sure that the depth behind the selection are restored, too
 	ParagraphList::iterator endpit = boost::next(getPar(selection.end));
 	ParagraphList::iterator undoendpit = endpit;
@@ -716,13 +684,7 @@ void LyXText::setParagraph(VSpace const 
 	}
 
 	redoParagraphs(getPar(selection.start), endpit);
-
-	clearSelection();
-	setCursor(selection.start.par(), selection.start.pos());
-	selection.cursor = cursor;
-	setCursor(selection.end.par(), selection.end.pos());
-	setSelection();
-	setCursor(tmpcursor.par(), tmpcursor.pos());
+	redoCursor();
 }
 
 

Reply via email to