}
-static void mathDispatch(Cursor & cur, FuncRequest const & cmd, bool display)
+static void mathDispatch(Cursor & cur, FuncRequest const & cmd)
{
cur.recordUndo();
docstring sel = cur.selectionAsString(false);
LATTEST(old_pos == cur.pos());
#endif
cur.nextInset()->edit(cur, true);
- // don't do that also for LFUN_MATH_MODE
- // unless you want end up with always changing
- // to mathrm when opening an inlined inset --
- // I really hate "LyXfunc overloading"...
- if (display)
- cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
- // Avoid an unnecessary undo step if cmd.argument
- // is empty
- if (!cmd.argument().empty())
- cur.dispatch(FuncRequest(LFUN_MATH_INSERT,
- cmd.argument()));
+ if (cmd.action() != LFUN_MATH_MODE)
+ // LFUN_MATH_MODE has a different meaning in math mode
+ cur.dispatch(cmd);
} else {
- // create a macro if we see "\\newcommand"
- // somewhere, and an ordinary formula
- // otherwise
- if (sel.find(from_ascii("\\newcommand")) == string::npos
- && sel.find(from_ascii("\\newlyxcommand")) == string::npos
- && sel.find(from_ascii("\\def")) == string::npos)
- {
- InsetMathHull * formula = new InsetMathHull(cur.buffer());
- string const selstr = to_utf8(sel);
- istringstream is(selstr);
- Lexer lex;
+ InsetMathHull * formula = new InsetMathHull(cur.buffer());
+ string const selstr = to_utf8(sel);
+ istringstream is(selstr);
+ Lexer lex;
+ lex.setStream(is);
+ if (!formula->readQuiet(lex)) {
+ // No valid formula, let's try with delims
+ is.str("$" + selstr + "$");
lex.setStream(is);
if (!formula->readQuiet(lex)) {
- // No valid formula, let's try with delims
- is.str("$" + selstr + "$");
- lex.setStream(is);
- if (!formula->readQuiet(lex)) {
- // Still not valid, leave it as is
- valid = false;
- delete formula;
- cur.insert(sel);
- } else
- cur.insert(formula);
- } else
- cur.insert(formula);
- } else {
- cur.insert(new MathMacroTemplate(cur.buffer(), sel));
+ // Still not valid, leave it as is
+ valid = false;
+ delete formula;
+ cur.insert(sel);
+ }
+ }
+ if (valid) {
+ cur.insert(formula);
+ cur.nextInset()->edit(cur, true);
+ LASSERT(cur.inMathed(), return);
+ cur.pos() = 0;
+ cur.resetAnchor();
+ cur.setSelection(true);
+ cur.pos() = cur.lastpos();
+ if (cmd.action() != LFUN_MATH_MODE)
+ // LFUN_MATH_MODE has a different meaning in math mode
+ cur.dispatch(cmd);
+ cur.clearSelection();
+ cur.pos() = cur.lastpos();
}
}
if (valid)
ParagraphList & pars = buf.text().paragraphs();
ParagraphList::iterator const bgn = pars.begin();
// The first paragraph of the area to be copied:
- ParagraphList::iterator start = next(bgn, pit);
+ ParagraphList::iterator start = lyx::next(bgn, pit);
// The final paragraph of area to be copied:
ParagraphList::iterator finish = start;
ParagraphList::iterator const end = pars.end();
ParagraphList & pars = buf.text().paragraphs();
ParagraphList::iterator bgn = pars.begin();
// The first paragraph of the area to be selected:
- ParagraphList::iterator start = next(bgn, pit);
+ ParagraphList::iterator start = lyx::next(bgn, pit);
// The final paragraph of area to be selected:
ParagraphList::iterator finish = start;
ParagraphList::iterator end = pars.end();
case LFUN_CHAR_DELETE_FORWARD:
if (!cur.selection()) {
- bool was_separator = cur.paragraph().isEnvSeparator(cur.pos());
if (cur.pos() == cur.paragraph().size())
// Par boundary, force full-screen update
singleParUpdate = false;
needsUpdate |= erase(cur);
cur.resetAnchor();
- if (was_separator && cur.pos() == cur.paragraph().size()
- && (!cur.paragraph().layout().isEnvironment()
- || cur.paragraph().size() > 0)) {
- // Force full-screen update
- singleParUpdate = false;
- needsUpdate |= erase(cur);
- cur.resetAnchor();
- }
- // It is possible to make it a lot faster still
- // just comment out the line below...
} else {
cutSelection(cur, true, false);
singleParUpdate = false;
cap::replaceSelection(cur);
pit_type pit = cur.pit();
Paragraph const & par = pars_[pit];
+ bool lastpar = (pit == pit_type(pars_.size() - 1));
+ Paragraph const & nextpar = lastpar ? par : pars_[pit + 1];
pit_type prev = pit;
if (pit > 0) {
if (!pars_[pit - 1].layout().isEnvironment())
prev = pit - 1;
}
if (prev < pit && cur.pos() == par.beginOfBody()
- && !par.isEnvSeparator(cur.pos())
+ && !par.size() && !par.isEnvSeparator(cur.pos())
&& !par.layout().isCommand()
&& pars_[prev].layout() != par.layout()
- && pars_[prev].layout().isEnvironment()) {
+ && pars_[prev].layout().isEnvironment()
+ && !nextpar.isEnvSeparator(nextpar.beginOfBody())) {
if (par.layout().isEnvironment()
&& pars_[prev].getDepth() == par.getDepth()) {
docstring const layout = par.layout().name();
DocumentClass const & tc = bv->buffer().params().documentClass();
lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
- lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "parbreak"));
+ lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
lyx::dispatch(FuncRequest(LFUN_LAYOUT, layout));
} else {
- lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "parbreak"));
+ lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
breakParagraph(cur);
}
Font const f(inherit_font, cur.current_font.language());
pars_[cur.pit() - 1].resetFonts(f);
} else {
+ if (par.isEnvSeparator(cur.pos()))
+ cur.posForward();
breakParagraph(cur, cmd.argument() == "inverse");
}
cur.resetAnchor();
case mouse_button::button1:
// Set the cursor
if (!bv->mouseSetCursor(cur, cmd.argument() == "region-select"))
- cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
+ cur.screenUpdateFlags(Update::FitCursor);
if (bvcur.wordSelection())
selectWord(bvcur, WHOLE_WORD);
break;
return;
}
if (!bv->mouseSetCursor(cur, false))
- cur.screenUpdateFlags(Update::SinglePar | Update::FitCursor);
+ cur.screenUpdateFlags(Update::FitCursor);
break;
}
tm->setCursorFromCoordinates(cur, cmd.x(), y);
cur.setTargetX(cmd.x());
+ // Don't allow selecting a separator inset
+ if (cur.pos() && cur.paragraph().isEnvSeparator(cur.pos() - 1))
+ cur.posBackward();
if (cmd.y() >= wh)
lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
else if (cmd.y() < 0)
changeDepth(cur, INC_DEPTH);
break;
- case LFUN_MATH_DISPLAY:
- mathDispatch(cur, cmd, true);
- break;
-
case LFUN_REGEXP_MODE:
regexpDispatch(cur, cmd);
break;
- case LFUN_MATH_MODE:
- if (cmd.argument() == "on")
+ case LFUN_MATH_MODE: {
+ if (cmd.argument() == "on" || cmd.argument() == "") {
// don't pass "on" as argument
// (it would appear literally in the first cell)
- mathDispatch(cur, FuncRequest(LFUN_MATH_MODE), false);
- else
- mathDispatch(cur, cmd, false);
+ docstring sel = cur.selectionAsString(false);
+ MathMacroTemplate * macro = new MathMacroTemplate(cur.buffer());
+ // create a macro template if we see "\\newcommand" somewhere, and
+ // an ordinary formula otherwise
+ if (!sel.empty()
+ && (sel.find(from_ascii("\\newcommand")) != string::npos
+ || sel.find(from_ascii("\\newlyxcommand")) != string::npos
+ || sel.find(from_ascii("\\def")) != string::npos)
+ && macro->fromString(sel)) {
+ cur.recordUndo();
+ replaceSelection(cur);
+ cur.insert(macro);
+ } else {
+ // no meaningful macro template was found
+ delete macro;
+ mathDispatch(cur,FuncRequest(LFUN_MATH_MODE));
+ }
+ } else
+ // The argument is meaningful
+ // We replace cmd with LFUN_MATH_INSERT because LFUN_MATH_MODE
+ // has a different meaning in math mode
+ mathDispatch(cur, FuncRequest(LFUN_MATH_INSERT,cmd.argument()));
break;
+ }
case LFUN_MATH_MACRO:
if (cmd.argument().empty())
}
break;
- // passthrough hat and underscore outside mathed:
+ case LFUN_MATH_DISPLAY:
case LFUN_MATH_SUBSCRIPT:
- mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "_"), false);
- break;
case LFUN_MATH_SUPERSCRIPT:
- mathDispatch(cur, FuncRequest(LFUN_SELF_INSERT, "^"), false);
- break;
-
case LFUN_MATH_INSERT:
case LFUN_MATH_AMS_MATRIX:
case LFUN_MATH_MATRIX:
case LFUN_MATH_DELIM:
- case LFUN_MATH_BIGDELIM: {
- cur.recordUndo();
- cap::replaceSelection(cur);
- cur.insert(new InsetMathHull(cur.buffer(), hullSimple));
- checkAndActivateInset(cur, true);
- LASSERT(cur.inMathed(), break);
- cur.dispatch(cmd);
+ case LFUN_MATH_BIGDELIM:
+ mathDispatch(cur, cmd);
break;
- }
case LFUN_FONT_EMPH: {
Font font(ignore_font, ignore_language);
case LFUN_ACCENT_GRAVE:
case LFUN_ACCENT_ACUTE:
case LFUN_ACCENT_TILDE:
+ case LFUN_ACCENT_PERISPOMENI:
case LFUN_ACCENT_CEDILLA:
case LFUN_ACCENT_MACRON:
case LFUN_ACCENT_DOT:
case LFUN_CAPTION_INSERT: {
code = CAPTION_CODE;
string arg = cmd.getArg(0);
- bool varia = arg != "LongTableNoNumber"
+ bool varia = arg != "Unnumbered"
&& cur.inset().allowsCaptionVariation(arg);
// not allowed in description items,
// and in specific insets
break;
case LFUN_LAYOUT: {
- enable = !cur.inset().forcePlainLayout();
-
+ DocumentClass const & tclass = cur.buffer()->params().documentClass();
docstring layout = cmd.argument();
- if (layout.empty()) {
- DocumentClass const & tclass = cur.buffer()->params().documentClass();
+ if (layout.empty())
layout = tclass.defaultLayoutName();
- }
+ enable = !cur.inset().forcePlainLayout() && tclass.hasLayout(layout);
+
flag.setOnOff(layout == cur.paragraph().layout().name());
break;
}
break;
// FIXME: why are accent lfuns forbidden with pass_thru layouts?
+ // Because they insert COMBINING DIACRITICAL Unicode characters,
+ // that cannot be handled by LaTeX but must be converted according
+ // to the definition in lib/unicodesymbols?
case LFUN_ACCENT_ACUTE:
case LFUN_ACCENT_BREVE:
case LFUN_ACCENT_CARON:
case LFUN_ACCENT_OGONEK:
case LFUN_ACCENT_TIE:
case LFUN_ACCENT_TILDE:
+ case LFUN_ACCENT_PERISPOMENI:
case LFUN_ACCENT_UMLAUT:
case LFUN_ACCENT_UNDERBAR:
case LFUN_ACCENT_UNDERDOT: