Author: vfr
Date: Mon Jan  3 13:50:47 2011
New Revision: 37071
URL: http://www.lyx.org/trac/changeset/37071

Log:
branch: Fix bug #7200: Crash when replacing newline by InsetQuote?.

We have to call cap::replaceSelection before determining whether we can insert 
an InsetQuote? or a normal quote.

At least we should have updated the par variable after calling 
cap::replaceSelection, because the paragraph might have been deleted.

see r37063.

Modified:
   lyx-devel/branches/BRANCH_1_6_X/src/Text3.cpp
   lyx-devel/branches/BRANCH_1_6_X/status.16x

Modified: lyx-devel/branches/BRANCH_1_6_X/src/Text3.cpp
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/src/Text3.cpp       Mon Jan  3 13:39:56 
2011        (r37070)
+++ lyx-devel/branches/BRANCH_1_6_X/src/Text3.cpp       Mon Jan  3 13:50:47 
2011        (r37071)
@@ -1281,33 +1281,37 @@
        }
 
        case LFUN_QUOTE_INSERT: {
-               Paragraph & par = cur.paragraph();
+               // this avoids a double undo
+               // FIXME: should not be needed, ideally
+               if (!cur.selection())
+                       cur.recordUndo();
+               cap::replaceSelection(cur);
+
+               Paragraph const & par = cur.paragraph();
                pos_type pos = cur.pos();
-               BufferParams const & bufparams = bv->buffer().params();
+
                Layout const & style = par.layout();
+               BufferParams const & bufparams = bv->buffer().params();
                InsetLayout const & ilayout = cur.inset().getLayout(bufparams);
-               if (!style.pass_thru && !ilayout.isPassThru()
-                   && par.getFontSettings(bufparams, pos).language()->lang() 
!= "hebrew") {
-                       // this avoids a double undo
-                       // FIXME: should not be needed, ideally
-                       if (!cur.selection())
-                               cur.recordUndo();
-                       cap::replaceSelection(cur);
-                       pos = cur.pos();
-                       char_type c;
-                       if (pos == 0)
-                               c = ' ';
-                       else if (cur.prevInset() && cur.prevInset()->isSpace())
-                               c = ' ';
-                       else
+               bool const hebrew = 
+                       par.getFontSettings(bufparams, pos).language()->lang() 
== "hebrew";
+               bool const allow_inset_quote = 
+                       !(style.pass_thru || ilayout.isPassThru() || hebrew);
+               
+               if (allow_inset_quote) {
+                       char_type c = ' ';
+                       if (pos > 0 && (!cur.prevInset() || 
!cur.prevInset()->isSpace()))
                                c = par.getChar(pos - 1);
-                       string arg = to_utf8(cmd.argument());
-                       cur.insert(new InsetQuotes(bv->buffer(), c, (arg == 
"single")
-                               ? InsetQuotes::SingleQuotes : 
InsetQuotes::DoubleQuotes));
+                       string const arg = to_utf8(cmd.argument());
+                       InsetQuotes::QuoteTimes const quote_type = (arg == 
"single")
+                               ? InsetQuotes::SingleQuotes : 
InsetQuotes::DoubleQuotes;
+                       cur.insert(new InsetQuotes(bv->buffer(), c, 
quote_type));
                        cur.posForward();
-               }
-               else
+               } else {
+                       // The cursor might have been invalidated by the 
replaceSelection.
+                       cur.buffer().changed();
                        lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
+               }                       
                break;
        }
 

Modified: lyx-devel/branches/BRANCH_1_6_X/status.16x
==============================================================================
--- lyx-devel/branches/BRANCH_1_6_X/status.16x  Mon Jan  3 13:39:56 2011        
(r37070)
+++ lyx-devel/branches/BRANCH_1_6_X/status.16x  Mon Jan  3 13:50:47 2011        
(r37071)
@@ -82,6 +82,9 @@
 - Fix crash when removing a math macro argument while instant preview
   is active (bug 7090).
 
+- Fix crash when inserting quotes with a selection spanning multiple
+  paragraphs (bug 7200).
+
 - Fix the painting of the workarea for a non-standard DPI and using
   emulated scaling on Windows Vista and Windows 7 (bug 7187).
 

Reply via email to