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_macroarg.h"
24 #include "math_mboxinset.h"
25 #include "math_parser.h"
26 #include "math_scriptinset.h"
27 #include "math_spaceinset.h"
28 #include "math_symbolinset.h"
29 #include "math_support.h"
30 #include "math_unknowninset.h"
32 #include "BufferView.h"
33 #include "CutAndPaste.h"
34 #include "FuncStatus.h"
36 #include "bufferview_funcs.h"
39 #include "dispatchresult.h"
40 #include "funcrequest.h"
42 #include "outputparams.h"
45 #include "support/lstrings.h"
47 #include "frontends/Dialogs.h"
48 #include "frontends/LyXView.h"
49 #include "frontends/Painter.h"
53 using lyx::cap::copySelection;
54 using lyx::cap::grabAndEraseSelection;
55 using lyx::cap::cutSelection;
56 using lyx::cap::pasteSelection;
57 using lyx::cap::replaceSelection;
58 using lyx::cap::selClearOrDel;
62 using std::istringstream;
77 MathNestInset::MathNestInset(idx_type nargs)
78 : cells_(nargs), lock_(false)
82 MathInset::idx_type MathNestInset::nargs() const
88 MathArray & MathNestInset::cell(idx_type i)
94 MathArray const & MathNestInset::cell(idx_type i) const
100 void MathNestInset::getCursorPos(LCursor const & cur, int & x, int & y) const
102 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
103 MathArray const & ar = cur.cell();
104 x = ar.xo() + ar.pos2x(cur.pos());
105 y = ar.yo() + cur.bv().top_y();
106 // move cursor visually into empty cells ("blue rectangles");
107 if (cur.cell().empty())
112 void MathNestInset::metrics(MetricsInfo const & mi) const
115 for (idx_type i = 0; i < nargs(); ++i)
120 bool MathNestInset::idxNext(LCursor & cur) const
122 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
123 if (cur.idx() == cur.lastidx())
131 bool MathNestInset::idxRight(LCursor & cur) const
137 bool MathNestInset::idxPrev(LCursor & cur) const
139 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
143 cur.pos() = cur.lastpos();
148 bool MathNestInset::idxLeft(LCursor & cur) const
154 bool MathNestInset::idxFirst(LCursor & cur) const
156 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
165 bool MathNestInset::idxLast(LCursor & cur) const
167 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
170 cur.idx() = cur.lastidx();
171 cur.pos() = cur.lastpos();
176 void MathNestInset::dump() const
178 WriteStream os(lyxerr);
179 os << "---------------------------------------------\n";
182 for (idx_type i = 0; i < nargs(); ++i)
183 os << cell(i) << "\n";
184 os << "---------------------------------------------\n";
188 void MathNestInset::draw(PainterInfo & pi, int x, int y) const
192 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
195 setPosCache(pi, x, y);
199 void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
201 // this should use the x/y values given, not the cached values
202 LCursor & cur = pi.base.bv->cursor();
203 if (!cur.selection())
205 if (!ptr_cmp(&cur.inset(), this))
207 CursorSlice s1 = cur.selBegin();
208 CursorSlice s2 = cur.selEnd();
209 //lyxerr << "MathNestInset::drawing selection: "
210 // << " s1: " << s1 << " s2: " << s2 << endl;
211 if (s1.idx() == s2.idx()) {
212 MathArray const & c = cell(s1.idx());
213 int x1 = c.xo() + c.pos2x(s1.pos());
214 int y1 = c.yo() - c.ascent();
215 int x2 = c.xo() + c.pos2x(s2.pos());
216 int y2 = c.yo() + c.descent();
217 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
218 //lyxerr << "MathNestInset::drawing selection 3: "
219 // << " x1: " << x1 << " x2: " << x2
220 // << " y1: " << y1 << " y2: " << y2 << endl;
222 for (idx_type i = 0; i < nargs(); ++i) {
223 if (idxBetween(i, s1.idx(), s2.idx())) {
224 MathArray const & c = cell(i);
226 int y1 = c.yo() - c.ascent();
227 int x2 = c.xo() + c.width();
228 int y2 = c.yo() + c.descent();
229 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
236 void MathNestInset::validate(LaTeXFeatures & features) const
238 for (idx_type i = 0; i < nargs(); ++i)
239 cell(i).validate(features);
243 void MathNestInset::replace(ReplaceData & rep)
245 for (idx_type i = 0; i < nargs(); ++i)
246 cell(i).replace(rep);
250 bool MathNestInset::contains(MathArray const & ar) const
252 for (idx_type i = 0; i < nargs(); ++i)
253 if (cell(i).contains(ar))
259 bool MathNestInset::lock() const
265 void MathNestInset::lock(bool l)
271 bool MathNestInset::isActive() const
277 MathArray MathNestInset::glue() const
280 for (size_t i = 0; i < nargs(); ++i)
286 void MathNestInset::write(WriteStream & os) const
288 os << '\\' << name().c_str();
289 for (size_t i = 0; i < nargs(); ++i)
290 os << '{' << cell(i) << '}';
292 os.pendingSpace(true);
293 if (lock_ && !os.latex()) {
295 os.pendingSpace(true);
300 void MathNestInset::normalize(NormalStream & os) const
302 os << '[' << name().c_str();
303 for (size_t i = 0; i < nargs(); ++i)
304 os << ' ' << cell(i);
309 int MathNestInset::latex(Buffer const &, std::ostream & os,
310 OutputParams const & runparams) const
312 WriteStream wi(os, runparams.moving_arg, true);
318 void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/)
324 MathArray & ar = cur.cell();
325 // remove base-only "scripts"
326 for (pos_type i = 0; i + 1 < ar.size(); ++i) {
327 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
328 if (p && p->nargs() == 1) {
329 MathArray ar = p->nuc();
332 cur.adjust(i, ar.size() - 1);
336 // glue adjacent font insets of the same kind
337 for (pos_type i = 0; i + 1 < size(); ++i) {
338 MathFontInset * p = operator[](i).nucleus()->asFontInset();
339 MathFontInset const * q = operator[](i + 1)->asFontInset();
340 if (p && q && p->name() == q->name()) {
341 p->cell(0).append(q->cell(0));
350 void MathNestInset::handleFont
351 (LCursor & cur, string const & arg, string const & font)
353 // this whole function is a hack and won't work for incremental font
355 recordUndo(cur, Undo::ATOMIC);
357 if (cur.inset().asMathInset()->name() == font)
358 cur.handleFont(font);
360 cur.handleNest(createMathInset(font));
366 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
368 recordUndo(cur, Undo::ATOMIC);
371 bv_funcs::string2font(arg, font, b);
372 if (font.color() != LColor::inherit) {
373 MathAtom at = createMathInset("color");
374 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
375 cur.handleNest(at, 1);
380 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
382 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
383 //CursorSlice sl = cur.current();
385 switch (cmd.action) {
389 cur.message(_("Paste"));
390 replaceSelection(cur);
392 istringstream is(cmd.argument.c_str());
394 pasteSelection(cur, n);
395 cur.clearSelection(); // bug 393
396 cur.bv().switchKeyMap();
402 cutSelection(cur, true, true);
403 cur.message(_("Cut"));
408 cur.message(_("Copy"));
411 case LFUN_MOUSE_PRESS:
412 lfunMousePress(cur, cmd);
415 case LFUN_MOUSE_MOTION:
416 lfunMouseMotion(cur, cmd);
419 case LFUN_MOUSE_RELEASE:
420 lfunMouseRelease(cur, cmd);
423 case LFUN_FINISHED_LEFT:
424 cur.bv().cursor() = cur;
427 case LFUN_FINISHED_RIGHT:
429 cur.bv().cursor() = cur;
432 case LFUN_FINISHED_UP:
433 cur.bv().cursor() = cur;
436 case LFUN_FINISHED_DOWN:
437 cur.bv().cursor() = cur;
442 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
443 cur.autocorrect() = false;
445 if (cur.inMacroMode())
446 cur.macroModeClose();
447 else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
448 cur.pushLeft(*cur.nextAtom().nucleus());
449 cur.inset().idxFirst(cur);
450 } else if (cur.posRight() || idxRight(cur)
451 || cur.popRight() || cur.selection())
454 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
459 cur.selHandle(cmd.action == LFUN_LEFTSEL);
460 cur.autocorrect() = false;
462 if (cur.inMacroMode())
463 cur.macroModeClose();
464 else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
466 cur.push(*cur.nextAtom().nucleus());
467 cur.inset().idxLast(cur);
468 } else if (cur.posLeft() || idxLeft(cur)
469 || cur.popLeft() || cur.selection())
472 cmd = FuncRequest(LFUN_FINISHED_LEFT);
477 cur.selHandle(cmd.action == LFUN_UPSEL);
479 cmd = FuncRequest(LFUN_FINISHED_UP);
484 cur.selHandle(cmd.action == LFUN_DOWNSEL);
486 cmd = FuncRequest(LFUN_FINISHED_DOWN);
489 case LFUN_MOUSE_DOUBLE:
490 case LFUN_MOUSE_TRIPLE:
495 cur.selection() = true;
496 cur.pos() = cur.lastpos();
497 cur.idx() = cur.lastidx();
500 case LFUN_UP_PARAGRAPHSEL:
501 case LFUN_UP_PARAGRAPH:
502 case LFUN_DOWN_PARAGRAPHSEL:
503 case LFUN_DOWN_PARAGRAPH:
508 case LFUN_WORDLEFTSEL:
510 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
511 cur.macroModeClose();
512 if (cur.pos() != 0) {
514 } else if (cur.col() != 0) {
515 cur.idx() -= cur.col();
517 } else if (cur.idx() != 0) {
521 cmd = FuncRequest(LFUN_FINISHED_LEFT);
525 case LFUN_WORDRIGHTSEL:
529 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
530 cur.macroModeClose();
532 if (cur.pos() != cur.lastpos()) {
533 cur.pos() = cur.lastpos();
534 } else if (cur.col() != cur.lastcol()) {
535 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
536 cur.pos() = cur.lastpos();
537 } else if (cur.idx() != cur.lastidx()) {
538 cur.idx() = cur.lastidx();
539 cur.pos() = cur.lastpos();
541 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
547 case LFUN_BEGINNINGBUFSEL:
548 case LFUN_BEGINNINGBUF:
549 cmd = FuncRequest(LFUN_FINISHED_LEFT);
556 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
559 case LFUN_CELL_FORWARD:
560 cur.inset().idxNext(cur);
563 case LFUN_CELL_BACKWARD:
564 cur.inset().idxPrev(cur);
567 case LFUN_DELETE_WORD_BACKWARD:
569 recordUndo(cur, Undo::ATOMIC);
573 case LFUN_DELETE_WORD_FORWARD:
577 cmd = FuncRequest(LFUN_FINISHED_LEFT);
582 cur.clearSelection();
584 cmd = FuncRequest(LFUN_FINISHED_LEFT);
587 case LFUN_INSET_TOGGLE:
590 if (cur.pos() != cur.lastpos()) {
591 // toggle previous inset ...
592 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
593 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
594 // ... or enclosing inset if we are in the last inset position
595 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
600 case LFUN_SELFINSERT:
602 if (cmd.argument.size() != 1) {
603 cur.insert(cmd.argument);
606 if (!interpret(cur, cmd.argument[0]))
607 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
611 // sprintf(dispatch_buffer, "%d %d",);
615 lyxerr << "LFUN_SETXY broken!" << endl;
618 istringstream is(cmd.argument.c_str());
620 cur.setScreenPos(x, y);
624 // Special casing for superscript in case of LyX handling
626 case LFUN_CIRCUMFLEX:
627 if (cmd.argument.empty()) {
628 // do superscript if LyX handles
630 recordUndo(cur, Undo::ATOMIC);
648 case LFUN_HUNG_UMLAUT:
652 case LFUN_FREEFONT_APPLY:
653 case LFUN_FREEFONT_UPDATE:
654 handleFont2(cur, cmd.argument);
658 handleFont(cur, cmd.argument, "mathbf");
661 handleFont(cur, cmd.argument, "mathsf");
664 handleFont(cur, cmd.argument, "mathcal");
667 handleFont(cur, cmd.argument, "mathrm");
670 handleFont(cur, cmd.argument, "texttt");
673 handleFont(cur, cmd.argument, "mathfrak");
676 handleFont(cur, cmd.argument, "mathit");
679 handleFont(cur, cmd.argument, "mathbb");
681 //case LFUN_FREEFONT_APPLY:
682 handleFont(cur, cmd.argument, "textrm");
685 handleFont(cur, cmd.argument, "textnormal");
690 cur.macroModeClose();
692 cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
694 cur.pushLeft(*cur.nextInset());
696 if (currentMode() == InsetBase::TEXT_MODE) {
697 cur.niceInsert(MathAtom(new MathHullInset("simple")));
698 cur.message(_("create new math text environment ($...$)"));
700 handleFont(cur, cmd.argument, "textrm");
701 cur.message(_("entered math text mode (textrm)"));
713 case LFUN_INSERT_MATRIX: {
714 recordUndo(cur, Undo::ATOMIC);
719 istringstream is(cmd.argument);
720 is >> m >> n >> v_align >> h_align;
727 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
731 case LFUN_MATH_DELIM: {
732 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
734 string rs = lyx::support::split(cmd.argument, ls, ' ');
735 // Reasonable default values
740 recordUndo(cur, Undo::ATOMIC);
741 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
745 case LFUN_SPACE_INSERT:
746 case LFUN_MATH_SPACE:
747 recordUndo(cur, Undo::ATOMIC);
748 cur.insert(MathAtom(new MathSpaceInset(",")));
752 // interpret this as if a backslash was typed
753 recordUndo(cur, Undo::ATOMIC);
754 interpret(cur, '\\');
757 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
758 // handling such that "self-insert" works on "arbitrary stuff" too, and
759 // math-insert only handles special math things like "matrix".
760 case LFUN_INSERT_MATH:
761 recordUndo(cur, Undo::ATOMIC);
762 cur.niceInsert(cmd.argument);
765 case LFUN_DIALOG_SHOW_NEW_INSET: {
766 string const & name = cmd.argument;
771 data = tmp.createDialogStr(name);
774 cur.bv().owner()->getDialogs().show(name, data, 0);
778 case LFUN_INSET_APPLY: {
779 string const name = cmd.getArg(0);
780 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
783 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
784 base->dispatch(cur, fr);
788 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
797 MathDimInset::priv_dispatch(cur, cmd);
803 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
804 FuncStatus & flag) const
806 // the font related toggles
807 //string tc = "mathnormal";
809 switch (cmd.action) {
811 case LFUN_TABULAR_FEATURE:
812 // FIXME: check temporarily disabled
814 char align = mathcursor::valign();
819 if (cmd.argument.empty()) {
823 if (!contains("tcb", cmd.argument[0])) {
827 flag.setOnOff(cmd.argument[0] == align);
830 flag.setOnOff(tc == "mathbf");
833 flag.setOnOff(tc == "mathsf");
836 flag.setOnOff(tc == "mathcal");
839 flag.setOnOff(tc == "mathrm");
842 flag.setOnOff(tc == "mathtt");
845 flag.setOnOff(tc == "mathbb");
848 flag.setOnOff(tc == "mathnormal");
851 case LFUN_MATH_MUTATE:
852 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
853 flag.setOnOff(false);
856 // we just need to be in math mode to enable that
858 case LFUN_MATH_SPACE:
859 case LFUN_MATH_LIMITS:
860 case LFUN_MATH_NONUMBER:
861 case LFUN_MATH_NUMBER:
862 case LFUN_MATH_EXTERN:
874 void MathNestInset::edit(LCursor & cur, bool left)
877 cur.idx() = left ? 0 : cur.lastidx();
878 cur.pos() = left ? 0 : cur.lastpos();
880 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
884 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
887 int dist_min = 1000000;
888 for (idx_type i = 0; i < nargs(); ++i) {
889 int d = cell(i).dist(x, y);
895 MathArray & ar = cell(idx_min);
898 cur.pos() = ar.x2pos(x - ar.xo());
899 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
902 for (pos_type i = 0, n = ar.size(); i < n; ++i)
903 if (ar[i]->covers(x, y))
904 return ar[i].nucleus()->editXY(cur, x, y);
910 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
912 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
914 if (cmd.button() == mouse_button::button1) {
915 // try to dispatch to enclosed insets first
916 //cur.bv().stuffClipboard(cur.grabSelection());
920 if (cmd.button() == mouse_button::button2) {
922 asArray(cur.bv().getClipboard(), ar);
923 cur.clearSelection();
924 cur.setScreenPos(cmd.x, cmd.y);
930 if (cmd.button() == mouse_button::button3) {
931 // try to dispatch to enclosed insets first
932 cur.bv().owner()->getDialogs().show("mathpanel");
940 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
942 lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
943 if (cmd.button() == mouse_button::button1) {
946 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
947 lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
949 cur.bv().cursor() = cur;
952 if (cmd.button() == mouse_button::button2) {
953 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
958 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
960 // only select with button 1
961 if (cmd.button() != mouse_button::button1)
964 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
970 cur.bv().cursor().setCursor(cur, true);
974 bool MathNestInset::interpret(LCursor & cur, char c)
976 lyxerr << "interpret 2: '" << c << "'" << endl;
980 if (cur.inMacroMode()) {
981 string name = cur.macroName();
982 lyxerr << "interpret macro name: '" << name << "'" << endl;
984 /// are we currently typing '#1' or '#2' or...?
988 if (n >= 1 && n <= 9)
989 cur.insert(new MathMacroArgument(n));
994 cur.activeMacro()->setName(name + c);
998 // handle 'special char' macros
1003 if (currentMode() == MathInset::TEXT_MODE)
1004 cur.niceInsert(createMathInset("textbackslash"));
1006 cur.niceInsert(createMathInset("backslash"));
1007 } else if (c == '{') {
1009 cur.niceInsert(MathAtom(new MathBraceInset));
1010 } else if (c == '%') {
1012 cur.niceInsert(MathAtom(new MathCommentInset));
1013 } else if (c == '#') {
1014 lyxerr << "setting name to " << name + c << endl;
1015 BOOST_ASSERT(cur.activeMacro());
1016 cur.activeMacro()->setName(name + c);
1017 lyxerr << "set name to " << name + c << endl;
1020 cur.niceInsert(createMathInset(string(1, c)));
1025 // leave macro mode and try again if necessary
1026 cur.macroModeClose();
1028 cur.niceInsert(MathAtom(new MathBraceInset));
1034 // This is annoying as one has to press <space> far too often.
1038 // leave autocorrect mode if necessary
1039 if (autocorrect() && c == ' ') {
1040 autocorrect() = false;
1045 // just clear selection on pressing the space bar
1046 if (cur.selection() && c == ' ') {
1047 cur.selection() = false;
1054 //lyxerr << "starting with macro" << endl;
1055 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1060 if (currentMode() == MathInset::TEXT_MODE)
1066 if (currentMode() == MathInset::TEXT_MODE) {
1067 // insert spaces in text mode,
1068 // but suppress direct insertion of two spaces in a row
1069 // the still allows typing '<space>a<space>' and deleting the 'a', but
1070 // it is better than nothing...
1071 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1075 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1076 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1081 // if are at the very end, leave the formula
1082 return cur.pos() != cur.lastpos();
1095 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%') {
1096 cur.niceInsert(createMathInset(string(1, c)));
1101 // cur.niceInsert(MathAtom(new MathCommentInset));
1105 // try auto-correction
1106 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1109 // no special circumstances, so insert the character without any fuss
1111 cur.autocorrect() = true;
1116 bool MathNestInset::script(LCursor & cur, bool up)
1118 // Hack to get \\^ and \\_ working
1119 lyxerr << "handling script: up: " << up << endl;
1120 if (cur.inMacroMode() && cur.macroName() == "\\") {
1122 cur.niceInsert(createMathInset("mathcircumflex"));
1124 interpret(cur, '_');
1128 cur.macroModeClose();
1129 string safe = grabAndEraseSelection(cur);
1130 if (asScriptInset() && cur.idx() == 0) {
1131 // we are in a nucleus of a script inset, move to _our_ script
1132 MathScriptInset * inset = asScriptInset();
1133 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1135 cur.idx() = inset->idxOfScript(up);
1137 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1139 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1141 cur.idx() = inset->idxOfScript(up);
1142 cur.pos() = cur.lastpos();
1144 // convert the thing to our left to a scriptinset or create a new
1145 // one if in the very first position of the array
1146 if (cur.pos() == 0) {
1147 lyxerr << "new scriptinset" << endl;
1148 cur.insert(new MathScriptInset(up));
1150 lyxerr << "converting prev atom " << endl;
1151 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1153 lyxerr << "new scriptinset 2: cur:\n" << cur << endl;
1155 lyxerr << "new scriptinset 3: cur:\n" << cur << endl;
1156 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1157 lyxerr << "new scriptinset 3: inset:\n" << inset << endl;
1162 lyxerr << "pasting 1: safe:\n" << safe << endl;
1165 lyxerr << "pasting 2: safe:\n" << safe << endl;