2 * \file math_nestinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_nestinset.h"
15 #include "math_arrayinset.h"
16 #include "math_braceinset.h"
17 #include "math_commentinset.h"
18 #include "math_data.h"
19 #include "math_deliminset.h"
20 #include "math_factory.h"
21 #include "math_hullinset.h"
22 #include "math_mathmlstream.h"
23 #include "math_parser.h"
24 #include "math_scriptinset.h"
25 #include "math_spaceinset.h"
26 #include "math_support.h"
27 #include "math_mboxinset.h"
28 #include "math_unknowninset.h"
30 #include "BufferView.h"
31 #include "FuncStatus.h"
33 #include "bufferview_funcs.h"
36 #include "dispatchresult.h"
37 #include "funcrequest.h"
39 #include "outputparams.h"
42 #include "support/std_sstream.h"
43 #include "support/lstrings.h"
45 #include "frontends/Dialogs.h"
46 #include "frontends/LyXView.h"
47 #include "frontends/Painter.h"
52 using std::istringstream;
66 MathNestInset::MathNestInset(idx_type nargs)
67 : cells_(nargs), lock_(false)
71 MathInset::idx_type MathNestInset::nargs() const
77 MathArray & MathNestInset::cell(idx_type i)
83 MathArray const & MathNestInset::cell(idx_type i) const
89 void MathNestInset::getCursorPos(CursorSlice const & cur,
90 int & x, int & y) const
92 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
93 MathArray const & ar = cur.cell();
94 x = ar.xo() + ar.pos2x(cur.pos());
96 // move cursor visually into empty cells ("blue rectangles");
97 if (cur.cell().empty())
102 void MathNestInset::substitute(MathMacro const & m)
104 for (idx_type i = 0; i < nargs(); ++i)
105 cell(i).substitute(m);
109 void MathNestInset::metrics(MetricsInfo const & mi) const
112 for (idx_type i = 0; i < nargs(); ++i)
117 bool MathNestInset::idxNext(LCursor & cur) const
119 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
120 if (cur.idx() == cur.lastidx())
128 bool MathNestInset::idxRight(LCursor & cur) const
134 bool MathNestInset::idxPrev(LCursor & cur) const
136 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
140 cur.pos() = cur.lastpos();
145 bool MathNestInset::idxLeft(LCursor & cur) const
151 bool MathNestInset::idxFirst(LCursor & cur) const
153 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
162 bool MathNestInset::idxLast(LCursor & cur) const
164 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
167 cur.idx() = cur.lastidx();
168 cur.pos() = cur.lastpos();
173 void MathNestInset::dump() const
175 WriteStream os(lyxerr);
176 os << "---------------------------------------------\n";
179 for (idx_type i = 0; i < nargs(); ++i)
180 os << cell(i) << "\n";
181 os << "---------------------------------------------\n";
185 void MathNestInset::draw(PainterInfo & pi, int x, int y) const
189 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
192 setPosCache(pi, x, y);
196 void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
198 //lyxerr << "MathNestInset::drawing selection: "
199 // << " x: " << x << " y: " << y << endl;
200 // this should use the x/y values given, not the cached values
201 LCursor & cur = pi.base.bv->cursor();
202 if (!cur.selection())
204 if (!ptr_cmp(&cur.inset(), this))
206 CursorSlice s1 = cur.selBegin();
207 CursorSlice s2 = cur.selEnd();
208 lyxerr << "MathNestInset::drawing selection: "
209 << " s1: " << s1 << " s2: " << s2 << endl;
210 if (s1.idx() == s2.idx()) {
211 MathArray const & c = cell(s1.idx());
212 int x1 = c.xo() + c.pos2x(s1.pos());
213 int y1 = c.yo() - c.ascent();
214 int x2 = c.xo() + c.pos2x(s2.pos());
215 int y2 = c.yo() + c.descent();
216 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
218 for (idx_type i = 0; i < nargs(); ++i) {
219 if (idxBetween(i, s1.idx(), s2.idx())) {
220 MathArray const & c = cell(i);
222 int y1 = c.yo() - c.ascent();
223 int x2 = c.xo() + c.width();
224 int y2 = c.yo() + c.descent();
225 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
232 void MathNestInset::validate(LaTeXFeatures & features) const
234 for (idx_type i = 0; i < nargs(); ++i)
235 cell(i).validate(features);
239 void MathNestInset::replace(ReplaceData & rep)
241 for (idx_type i = 0; i < nargs(); ++i)
242 cell(i).replace(rep);
246 bool MathNestInset::contains(MathArray const & ar) const
248 for (idx_type i = 0; i < nargs(); ++i)
249 if (cell(i).contains(ar))
255 bool MathNestInset::lock() const
261 void MathNestInset::lock(bool l)
267 bool MathNestInset::isActive() const
273 MathArray MathNestInset::glue() const
276 for (size_t i = 0; i < nargs(); ++i)
282 void MathNestInset::write(WriteStream & os) const
284 os << '\\' << name().c_str();
285 for (size_t i = 0; i < nargs(); ++i)
286 os << '{' << cell(i) << '}';
288 os.pendingSpace(true);
289 if (lock_ && !os.latex()) {
291 os.pendingSpace(true);
296 void MathNestInset::normalize(NormalStream & os) const
298 os << '[' << name().c_str();
299 for (size_t i = 0; i < nargs(); ++i)
300 os << ' ' << cell(i);
305 int MathNestInset::latex(Buffer const &, std::ostream & os,
306 OutputParams const & runparams) const
308 WriteStream wi(os, runparams.moving_arg, true);
314 void MathNestInset::notifyCursorLeaves(LCursor & cur)
318 MathArray & ar = cur.cell();
319 // remove base-only "scripts"
320 for (pos_type i = 0; i + 1 < size(); ++i) {
321 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
322 if (p && p->nargs() == 1) {
323 MathArray ar = p->nuc();
326 cur.adjust(i, ar.size() - 1);
330 // glue adjacent font insets of the same kind
331 for (pos_type i = 0; i + 1 < size(); ++i) {
332 MathFontInset * p = operator[](i).nucleus()->asFontInset();
333 MathFontInset const * q = operator[](i + 1)->asFontInset();
334 if (p && q && p->name() == q->name()) {
335 p->cell(0).append(q->cell(0));
344 void MathNestInset::handleFont
345 (LCursor & cur, string const & arg, string const & font)
347 // this whole function is a hack and won't work for incremental font
349 recordUndo(cur, Undo::ATOMIC);
351 if (cur.inset().asMathInset()->name() == font)
352 cur.handleFont(font);
354 cur.handleNest(createMathInset(font));
360 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
362 recordUndo(cur, Undo::ATOMIC);
365 bv_funcs::string2font(arg, font, b);
366 if (font.color() != LColor::inherit) {
367 MathAtom at = createMathInset("color");
368 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
369 cur.handleNest(at, 1);
374 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
376 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
377 //CursorSlice sl = cur.current();
379 switch (cmd.action) {
381 case LFUN_PASTESELECTION: {
383 mathed_parse_cell(ar, cur.bv().getClipboard());
384 cur.cell().insert(cur.pos(), ar);
385 cur.pos() += ar.size();
390 if (!cmd.argument.empty()) {
392 mathed_parse_cell(ar, cmd.argument);
393 cur.cell().insert(cur.pos(), ar);
394 cur.pos() += ar.size();
400 istringstream is(cmd.argument.c_str());
403 cur.macroModeClose();
404 recordUndo(cur, Undo::ATOMIC);
410 case LFUN_MOUSE_PRESS:
411 lfunMousePress(cur, cmd);
414 case LFUN_MOUSE_MOTION:
415 lfunMouseMotion(cur, cmd);
418 case LFUN_MOUSE_RELEASE:
419 lfunMouseRelease(cur, cmd);
422 case LFUN_FINISHED_LEFT:
423 cur.bv().cursor() = cur;
426 case LFUN_FINISHED_RIGHT:
428 cur.bv().cursor() = cur;
431 case LFUN_FINISHED_UP:
432 //idxUpDown(cur, true);
433 cur.bv().cursor() = cur;
436 case LFUN_FINISHED_DOWN:
437 //idxUpDown(cur, false);
438 cur.bv().cursor() = cur;
443 lyxerr << "mathnest RIGHT: from:\n" << cur << endl;
444 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
445 cur.autocorrect() = false;
447 if (cur.inMacroMode())
448 cur.macroModeClose();
449 else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
450 cur.pushLeft(*cur.nextAtom().nucleus());
451 cur.inset().idxFirst(cur);
452 } else if (cur.posRight() || idxRight(cur)
453 || cur.popRight() || cur.selection())
456 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
457 lyxerr << "mathnest RIGHT: to:\n" << cur << endl;
462 cur.selHandle(cmd.action == LFUN_LEFTSEL);
463 cur.autocorrect() = false;
465 if (cur.inMacroMode())
466 cur.macroModeClose();
467 else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
469 cur.push(*cur.nextAtom().nucleus());
470 cur.inset().idxLast(cur);
471 } else if (cur.posLeft() || idxLeft(cur)
472 || cur.popLeft() || cur.selection())
475 cmd = FuncRequest(LFUN_FINISHED_LEFT);
480 cur.selHandle(cmd.action == LFUN_UPSEL);
482 cmd = FuncRequest(LFUN_FINISHED_UP);
487 cur.selHandle(cmd.action == LFUN_DOWNSEL);
489 cmd = FuncRequest(LFUN_FINISHED_DOWN);
492 case LFUN_MOUSE_DOUBLE:
493 case LFUN_MOUSE_TRIPLE:
498 cur.selection() = true;
499 cur.pos() = cur.lastpos();
500 cur.idx() = cur.lastidx();
503 case LFUN_UP_PARAGRAPHSEL:
504 case LFUN_UP_PARAGRAPH:
505 case LFUN_DOWN_PARAGRAPHSEL:
506 case LFUN_DOWN_PARAGRAPH:
511 case LFUN_WORDLEFTSEL:
513 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
514 cur.macroModeClose();
515 if (cur.pos() != 0) {
517 } else if (cur.col() != 0) {
518 cur.idx() -= cur.col();
520 } else if (cur.idx() != 0) {
524 cmd = FuncRequest(LFUN_FINISHED_LEFT);
528 case LFUN_WORDRIGHTSEL:
532 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
533 cur.macroModeClose();
535 if (cur.pos() != cur.lastpos()) {
536 cur.pos() = cur.lastpos();
537 } else if (cur.col() != cur.lastcol()) {
538 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
539 cur.pos() = cur.lastpos();
540 } else if (cur.idx() != cur.lastidx()) {
541 cur.idx() = cur.lastidx();
542 cur.pos() = cur.lastpos();
544 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
550 case LFUN_BEGINNINGBUFSEL:
551 case LFUN_BEGINNINGBUF:
552 cmd = FuncRequest(LFUN_FINISHED_LEFT);
559 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
562 case LFUN_CELL_FORWARD:
563 cur.inset().idxNext(cur);
566 case LFUN_CELL_BACKWARD:
567 cur.inset().idxPrev(cur);
570 case LFUN_DELETE_WORD_BACKWARD:
572 recordUndo(cur, Undo::ATOMIC);
576 case LFUN_DELETE_WORD_FORWARD:
578 recordUndo(cur, Undo::ATOMIC);
580 cmd = FuncRequest(LFUN_FINISHED_LEFT);
585 cur.clearSelection();
587 cmd = FuncRequest(LFUN_FINISHED_LEFT);
590 case LFUN_INSET_TOGGLE:
592 if (cur.pos() != cur.lastpos()) {
593 // toggle previous inset ...
594 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
595 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
596 // ... or enclosing inset if we are in the last inset position
597 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
602 case LFUN_SELFINSERT:
603 if (cmd.argument.empty()) {
604 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
607 recordUndo(cur, Undo::ATOMIC);
608 if (cmd.argument.size() != 1) {
609 cur.insert(cmd.argument);
612 if (!interpret(cur, cmd.argument[0]))
613 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
618 // this needs to be incorporated
620 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
621 bool remove_inset = false;
623 DispatchResult result(true);
624 bool was_macro = cur.inMacroMode();
631 // sprintf(dispatch_buffer, "%d %d",);
632 // DispatchResult= dispatch_buffer;
635 lyxerr << "LFUN_SETXY broken!" << endl;
638 istringstream is(cmd.argument.c_str());
640 cur.setScreenPos(x, y);
645 recordUndo(cur, Undo::DELETE);
653 // Special casing for superscript in case of LyX handling
655 case LFUN_CIRCUMFLEX:
656 if (cmd.argument.empty()) {
657 // do superscript if LyX handles
659 recordUndo(cur, Undo::ATOMIC);
677 case LFUN_HUNG_UMLAUT:
681 case LFUN_FREEFONT_APPLY:
682 case LFUN_FREEFONT_UPDATE:
683 handleFont2(cur, cmd.argument);
687 handleFont(cur, cmd.argument, "mathbf");
690 handleFont(cur, cmd.argument, "mathsf");
693 handleFont(cur, cmd.argument, "mathcal");
696 handleFont(cur, cmd.argument, "mathrm");
699 handleFont(cur, cmd.argument, "texttt");
702 handleFont(cur, cmd.argument, "mathfrak");
705 handleFont(cur, cmd.argument, "mathit");
708 handleFont(cur, cmd.argument, "mathbb");
710 //case LFUN_FREEFONT_APPLY:
711 handleFont(cur, cmd.argument, "textrm");
714 handleFont(cur, cmd.argument, "textnormal");
719 cur.macroModeClose();
721 cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
723 cur.pushLeft(*cur.nextInset());
725 if (currentMode() == InsetBase::TEXT_MODE)
726 cur.niceInsert(MathAtom(new MathHullInset("simple")));
728 handleFont(cur, cmd.argument, "textrm");
729 //cur.owner()->message(_("math text mode toggled"));
736 recordUndo(cur, Undo::ATOMIC);
742 case LFUN_INSERT_MATRIX: {
743 recordUndo(cur, Undo::ATOMIC);
748 istringstream is(cmd.argument);
749 is >> m >> n >> v_align >> h_align;
756 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
760 case LFUN_MATH_DELIM: {
761 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
763 string rs = lyx::support::split(cmd.argument, ls, ' ');
764 // Reasonable default values
769 recordUndo(cur, Undo::ATOMIC);
770 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
774 case LFUN_SPACE_INSERT:
775 case LFUN_MATH_SPACE:
776 recordUndo(cur, Undo::ATOMIC);
777 cur.insert(MathAtom(new MathSpaceInset(",")));
781 // interpret this as if a backslash was typed
782 recordUndo(cur, Undo::ATOMIC);
783 interpret(cur, '\\');
786 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
787 // handling such that "self-insert" works on "arbitrary stuff" too, and
788 // math-insert only handles special math things like "matrix".
789 case LFUN_INSERT_MATH:
790 recordUndo(cur, Undo::ATOMIC);
791 cur.niceInsert(cmd.argument);
794 case LFUN_DIALOG_SHOW_NEW_INSET: {
795 string const & name = cmd.argument;
800 data = tmp.createDialogStr(name);
803 cur.bv().owner()->getDialogs().show(name, data, 0);
807 case LFUN_INSET_APPLY: {
808 string const name = cmd.getArg(0);
809 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
812 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
813 base->dispatch(cur, fr);
817 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
830 case LFUN_WORD_REPLACE:
832 if (!searchForward(&cur.bv(), cmd.getArg(0), false, false))
839 BOOST_ASSERT(cur.inMathed());
841 if (result.dispatched()) {
843 cur.bv().stuffClipboard(cur.grabSelection());
846 cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
852 MathDimInset::priv_dispatch(cur, cmd);
858 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
859 FuncStatus & flag) const
861 // the font related toggles
862 //string tc = "mathnormal";
864 switch (cmd.action) {
866 case LFUN_TABULAR_FEATURE:
867 // FIXME: check temporarily disabled
869 char align = mathcursor::valign();
874 if (cmd.argument.empty()) {
878 if (!contains("tcb", cmd.argument[0])) {
882 flag.setOnOff(cmd.argument[0] == align);
885 flag.setOnOff(tc == "mathbf");
888 flag.setOnOff(tc == "mathsf");
891 flag.setOnOff(tc == "mathcal");
894 flag.setOnOff(tc == "mathrm");
897 flag.setOnOff(tc == "mathtt");
900 flag.setOnOff(tc == "mathbb");
903 flag.setOnOff(tc == "mathnormal");
906 case LFUN_MATH_MUTATE:
907 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
908 flag.setOnOff(false);
911 // we just need to be in math mode to enable that
913 case LFUN_MATH_SPACE:
914 case LFUN_MATH_LIMITS:
915 case LFUN_MATH_NONUMBER:
916 case LFUN_MATH_NUMBER:
917 case LFUN_MATH_EXTERN:
929 void MathNestInset::edit(LCursor & cur, bool left)
932 cur.idx() = left ? 0 : cur.lastidx();
933 cur.pos() = left ? 0 : cur.lastpos();
935 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
939 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
942 int dist_min = 1000000;
943 for (idx_type i = 0; i < nargs(); ++i) {
944 int d = cell(i).dist(x, y);
950 MathArray & ar = cell(idx_min);
953 cur.pos() = ar.x2pos(x - ar.xo());
954 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
957 for (pos_type i = 0, n = ar.size(); i < n; ++i)
958 if (ar[i]->covers(x, y))
959 return ar[i].nucleus()->editXY(cur, x, y);
965 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
967 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
969 if (cmd.button() == mouse_button::button1) {
970 // try to dispatch to enclosed insets first
971 //cur.bv().stuffClipboard(cur.grabSelection());
975 if (cmd.button() == mouse_button::button2) {
977 asArray(cur.bv().getClipboard(), ar);
978 cur.clearSelection();
979 cur.setScreenPos(cmd.x, cmd.y);
985 if (cmd.button() == mouse_button::button3) {
986 // try to dispatch to enclosed insets first
987 cur.bv().owner()->getDialogs().show("mathpanel");
995 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
997 lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
998 if (cmd.button() == mouse_button::button1) {
1001 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
1002 lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
1004 cur.bv().cursor() = cur;
1007 if (cmd.button() == mouse_button::button2) {
1008 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
1013 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
1015 // only select with button 1
1016 if (cmd.button() != mouse_button::button1)
1019 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
1025 cur.bv().cursor().setCursor(cur, true);
1029 bool MathNestInset::interpret(LCursor & cur, char c)
1031 lyxerr << "interpret 2: '" << c << "'" << endl;
1033 /// are we currently typing '#1' or '#2' or...?
1034 if (cur.pos() > 0 && cur.prevAtom()->getChar() == '#') {
1037 #ifdef WITH_WARNINGS
1042 MathMacroTemplate const * p = formula()->asMacroTemplate();
1043 if (p && 1 <= n && n <= p->numargs())
1044 cur.insert(MathAtom(new MathMacroArgument(c - '0')));
1046 cur.insert(createMathInset("#"));
1047 interpret(cur, c); // try again
1054 if (cur.inMacroMode()) {
1055 string name = cur.macroName();
1056 //lyxerr << "interpret name: '" << name << "'" << endl;
1059 cur.activeMacro()->setName(cur.activeMacro()->name() + c);
1063 // handle 'special char' macros
1068 if (currentMode() == MathInset::TEXT_MODE)
1069 cur.niceInsert(createMathInset("textbackslash"));
1071 cur.niceInsert(createMathInset("backslash"));
1072 } else if (c == '{') {
1073 cur.niceInsert(MathAtom(new MathBraceInset));
1075 cur.niceInsert(createMathInset(string(1, c)));
1080 // leave macro mode and try again if necessary
1081 cur.macroModeClose();
1083 cur.niceInsert(MathAtom(new MathBraceInset));
1089 // This is annoying as one has to press <space> far too often.
1093 // leave autocorrect mode if necessary
1094 if (autocorrect() && c == ' ') {
1095 autocorrect() = false;
1100 // just clear selection on pressing the space bar
1101 if (cur.selection() && c == ' ') {
1102 cur.selection() = false;
1106 cur.selClearOrDel();
1109 //lyxerr << "starting with macro" << endl;
1110 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1115 if (currentMode() == MathInset::TEXT_MODE)
1121 if (currentMode() == MathInset::TEXT_MODE) {
1122 // insert spaces in text mode,
1123 // but suppress direct insertion of two spaces in a row
1124 // the still allows typing '<space>a<space>' and deleting the 'a', but
1125 // it is better than nothing...
1126 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1130 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1131 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1136 // if are at the very end, leave the formula
1137 return cur.pos() != cur.lastpos();
1150 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1151 cur.niceInsert(createMathInset(string(1, c)));
1156 cur.niceInsert(MathAtom(new MathCommentInset));
1160 // try auto-correction
1161 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1164 // no special circumstances, so insert the character without any fuss
1166 cur.autocorrect() = true;
1171 bool MathNestInset::script(LCursor & cur, bool up)
1173 // Hack to get \\^ and \\_ working
1174 lyxerr << "handling script: up: " << up << endl;
1175 if (cur.inMacroMode() && cur.macroName() == "\\") {
1177 cur.niceInsert(createMathInset("mathcircumflex"));
1179 interpret(cur, '_');
1183 cur.macroModeClose();
1184 string safe = cur.grabAndEraseSelection();
1185 if (asScriptInset() && cur.idx() == 0) {
1186 // we are in a nucleus of a script inset, move to _our_ script
1187 MathScriptInset * inset = asScriptInset();
1188 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1190 cur.idx() = inset->idxOfScript(up);
1192 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1194 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1196 cur.idx() = inset->idxOfScript(up);
1197 cur.pos() = cur.lastpos();
1199 // convert the thing to our left to a scriptinset or create a new
1200 // one if in the very first position of the array
1201 if (cur.pos() == 0) {
1202 lyxerr << "new scriptinset" << endl;
1203 cur.insert(new MathScriptInset(up));
1205 lyxerr << "converting prev atom " << endl;
1206 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1208 lyxerr << "new scriptinset 2: cur:\n" << cur << endl;
1210 lyxerr << "new scriptinset 3: cur:\n" << cur << endl;
1211 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1212 lyxerr << "new scriptinset 3: inset:\n" << inset << endl;
1217 lyxerr << "pasting 1: safe:\n" << safe << endl;
1220 lyxerr << "pasting 2: safe:\n" << safe << endl;