#include <config.h>
#include "Buffer.h"
+#include "BufferParams.h"
#include "BufferView.h"
#include "CoordCache.h"
#include "Cursor.h"
}
-// this (intentionally) does neither touch anchor nor selection status
void Cursor::setCursor(DocIterator const & cur)
{
DocIterator::operator=(cur);
}
+void Cursor::setCursorSelectionTo(DocIterator dit)
+{
+ size_t i = 0;
+ // normalise dit
+ while (i < dit.depth() && i < anchor_.depth() && dit[i] == anchor_[i])
+ ++i;
+ if (i != dit.depth()) {
+ // otherwise the cursor is already normal
+ if (i == anchor_.depth())
+ // dit is a proper extension of the anchor_
+ dit.cutOff(i - 1);
+ else if (i + 1 < dit.depth()) {
+ // one has dit[i] != anchor_[i] but either dit[i-1] == anchor_[i-1]
+ // or i == 0. Remove excess.
+ dit.cutOff(i);
+ if (dit[i] > anchor_[i])
+ // place dit after the inset it was in
+ ++dit.pos();
+ }
+ }
+ setCursor(dit);
+ setSelection();
+}
+
+
void Cursor::setCursorToAnchor()
{
if (selection()) {
InsetMathNest * const in = inset().asInsetMath()->asNestInset();
if (in && in->interpretString(*this, s))
return true;
- MathAtom atom = buffer()->getMacro(name, *this, false) ?
- MathAtom(new MathMacro(buffer(), name)) : createInsetMath(name, buffer());
+ bool const user_macro = buffer()->getMacro(name, *this, false);
+ MathAtom atom = user_macro ? MathAtom(new MathMacro(buffer(), name))
+ : createInsetMath(name, buffer());
// try to put argument into macro, if we just inserted a macro
bool macroArg = false;
else if (atom.nucleus()->nargs() > 0)
atom.nucleus()->cell(0).append(selection);
- bool ert_macro = atomAsMacro && !atomAsMacro->macro();
+ MathWordList const & words = mathedWordList();
+ MathWordList::const_iterator it = words.find(name);
+ bool keep_mathmode = it != words.end() && (it->second.inset == "font"
+ || it->second.inset == "oldfont"
+ || it->second.inset == "mbox");
+ bool ert_macro = !user_macro && it == words.end() && atomAsMacro;
if (in && in->currentMode() == Inset::TEXT_MODE
&& atom.nucleus()->currentMode() == Inset::MATH_MODE
posForward();
} else if (in && in->currentMode() == Inset::MATH_MODE
&& atom.nucleus()->currentMode() == Inset::TEXT_MODE
- && name != from_ascii("text")) {
+ && !keep_mathmode) {
MathAtom at = createInsetMath("text", buffer());
at.nucleus()->cell(0).push_back(atom);
niceInsert(at);
<< pos() << ' ' << lastpos() << " in idx: " << idx()
<< " in atom: '";
odocstringstream os;
- otexrowstream ots(os, false);
+ otexrowstream ots(os);
WriteStream wi(ots, false, true, WriteStream::wsDefault);
inset().asInsetMath()->write(wi);
lyxerr << to_utf8(os.str()) << endl;
{
if (empty())
return 0;
+ BufferParams const & bp = bv().buffer().params();
+ if (bp.useNonTeXFonts)
+ return encodings.fromLyXName("utf8-plain");
+
CursorSlice const & sl = innerTextSlice();
Text const & text = *sl.text();
- Font font = text.getPar(sl.pit()).getFont(
- bv().buffer().params(), sl.pos(), text.outerFont(sl.pit()));
+ Font font = text.getPar(sl.pit()).getFont(bp, sl.pos(),
+ text.outerFont(sl.pit()));
return font.language()->encoding();
}
// The logic here should more or less match to the
// Cursor::setCurrentFont logic, i.e. the cursor height should
// give a hint what will happen if a character is entered.
+ // FIXME: this is not the case, what about removing this method ? (see #10478).
// HACK. far from being perfect...