bool InsetMathMacro::editMode(BufferView const * bv) const {
// find this in cursor trace
- Cursor const & cur = bv->cursor();
+ DocIterator const & cur =
+ // Do not move the reference while selecting with the mouse to avoid
+ // flicker due to changing metrics
+ bv->mouseSelecting() ? bv->cursor().realAnchor() : bv->cursor();
for (size_t i = 0; i != cur.depth(); ++i)
if (&cur[i].inset() == this) {
// look if there is no other macro in edit mode above
bool InsetMathMacro::completionSupported(Cursor const & cur) const
{
+ if (cur.buffer()->isReadonly())
+ return false;
+
if (displayMode() != DISPLAY_UNFOLDED)
return InsetMathNest::completionSupported(cur);
bool InsetMathMacro::inlineCompletionSupported(Cursor const & cur) const
{
+ if (cur.buffer()->isReadonly())
+ return false;
+
if (displayMode() != DISPLAY_UNFOLDED)
return InsetMathNest::inlineCompletionSupported(cur);
if (displayMode() != DISPLAY_UNFOLDED)
return InsetMathNest::completionPrefix(cur);
- if (!completionSupported(cur))
- return docstring();
-
return "\\" + name();
}
-bool InsetMathMacro::insertCompletion(Cursor & cur, docstring const & s,
- bool finished)
+bool InsetMathMacro::insertCompletion(Cursor & cur, docstring const & s, bool finished)
{
+ if (cur.buffer()->isReadonly())
+ return false;
+
if (displayMode() != DISPLAY_UNFOLDED)
return InsetMathNest::insertCompletion(cur, s, finished);
if (!completionSupported(cur))
return false;
+ // Contrary to Text, the whole inset should be recorded (#12581).
+ cur.recordUndoInset();
+
// append completion
docstring newName = name() + s;
asArray(newName, cell(0));