]> git.lyx.org Git - lyx.git/blobdiff - src/Cursor.cpp
(finishing patch -- question was restored, but there were still problems)
[lyx.git] / src / Cursor.cpp
index e4a34b158ce88590237ee7ad3c4c75ec6b118409..a76c68fae3893d4daa295de8330ee6b7c62f30c4 100644 (file)
@@ -26,6 +26,7 @@
 #include "FuncCode.h"
 #include "FuncRequest.h"
 #include "Language.h"
+#include "Layout.h"
 #include "LyXAction.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
@@ -332,6 +333,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
        fixIfBroken();
        FuncRequest cmd = cmd0;
        Cursor safe = *this;
+       disp_ = DispatchResult();
 
        buffer()->undo().beginUndoGroup();
        
@@ -339,7 +341,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
        if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint)
            && nextInset()) {
                disp_.dispatched(true);
-               disp_.update(Update::FitCursor | Update::Force);
+               disp_.screenUpdate(Update::FitCursor | Update::Force);
                FuncRequest tmpcmd = cmd;
                LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: "
                        << cmd0 << endl << *this);
@@ -362,7 +364,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                // The common case is 'LFUN handled, need update', so make the
                // LFUN handler's life easier by assuming this as default value.
                // The handler can reset the update and val flags if necessary.
-               disp_.update(Update::FitCursor | Update::Force);
+               disp_.screenUpdate(Update::FitCursor | Update::Force);
                disp_.dispatched(true);
                inset().dispatch(*this, cmd);
                if (disp_.dispatched())
@@ -383,7 +385,7 @@ void Cursor::dispatch(FuncRequest const & cmd0)
                        safe.pos() = safe.lastpos();
                }
                operator=(safe);
-               disp_.update(Update::None);
+               disp_.screenUpdate(Update::None);
                disp_.dispatched(false);
        } else {
                // restore the previous one because nested Cursor::dispatch calls
@@ -1314,7 +1316,7 @@ void Cursor::insert(Inset * inset0)
 {
        LASSERT(inset0, /**/);
        if (inMathed())
-               insert(MathAtom(inset0));
+               insert(MathAtom(inset0->asInsetMath()));
        else {
                text()->insertInset(*this, inset0);
                inset0->setBuffer(bv_->buffer());
@@ -1351,6 +1353,15 @@ void Cursor::niceInsert(MathAtom const & t)
                MathData ar(buffer());
                asArray(safe, ar);
                insert(ar);
+       } else if (t->asMacro() && !safe.empty()) {
+               MathData ar(buffer());
+               asArray(safe, ar);
+               docstring const name = t->asMacro()->name();
+               MacroData const * data = buffer()->getMacro(name);
+               if (data && data->numargs() - data->optionals() > 0) {
+                       plainInsert(MathAtom(new InsetMathBrace(ar)));
+                       posBackward();
+               }
        }
 }
 
@@ -2015,15 +2026,18 @@ void Cursor::errorMessage(docstring const & msg) const
 }
 
 
-static docstring parbreak(InsetCode code)
+namespace {
+docstring parbreak(Cursor const * cur)
 {
        odocstringstream os;
        os << '\n';
-       // only add blank line if we're not in an ERT or Listings inset
-       if (code != ERT_CODE && code != LISTINGS_CODE)
+       // only add blank line if we're not in a ParbreakIsNewline situation
+       if (!cur->inset().getLayout().parbreakIsNewline() 
+           && !cur->paragraph().layout().parbreak_is_newline)
                os << '\n';
        return os.str();
 }
+}
 
 
 docstring Cursor::selectionAsString(bool with_label) const
@@ -2059,13 +2073,13 @@ docstring Cursor::selectionAsString(bool with_label) const
        // First paragraph in selection
        docstring result = pars[startpit].
                asString(startpos, pars[startpit].size(), label)
-               + parbreak(inset().lyxCode());
+               + parbreak(this);
 
        // The paragraphs in between (if any)
        for (pit_type pit = startpit + 1; pit != endpit; ++pit) {
                Paragraph const & par = pars[pit];
                result += par.asString(0, par.size(), label)
-                       + parbreak(inset().lyxCode());
+                       + parbreak(this);
        }
 
        // Last paragraph in selection
@@ -2122,7 +2136,7 @@ void Cursor::dispatched()
 
 void Cursor::screenUpdateFlags(Update::flags f)
 {
-       disp_.update(f);
+       disp_.screenUpdate(f);
 }
 
 
@@ -2146,7 +2160,7 @@ bool Cursor::needBufferUpdate() const
 
 void Cursor::noScreenUpdate()
 {
-       disp_.update(Update::None);
+       disp_.screenUpdate(Update::None);
 }