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"
32 #include "bufferview_funcs.h"
35 #include "dispatchresult.h"
36 #include "funcrequest.h"
41 #include "support/std_sstream.h"
42 #include "support/lstrings.h"
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.h"
46 #include "frontends/Painter.h"
51 using std::istringstream;
65 MathNestInset::MathNestInset(idx_type nargs)
66 : cells_(nargs), lock_(false)
70 MathInset::idx_type MathNestInset::nargs() const
76 MathArray & MathNestInset::cell(idx_type i)
82 MathArray const & MathNestInset::cell(idx_type i) const
88 void MathNestInset::getCursorPos(CursorSlice const & cur,
89 int & x, int & y) const
91 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
92 MathArray const & ar = cur.cell();
93 x = ar.xo() + ar.pos2x(cur.pos());
95 // move cursor visually into empty cells ("blue rectangles");
96 if (cur.cell().empty())
101 void MathNestInset::substitute(MathMacro const & m)
103 for (idx_type i = 0; i < nargs(); ++i)
104 cell(i).substitute(m);
108 void MathNestInset::metrics(MetricsInfo const & mi) const
111 for (idx_type i = 0; i < nargs(); ++i)
116 bool MathNestInset::idxNext(LCursor & cur) const
118 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
119 if (cur.idx() == cur.lastidx())
127 bool MathNestInset::idxRight(LCursor & cur) const
133 bool MathNestInset::idxPrev(LCursor & cur) const
135 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
139 cur.pos() = cur.lastpos();
144 bool MathNestInset::idxLeft(LCursor & cur) const
150 bool MathNestInset::idxFirst(LCursor & cur) const
152 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
161 bool MathNestInset::idxLast(LCursor & cur) const
163 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
166 cur.idx() = cur.lastidx();
167 cur.pos() = cur.lastpos();
172 void MathNestInset::dump() const
174 WriteStream os(lyxerr);
175 os << "---------------------------------------------\n";
178 for (idx_type i = 0; i < nargs(); ++i)
179 os << cell(i) << "\n";
180 os << "---------------------------------------------\n";
184 //void MathNestInset::draw(PainterInfo & pi, int x, int y) const
185 void MathNestInset::draw(PainterInfo &, int, int) const
189 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
195 void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
197 // this should use the x/y values given, not the cached values
198 LCursor & cur = pi.base.bv->cursor();
199 if (!cur.selection())
201 if (!ptr_cmp(&cur.inset(), this))
203 CursorSlice s1 = cur.selBegin();
204 CursorSlice s2 = cur.selEnd();
205 if (s1.idx() == s2.idx()) {
206 MathArray const & c = cell(s1.idx());
207 int x1 = c.xo() + c.pos2x(s1.pos());
208 int y1 = c.yo() - c.ascent();
209 int x2 = c.xo() + c.pos2x(s2.pos());
210 int y2 = c.yo() + c.descent();
211 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
213 for (idx_type i = 0; i < nargs(); ++i) {
214 if (idxBetween(i, s1.idx(), s2.idx())) {
215 MathArray const & c = cell(i);
217 int y1 = c.yo() - c.ascent();
218 int x2 = c.xo() + c.width();
219 int y2 = c.yo() + c.descent();
220 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
227 void MathNestInset::validate(LaTeXFeatures & features) const
229 for (idx_type i = 0; i < nargs(); ++i)
230 cell(i).validate(features);
234 void MathNestInset::replace(ReplaceData & rep)
236 for (idx_type i = 0; i < nargs(); ++i)
237 cell(i).replace(rep);
241 bool MathNestInset::contains(MathArray const & ar) const
243 for (idx_type i = 0; i < nargs(); ++i)
244 if (cell(i).contains(ar))
250 bool MathNestInset::lock() const
256 void MathNestInset::lock(bool l)
262 bool MathNestInset::isActive() const
268 MathArray MathNestInset::glue() const
271 for (size_t i = 0; i < nargs(); ++i)
277 void MathNestInset::write(WriteStream & os) const
279 os << '\\' << name().c_str();
280 for (size_t i = 0; i < nargs(); ++i)
281 os << '{' << cell(i) << '}';
283 os.pendingSpace(true);
284 if (lock_ && !os.latex()) {
286 os.pendingSpace(true);
291 void MathNestInset::normalize(NormalStream & os) const
293 os << '[' << name().c_str();
294 for (size_t i = 0; i < nargs(); ++i)
295 os << ' ' << cell(i);
300 void MathNestInset::notifyCursorLeaves(LCursor & cur)
303 MathArray & ar = cur.cell();
304 // remove base-only "scripts"
305 for (pos_type i = 0; i + 1 < size(); ++i) {
306 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
307 if (p && p->cell(0).empty() && p->cell(1).empty()) {
308 MathArray ar = p->nuc();
311 mathcursor->adjust(i, ar.size() - 1);
315 // glue adjacent font insets of the same kind
316 for (pos_type i = 0; i + 1 < size(); ++i) {
317 MathFontInset * p = operator[](i).nucleus()->asFontInset();
318 MathFontInset const * q = operator[](i + 1)->asFontInset();
319 if (p && q && p->name() == q->name()) {
320 p->cell(0).append(q->cell(0));
322 mathcursor->adjust(i, -1);
329 void MathNestInset::handleFont
330 (LCursor & cur, string const & arg, string const & font)
332 // this whole function is a hack and won't work for incremental font
334 recordUndo(cur, Undo::ATOMIC);
336 if (cur.inset().asMathInset()->name() == font)
337 cur.handleFont(font);
339 cur.handleNest(createMathInset(font));
345 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
347 recordUndo(cur, Undo::ATOMIC);
350 bv_funcs::string2font(arg, font, b);
351 if (font.color() != LColor::inherit) {
352 MathAtom at = createMathInset("color");
353 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
354 cur.handleNest(at, 1);
359 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
361 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
362 //CursorSlice sl = cur.current();
364 switch (cmd.action) {
366 case LFUN_PASTESELECTION: {
368 mathed_parse_cell(ar, cur.bv().getClipboard());
369 cur.cell().insert(cur.pos(), ar);
370 cur.pos() += ar.size();
375 if (!cmd.argument.empty()) {
377 mathed_parse_cell(ar, cmd.argument);
378 cur.cell().insert(cur.pos(), ar);
379 cur.pos() += ar.size();
385 istringstream is(cmd.argument.c_str());
388 cur.macroModeClose();
389 recordUndo(cur, Undo::ATOMIC);
395 case LFUN_MOUSE_PRESS:
396 lfunMousePress(cur, cmd);
399 case LFUN_MOUSE_MOTION:
400 lfunMouseMotion(cur, cmd);
403 case LFUN_MOUSE_RELEASE:
404 lfunMouseRelease(cur, cmd);
407 case LFUN_FINISHED_LEFT:
408 cur.bv().cursor() = cur;
411 case LFUN_FINISHED_RIGHT:
413 cur.bv().cursor() = cur;
416 case LFUN_FINISHED_UP:
417 //idxUpDown(cur, true);
418 cur.bv().cursor() = cur;
421 case LFUN_FINISHED_DOWN:
422 //idxUpDown(cur, false);
423 cur.bv().cursor() = cur;
428 lyxerr << "mathnest RIGHT: from:\n" << cur << endl;
429 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
430 cur.autocorrect() = false;
432 if (cur.inMacroMode())
433 cur.macroModeClose();
434 else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
435 cur.pushLeft(*cur.nextAtom().nucleus());
436 cur.inset().idxFirst(cur);
437 } else if (cur.posRight() || idxRight(cur)
438 || cur.popRight() || cur.selection())
441 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
442 lyxerr << "mathnest RIGHT: to:\n" << cur << endl;
447 cur.selHandle(cmd.action == LFUN_LEFTSEL);
448 cur.autocorrect() = false;
450 if (cur.inMacroMode())
451 cur.macroModeClose();
452 else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
454 cur.push(*cur.nextAtom().nucleus());
455 cur.inset().idxLast(cur);
456 } else if (cur.posLeft() || idxLeft(cur)
457 || cur.popLeft() || cur.selection())
460 cmd = FuncRequest(LFUN_FINISHED_LEFT);
465 cur.selHandle(cmd.action == LFUN_UPSEL);
467 cmd = FuncRequest(LFUN_FINISHED_UP);
472 cur.selHandle(cmd.action == LFUN_DOWNSEL);
474 cmd = FuncRequest(LFUN_FINISHED_DOWN);
477 case LFUN_MOUSE_DOUBLE:
478 case LFUN_MOUSE_TRIPLE:
483 cur.selection() = true;
484 cur.pos() = cur.lastpos();
485 cur.idx() = cur.lastidx();
488 case LFUN_UP_PARAGRAPHSEL:
489 case LFUN_UP_PARAGRAPH:
490 case LFUN_DOWN_PARAGRAPHSEL:
491 case LFUN_DOWN_PARAGRAPH:
496 case LFUN_WORDLEFTSEL:
498 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
499 cur.macroModeClose();
500 if (cur.pos() != 0) {
502 } else if (cur.col() != 0) {
503 cur.idx() -= cur.col();
505 } else if (cur.idx() != 0) {
509 cmd = FuncRequest(LFUN_FINISHED_LEFT);
513 case LFUN_WORDRIGHTSEL:
517 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
518 cur.macroModeClose();
520 if (cur.pos() != cur.lastpos()) {
521 cur.pos() = cur.lastpos();
522 } else if (cur.col() != cur.lastcol()) {
523 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
524 cur.pos() = cur.lastpos();
525 } else if (cur.idx() != cur.lastidx()) {
526 cur.idx() = cur.lastidx();
527 cur.pos() = cur.lastpos();
529 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
535 case LFUN_BEGINNINGBUFSEL:
536 case LFUN_BEGINNINGBUF:
537 cmd = FuncRequest(LFUN_FINISHED_LEFT);
544 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
547 case LFUN_CELL_FORWARD:
548 cur.inset().idxNext(cur);
551 case LFUN_CELL_BACKWARD:
552 cur.inset().idxPrev(cur);
555 case LFUN_DELETE_WORD_BACKWARD:
557 recordUndo(cur, Undo::ATOMIC);
561 case LFUN_DELETE_WORD_FORWARD:
563 recordUndo(cur, Undo::ATOMIC);
565 cmd = FuncRequest(LFUN_FINISHED_LEFT);
572 cmd = FuncRequest(LFUN_FINISHED_LEFT);
575 case LFUN_INSET_TOGGLE:
577 if (cur.pos() != cur.lastpos()) {
578 // toggle previous inset ...
579 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
580 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
581 // ... or enclosing inset if we are in the last inset position
582 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
587 case LFUN_SELFINSERT:
588 if (cmd.argument.empty()) {
589 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
592 recordUndo(cur, Undo::ATOMIC);
593 if (cmd.argument.size() != 1) {
594 cur.insert(cmd.argument);
597 if (!interpret(cur, cmd.argument[0]))
598 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
603 // this needs to be incorporated
605 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
606 bool remove_inset = false;
608 DispatchResult result(true);
609 bool was_macro = cur.inMacroMode();
616 // sprintf(dispatch_buffer, "%d %d",);
617 // DispatchResult= dispatch_buffer;
620 lyxerr << "LFUN_SETXY broken!" << endl;
623 istringstream is(cmd.argument.c_str());
625 cur.setScreenPos(x, y);
630 recordUndo(cur, Undo::DELETE);
638 // Special casing for superscript in case of LyX handling
640 case LFUN_CIRCUMFLEX:
641 if (cmd.argument.empty()) {
642 // do superscript if LyX handles
644 recordUndo(cur, Undo::ATOMIC);
662 case LFUN_HUNG_UMLAUT:
666 case LFUN_FREEFONT_APPLY:
667 case LFUN_FREEFONT_UPDATE:
668 handleFont2(cur, cmd.argument);
672 handleFont(cur, cmd.argument, "mathbf");
675 handleFont(cur, cmd.argument, "mathsf");
678 handleFont(cur, cmd.argument, "mathcal");
681 handleFont(cur, cmd.argument, "mathrm");
684 handleFont(cur, cmd.argument, "texttt");
687 handleFont(cur, cmd.argument, "mathfrak");
690 handleFont(cur, cmd.argument, "mathit");
693 handleFont(cur, cmd.argument, "mathbb");
695 //case LFUN_FREEFONT_APPLY:
696 handleFont(cur, cmd.argument, "textrm");
699 handleFont(cur, cmd.argument, "textnormal");
704 cur.macroModeClose();
706 cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
708 cur.pushLeft(*cur.nextInset());
710 if (currentMode() == InsetBase::TEXT_MODE)
711 cur.niceInsert(MathAtom(new MathHullInset("simple")));
713 handleFont(cur, cmd.argument, "textrm");
714 //cur.owner()->message(_("math text mode toggled"));
721 recordUndo(cur, Undo::ATOMIC);
727 case LFUN_INSERT_MATRIX: {
728 recordUndo(cur, Undo::ATOMIC);
733 istringstream is(cmd.argument);
734 is >> m >> n >> v_align >> h_align;
741 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
745 case LFUN_MATH_DELIM: {
746 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
748 string rs = lyx::support::split(cmd.argument, ls, ' ');
749 // Reasonable default values
754 recordUndo(cur, Undo::ATOMIC);
755 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
759 case LFUN_SPACE_INSERT:
760 case LFUN_MATH_SPACE:
761 recordUndo(cur, Undo::ATOMIC);
762 cur.insert(MathAtom(new MathSpaceInset(",")));
766 // interpret this as if a backslash was typed
767 recordUndo(cur, Undo::ATOMIC);
768 interpret(cur, '\\');
771 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
772 // handling such that "self-insert" works on "arbitrary stuff" too, and
773 // math-insert only handles special math things like "matrix".
774 case LFUN_INSERT_MATH:
775 recordUndo(cur, Undo::ATOMIC);
776 cur.niceInsert(cmd.argument);
779 case LFUN_DIALOG_SHOW_NEW_INSET: {
780 string const & name = cmd.argument;
785 data = tmp.createDialogStr(name);
788 cur.bv().owner()->getDialogs().show(name, data, 0);
792 case LFUN_INSET_APPLY: {
793 string const name = cmd.getArg(0);
794 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
797 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
798 base->dispatch(cur, fr);
802 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
815 case LFUN_WORD_REPLACE:
817 if (!searchForward(&cur.bv(), cmd.getArg(0), false, false))
824 BOOST_ASSERT(cur.inMathed());
826 if (result.dispatched()) {
828 cur.bv().stuffClipboard(cur.grabSelection());
831 cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
837 MathDimInset::priv_dispatch(cur, cmd);
843 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
844 FuncStatus & flag) const
846 // the font related toggles
847 //string tc = "mathnormal";
849 switch (cmd.action) {
851 case LFUN_TABULAR_FEATURE:
852 // FIXME: check temporarily disabled
854 char align = mathcursor::valign();
859 if (cmd.argument.empty()) {
863 if (!contains("tcb", cmd.argument[0])) {
867 flag.setOnOff(cmd.argument[0] == align);
870 flag.setOnOff(tc == "mathbf");
873 flag.setOnOff(tc == "mathsf");
876 flag.setOnOff(tc == "mathcal");
879 flag.setOnOff(tc == "mathrm");
882 flag.setOnOff(tc == "mathtt");
885 flag.setOnOff(tc == "mathbb");
888 flag.setOnOff(tc == "mathnormal");
891 case LFUN_MATH_MUTATE:
892 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
893 flag.setOnOff(false);
896 // we just need to be in math mode to enable that
898 case LFUN_MATH_SPACE:
899 case LFUN_MATH_LIMITS:
900 case LFUN_MATH_NONUMBER:
901 case LFUN_MATH_NUMBER:
902 case LFUN_MATH_EXTERN:
914 void MathNestInset::edit(LCursor & cur, bool left)
917 cur.idx() = left ? 0 : cur.lastidx();
918 cur.pos() = left ? 0 : cur.lastpos();
920 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
924 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
927 int dist_min = 1000000;
928 for (idx_type i = 0; i < nargs(); ++i) {
929 int d = cell(i).dist(x, y);
935 MathArray & ar = cell(idx_min);
938 cur.pos() = ar.x2pos(x - ar.xo());
939 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
942 for (pos_type i = 0, n = ar.size(); i < n; ++i)
943 if (ar[i]->covers(x, y))
944 return ar[i].nucleus()->editXY(cur, x, y);
950 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
952 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
954 if (cmd.button() == mouse_button::button1) {
955 // try to dispatch to enclosed insets first
956 //cur.bv().stuffClipboard(cur.grabSelection());
960 if (cmd.button() == mouse_button::button2) {
962 asArray(cur.bv().getClipboard(), ar);
964 cur.setScreenPos(cmd.x, cmd.y);
970 if (cmd.button() == mouse_button::button3) {
971 // try to dispatch to enclosed insets first
972 cur.bv().owner()->getDialogs().show("mathpanel");
980 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
982 lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
983 if (cmd.button() == mouse_button::button1) {
987 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
988 lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
989 cur.bv().cursor() = cur;
992 if (cmd.button() == mouse_button::button2) {
993 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
998 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
1000 // only select with button 1
1001 if (cmd.button() != mouse_button::button1)
1004 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
1010 if (!cur.selection())
1013 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
1014 cur.bv().cursor().setCursor(cur, true);
1018 bool MathNestInset::interpret(LCursor & cur, char c)
1020 lyxerr << "interpret 2: '" << c << "'" << endl;
1022 /// are we currently typing '#1' or '#2' or...?
1023 if (cur.pos() > 0 && cur.prevAtom()->getChar() == '#') {
1026 #ifdef WITH_WARNINGS
1031 MathMacroTemplate const * p = formula()->asMacroTemplate();
1032 if (p && 1 <= n && n <= p->numargs())
1033 cur.insert(MathAtom(new MathMacroArgument(c - '0')));
1035 cur.insert(createMathInset("#"));
1036 interpret(cur, c); // try again
1043 if (cur.inMacroMode()) {
1044 string name = cur.macroName();
1045 //lyxerr << "interpret name: '" << name << "'" << endl;
1048 cur.activeMacro()->setName(cur.activeMacro()->name() + c);
1052 // handle 'special char' macros
1057 if (currentMode() == MathInset::TEXT_MODE)
1058 cur.niceInsert(createMathInset("textbackslash"));
1060 cur.niceInsert(createMathInset("backslash"));
1061 } else if (c == '{') {
1062 cur.niceInsert(MathAtom(new MathBraceInset));
1064 cur.niceInsert(createMathInset(string(1, c)));
1069 // leave macro mode and try again if necessary
1070 cur.macroModeClose();
1072 cur.niceInsert(MathAtom(new MathBraceInset));
1078 // This is annoying as one has to press <space> far too often.
1082 // leave autocorrect mode if necessary
1083 if (autocorrect() && c == ' ') {
1084 autocorrect() = false;
1089 // just clear selection on pressing the space bar
1090 if (cur.selection() && c == ' ') {
1091 cur.selection() = false;
1095 cur.selClearOrDel();
1098 //lyxerr << "starting with macro" << endl;
1099 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1104 if (currentMode() == MathInset::TEXT_MODE)
1110 if (currentMode() == MathInset::TEXT_MODE) {
1111 // insert spaces in text mode,
1112 // but suppress direct insertion of two spaces in a row
1113 // the still allows typing '<space>a<space>' and deleting the 'a', but
1114 // it is better than nothing...
1115 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1119 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1120 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1125 // if are at the very end, leave the formula
1126 return cur.pos() != cur.lastpos();
1139 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1140 cur.niceInsert(createMathInset(string(1, c)));
1145 cur.niceInsert(MathAtom(new MathCommentInset));
1149 // try auto-correction
1150 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1153 // no special circumstances, so insert the character without any fuss
1155 cur.autocorrect() = true;
1160 bool MathNestInset::script(LCursor & cur, bool up)
1162 // Hack to get \\^ and \\_ working
1163 lyxerr << "handling script: up: " << up << endl;
1164 if (cur.inMacroMode() && cur.macroName() == "\\") {
1166 cur.niceInsert(createMathInset("mathcircumflex"));
1168 interpret(cur, '_');
1172 cur.macroModeClose();
1173 string safe = cur.grabAndEraseSelection();
1174 if (asScriptInset() && cur.idx() == 0) {
1175 // we are in a nucleus of a script inset, move to _our_ script
1176 MathScriptInset * inset = asScriptInset();
1177 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1179 cur.idx() = inset->idxOfScript(up);
1181 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1183 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1185 cur.idx() = inset->idxOfScript(up);
1186 cur.pos() = cur.lastpos();
1188 // convert the thing to our left to a scriptinset or create a new
1189 // one if in the very first position of the array
1190 if (cur.pos() == 0) {
1191 lyxerr << "new scriptinset" << endl;
1192 cur.insert(new MathScriptInset(up));
1194 lyxerr << "converting prev atom " << endl;
1195 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1197 lyxerr << "new scriptinset 2: cur:\n" << cur << endl;
1199 lyxerr << "new scriptinset 3: cur:\n" << cur << endl;
1200 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1201 lyxerr << "new scriptinset 3: inset:\n" << inset << endl;
1206 lyxerr << "pasting 1: safe:\n" << safe << endl;
1209 lyxerr << "pasting 2: safe:\n" << safe << endl;