]> git.lyx.org Git - features.git/commitdiff
Fix bug #7200: Crash when replacing newline by InsetQuote.
authorVincent van Ravesteijn <vfr@lyx.org>
Sun, 2 Jan 2011 12:07:33 +0000 (12:07 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Sun, 2 Jan 2011 12:07:33 +0000 (12:07 +0000)
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.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37063 a592a061-630c-0410-9148-cb99ea01b6c8

src/Text3.cpp

index 6807238594894adb450ad42d1f0adc3d111e780c..dc67626396017e6dc4ada1eab4019e882f6d2876 100644 (file)
@@ -1348,33 +1348,37 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        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();
                InsetLayout const & ilayout = cur.inset().getLayout();
-               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
+               BufferParams const & bufparams = bv->buffer().params();
+               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(cur.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(cur.buffer(), c, quote_type));
                        cur.posForward();
-               }
-               else
+               } else {
+                       // The cursor might have been invalidated by the replaceSelection.
+                       cur.buffer()->changed(true);
                        lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
+               }                       
                break;
        }
 
@@ -2207,7 +2211,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
                return;
        }
-
        if (!needsUpdate
            && &oldTopSlice.inset() == &cur.inset()
            && oldTopSlice.idx() == cur.idx()