Alfredo Braunstein wrote:
> Juergen Spitzmueller wrote:
> >                  bv->beforeChange(this);
> > +                // FIXME: WTF doesn't this work?
> > +                // overwriteSelection(bv->getLyXText());
>
> Had a deeper look. The problem is that bv->beforeChange(this) toggles the
> selection... to just drop it seems safe (it seems it does only this).

Well spotted, Alfredo, many thanks! It almost drove me mad...
Either changing the order or dropping bv->beforeChange(this) fixes it. I think 
it can be dropped, since it only (as Alfredo said) toggles an existing 
selection which is redundant when the selection gets deleted anyway. I've 
tested that. FYI here is the code of beforeChange():

BufferView_pimpl.C: 711
        void BufferView::Pimpl::beforeChange(LyXText * text)
        {
                toggleSelection();
                text->clearSelection();
        }

Attached is an updated patch that does also fix bug 441.
Are you joining the party, Lars?

Juergen.

N.B: Undoing break-paragraph crashes LyX. This is not related to my patch 
though.


Index: src/ChangeLog
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/ChangeLog,v
retrieving revision 1.1406
diff -u -r1.1406 ChangeLog
--- src/ChangeLog	2003/07/08 06:40:21	1.1406
+++ src/ChangeLog	2003/07/08 11:27:22
@@ -136,6 +136,11 @@
 
 	* version.C.in: change docversion to 1.4
 
+2003-06-16  Juergen Spitzmueller  <[EMAIL PROTECTED]>
+
+	* text3.C: introduce function overwriteSelection() and use it
+	to delete selections in some cases (bugs 441, 673, 702, 954).
+
 2003-06-22  Alfredo Braunstein  <[EMAIL PROTECTED]>
 
 	* buffer.C: fix a bug just introduced
Index: src/text3.C
===================================================================
RCS file: /cvs/lyx/lyx-devel/src/text3.C,v
retrieving revision 1.86
diff -u -r1.86 text3.C
--- src/text3.C	2003/07/01 11:51:19	1.86
+++ src/text3.C	2003/07/08 11:27:25
@@ -140,6 +140,15 @@
 		return inset;
 	}
 
+	void replaceSelection(LyXText * lt)
+	{
+		if (lt->selection.set()) {
+			lt->update();
+			lt->cutSelection(true, false);
+			lt->update();
+		}
+	}
+
 } // anon namespace
 
 
@@ -369,6 +378,7 @@
 {
 	lt->update();
 	InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
+	replaceSelection(lt);
 	if (!bv->insertInset(new_inset))
 		delete new_inset;
 	else
@@ -723,7 +733,7 @@
 		if (cursor.pos() <= body)
 			break;
 
-		bv->beforeChange(this);
+		replaceSelection(bv->getLyXText());
 		insertInset(new InsetNewline);
 		update();
 		setCursor(cursor.par(), cursor.pos());
@@ -833,7 +843,7 @@
 		break;
 
 	case LFUN_BREAKPARAGRAPH:
-		bv->beforeChange(this);
+		replaceSelection(bv->getLyXText());
 		breakParagraph(bv->buffer()->paragraphs, 0);
 		update();
 		selection.cursor = cursor;
@@ -842,7 +852,7 @@
 		break;
 
 	case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
-		bv->beforeChange(this);
+		replaceSelection(bv->getLyXText());
 		breakParagraph(bv->buffer()->paragraphs, 1);
 		update();
 		selection.cursor = cursor;
@@ -855,7 +865,7 @@
 		// indentation and add a "defskip" at the top.
 		// Otherwise, do the same as LFUN_BREAKPARAGRAPH.
 		LyXCursor cur = cursor;
-		bv->beforeChange(this);
+		replaceSelection(bv->getLyXText());
 		if (cur.pos() == 0) {
 			if (cur.par()->params().spaceTop() == VSpace(VSpace::NONE)) {
 				setParagraph(
@@ -1028,6 +1038,7 @@
 
 	case LFUN_PASTE: {
 		cmd.message(_("Paste"));
+		replaceSelection(bv->getLyXText());
 		// clear the selection
 		bv->toggleSelection();
 		clearSelection();
@@ -1200,6 +1211,7 @@
 	}
 
 	case LFUN_QUOTE: {
+		replaceSelection(bv->getLyXText());
 		ParagraphList::iterator pit = cursor.par();
 		lyx::pos_type pos = cursor.pos();
 		char c;
@@ -1221,6 +1233,7 @@
 	}
 
 	case LFUN_DATE_INSERT: {
+		replaceSelection(bv->getLyXText());
 		time_t now_time_t = time(NULL);
 		struct tm * now_tm = localtime(&now_time_t);
 		setlocale(LC_TIME, "");

Reply via email to