]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
fix crash when collapsing ert with cursor inside
[lyx.git] / src / text3.C
index 5fb9e0ddcabb84ea224ec029ce3445020055e716..1f706305193f81c68058b2f9a2b366e563609f65 100644 (file)
@@ -61,6 +61,8 @@
 #include "mathed/math_hullinset.h"
 #include "mathed/math_macrotemplate.h"
 
+#include <boost/current_function.hpp>
+
 #include <clocale>
 #include <sstream>
 
@@ -299,7 +301,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                bool start = !par.params().startOfAppendix();
 
 #ifdef WITH_WARNINGS
-#warning The code below only makes sense a top level.
+#warning The code below only makes sense at top level.
 // Should LFUN_APPENDIX be restricted to top-level paragraphs?
 #endif
                // ensure that we have only one start_of_appendix in this document
@@ -713,19 +715,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
-       case LFUN_INSET_APPLY: {
-               string const name = cmd.getArg(0);
-               InsetBase * inset = bv->owner()->getDialogs().getOpenInset(name);
-               if (inset) {
-                       FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
-                       inset->dispatch(cur, fr);
-               } else {
-                       FuncRequest fr(LFUN_INSET_INSERT, cmd.argument);
-                       dispatch(cur, fr);
-               }
-               break;
-       }
-
        case LFUN_INSET_INSERT: {
                recordUndo(cur);
                InsetBase * inset = createInset(bv, cmd);
@@ -992,6 +981,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                        cur.resetAnchor();
                        cursorEnd(cur);
                        cur.setSelection();
+                       bv->cursor() = cur;
                        bv->haveSelection(cur.selection());
                }
                break;
@@ -999,6 +989,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_DOUBLE:
                if (cmd.button() == mouse_button::button1) {
                        selectWord(cur, lyx::WHOLE_WORD_STRICT);
+                       bv->cursor() = cur;
                        bv->haveSelection(cur.selection());
                }
                break;
@@ -1123,6 +1114,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                cur.clearSelection();
                LyXFont const old_font = real_current_font;
 
+               // Prevents language turds in new lyxtexts under non-english
+               BufferParams const & bufparams = cur.buffer().params();
+               Language const * lang = cur.paragraph().getParLanguage(bufparams);
+               current_font.setLanguage(lang);
+               real_current_font.setLanguage(lang);
+
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
                for (; cit != end; ++cit)
@@ -1182,12 +1179,9 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_INSERT_BRANCH:
        case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT:
-       case LFUN_INSET_FLOAT:
        case LFUN_INSET_FOOTNOTE:
        case LFUN_INSET_MARGINAL:
        case LFUN_INSET_OPTARG:
-       case LFUN_INSET_WIDE_FLOAT:
-       case LFUN_INSET_WRAP:
        case LFUN_TABULAR_INSERT:
        case LFUN_ENVIRONMENT_INSERT:
                // Open the inset, and move the current selection
@@ -1196,6 +1190,16 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
                cur.posRight();
                break;
 
+       case LFUN_INSET_FLOAT:
+       case LFUN_INSET_WIDE_FLOAT:
+       case LFUN_INSET_WRAP:
+               doInsertInset(cur, this, cmd, true, true);
+               cur.posRight();
+               // FIXME: the "Caption" name should not be hardcoded,
+               // but given by the float definition.
+               cur.dispatch(FuncRequest(LFUN_LAYOUT, "Caption"));
+               break;
+
        case LFUN_INDEX_INSERT:
                // Just open the inset
                doInsertInset(cur, this, cmd, true, false);
@@ -1549,7 +1553,7 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
 
        case LFUN_APPENDIX:
                flag.setOnOff(cur.paragraph().params().startOfAppendix());
-               break;
+               return true;
 
 #if 0
        // the functions which insert insets
@@ -1726,29 +1730,37 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_INSET_DIALOG_SHOW:
                break;
 
+       case LFUN_INSET_MODIFY:
+               // We need to disable this, because we may get called for a
+               // tabular cell via
+               // InsetTabular::getStatus() -> InsetText::getStatus()
+               // and we don't handle LFUN_INSET_MODIFY.
+               enable = false;
+               break;
+
        case LFUN_EMPH:
                flag.setOnOff(font.emph() == LyXFont::ON);
-               break;
+               return true;
 
        case LFUN_NOUN:
                flag.setOnOff(font.noun() == LyXFont::ON);
-               break;
+               return true;
 
        case LFUN_BOLD:
                flag.setOnOff(font.series() == LyXFont::BOLD_SERIES);
-               break;
+               return true;
 
        case LFUN_SANS:
                flag.setOnOff(font.family() == LyXFont::SANS_FAMILY);
-               break;
+               return true;
 
        case LFUN_ROMAN:
                flag.setOnOff(font.family() == LyXFont::ROMAN_FAMILY);
-               break;
+               return true;
 
        case LFUN_CODE:
                flag.setOnOff(font.family() == LyXFont::TYPEWRITER_FAMILY);
-               break;
+               return true;
 
        case LFUN_DELETE_WORD_FORWARD:
        case LFUN_DELETE_WORD_BACKWARD:
@@ -1787,7 +1799,6 @@ bool LyXText::getStatus(LCursor & cur, FuncRequest const & cmd,
        case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
        case LFUN_BREAKPARAGRAPH_SKIP:
        case LFUN_PARAGRAPH_SPACING:
-       case LFUN_INSET_APPLY:
        case LFUN_INSET_INSERT:
        case LFUN_NEXT_INSET_TOGGLE:
        case LFUN_UPCASE_WORD: