From d857fc89c81b96ca5312d659c62680097320d90b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 12 Dec 2001 14:37:59 +0000 Subject: [PATCH] Martin's super/subscript patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3199 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 11 ++++++++ src/LyXAction.C | 2 ++ src/commandtags.h | 2 ++ src/lyx_main.C | 4 +++ src/lyxfunc.C | 4 +++ src/mathed/formulabase.C | 11 +++++++- src/mathed/math_cursor.C | 56 +++++++++++++++++++++------------------- src/mathed/math_cursor.h | 2 ++ 8 files changed, 65 insertions(+), 27 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index ff7482b25b..d57edf7832 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2001-12-12 Martin Vermeer + + * commandtags.h: + * LyXAction.C: + * lyx_main.C: + * lyxfunc.C: + * mathed/formulabase.C: + * mathed/math_cursor.[Ch]: + make sub/superscript into functions LFUN_SUB/SUPERSCRIPT. + + 2001-12-12 Lars Gullik Bjønnes * lyxlength.[Ch] (operator!=): new function diff --git a/src/LyXAction.C b/src/LyXAction.C index 9d761f0ec1..dd15b2ee5e 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -281,6 +281,8 @@ void LyXAction::init() { LFUN_GREEK_TOGGLE, "math-greek-toggle", "", Noop }, { LFUN_INSERT_MATH, "math-insert", N_("Insert math symbol"), Noop }, + { LFUN_SUBSCRIPT, "math-subscript", "", Noop }, + { LFUN_SUPERSCRIPT, "math-superscript", "", Noop }, { LFUN_MATH_LIMITS, "math-limits", "", Noop }, { LFUN_MATH_MACRO, "math-macro", "", Noop }, { LFUN_MATH_MUTATE, "math-mutate", "", Noop }, diff --git a/src/commandtags.h b/src/commandtags.h index d6d2a8b2ad..9a68f354bb 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -94,6 +94,8 @@ enum kb_action { LFUN_BREAKPARAGRAPHKEEPLAYOUT, LFUN_QUOTE, LFUN_CIRCUMFLEX, + LFUN_SUBSCRIPT, + LFUN_SUPERSCRIPT, LFUN_GRAVE, LFUN_ACUTE, LFUN_TILDE, diff --git a/src/lyx_main.C b/src/lyx_main.C index 1dfd3ced2f..9b738a9bc0 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -523,6 +523,10 @@ void LyX::defaultKeyBindings(kb_keymap * kbmap) kbmap->bind("Delete", LFUN_DELETE); kbmap->bind("BackSpace", LFUN_BACKSPACE); + + // sub- and superscript -MV + kbmap->bind("~S-underscore", LFUN_SUBSCRIPT); + kbmap->bind("~S-asciicircum", LFUN_SUPERSCRIPT); // kbmap->bindings to enable the use of the numeric keypad // e.g. Num Lock set diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 1c0fceb1fe..be9d478136 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -573,6 +573,8 @@ func_status::value_type LyXFunc::getStatus(int ac, case LFUN_MATH_LIMITS: case LFUN_MATH_NONUMBER: case LFUN_MATH_NUMBER: + case LFUN_SUBSCRIPT: + case LFUN_SUPERSCRIPT: disable = !mathcursor; break; @@ -1438,6 +1440,8 @@ string const LyXFunc::dispatch(int ac, case LFUN_MATH_NUMBER: case LFUN_MATH_NONUMBER: case LFUN_MATH_LIMITS: + case LFUN_SUBSCRIPT: + case LFUN_SUPERSCRIPT: { setErrorMessage(N_("This is only allowed in math mode!")); } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 613407bb04..05ad274999 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -556,7 +556,16 @@ InsetFormulaBase::localDispatch(BufferView * bv, kb_action action, updateLocal(bv, true); break; } - + + case LFUN_SUPERSCRIPT: + case LFUN_SUBSCRIPT: + { + bv->lockedInsetStoreUndo(Undo::EDIT); + mathcursor->script((action == LFUN_SUPERSCRIPT)); + updateLocal(bv, true); + break; + } + case LFUN_MATH_DELIM: { lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n"; diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 41d078b512..39ead61ef6 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -1221,36 +1221,40 @@ bool MathCursor::interpret(string const & s) return true; } +bool MathCursor::script(bool up) +{ + macroModeClose(); + lyxerr << "script 2: '" << up << "'\n"; + selCut(); + if (hasPrevAtom() && prevAtom()->asScriptInset()) { + prevAtom()->asScriptInset()->ensure(up); + pushRight(prevAtom()); + idx() = up; + pos() = size(); + } else if (hasNextAtom() && nextAtom()->asScriptInset()) { + nextAtom()->asScriptInset()->ensure(up); + pushLeft(nextAtom()); + idx() = up; + pos() = 0; + } else { + plainInsert(MathAtom(new MathScriptInset(up))); + prevAtom()->asScriptInset()->ensure(up); + pushRight(prevAtom()); + idx() = up; + pos() = 0; + } + selPaste(); + dump("1"); + return true; +} + bool MathCursor::interpret(char c) { - //lyxerr << "interpret 2: '" << c << "'\n"; - if (c == '^' || c == '_') { - macroModeClose(); - const bool up = (c == '^'); - selCut(); - if (hasPrevAtom() && prevAtom()->asScriptInset()) { - prevAtom()->asScriptInset()->ensure(up); - pushRight(prevAtom()); - idx() = up; - pos() = size(); - } else if (hasNextAtom() && nextAtom()->asScriptInset()) { - nextAtom()->asScriptInset()->ensure(up); - pushLeft(nextAtom()); - idx() = up; - pos() = 0; - } else { - plainInsert(MathAtom(new MathScriptInset(up))); - prevAtom()->asScriptInset()->ensure(up); - pushRight(prevAtom()); - idx() = up; - pos() = 0; - } - selPaste(); - dump("1"); - return true; - } + lyxerr << "interpret 2: '" << c << "'\n"; + + // Removed super/subscript handling from here to ::script -MV // handle macroMode if (inMacroMode()) { diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 0a764c16c5..2233d84338 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -115,6 +115,8 @@ public: /// size of current cell size_type size() const; /// + bool script(bool); + /// bool interpret(string const &); /// bool interpret(char); -- 2.39.2