void InsetMathNest::write(WriteStream & os) const
{
+ MathEnsurer ensurer(os, currentMode() == MATH_MODE);
ModeSpecifier specifier(os, currentMode(), lockedMode());
docstring const latex_name = name();
os << '\\' << latex_name;
}
-int InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const
+void InsetMathNest::latex(otexstream & os, OutputParams const & runparams) const
{
WriteStream wi(os.os(), runparams.moving_arg, true,
runparams.dryrun ? WriteStream::wsDryrun : WriteStream::wsDefault,
wi.canBreakLine(os.canBreakLine());
write(wi);
os.canBreakLine(wi.canBreakLine());
- return wi.line();
+
+ int lf = wi.line();
+ if (lf > 0 && runparams.lastid != -1) {
+ --lf;
+ os.texrow().newline();
+ os.texrow().start(runparams.lastid, runparams.lastpos);
+ }
+ os.texrow().newlines(lf);
}
bool InsetMathNest::setMouseHover(BufferView const * bv, bool mouse_hover)
+ const
{
mouse_hover_[bv] = mouse_hover;
return true;
break;
}
- case LFUN_SPACE_INSERT:
+ case LFUN_SPACE_INSERT: {
cur.recordUndoSelection();
- cur.insert(MathAtom(new InsetMathSpace));
+ string const name = cmd.getArg(0);
+ if (name == "normal")
+ cur.insert(MathAtom(new InsetMathSpace(" ", "")));
+ else if (name == "protected")
+ cur.insert(MathAtom(new InsetMathSpace("~", "")));
+ else if (name == "thin" || name == "med" || name == "thick")
+ cur.insert(MathAtom(new InsetMathSpace(name + "space", "")));
+ else if (name == "hfill*")
+ cur.insert(MathAtom(new InsetMathSpace("hspace*{\\fill}", "")));
+ else if (name == "quad" || name == "qquad" ||
+ name == "enspace" || name == "enskip" ||
+ name == "negthinspace" || name == "negmedspace" ||
+ name == "negthickspace" || name == "hfill")
+ cur.insert(MathAtom(new InsetMathSpace(name, "")));
+ else if (name == "hspace" || name == "hspace*") {
+ string const len = cmd.getArg(1);
+ if (len.empty() || !isValidLength(len)) {
+ lyxerr << "LyX function 'space-insert " << name << "' "
+ "needs a valid length argument." << endl;
+ break;
+ }
+ cur.insert(MathAtom(new InsetMathSpace(name, len)));
+ } else
+ cur.insert(MathAtom(new InsetMathSpace));
break;
+ }
case LFUN_MATH_SPACE:
cur.recordUndoSelection();
break;
}
+ case LFUN_DIALOG_SHOW_NEW_INSET: {
+ docstring const & name = cmd.argument();
+ if (name == "space")
+ flag.setEnabled(false);
+ break;
+ }
+
+
case LFUN_MATH_DELIM:
case LFUN_MATH_BIGDELIM:
// Don't do this with multi-cell selections
flag.setEnabled(false);
break;
+ case LFUN_SPACE_INSERT: {
+ docstring const & name = cmd.argument();
+ if (name == "visible")
+ flag.setEnabled(false);
+ break;
+ }
+
case LFUN_INSET_DISSOLVE:
flag.setEnabled(!asHullInset());
break;
{
//lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
BufferView & bv = cur.bv();
+ if (cmd.button() == mouse_button::button3) {
+ // Don't do anything if we right-click a
+ // selection, a context menu will popup.
+ if (bv.cursor().selection() && cur >= bv.cursor().selectionBegin()
+ && cur < bv.cursor().selectionEnd()) {
+ cur.noScreenUpdate();
+ return;
+ }
+ }
bool do_selection = cmd.button() == mouse_button::button1
&& cmd.argument() == "region-select";
bv.mouseSetCursor(cur, do_selection);
bool reduced = cap::reduceSelectionToOneCell(cur);
if (reduced || !cur.selection()) {
docstring const safe = cap::grabAndEraseSelection(cur);
- cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
+ if (!cur.inRegexped())
+ cur.insert(MathAtom(new InsetMathUnknown(from_ascii("\\"), safe, false)));
+ else
+ cur.niceInsert(createInsetMath("backslash", buf));
}
return true;
}
}
// These should be treated differently when not in text mode:
- if (currentMode() != InsetMath::TEXT_MODE) {
+ if (cur.inRegexped()) {
+ switch (c) {
+ case '\\':
+ cur.niceInsert(createInsetMath("backslash", buf));
+ break;
+ case '^':
+ cur.niceInsert(createInsetMath("mathcircumflex", buf));
+ break;
+ case '{':
+ case '}':
+ case '#':
+ case '%':
+ case '_':
+ cur.niceInsert(createInsetMath(docstring(1, c), buf));
+ break;
+ case '~':
+ cur.niceInsert(createInsetMath("sim", buf));
+ break;
+ default:
+ cur.insert(c);
+ }
+ return true;
+ } else if (currentMode() != InsetMath::TEXT_MODE) {
if (c == '_') {
script(cur, false, save_selection);
return true;