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 x, int y) const
201 // FIXME: hack to get position cache warm
204 // this should use the x/y values given, not the cached values
205 LCursor & cur = pi.base.bv->cursor();
206 if (!cur.selection())
208 if (!ptr_cmp(&cur.inset(), this))
210 CursorSlice s1 = cur.selBegin();
211 CursorSlice s2 = cur.selEnd();
212 //lyxerr << "MathNestInset::drawing selection: "
213 // << " s1: " << s1 << " s2: " << s2 << endl;
214 if (s1.idx() == s2.idx()) {
215 MathArray const & c = cell(s1.idx());
216 int x1 = c.xo() + c.pos2x(s1.pos());
217 int y1 = c.yo() - c.ascent();
218 int x2 = c.xo() + c.pos2x(s2.pos());
219 int y2 = c.yo() + c.descent();
220 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
221 //lyxerr << "MathNestInset::drawing selection 3: "
222 // << " x1: " << x1 << " x2: " << x2
223 // << " y1: " << y1 << " y2: " << y2 << endl;
225 for (idx_type i = 0; i < nargs(); ++i) {
226 if (idxBetween(i, s1.idx(), s2.idx())) {
227 MathArray const & c = cell(i);
229 int y1 = c.yo() - c.ascent();
230 int x2 = c.xo() + c.width();
231 int y2 = c.yo() + c.descent();
232 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
239 void MathNestInset::validate(LaTeXFeatures & features) const
241 for (idx_type i = 0; i < nargs(); ++i)
242 cell(i).validate(features);
246 void MathNestInset::replace(ReplaceData & rep)
248 for (idx_type i = 0; i < nargs(); ++i)
249 cell(i).replace(rep);
253 bool MathNestInset::contains(MathArray const & ar) const
255 for (idx_type i = 0; i < nargs(); ++i)
256 if (cell(i).contains(ar))
262 bool MathNestInset::lock() const
268 void MathNestInset::lock(bool l)
274 bool MathNestInset::isActive() const
280 MathArray MathNestInset::glue() const
283 for (size_t i = 0; i < nargs(); ++i)
289 void MathNestInset::write(WriteStream & os) const
291 os << '\\' << name().c_str();
292 for (size_t i = 0; i < nargs(); ++i)
293 os << '{' << cell(i) << '}';
295 os.pendingSpace(true);
296 if (lock_ && !os.latex()) {
298 os.pendingSpace(true);
303 void MathNestInset::normalize(NormalStream & os) const
305 os << '[' << name().c_str();
306 for (size_t i = 0; i < nargs(); ++i)
307 os << ' ' << cell(i);
312 int MathNestInset::latex(Buffer const &, std::ostream & os,
313 OutputParams const & runparams) const
315 WriteStream wi(os, runparams.moving_arg, true);
321 void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/)
327 MathArray & ar = cur.cell();
328 // remove base-only "scripts"
329 for (pos_type i = 0; i + 1 < ar.size(); ++i) {
330 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
331 if (p && p->nargs() == 1) {
332 MathArray ar = p->nuc();
335 cur.adjust(i, ar.size() - 1);
339 // glue adjacent font insets of the same kind
340 for (pos_type i = 0; i + 1 < size(); ++i) {
341 MathFontInset * p = operator[](i).nucleus()->asFontInset();
342 MathFontInset const * q = operator[](i + 1)->asFontInset();
343 if (p && q && p->name() == q->name()) {
344 p->cell(0).append(q->cell(0));
353 void MathNestInset::handleFont
354 (LCursor & cur, string const & arg, string const & font)
356 // this whole function is a hack and won't work for incremental font
358 recordUndo(cur, Undo::ATOMIC);
360 if (cur.inset().asMathInset()->name() == font)
361 cur.handleFont(font);
363 cur.handleNest(createMathInset(font));
369 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
371 recordUndo(cur, Undo::ATOMIC);
374 bv_funcs::string2font(arg, font, b);
375 if (font.color() != LColor::inherit) {
376 MathAtom at = createMathInset("color");
377 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
378 cur.handleNest(at, 1);
383 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
385 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
386 //CursorSlice sl = cur.current();
388 switch (cmd.action) {
392 cur.message(_("Paste"));
393 replaceSelection(cur);
395 istringstream is(cmd.argument);
397 pasteSelection(cur, n);
398 cur.clearSelection(); // bug 393
399 cur.bv().switchKeyMap();
405 cutSelection(cur, true, true);
406 cur.message(_("Cut"));
411 cur.message(_("Copy"));
414 case LFUN_MOUSE_PRESS:
415 lfunMousePress(cur, cmd);
418 case LFUN_MOUSE_MOTION:
419 lfunMouseMotion(cur, cmd);
422 case LFUN_MOUSE_RELEASE:
423 lfunMouseRelease(cur, cmd);
426 case LFUN_FINISHED_LEFT:
427 cur.bv().cursor() = cur;
430 case LFUN_FINISHED_RIGHT:
432 cur.bv().cursor() = cur;
435 case LFUN_FINISHED_UP:
436 cur.bv().cursor() = cur;
439 case LFUN_FINISHED_DOWN:
440 cur.bv().cursor() = cur;
445 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
446 cur.autocorrect() = false;
448 cur.macroModeClose();
449 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);
461 cur.selHandle(cmd.action == LFUN_LEFTSEL);
462 cur.autocorrect() = false;
464 cur.macroModeClose();
465 if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
467 cur.push(*cur.nextAtom().nucleus());
468 cur.inset().idxLast(cur);
469 } else if (cur.posLeft() || idxLeft(cur)
470 || cur.popLeft() || cur.selection())
473 cmd = FuncRequest(LFUN_FINISHED_LEFT);
478 cur.selHandle(cmd.action == LFUN_UPSEL);
480 cmd = FuncRequest(LFUN_FINISHED_UP);
485 cur.selHandle(cmd.action == LFUN_DOWNSEL);
487 cmd = FuncRequest(LFUN_FINISHED_DOWN);
490 case LFUN_MOUSE_DOUBLE:
491 case LFUN_MOUSE_TRIPLE:
496 cur.selection() = true;
497 cur.pos() = cur.lastpos();
498 cur.idx() = cur.lastidx();
501 case LFUN_UP_PARAGRAPHSEL:
502 case LFUN_UP_PARAGRAPH:
503 case LFUN_DOWN_PARAGRAPHSEL:
504 case LFUN_DOWN_PARAGRAPH:
509 case LFUN_WORDLEFTSEL:
511 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
512 cur.macroModeClose();
513 if (cur.pos() != 0) {
515 } else if (cur.col() != 0) {
516 cur.idx() -= cur.col();
518 } else if (cur.idx() != 0) {
522 cmd = FuncRequest(LFUN_FINISHED_LEFT);
526 case LFUN_WORDRIGHTSEL:
530 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
531 cur.macroModeClose();
533 if (cur.pos() != cur.lastpos()) {
534 cur.pos() = cur.lastpos();
535 } else if (cur.col() != cur.lastcol()) {
536 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
537 cur.pos() = cur.lastpos();
538 } else if (cur.idx() != cur.lastidx()) {
539 cur.idx() = cur.lastidx();
540 cur.pos() = cur.lastpos();
542 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
548 cmd = FuncRequest(LFUN_FINISHED_LEFT);
553 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
556 case LFUN_CELL_FORWARD:
557 cur.inset().idxNext(cur);
560 case LFUN_CELL_BACKWARD:
561 cur.inset().idxPrev(cur);
564 case LFUN_DELETE_WORD_BACKWARD:
566 recordUndo(cur, Undo::ATOMIC);
570 case LFUN_DELETE_WORD_FORWARD:
574 cmd = FuncRequest(LFUN_FINISHED_LEFT);
579 cur.clearSelection();
581 cmd = FuncRequest(LFUN_FINISHED_LEFT);
584 case LFUN_INSET_TOGGLE:
587 if (cur.pos() != cur.lastpos()) {
588 // toggle previous inset ...
589 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
590 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
591 // ... or enclosing inset if we are in the last inset position
592 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
597 case LFUN_SELFINSERT:
599 if (cmd.argument.size() != 1) {
600 cur.insert(cmd.argument);
603 if (!interpret(cur, cmd.argument[0]))
604 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
608 // sprintf(dispatch_buffer, "%d %d",);
612 lyxerr << "LFUN_SETXY broken!" << endl;
615 istringstream is(cmd.argument);
617 cur.setScreenPos(x, y);
621 // Special casing for superscript in case of LyX handling
623 case LFUN_CIRCUMFLEX:
624 if (cmd.argument.empty()) {
625 // do superscript if LyX handles
627 recordUndo(cur, Undo::ATOMIC);
645 case LFUN_HUNG_UMLAUT:
649 case LFUN_FREEFONT_APPLY:
650 case LFUN_FREEFONT_UPDATE:
651 handleFont2(cur, cmd.argument);
655 handleFont(cur, cmd.argument, "mathbf");
658 handleFont(cur, cmd.argument, "mathsf");
661 handleFont(cur, cmd.argument, "mathcal");
664 handleFont(cur, cmd.argument, "mathrm");
667 handleFont(cur, cmd.argument, "texttt");
670 handleFont(cur, cmd.argument, "mathfrak");
673 handleFont(cur, cmd.argument, "mathit");
676 handleFont(cur, cmd.argument, "mathbb");
678 //case LFUN_FREEFONT_APPLY:
679 handleFont(cur, cmd.argument, "textrm");
682 handleFont(cur, cmd.argument, "textnormal");
687 // ignore math-mode on when already in math mode
688 if (currentMode() == InsetBase::MATH_MODE && cmd.argument == "on")
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) const
887 int dist_min = 1000000;
888 for (idx_type i = 0; i < nargs(); ++i) {
889 int d = cell(i).dist(x, y);
895 MathArray const & ar = cell(idx_min);
896 cur.push(const_cast<MathNestInset&>(*this));
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);
906 return const_cast<MathNestInset*>(this);
910 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
912 lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
913 if (cmd.button() == mouse_button::button1) {
916 lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
918 cur.bv().cursor() = cur;
921 if (cmd.button() == mouse_button::button2) {
922 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
927 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
929 // only select with button 1
930 if (cmd.button() == mouse_button::button1) {
931 LCursor & bvcur = cur.bv().cursor();
932 if (abs(cmd.x - first_x) + abs(cmd.y - first_y) > 4
933 && bvcur.anchor_.hasPart(cur)) {
937 bvcur.setCursor(cur);
938 bvcur.selection() = true;
944 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
946 lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
948 if (cmd.button() == mouse_button::button1) {
949 //cur.bv().stuffClipboard(cur.grabSelection());
953 if (cmd.button() == mouse_button::button2) {
955 asArray(cur.bv().getClipboard(), ar);
956 cur.clearSelection();
957 cur.setScreenPos(cmd.x, cmd.y);
963 if (cmd.button() == mouse_button::button3) {
964 // try to dispatch to enclosed insets first
965 cur.bv().owner()->getDialogs().show("mathpanel");
973 bool MathNestInset::interpret(LCursor & cur, char c)
975 lyxerr << "interpret 2: '" << c << "'" << endl;
979 if (cur.inMacroMode()) {
980 string name = cur.macroName();
982 /// are we currently typing '#1' or '#2' or...?
986 if (n >= 1 && n <= 9)
987 cur.insert(new MathMacroArgument(n));
992 cur.activeMacro()->setName(name + c);
996 // handle 'special char' macros
1001 if (currentMode() == MathInset::TEXT_MODE)
1002 cur.niceInsert(createMathInset("textbackslash"));
1004 cur.niceInsert(createMathInset("backslash"));
1005 } else if (c == '{') {
1007 cur.niceInsert(MathAtom(new MathBraceInset));
1008 } else if (c == '%') {
1010 cur.niceInsert(MathAtom(new MathCommentInset));
1011 } else if (c == '#') {
1012 BOOST_ASSERT(cur.activeMacro());
1013 cur.activeMacro()->setName(name + c);
1016 cur.niceInsert(createMathInset(string(1, c)));
1021 // leave macro mode and try again if necessary
1022 cur.macroModeClose();
1024 cur.niceInsert(MathAtom(new MathBraceInset));
1030 // This is annoying as one has to press <space> far too often.
1034 // leave autocorrect mode if necessary
1035 if (autocorrect() && c == ' ') {
1036 autocorrect() = false;
1041 // just clear selection on pressing the space bar
1042 if (cur.selection() && c == ' ') {
1043 cur.selection() = false;
1050 //lyxerr << "starting with macro" << endl;
1051 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1056 if (currentMode() == MathInset::TEXT_MODE)
1062 if (currentMode() == MathInset::TEXT_MODE) {
1063 // insert spaces in text mode,
1064 // but suppress direct insertion of two spaces in a row
1065 // the still allows typing '<space>a<space>' and deleting the 'a', but
1066 // it is better than nothing...
1067 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1071 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1072 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1077 // if are at the very end, leave the formula
1078 return cur.pos() != cur.lastpos();
1091 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%') {
1092 cur.niceInsert(createMathInset(string(1, c)));
1097 cur.niceInsert(createMathInset("sim"));
1101 // try auto-correction
1102 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1105 // no special circumstances, so insert the character without any fuss
1107 cur.autocorrect() = true;
1112 bool MathNestInset::script(LCursor & cur, bool up)
1114 // Hack to get \^ and \_ working
1115 lyxerr << "handling script: up: " << up << endl;
1116 if (cur.inMacroMode() && cur.macroName() == "\\") {
1118 cur.niceInsert(createMathInset("mathcircumflex"));
1120 interpret(cur, '_');
1124 cur.macroModeClose();
1125 string safe = grabAndEraseSelection(cur);
1126 if (asScriptInset() && cur.idx() == 0) {
1127 // we are in a nucleus of a script inset, move to _our_ script
1128 MathScriptInset * inset = asScriptInset();
1129 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1131 cur.idx() = inset->idxOfScript(up);
1133 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1135 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1137 cur.idx() = inset->idxOfScript(up);
1138 cur.pos() = cur.lastpos();
1140 // convert the thing to our left to a scriptinset or create a new
1141 // one if in the very first position of the array
1142 if (cur.pos() == 0) {
1143 lyxerr << "new scriptinset" << endl;
1144 cur.insert(new MathScriptInset(up));
1146 lyxerr << "converting prev atom " << endl;
1147 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1150 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1155 lyxerr << "pasting 1: safe:\n" << safe << endl;
1158 lyxerr << "pasting 2: safe:\n" << safe << endl;