]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetSpace.cpp
Output a parbreak after a command.
[lyx.git] / src / insets / InsetSpace.cpp
index c516b137ee8cb0ab312631de53f326e74e5e7317..f7a1cd92ae8fc511171d61904e5266c9b13f7e91 100644 (file)
@@ -146,10 +146,16 @@ void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action()) {
 
-       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_MODIFY: {
                cur.recordUndo();
-               string2params(to_utf8(cmd.argument()), params_);
+               string arg = to_utf8(cmd.argument());
+               if (arg == "space \\hspace{}")
+                       arg += params_.length.len().empty()
+                               ? " \\length 1" + string(stringFromUnit(Length::defaultUnit()))
+                               : " \\length " + params_.length.asString();
+               string2params(arg, params_);
                break;
+       }
 
        case LFUN_INSET_DIALOG_UPDATE:
                cur.bv().updateDialog("space", params2string(params()));
@@ -172,7 +178,7 @@ bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
                        InsetSpaceParams params;
                        string2params(to_utf8(cmd.argument()), params);
                        status.setOnOff(params_.kind == params.kind);
-                       status.setEnabled(true);        
+                       status.setEnabled(true);
                } else
                        status.setEnabled(false);
                return true;
@@ -621,7 +627,8 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
 }
 
 
-int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
+int InsetSpace::plaintext(odocstringstream & os,
+        OutputParams const &, size_t) const
 {
        switch (params_.kind) {
        case InsetSpaceParams::HFILL:
@@ -646,9 +653,17 @@ int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
        case InsetSpaceParams::DOWNBRACEFILL:
                os << "/-^-\\";
                return 5;
+       case InsetSpaceParams::VISIBLE:
+               os.put(0x2423);
+               return 1;
        case InsetSpaceParams::ENSKIP:
                os.put(0x2002);
                return 1;
+       case InsetSpaceParams::ENSPACE:
+               os.put(0x2060); // WORD JOINER, makes the breakable en space unbreakable
+               os.put(0x2002);
+               os.put(0x2060); // WORD JOINER, makes the breakable en space unbreakable
+               return 3;
        case InsetSpaceParams::QUAD:
                os.put(0x2003);
                return 1;
@@ -657,13 +672,17 @@ int InsetSpace::plaintext(odocstream & os, OutputParams const &) const
                os.put(0x2003);
                return 2;
        case InsetSpaceParams::THIN:
-               os.put(0x2009);
+               os.put(0x202f);
                return 1;
        case InsetSpaceParams::MEDIUM:
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable medium space breakable
                os.put(0x2005);
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable medium space breakable
                return 1;
        case InsetSpaceParams::THICK:
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable thick space breakable
                os.put(0x2004);
+               os.put(0x200b); // ZERO WIDTH SPACE, makes the unbreakable thick space breakable
                return 1;
        case InsetSpaceParams::PROTECTED:
        case InsetSpaceParams::CUSTOM_PROTECTED:
@@ -738,20 +757,27 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
                output = " ";
                break;
        case InsetSpaceParams::ENSKIP:
-       case InsetSpaceParams::ENSPACE:
                output ="&ensp;";
                break;
+       case InsetSpaceParams::ENSPACE:
+               output ="&#x2060;&ensp;&#x2060;";
+               break;
        case InsetSpaceParams::QQUAD:
-               output ="&emsp;";
+               output ="&emsp;&emsp;";
+               break;
        case InsetSpaceParams::THICK:
+               output ="&#x2004;";
+               break;
        case InsetSpaceParams::QUAD:
                output ="&emsp;";
                break;
+       case InsetSpaceParams::MEDIUM:
+               output ="&#x2005;";
+               break;
        case InsetSpaceParams::THIN:
                output ="&thinsp;";
                break;
        case InsetSpaceParams::PROTECTED:
-       case InsetSpaceParams::MEDIUM:
        case InsetSpaceParams::NEGTHIN:
        case InsetSpaceParams::NEGMEDIUM:
        case InsetSpaceParams::NEGTHICK:
@@ -773,9 +799,13 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
                // Can we do anything with those in HTML?
                break;
        case InsetSpaceParams::CUSTOM:
+               // FIXME XHTML
+               // Probably we could do some sort of blank span?
+               break;
        case InsetSpaceParams::CUSTOM_PROTECTED:
                // FIXME XHTML
                // Probably we could do some sort of blank span?
+               output ="&nbsp;";
                break;
        }
        // don't escape the entities!
@@ -794,11 +824,13 @@ void InsetSpace::validate(LaTeXFeatures & features) const
 
 void InsetSpace::toString(odocstream & os) const
 {
-       plaintext(os, OutputParams(0));
+       odocstringstream ods;
+       plaintext(ods, OutputParams(0));
+       os << ods.str();
 }
 
 
-void InsetSpace::forToc(docstring & os, size_t) const
+void InsetSpace::forOutliner(docstring & os, size_t) const
 {
        // There's no need to be cute here.
        os += " ";
@@ -818,9 +850,9 @@ bool InsetSpace::isStretchableSpace() const
 }
 
 
-docstring InsetSpace::contextMenuName() const
+string InsetSpace::contextMenuName() const
 {
-       return from_ascii("context-space");
+       return "context-space";
 }
 
 
@@ -840,7 +872,8 @@ void InsetSpace::string2params(string const & in, InsetSpaceParams & params)
                params.math = true;
        else {
                params.math = false;
-               LASSERT(name == "space", /**/);
+               // we can try to read this even if the name is wrong
+               LATTEST(name == "space");
        }
 
        // There are cases, such as when we are called via getStatus() from