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(LCursor const & cur, 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());
94 y = ar.yo() + cur.bv().top_y();
95 // move cursor visually into empty cells ("blue rectangles");
96 if (cur.cell().empty())
101 void MathNestInset::metrics(MetricsInfo const & mi) const
104 for (idx_type i = 0; i < nargs(); ++i)
109 bool MathNestInset::idxNext(LCursor & cur) const
111 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
112 if (cur.idx() == cur.lastidx())
120 bool MathNestInset::idxRight(LCursor & cur) const
126 bool MathNestInset::idxPrev(LCursor & cur) const
128 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
132 cur.pos() = cur.lastpos();
137 bool MathNestInset::idxLeft(LCursor & cur) const
143 bool MathNestInset::idxFirst(LCursor & cur) const
145 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
154 bool MathNestInset::idxLast(LCursor & cur) const
156 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
159 cur.idx() = cur.lastidx();
160 cur.pos() = cur.lastpos();
165 void MathNestInset::dump() const
167 WriteStream os(lyxerr);
168 os << "---------------------------------------------\n";
171 for (idx_type i = 0; i < nargs(); ++i)
172 os << cell(i) << "\n";
173 os << "---------------------------------------------\n";
177 void MathNestInset::draw(PainterInfo & pi, int x, int y) const
181 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
184 setPosCache(pi, x, y);
188 void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
190 // this should use the x/y values given, not the cached values
191 LCursor & cur = pi.base.bv->cursor();
192 if (!cur.selection())
194 if (!ptr_cmp(&cur.inset(), this))
196 CursorSlice s1 = cur.selBegin();
197 CursorSlice s2 = cur.selEnd();
198 lyxerr << "MathNestInset::drawing selection: "
199 << " s1: " << s1 << " s2: " << s2 << endl;
200 if (s1.idx() == s2.idx()) {
201 MathArray const & c = cell(s1.idx());
202 int x1 = c.xo() + c.pos2x(s1.pos());
203 int y1 = c.yo() - c.ascent();
204 int x2 = c.xo() + c.pos2x(s2.pos());
205 int y2 = c.yo() + c.descent();
206 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
207 lyxerr << "MathNestInset::drawing selection 3: "
208 << " x1: " << x1 << " x2: " << x2
209 << " y1: " << y1 << " y2: " << y2 << endl;
211 for (idx_type i = 0; i < nargs(); ++i) {
212 if (idxBetween(i, s1.idx(), s2.idx())) {
213 MathArray const & c = cell(i);
215 int y1 = c.yo() - c.ascent();
216 int x2 = c.xo() + c.width();
217 int y2 = c.yo() + c.descent();
218 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
225 void MathNestInset::validate(LaTeXFeatures & features) const
227 for (idx_type i = 0; i < nargs(); ++i)
228 cell(i).validate(features);
232 void MathNestInset::replace(ReplaceData & rep)
234 for (idx_type i = 0; i < nargs(); ++i)
235 cell(i).replace(rep);
239 bool MathNestInset::contains(MathArray const & ar) const
241 for (idx_type i = 0; i < nargs(); ++i)
242 if (cell(i).contains(ar))
248 bool MathNestInset::lock() const
254 void MathNestInset::lock(bool l)
260 bool MathNestInset::isActive() const
266 MathArray MathNestInset::glue() const
269 for (size_t i = 0; i < nargs(); ++i)
275 void MathNestInset::write(WriteStream & os) const
277 os << '\\' << name().c_str();
278 for (size_t i = 0; i < nargs(); ++i)
279 os << '{' << cell(i) << '}';
281 os.pendingSpace(true);
282 if (lock_ && !os.latex()) {
284 os.pendingSpace(true);
289 void MathNestInset::normalize(NormalStream & os) const
291 os << '[' << name().c_str();
292 for (size_t i = 0; i < nargs(); ++i)
293 os << ' ' << cell(i);
298 int MathNestInset::latex(Buffer const &, std::ostream & os,
299 OutputParams const & runparams) const
301 WriteStream wi(os, runparams.moving_arg, true);
307 void MathNestInset::notifyCursorLeaves(LCursor & cur)
311 MathArray & ar = cur.cell();
312 // remove base-only "scripts"
313 for (pos_type i = 0; i + 1 < size(); ++i) {
314 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
315 if (p && p->nargs() == 1) {
316 MathArray ar = p->nuc();
319 cur.adjust(i, ar.size() - 1);
323 // glue adjacent font insets of the same kind
324 for (pos_type i = 0; i + 1 < size(); ++i) {
325 MathFontInset * p = operator[](i).nucleus()->asFontInset();
326 MathFontInset const * q = operator[](i + 1)->asFontInset();
327 if (p && q && p->name() == q->name()) {
328 p->cell(0).append(q->cell(0));
337 void MathNestInset::handleFont
338 (LCursor & cur, string const & arg, string const & font)
340 // this whole function is a hack and won't work for incremental font
342 recordUndo(cur, Undo::ATOMIC);
344 if (cur.inset().asMathInset()->name() == font)
345 cur.handleFont(font);
347 cur.handleNest(createMathInset(font));
353 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
355 recordUndo(cur, Undo::ATOMIC);
358 bv_funcs::string2font(arg, font, b);
359 if (font.color() != LColor::inherit) {
360 MathAtom at = createMathInset("color");
361 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
362 cur.handleNest(at, 1);
367 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
369 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
370 //CursorSlice sl = cur.current();
372 switch (cmd.action) {
374 case LFUN_PASTESELECTION: {
376 mathed_parse_cell(ar, cur.bv().getClipboard());
377 cur.cell().insert(cur.pos(), ar);
378 cur.pos() += ar.size();
383 if (!cmd.argument.empty()) {
385 mathed_parse_cell(ar, cmd.argument);
386 cur.cell().insert(cur.pos(), ar);
387 cur.pos() += ar.size();
393 istringstream is(cmd.argument.c_str());
396 cur.macroModeClose();
397 recordUndo(cur, Undo::ATOMIC);
403 case LFUN_MOUSE_PRESS:
404 lfunMousePress(cur, cmd);
407 case LFUN_MOUSE_MOTION:
408 lfunMouseMotion(cur, cmd);
411 case LFUN_MOUSE_RELEASE:
412 lfunMouseRelease(cur, cmd);
415 case LFUN_FINISHED_LEFT:
416 cur.bv().cursor() = cur;
419 case LFUN_FINISHED_RIGHT:
421 cur.bv().cursor() = cur;
424 case LFUN_FINISHED_UP:
425 //idxUpDown(cur, true);
426 cur.bv().cursor() = cur;
429 case LFUN_FINISHED_DOWN:
430 //idxUpDown(cur, false);
431 cur.bv().cursor() = cur;
436 lyxerr << "mathnest RIGHT: from:\n" << cur << endl;
437 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
438 cur.autocorrect() = false;
440 if (cur.inMacroMode())
441 cur.macroModeClose();
442 else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
443 cur.pushLeft(*cur.nextAtom().nucleus());
444 cur.inset().idxFirst(cur);
445 } else if (cur.posRight() || idxRight(cur)
446 || cur.popRight() || cur.selection())
449 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
450 lyxerr << "mathnest RIGHT: to:\n" << cur << endl;
455 cur.selHandle(cmd.action == LFUN_LEFTSEL);
456 cur.autocorrect() = false;
458 if (cur.inMacroMode())
459 cur.macroModeClose();
460 else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
462 cur.push(*cur.nextAtom().nucleus());
463 cur.inset().idxLast(cur);
464 } else if (cur.posLeft() || idxLeft(cur)
465 || cur.popLeft() || cur.selection())
468 cmd = FuncRequest(LFUN_FINISHED_LEFT);
473 cur.selHandle(cmd.action == LFUN_UPSEL);
475 cmd = FuncRequest(LFUN_FINISHED_UP);
480 cur.selHandle(cmd.action == LFUN_DOWNSEL);
482 cmd = FuncRequest(LFUN_FINISHED_DOWN);
485 case LFUN_MOUSE_DOUBLE:
486 case LFUN_MOUSE_TRIPLE:
491 cur.selection() = true;
492 cur.pos() = cur.lastpos();
493 cur.idx() = cur.lastidx();
496 case LFUN_UP_PARAGRAPHSEL:
497 case LFUN_UP_PARAGRAPH:
498 case LFUN_DOWN_PARAGRAPHSEL:
499 case LFUN_DOWN_PARAGRAPH:
504 case LFUN_WORDLEFTSEL:
506 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
507 cur.macroModeClose();
508 if (cur.pos() != 0) {
510 } else if (cur.col() != 0) {
511 cur.idx() -= cur.col();
513 } else if (cur.idx() != 0) {
517 cmd = FuncRequest(LFUN_FINISHED_LEFT);
521 case LFUN_WORDRIGHTSEL:
525 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
526 cur.macroModeClose();
528 if (cur.pos() != cur.lastpos()) {
529 cur.pos() = cur.lastpos();
530 } else if (cur.col() != cur.lastcol()) {
531 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
532 cur.pos() = cur.lastpos();
533 } else if (cur.idx() != cur.lastidx()) {
534 cur.idx() = cur.lastidx();
535 cur.pos() = cur.lastpos();
537 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
543 case LFUN_BEGINNINGBUFSEL:
544 case LFUN_BEGINNINGBUF:
545 cmd = FuncRequest(LFUN_FINISHED_LEFT);
552 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
555 case LFUN_CELL_FORWARD:
556 cur.inset().idxNext(cur);
559 case LFUN_CELL_BACKWARD:
560 cur.inset().idxPrev(cur);
563 case LFUN_DELETE_WORD_BACKWARD:
565 recordUndo(cur, Undo::ATOMIC);
569 case LFUN_DELETE_WORD_FORWARD:
571 recordUndo(cur, Undo::ATOMIC);
573 cmd = FuncRequest(LFUN_FINISHED_LEFT);
578 cur.clearSelection();
580 cmd = FuncRequest(LFUN_FINISHED_LEFT);
583 case LFUN_INSET_TOGGLE:
585 if (cur.pos() != cur.lastpos()) {
586 // toggle previous inset ...
587 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
588 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
589 // ... or enclosing inset if we are in the last inset position
590 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
595 case LFUN_SELFINSERT:
596 if (cmd.argument.empty()) {
597 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
600 recordUndo(cur, Undo::ATOMIC);
601 if (cmd.argument.size() != 1) {
602 cur.insert(cmd.argument);
605 if (!interpret(cur, cmd.argument[0]))
606 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
611 // this needs to be incorporated
613 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
614 bool remove_inset = false;
616 DispatchResult result(true);
617 bool was_macro = cur.inMacroMode();
624 // sprintf(dispatch_buffer, "%d %d",);
625 // DispatchResult= dispatch_buffer;
628 lyxerr << "LFUN_SETXY broken!" << endl;
631 istringstream is(cmd.argument.c_str());
633 cur.setScreenPos(x, y);
638 recordUndo(cur, Undo::DELETE);
646 // Special casing for superscript in case of LyX handling
648 case LFUN_CIRCUMFLEX:
649 if (cmd.argument.empty()) {
650 // do superscript if LyX handles
652 recordUndo(cur, Undo::ATOMIC);
670 case LFUN_HUNG_UMLAUT:
674 case LFUN_FREEFONT_APPLY:
675 case LFUN_FREEFONT_UPDATE:
676 handleFont2(cur, cmd.argument);
680 handleFont(cur, cmd.argument, "mathbf");
683 handleFont(cur, cmd.argument, "mathsf");
686 handleFont(cur, cmd.argument, "mathcal");
689 handleFont(cur, cmd.argument, "mathrm");
692 handleFont(cur, cmd.argument, "texttt");
695 handleFont(cur, cmd.argument, "mathfrak");
698 handleFont(cur, cmd.argument, "mathit");
701 handleFont(cur, cmd.argument, "mathbb");
703 //case LFUN_FREEFONT_APPLY:
704 handleFont(cur, cmd.argument, "textrm");
707 handleFont(cur, cmd.argument, "textnormal");
712 cur.macroModeClose();
714 cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
716 cur.pushLeft(*cur.nextInset());
718 if (currentMode() == InsetBase::TEXT_MODE)
719 cur.niceInsert(MathAtom(new MathHullInset("simple")));
721 handleFont(cur, cmd.argument, "textrm");
722 //cur.owner()->message(_("math text mode toggled"));
729 recordUndo(cur, Undo::ATOMIC);
735 case LFUN_INSERT_MATRIX: {
736 recordUndo(cur, Undo::ATOMIC);
741 istringstream is(cmd.argument);
742 is >> m >> n >> v_align >> h_align;
749 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
753 case LFUN_MATH_DELIM: {
754 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
756 string rs = lyx::support::split(cmd.argument, ls, ' ');
757 // Reasonable default values
762 recordUndo(cur, Undo::ATOMIC);
763 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
767 case LFUN_SPACE_INSERT:
768 case LFUN_MATH_SPACE:
769 recordUndo(cur, Undo::ATOMIC);
770 cur.insert(MathAtom(new MathSpaceInset(",")));
774 // interpret this as if a backslash was typed
775 recordUndo(cur, Undo::ATOMIC);
776 interpret(cur, '\\');
779 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
780 // handling such that "self-insert" works on "arbitrary stuff" too, and
781 // math-insert only handles special math things like "matrix".
782 case LFUN_INSERT_MATH:
783 recordUndo(cur, Undo::ATOMIC);
784 cur.niceInsert(cmd.argument);
787 case LFUN_DIALOG_SHOW_NEW_INSET: {
788 string const & name = cmd.argument;
793 data = tmp.createDialogStr(name);
796 cur.bv().owner()->getDialogs().show(name, data, 0);
800 case LFUN_INSET_APPLY: {
801 string const name = cmd.getArg(0);
802 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
805 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
806 base->dispatch(cur, fr);
810 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
823 case LFUN_WORD_REPLACE:
825 if (!searchForward(&cur.bv(), cmd.getArg(0), false, false))
832 BOOST_ASSERT(cur.inMathed());
834 if (result.dispatched()) {
836 cur.bv().stuffClipboard(cur.grabSelection());
839 cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE));
845 MathDimInset::priv_dispatch(cur, cmd);
851 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
852 FuncStatus & flag) const
854 // the font related toggles
855 //string tc = "mathnormal";
857 switch (cmd.action) {
859 case LFUN_TABULAR_FEATURE:
860 // FIXME: check temporarily disabled
862 char align = mathcursor::valign();
867 if (cmd.argument.empty()) {
871 if (!contains("tcb", cmd.argument[0])) {
875 flag.setOnOff(cmd.argument[0] == align);
878 flag.setOnOff(tc == "mathbf");
881 flag.setOnOff(tc == "mathsf");
884 flag.setOnOff(tc == "mathcal");
887 flag.setOnOff(tc == "mathrm");
890 flag.setOnOff(tc == "mathtt");
893 flag.setOnOff(tc == "mathbb");
896 flag.setOnOff(tc == "mathnormal");
899 case LFUN_MATH_MUTATE:
900 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
901 flag.setOnOff(false);
904 // we just need to be in math mode to enable that
906 case LFUN_MATH_SPACE:
907 case LFUN_MATH_LIMITS:
908 case LFUN_MATH_NONUMBER:
909 case LFUN_MATH_NUMBER:
910 case LFUN_MATH_EXTERN:
922 void MathNestInset::edit(LCursor & cur, bool left)
925 cur.idx() = left ? 0 : cur.lastidx();
926 cur.pos() = left ? 0 : cur.lastpos();
928 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
932 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y)
935 int dist_min = 1000000;
936 for (idx_type i = 0; i < nargs(); ++i) {
937 int d = cell(i).dist(x, y);
943 MathArray & ar = cell(idx_min);
946 cur.pos() = ar.x2pos(x - ar.xo());
947 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
950 for (pos_type i = 0, n = ar.size(); i < n; ++i)
951 if (ar[i]->covers(x, y))
952 return ar[i].nucleus()->editXY(cur, x, y);
958 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
960 //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
962 if (cmd.button() == mouse_button::button1) {
963 // try to dispatch to enclosed insets first
964 //cur.bv().stuffClipboard(cur.grabSelection());
968 if (cmd.button() == mouse_button::button2) {
970 asArray(cur.bv().getClipboard(), ar);
971 cur.clearSelection();
972 cur.setScreenPos(cmd.x, cmd.y);
978 if (cmd.button() == mouse_button::button3) {
979 // try to dispatch to enclosed insets first
980 cur.bv().owner()->getDialogs().show("mathpanel");
988 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
990 lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl;
991 if (cmd.button() == mouse_button::button1) {
994 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
995 lyxerr << "lfunMousePress: setting cursor to: " << cur << endl;
997 cur.bv().cursor() = cur;
1000 if (cmd.button() == mouse_button::button2) {
1001 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
1006 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
1008 // only select with button 1
1009 if (cmd.button() != mouse_button::button1)
1012 if (abs(cmd.x - first_x) < 2 && abs(cmd.y - first_y) < 2)
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;