namespace lyx {
using cap::grabAndEraseSelection;
+using cap::reduceSelectionToOneCell;
namespace {
buffer->listMacroNames(macros);
MacroNameSet::iterator it = macros.begin();
MacroNameSet::iterator end = macros.end();
- odocstringstream macro_preamble;
+ docstring macro_preamble;
for (; it != end; ++it) {
MacroData const * data = buffer->getMacro(*it, pos, true);
if (data) {
- data->write(macro_preamble, true);
- macro_preamble << endl;
+ odocstringstream mac_preamble;
+ data->write(mac_preamble, false);
+ docstring const mps = mac_preamble.str();
+ bool const is_new_def = prefixIs(mps, from_ascii("\\newcomm"));
+ // assure that \newcommand definitions of macros are only added once
+ if (!is_new_def || !preview_->hasMacroDef(mps, *buffer)) {
+ if (is_new_def)
+ preview_->addMacroDef(mps, *buffer);
+ if (!macro_preamble.empty())
+ macro_preamble += '\n';
+ macro_preamble += mps;
+ }
}
}
'{' + convert<docstring>(num) + '}';
}
}
- docstring const snippet = macro_preamble.str() +
- setcnt + latexString(*this);
+ docstring const snippet = macro_preamble + setcnt + latexString(*this);
LYXERR(Debug::MACROS, "Preview snippet: " << snippet);
preview_->addPreview(snippet, *buffer, forexport);
}
void InsetMathHull::infoize(odocstream & os) const
{
- os << "Type: " << hullName(type_);
+ os << bformat(_("Type: %1$s"), hullName(type_));
}
extra = from_ascii("noextra");
string const lang = to_ascii(dlang);
- // FIXME: temporarily disabled
- //if (cur.selection()) {
- // MathData ar;
- // selGet(cur.ar);
- // lyxerr << "use selection: " << ar << endl;
- // insert(pipeThroughExtern(lang, extra, ar));
- // return;
- //}
+ // replace selection with result of computation
+ if (reduceSelectionToOneCell(cur)) {
+ MathData ar;
+ asArray(grabAndEraseSelection(cur), ar);
+ lyxerr << "use selection: " << ar << endl;
+ cur.insert(pipeThroughExtern(lang, extra, ar));
+ return;
+ }
// only inline, display or eqnarray math is allowed
if (getType() > hullEqnArray) {
if (getType() == hullSimple) {
size_type pos = cur.cell().find_last(eq);
MathData ar;
- if (cur.inMathed() && cur.selection()) {
- asArray(grabAndEraseSelection(cur), ar);
- } else if (!pos == cur.cell().empty()) {
+ if (pos == cur.cell().size()) {
ar = cur.cell();
lyxerr << "use whole cell: " << ar << endl;
} else {
enable = display() != Inline;
}
status.setEnabled(enable);
+ status.setOnOff(display() != Inline);
return true;
}