]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
Move bind file format tag to LyXAction.cpp, and rename it.
[lyx.git] / src / Text3.cpp
index 9b4c6d9aff8f9c9f2aa418de76db4f3ce8aabfee..cc234fa512cd9c31a49b2889b549ae37da95fee4 100644 (file)
@@ -245,7 +245,7 @@ static bool doInsertInset(Cursor & cur, Text * text,
                if (edit)
                        inset->edit(cur, true);
                // Now put this into inset
-               cur.text()->insertStringAsLines(cur, ds, cur.current_font);
+               cur.text()->insertStringAsLines(cur, ds, Font(inherit_font));
                cur.leaveInset(*inset);
                return true;
        }
@@ -477,7 +477,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        // Signals that a full-screen update is required
        bool needsUpdate = !(lyxaction.funcHasFlag(cmd.action(),
                LyXAction::NoUpdate) || singleParUpdate);
-
+       int const last_pid = cur.paragraph().id();
+       pos_type const last_pos = cur.pos();
+       bool const last_misspelled = lyxrc.spellcheck_continuously && cur.paragraph().isMisspelled(cur.pos());
+       
        FuncCode const act = cmd.action();
        switch (act) {
 
@@ -625,7 +628,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                Cursor dummy = cur;
                                dummy.pos() = dummy.pit() = 0;
                                if (cur.bv().checkDepm(dummy, cur))
-                                       cur.forceBufferUpdate();;
+                                       cur.forceBufferUpdate();
                        }
                }
                break;
@@ -836,7 +839,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                Cursor dummy = cur;
                                dummy.pos() = dummy.pit() = 0;
                                if (cur.bv().checkDepm(dummy, cur))
-                                       cur.forceBufferUpdate();;
+                                       cur.forceBufferUpdate();
                        }
                }
                break;
@@ -1012,7 +1015,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        singleParUpdate = false;
                }
                moveCursor(cur, false);
-               cur.forceBufferUpdate();
                break;
 
        case LFUN_CHAR_DELETE_BACKWARD:
@@ -1030,7 +1032,6 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        cutSelection(cur, true, false);
                        singleParUpdate = false;
                }
-               cur.forceBufferUpdate();
                break;
 
        case LFUN_BREAK_PARAGRAPH:
@@ -1075,7 +1076,10 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        if (cur.selection())
                                cutSelection(cur, true, false);
                        cur.insert(inset);
-                       cur.posForward();
+                       if (inset->editable() && inset->asInsetText())
+                               inset->edit(cur, true);
+                       else
+                               cur.posForward();
 
                        // trigger InstantPreview now
                        if (inset->lyxCode() == EXTERNAL_CODE) {
@@ -1344,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;
        }
 
@@ -1560,7 +1568,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                }
                p["target"] = (cmd.argument().empty()) ?
                        content : cmd.argument();
-               string const data = InsetCommand::params2string("href", p);
+               string const data = InsetCommand::params2string(p);
                if (p["target"].empty()) {
                        bv->showDialog("href", data);
                } else {
@@ -1576,7 +1584,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                p["name"] = (cmd.argument().empty()) ?
                        cur.getPossibleLabel() :
                        cmd.argument();
-               string const data = InsetCommand::params2string("label", p);
+               string const data = InsetCommand::params2string(p);
 
                if (cmd.argument().empty()) {
                        bv->showDialog("label", data);
@@ -1618,6 +1626,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_ARGUMENT_INSERT:
        case LFUN_INDEX_INSERT:
        case LFUN_PREVIEW_INSERT:
+       case LFUN_SCRIPT_INSERT:
                // Open the inset, and move the current selection
                // inside it.
                doInsertInset(cur, this, cmd, true, true);
@@ -1692,7 +1701,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        p["symbol"] = bv->cursor().innerText()->getStringToIndex(bv->cursor());
                else
                        p["symbol"] = cmd.argument();
-               string const data = InsetCommand::params2string("nomenclature", p);
+               string const data = InsetCommand::params2string(p);
                bv->showDialog("nomenclature", data);
                break;
        }
@@ -1703,7 +1712,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                        p["type"] = from_ascii("idx");
                else
                        p["type"] = cmd.argument();
-               string const data = InsetCommand::params2string("index_print", p);
+               string const data = InsetCommand::params2string(p);
                FuncRequest fr(LFUN_INSET_INSERT, data);
                dispatch(cur, fr);
                break;
@@ -1735,6 +1744,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MATH_MODE:
                if (cmd.argument() == "on")
                        // don't pass "on" as argument
+                       // (it would appear literally in the first cell)
                        mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
                else
                        mathDispatch(cur, cmd, false);
@@ -1744,6 +1754,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                if (cmd.argument().empty())
                        cur.errorMessage(from_utf8(N_("Missing argument")));
                else {
+                       cur.recordUndo();
                        string s = to_utf8(cmd.argument());
                        string const s1 = token(s, ' ', 1);
                        int const nargs = s1.empty() ? 0 : convert<int>(s1);
@@ -2168,6 +2179,20 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
        needsUpdate |= (cur.pos() != cur.lastpos()) && cur.selection();
 
+       if (lyxrc.spellcheck_continuously && !needsUpdate) {
+               // Check for misspelled text
+               // The redraw is useful because of the painting of
+               // misspelled markers depends on the cursor position.
+               // Trigger a redraw for cursor moves inside misspelled text.
+               if (!cur.inTexted()) {
+                       // move from regular text to math
+                       needsUpdate = last_misspelled;
+               } else if (cur.paragraph().id() != last_pid || cur.pos() != last_pos) {
+                       // move inside regular text
+                       needsUpdate = last_misspelled || cur.paragraph().isMisspelled(cur.pos());
+               }
+       }
+
        // FIXME: The cursor flag is reset two lines below
        // so we need to check here if some of the LFUN did touch that.
        // for now only Text::erase() and Text::backspace() do that.
@@ -2187,7 +2212,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()
@@ -2452,6 +2476,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_PREVIEW_INSERT:
                code = PREVIEW_CODE;
                break;
+       case LFUN_SCRIPT_INSERT:
+               code = SCRIPT_CODE;
+               break;
 
        case LFUN_MATH_INSERT:
        case LFUN_MATH_AMS_MATRIX: