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 //lyxerr << "MathNestInset::drawing selection: "
198 // << " x: " << x << " y: " << y << endl;
199 // this should use the x/y values given, not the cached values
200 LCursor & cur = pi.base.bv->cursor();
201 if (!cur.selection())
203 if (!ptr_cmp(&cur.inset(), this))
205 CursorSlice s1 = cur.selBegin();
206 CursorSlice s2 = cur.selEnd();
207 lyxerr << "MathNestInset::drawing selection: "
208 << " s1: " << s1 << " s2: " << s2 << endl;
209 if (s1.idx() == s2.idx()) {
210 MathArray const & c = cell(s1.idx());
211 int x1 = c.xo() + c.pos2x(s1.pos());
212 int y1 = c.yo() - c.ascent();
213 int x2 = c.xo() + c.pos2x(s2.pos());
214 int y2 = c.yo() + c.descent();
215 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
217 for (idx_type i = 0; i < nargs(); ++i) {
218 if (idxBetween(i, s1.idx(), s2.idx())) {
219 MathArray const & c = cell(i);
221 int y1 = c.yo() - c.ascent();
222 int x2 = c.xo() + c.width();
223 int y2 = c.yo() + c.descent();
224 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
231 void MathNestInset::validate(LaTeXFeatures & features) const
233 for (idx_type i = 0; i < nargs(); ++i)
234 cell(i).validate(features);
238 void MathNestInset::replace(ReplaceData & rep)
240 for (idx_type i = 0; i < nargs(); ++i)
241 cell(i).replace(rep);
245 bool MathNestInset::contains(MathArray const & ar) const
247 for (idx_type i = 0; i < nargs(); ++i)
248 if (cell(i).contains(ar))
254 bool MathNestInset::lock() const
260 void MathNestInset::lock(bool l)
266 bool MathNestInset::isActive() const
272 MathArray MathNestInset::glue() const
275 for (size_t i = 0; i < nargs(); ++i)
281 void MathNestInset::write(WriteStream & os) const
283 os << '\\' << name().c_str();
284 for (size_t i = 0; i < nargs(); ++i)
285 os << '{' << cell(i) << '}';
287 os.pendingSpace(true);
288 if (lock_ && !os.latex()) {
290 os.pendingSpace(true);
295 void MathNestInset::normalize(NormalStream & os) const
297 os << '[' << name().c_str();
298 for (size_t i = 0; i < nargs(); ++i)
299 os << ' ' << cell(i);
304 void MathNestInset::notifyCursorLeaves(LCursor & cur)
307 MathArray & ar = cur.cell();
308 // remove base-only "scripts"
309 for (pos_type i = 0; i + 1 < size(); ++i) {
310 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
311 if (p && p->cell(0).empty() && p->cell(1).empty()) {
312 MathArray ar = p->nuc();
315 mathcursor->adjust(i, ar.size() - 1);
319 // glue adjacent font insets of the same kind
320 for (pos_type i = 0; i + 1 < size(); ++i) {
321 MathFontInset * p = operator[](i).nucleus()->asFontInset();
322 MathFontInset const * q = operator[](i + 1)->asFontInset();
323 if (p && q && p->name() == q->name()) {
324 p->cell(0).append(q->cell(0));
326 mathcursor->adjust(i, -1);
333 void MathNestInset::handleFont
334 (LCursor & cur, string const & arg, string const & font)
336 // this whole function is a hack and won't work for incremental font
338 recordUndo(cur, Undo::ATOMIC);
340 if (cur.inset().asMathInset()->name() == font)
341 cur.handleFont(font);
343 cur.handleNest(createMathInset(font));
349 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
351 recordUndo(cur, Undo::ATOMIC);
354 bv_funcs::string2font(arg, font, b);
355 if (font.color() != LColor::inherit) {
356 MathAtom at = createMathInset("color");
357 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
358 cur.handleNest(at, 1);
363 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
365 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
366 //CursorSlice sl = cur.current();
368 switch (cmd.action) {
370 case LFUN_PASTESELECTION: {
372 mathed_parse_cell(ar, cur.bv().getClipboard());
373 cur.cell().insert(cur.pos(), ar);
374 cur.pos() += ar.size();
379 if (!cmd.argument.empty()) {
381 mathed_parse_cell(ar, cmd.argument);
382 cur.cell().insert(cur.pos(), ar);
383 cur.pos() += ar.size();
389 istringstream is(cmd.argument.c_str());
392 cur.macroModeClose();
393 recordUndo(cur, Undo::ATOMIC);
399 case LFUN_MOUSE_PRESS:
400 lfunMousePress(cur, cmd);
403 case LFUN_MOUSE_MOTION:
404 lfunMouseMotion(cur, cmd);
407 case LFUN_MOUSE_RELEASE:
408 lfunMouseRelease(cur, cmd);
411 case LFUN_FINISHED_LEFT:
412 cur.bv().cursor() = cur;
415 case LFUN_FINISHED_RIGHT:
417 cur.bv().cursor() = cur;
420 case LFUN_FINISHED_UP:
421 //idxUpDown(cur, true);
422 cur.bv().cursor() = cur;
425 case LFUN_FINISHED_DOWN:
426 //idxUpDown(cur, false);
427 cur.bv().cursor() = cur;
432 lyxerr << "mathnest RIGHT: from:\n" << cur << endl;
433 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
434 cur.autocorrect() = false;
436 if (cur.inMacroMode())
437 cur.macroModeClose();
438 else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
439 cur.pushLeft(*cur.nextAtom().nucleus());
440 cur.inset().idxFirst(cur);
441 } else if (cur.posRight() || idxRight(cur)
442 || cur.popRight() || cur.selection())
445 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
446 lyxerr << "mathnest RIGHT: to:\n" << cur << endl;
451 cur.selHandle(cmd.action == LFUN_LEFTSEL);
452 cur.autocorrect() = false;
454 if (cur.inMacroMode())
455 cur.macroModeClose();
456 else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
458 cur.push(*cur.nextAtom().nucleus());
459 cur.inset().idxLast(cur);
460 } else if (cur.posLeft() || idxLeft(cur)
461 || cur.popLeft() || cur.selection())
464 cmd = FuncRequest(LFUN_FINISHED_LEFT);
469 cur.selHandle(cmd.action == LFUN_UPSEL);
471 cmd = FuncRequest(LFUN_FINISHED_UP);
476 cur.selHandle(cmd.action == LFUN_DOWNSEL);
478 cmd = FuncRequest(LFUN_FINISHED_DOWN);
481 case LFUN_MOUSE_DOUBLE:
482 case LFUN_MOUSE_TRIPLE:
487 cur.selection() = true;
488 cur.pos() = cur.lastpos();
489 cur.idx() = cur.lastidx();
492 case LFUN_UP_PARAGRAPHSEL:
493 case LFUN_UP_PARAGRAPH:
494 case LFUN_DOWN_PARAGRAPHSEL:
495 case LFUN_DOWN_PARAGRAPH:
500 case LFUN_WORDLEFTSEL:
502 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
503 cur.macroModeClose();
504 if (cur.pos() != 0) {
506 } else if (cur.col() != 0) {
507 cur.idx() -= cur.col();
509 } else if (cur.idx() != 0) {
513 cmd = FuncRequest(LFUN_FINISHED_LEFT);
517 case LFUN_WORDRIGHTSEL:
521 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
522 cur.macroModeClose();
524 if (cur.pos() != cur.lastpos()) {
525 cur.pos() = cur.lastpos();
526 } else if (cur.col() != cur.lastcol()) {
527 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
528 cur.pos() = cur.lastpos();
529 } else if (cur.idx() != cur.lastidx()) {
530 cur.idx() = cur.lastidx();
531 cur.pos() = cur.lastpos();
533 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
539 case LFUN_BEGINNINGBUFSEL:
540 case LFUN_BEGINNINGBUF:
541 cmd = FuncRequest(LFUN_FINISHED_LEFT);
548 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
551 case LFUN_CELL_FORWARD:
552 cur.inset().idxNext(cur);
555 case LFUN_CELL_BACKWARD:
556 cur.inset().idxPrev(cur);
559 case LFUN_DELETE_WORD_BACKWARD:
561 recordUndo(cur, Undo::ATOMIC);
565 case LFUN_DELETE_WORD_FORWARD:
567 recordUndo(cur, Undo::ATOMIC);
569 cmd = FuncRequest(LFUN_FINISHED_LEFT);
576 cmd = FuncRequest(LFUN_FINISHED_LEFT);
579 case LFUN_INSET_TOGGLE:
581 if (cur.pos() != cur.lastpos()) {
582 // toggle previous inset ...
583 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
584 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
585 // ... or enclosing inset if we are in the last inset position
586 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
591 case LFUN_SELFINSERT:
592 if (cmd.argument.empty()) {
593 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
596 recordUndo(cur, Undo::ATOMIC);
597 if (cmd.argument.size() != 1) {
598 cur.insert(cmd.argument);
601 if (!interpret(cur, cmd.argument[0]))
602 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
607 // this needs to be incorporated
609 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
610 bool remove_inset = false;
612 DispatchResult result(true);
613 bool was_macro = cur.inMacroMode();
620 // sprintf(dispatch_buffer, "%d %d",);
621 // DispatchResult= dispatch_buffer;
624 lyxerr << "LFUN_SETXY broken!" << endl;
627 istringstream is(cmd.argument.c_str());
629 cur.setScreenPos(x, y);
634 recordUndo(cur, Undo::DELETE);
642 // Special casing for superscript in case of LyX handling
644 case LFUN_CIRCUMFLEX:
645 if (cmd.argument.empty()) {
646 // do superscript if LyX handles
648 recordUndo(cur, Undo::ATOMIC);
666 case LFUN_HUNG_UMLAUT:
670 case LFUN_FREEFONT_APPLY:
671 case LFUN_FREEFONT_UPDATE:
672 handleFont2(cur, cmd.argument);
676 handleFont(cur, cmd.argument, "mathbf");
679 handleFont(cur, cmd.argument, "mathsf");
682 handleFont(cur, cmd.argument, "mathcal");
685 handleFont(cur, cmd.argument, "mathrm");
688 handleFont(cur, cmd.argument, "texttt");
691 handleFont(cur, cmd.argument, "mathfrak");
694 handleFont(cur, cmd.argument, "mathit");
697 handleFont(cur, cmd.argument, "mathbb");
699 //case LFUN_FREEFONT_APPLY:
700 handleFont(cur, cmd.argument, "textrm");
703 handleFont(cur, cmd.argument, "textnormal");
708 cur.macroModeClose();
710 cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
712 cur.pushLeft(*cur.nextInset());
714 if (currentMode() == InsetBase::TEXT_MODE)
715 cur.niceInsert(MathAtom(new MathHullInset("simple")));
717 handleFont(cur, cmd.argument, "textrm");
718 //cur.owner()->message(_("math text mode toggled"));
725 recordUndo(cur, Undo::ATOMIC);
731 case LFUN_INSERT_MATRIX: {
732 recordUndo(cur, Undo::ATOMIC);
737 istringstream is(cmd.argument);
738 is >> m >> n >> v_align >> h_align;
745 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
749 case LFUN_MATH_DELIM: {
750 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
752 string rs = lyx::support::split(cmd.argument, ls, ' ');
753 // Reasonable default values
758 recordUndo(cur, Undo::ATOMIC);
759 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
763 case LFUN_SPACE_INSERT:
764 case LFUN_MATH_SPACE:
765 recordUndo(cur, Undo::ATOMIC);
766 cur.insert(MathAtom(new MathSpaceInset(",")));
770 // interpret this as if a backslash was typed
771 recordUndo(cur, Undo::ATOMIC);
772 interpret(cur, '\\');
775 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
776 // handling such that "self-insert" works on "arbitrary stuff" too, and
777 // math-insert only handles special math things like "matrix".
778 case LFUN_INSERT_MATH:
779 recordUndo(cur, Undo::ATOMIC);
780 cur.niceInsert(cmd.argument);
783 case LFUN_DIALOG_SHOW_NEW_INSET: {
784 string const & name = cmd.argument;
789 data = tmp.createDialogStr(name);
792 cur.bv().owner()->getDialogs().show(name, data, 0);
796 case LFUN_INSET_APPLY: {
797 string const name = cmd.getArg(0);
798 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
801 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
802 base->dispatch(cur, fr);
806 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
819 case LFUN_WORD_REPLACE:
821 if (!searchForward(&cur.bv(), cmd.getArg(0), false, false))
828 BOOST_ASSERT(cur.inMathed());
830 if (result.dispatched()) {
832 cur.bv().stuffClipboard(cur.grabSelection());
835 cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
841 MathDimInset::priv_dispatch(cur, cmd);
847 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
848 FuncStatus & flag) const
850 // the font related toggles
851 //string tc = "mathnormal";
853 switch (cmd.action) {
855 case LFUN_TABULAR_FEATURE:
856 // FIXME: check temporarily disabled
858 char align = mathcursor::valign();
863 if (cmd.argument.empty()) {
867 if (!contains("tcb", cmd.argument[0])) {
871 flag.setOnOff(cmd.argument[0] == align);
874 flag.setOnOff(tc == "mathbf");
877 flag.setOnOff(tc == "mathsf");
880 flag.setOnOff(tc == "mathcal");
883 flag.setOnOff(tc == "mathrm");
886 flag.setOnOff(tc == "mathtt");
889 flag.setOnOff(tc == "mathbb");
892 flag.setOnOff(tc == "mathnormal");
895 case LFUN_MATH_MUTATE:
896 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
897 flag.setOnOff(false);
900 // we just need to be in math mode to enable that
902 case LFUN_MATH_SPACE:
903 case LFUN_MATH_LIMITS:
904 case LFUN_MATH_NONUMBER:
905 case LFUN_MATH_NUMBER:
906 case LFUN_MATH_EXTERN:
918 void MathNestInset::edit(LCursor & cur, bool left)
921 cur.idx() = left ? 0 : cur.lastidx();
922 cur.pos() = left ? 0 : cur.lastpos();
924 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
928 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
931 int dist_min = 1000000;
932 for (idx_type i = 0; i < nargs(); ++i) {
933 int d = cell(i).dist(x, y);
939 MathArray & ar = cell(idx_min);
942 cur.pos() = ar.x2pos(x - ar.xo());
943 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
946 for (pos_type i = 0, n = ar.size(); i < n; ++i)
947 if (ar[i]->covers(x, y))
948 return ar[i].nucleus()->editXY(cur, x, y);
954 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
956 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
958 if (cmd.button() == mouse_button::button1) {
959 // try to dispatch to enclosed insets first
960 //cur.bv().stuffClipboard(cur.grabSelection());
964 if (cmd.button() == mouse_button::button2) {
966 asArray(cur.bv().getClipboard(), ar);
968 cur.setScreenPos(cmd.x, cmd.y);
974 if (cmd.button() == mouse_button::button3) {
975 // try to dispatch to enclosed insets first
976 cur.bv().owner()->getDialogs().show("mathpanel");
984 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
986 lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
987 if (cmd.button() == mouse_button::button1) {
991 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
992 lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
993 cur.bv().cursor() = cur;
996 if (cmd.button() == mouse_button::button2) {
997 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
1002 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
1004 // only select with button 1
1005 if (cmd.button() != mouse_button::button1)
1008 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
1014 if (!cur.selection())
1017 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
1018 cur.bv().cursor().setCursor(cur, true);
1022 bool MathNestInset::interpret(LCursor & cur, char c)
1024 lyxerr << "interpret 2: '" << c << "'" << endl;
1026 /// are we currently typing '#1' or '#2' or...?
1027 if (cur.pos() > 0 && cur.prevAtom()->getChar() == '#') {
1030 #ifdef WITH_WARNINGS
1035 MathMacroTemplate const * p = formula()->asMacroTemplate();
1036 if (p && 1 <= n && n <= p->numargs())
1037 cur.insert(MathAtom(new MathMacroArgument(c - '0')));
1039 cur.insert(createMathInset("#"));
1040 interpret(cur, c); // try again
1047 if (cur.inMacroMode()) {
1048 string name = cur.macroName();
1049 //lyxerr << "interpret name: '" << name << "'" << endl;
1052 cur.activeMacro()->setName(cur.activeMacro()->name() + c);
1056 // handle 'special char' macros
1061 if (currentMode() == MathInset::TEXT_MODE)
1062 cur.niceInsert(createMathInset("textbackslash"));
1064 cur.niceInsert(createMathInset("backslash"));
1065 } else if (c == '{') {
1066 cur.niceInsert(MathAtom(new MathBraceInset));
1068 cur.niceInsert(createMathInset(string(1, c)));
1073 // leave macro mode and try again if necessary
1074 cur.macroModeClose();
1076 cur.niceInsert(MathAtom(new MathBraceInset));
1082 // This is annoying as one has to press <space> far too often.
1086 // leave autocorrect mode if necessary
1087 if (autocorrect() && c == ' ') {
1088 autocorrect() = false;
1093 // just clear selection on pressing the space bar
1094 if (cur.selection() && c == ' ') {
1095 cur.selection() = false;
1099 cur.selClearOrDel();
1102 //lyxerr << "starting with macro" << endl;
1103 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1108 if (currentMode() == MathInset::TEXT_MODE)
1114 if (currentMode() == MathInset::TEXT_MODE) {
1115 // insert spaces in text mode,
1116 // but suppress direct insertion of two spaces in a row
1117 // the still allows typing '<space>a<space>' and deleting the 'a', but
1118 // it is better than nothing...
1119 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1123 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1124 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1129 // if are at the very end, leave the formula
1130 return cur.pos() != cur.lastpos();
1143 if (c == '{' || c == '}' || c == '#' || c == '&' || c == '$') {
1144 cur.niceInsert(createMathInset(string(1, c)));
1149 cur.niceInsert(MathAtom(new MathCommentInset));
1153 // try auto-correction
1154 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1157 // no special circumstances, so insert the character without any fuss
1159 cur.autocorrect() = true;
1164 bool MathNestInset::script(LCursor & cur, bool up)
1166 // Hack to get \\^ and \\_ working
1167 lyxerr << "handling script: up: " << up << endl;
1168 if (cur.inMacroMode() && cur.macroName() == "\\") {
1170 cur.niceInsert(createMathInset("mathcircumflex"));
1172 interpret(cur, '_');
1176 cur.macroModeClose();
1177 string safe = cur.grabAndEraseSelection();
1178 if (asScriptInset() && cur.idx() == 0) {
1179 // we are in a nucleus of a script inset, move to _our_ script
1180 MathScriptInset * inset = asScriptInset();
1181 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1183 cur.idx() = inset->idxOfScript(up);
1185 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1187 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1189 cur.idx() = inset->idxOfScript(up);
1190 cur.pos() = cur.lastpos();
1192 // convert the thing to our left to a scriptinset or create a new
1193 // one if in the very first position of the array
1194 if (cur.pos() == 0) {
1195 lyxerr << "new scriptinset" << endl;
1196 cur.insert(new MathScriptInset(up));
1198 lyxerr << "converting prev atom " << endl;
1199 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1201 lyxerr << "new scriptinset 2: cur:\n" << cur << endl;
1203 lyxerr << "new scriptinset 3: cur:\n" << cur << endl;
1204 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1205 lyxerr << "new scriptinset 3: inset:\n" << inset << endl;
1210 lyxerr << "pasting 1: safe:\n" << safe << endl;
1213 lyxerr << "pasting 2: safe:\n" << safe << endl;