From 1b411d8e9cc2e0a712cad317fb7820221cae69c5 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 11 Jan 2006 17:08:50 +0000 Subject: [PATCH] fix bug 2034 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10726 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 5 +++++ src/cursor.C | 13 +++++-------- src/cursor.h | 6 ++++-- src/mathed/ChangeLog | 12 +++++++++--- src/mathed/math_nestinset.C | 16 ++++++++++++++-- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 052d0c1309..69cd935086 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2006-01-11 Jean-Marc Lasgouttes + + * cursor.C (macroModeClose): returns true if an inset actually got + inserted; revert faulty fix to bug 2034. + 2006-01-10 Jean-Marc Lasgouttes * tabular.C (getLabelList): remove (not used anymore). diff --git a/src/cursor.C b/src/cursor.C index 111fb78a9a..0404582243 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -825,10 +825,10 @@ bool LCursor::down() } -void LCursor::macroModeClose() +bool LCursor::macroModeClose() { if (!inMacroMode()) - return; + return false; MathUnknownInset * p = activeMacro(); p->finalize(); string const s = p->name(); @@ -837,7 +837,7 @@ void LCursor::macroModeClose() // do nothing if the macro name is empty if (s == "\\") - return; + return false; // prevent entering of recursive macros // FIXME: this is only a weak attempt... only prevents immediate @@ -847,11 +847,8 @@ void LCursor::macroModeClose() if (macro && macro->getInsetName() == name) lyxerr << "can't enter recursive macro" << endl; - // Going back and forth between LCursor and mathed is a bit - // ridiculous, but the alternative was to duplicate the code - // in MathNestInset::doDispatch/LFUN_INSERT_MATH (which puts - // the cursor in the newly created inset). (JMarc 2005/12/20) - dispatch(FuncRequest(LFUN_INSERT_MATH, s)); + plainInsert(createMathInset(name)); + return true; } diff --git a/src/cursor.h b/src/cursor.h index 817cdd4817..1ec6255b0b 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -256,8 +256,10 @@ public: /// in pixels from top of screen void setScreenPos(int x, int y); /// current offset in the top cell - /// interpret name a name of a macro - void macroModeClose(); + + /// interpret name a name of a macro. Returns true if + /// something got inserted. + bool macroModeClose(); /// are we currently typing the name of a macro? bool inMacroMode() const; /// get access to the macro we are currently typing diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 671fd0f22c..07e96be679 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,8 +1,14 @@ +2006-01-11 Jean-Marc Lasgouttes + + * math_nestinset.C (doDispatch/LFUN_SELFINSERT): when inserting a + space and macromode is on, try to put the cursor inside the newly + created inset (bug 2034). + 2006-01-10 Martin Vermeer * math_hullinset (doDispatch): fix default label setting (eq:) -2006-01-01 +2006-01-01 Lars Gullik Bjønnes * command_inset.C (editXY): unused parameters @@ -62,8 +68,8 @@ 2005-10-13 Georg Baum - * math_gridinset.[Ch] (eolString, write): Output \\ at the end of the last - line if it is empty (fixes bug 2067) + * math_gridinset.[Ch] (eolString, write): Output \\ at the end of + the last line if it is empty (fixes bug 2067) * math_hullinset.[Ch] (eolString): Adjust to the changes above * math_hullinset.C (delRow): Allow to delete the last dummy row * math_parser.C (delEmptyLastRow): Delete the last dummy row. diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index d597bebeb0..e5b88bab5e 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -340,7 +340,7 @@ int MathNestInset::latex(Buffer const &, std::ostream & os, } -void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/) +void MathNestInset::notifyCursorLeaves(LCursor & cur) { #ifdef WITH_WARNINGS #warning look here @@ -669,7 +669,19 @@ void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd) // undoes the complete macro, not only the last character. if (!cur.inMacroMode()) recordUndo(cur); - if (!interpret(cur, cmd.argument[0])) { + + // spacial handling of space. If we insert an inset + // via macro mode, we want to put the cursor inside it + // if relevant. Think typing "\frac". + if (cmd.argument[0] == ' ' + && cur.inMacroMode() && cur.macroName() != "\\" + && cur.macroModeClose()) { + MathAtom const atom = cur.prevAtom(); + if (atom->asNestInset() && atom->nargs() > 0) { + cur.posLeft(); + cur.pushLeft(*cur.nextInset()); + } + } else if (!interpret(cur, cmd.argument[0])) { cmd = FuncRequest(LFUN_FINISHED_RIGHT); cur.undispatched(); }