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_support.h"
29 #include "math_unknowninset.h"
31 #include "BufferView.h"
32 #include "CutAndPaste.h"
33 #include "FuncStatus.h"
35 #include "bufferview_funcs.h"
38 #include "dispatchresult.h"
39 #include "funcrequest.h"
41 #include "outputparams.h"
44 #include "support/std_sstream.h"
45 #include "support/lstrings.h"
47 #include "frontends/Dialogs.h"
48 #include "frontends/LyXView.h"
49 #include "frontends/Painter.h"
51 using lyx::cap::copySelection;
52 using lyx::cap::grabAndEraseSelection;
53 using lyx::cap::cutSelection;
54 using lyx::cap::pasteSelection;
55 using lyx::cap::replaceSelection;
56 using lyx::cap::selClearOrDel;
60 using std::istringstream;
75 MathNestInset::MathNestInset(idx_type nargs)
76 : cells_(nargs), lock_(false)
80 MathInset::idx_type MathNestInset::nargs() const
86 MathArray & MathNestInset::cell(idx_type i)
92 MathArray const & MathNestInset::cell(idx_type i) const
98 void MathNestInset::getCursorPos(LCursor const & cur, int & x, int & y) const
100 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
101 MathArray const & ar = cur.cell();
102 x = ar.xo() + ar.pos2x(cur.pos());
103 y = ar.yo() + cur.bv().top_y();
104 // move cursor visually into empty cells ("blue rectangles");
105 if (cur.cell().empty())
110 void MathNestInset::metrics(MetricsInfo const & mi) const
113 for (idx_type i = 0; i < nargs(); ++i)
118 bool MathNestInset::idxNext(LCursor & cur) const
120 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
121 if (cur.idx() == cur.lastidx())
129 bool MathNestInset::idxRight(LCursor & cur) const
135 bool MathNestInset::idxPrev(LCursor & cur) const
137 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
141 cur.pos() = cur.lastpos();
146 bool MathNestInset::idxLeft(LCursor & cur) const
152 bool MathNestInset::idxFirst(LCursor & cur) const
154 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
163 bool MathNestInset::idxLast(LCursor & cur) const
165 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
168 cur.idx() = cur.lastidx();
169 cur.pos() = cur.lastpos();
174 void MathNestInset::dump() const
176 WriteStream os(lyxerr);
177 os << "---------------------------------------------\n";
180 for (idx_type i = 0; i < nargs(); ++i)
181 os << cell(i) << "\n";
182 os << "---------------------------------------------\n";
186 void MathNestInset::draw(PainterInfo & pi, int x, int y) const
190 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
193 setPosCache(pi, x, y);
197 void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
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);
216 //lyxerr << "MathNestInset::drawing selection 3: "
217 // << " x1: " << x1 << " x2: " << x2
218 // << " y1: " << y1 << " y2: " << y2 << endl;
220 for (idx_type i = 0; i < nargs(); ++i) {
221 if (idxBetween(i, s1.idx(), s2.idx())) {
222 MathArray const & c = cell(i);
224 int y1 = c.yo() - c.ascent();
225 int x2 = c.xo() + c.width();
226 int y2 = c.yo() + c.descent();
227 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
234 void MathNestInset::validate(LaTeXFeatures & features) const
236 for (idx_type i = 0; i < nargs(); ++i)
237 cell(i).validate(features);
241 void MathNestInset::replace(ReplaceData & rep)
243 for (idx_type i = 0; i < nargs(); ++i)
244 cell(i).replace(rep);
248 bool MathNestInset::contains(MathArray const & ar) const
250 for (idx_type i = 0; i < nargs(); ++i)
251 if (cell(i).contains(ar))
257 bool MathNestInset::lock() const
263 void MathNestInset::lock(bool l)
269 bool MathNestInset::isActive() const
275 MathArray MathNestInset::glue() const
278 for (size_t i = 0; i < nargs(); ++i)
284 void MathNestInset::write(WriteStream & os) const
286 os << '\\' << name().c_str();
287 for (size_t i = 0; i < nargs(); ++i)
288 os << '{' << cell(i) << '}';
290 os.pendingSpace(true);
291 if (lock_ && !os.latex()) {
293 os.pendingSpace(true);
298 void MathNestInset::normalize(NormalStream & os) const
300 os << '[' << name().c_str();
301 for (size_t i = 0; i < nargs(); ++i)
302 os << ' ' << cell(i);
307 int MathNestInset::latex(Buffer const &, std::ostream & os,
308 OutputParams const & runparams) const
310 WriteStream wi(os, runparams.moving_arg, true);
316 void MathNestInset::notifyCursorLeaves(LCursor & cur)
320 MathArray & ar = cur.cell();
321 // remove base-only "scripts"
322 for (pos_type i = 0; i + 1 < ar.size(); ++i) {
323 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
324 if (p && p->nargs() == 1) {
325 MathArray ar = p->nuc();
328 cur.adjust(i, ar.size() - 1);
332 // glue adjacent font insets of the same kind
333 for (pos_type i = 0; i + 1 < size(); ++i) {
334 MathFontInset * p = operator[](i).nucleus()->asFontInset();
335 MathFontInset const * q = operator[](i + 1)->asFontInset();
336 if (p && q && p->name() == q->name()) {
337 p->cell(0).append(q->cell(0));
346 void MathNestInset::handleFont
347 (LCursor & cur, string const & arg, string const & font)
349 // this whole function is a hack and won't work for incremental font
351 recordUndo(cur, Undo::ATOMIC);
353 if (cur.inset().asMathInset()->name() == font)
354 cur.handleFont(font);
356 cur.handleNest(createMathInset(font));
362 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
364 recordUndo(cur, Undo::ATOMIC);
367 bv_funcs::string2font(arg, font, b);
368 if (font.color() != LColor::inherit) {
369 MathAtom at = createMathInset("color");
370 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
371 cur.handleNest(at, 1);
376 void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
378 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
379 //CursorSlice sl = cur.current();
381 switch (cmd.action) {
384 cur.message(_("Paste"));
385 replaceSelection(cur);
387 istringstream is(cmd.argument.c_str());
389 pasteSelection(cur, n);
390 cur.clearSelection(); // bug 393
391 cur.bv().switchKeyMap();
397 cutSelection(cur, true, true);
398 cur.message(_("Cut"));
403 cur.message(_("Copy"));
406 case LFUN_MOUSE_PRESS:
407 lfunMousePress(cur, cmd);
410 case LFUN_MOUSE_MOTION:
411 lfunMouseMotion(cur, cmd);
414 case LFUN_MOUSE_RELEASE:
415 lfunMouseRelease(cur, cmd);
418 case LFUN_FINISHED_LEFT:
419 cur.bv().cursor() = cur;
422 case LFUN_FINISHED_RIGHT:
424 cur.bv().cursor() = cur;
427 case LFUN_FINISHED_UP:
428 //idxUpDown(cur, true);
429 cur.bv().cursor() = cur;
432 case LFUN_FINISHED_DOWN:
433 //idxUpDown(cur, false);
434 cur.bv().cursor() = cur;
439 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
440 cur.autocorrect() = false;
442 if (cur.inMacroMode())
443 cur.macroModeClose();
444 else if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
445 cur.pushLeft(*cur.nextAtom().nucleus());
446 cur.inset().idxFirst(cur);
447 } else if (cur.posRight() || idxRight(cur)
448 || cur.popRight() || cur.selection())
451 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
456 cur.selHandle(cmd.action == LFUN_LEFTSEL);
457 cur.autocorrect() = false;
459 if (cur.inMacroMode())
460 cur.macroModeClose();
461 else if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
463 cur.push(*cur.nextAtom().nucleus());
464 cur.inset().idxLast(cur);
465 } else if (cur.posLeft() || idxLeft(cur)
466 || cur.popLeft() || cur.selection())
469 cmd = FuncRequest(LFUN_FINISHED_LEFT);
474 cur.selHandle(cmd.action == LFUN_UPSEL);
476 cmd = FuncRequest(LFUN_FINISHED_UP);
481 cur.selHandle(cmd.action == LFUN_DOWNSEL);
483 cmd = FuncRequest(LFUN_FINISHED_DOWN);
486 case LFUN_MOUSE_DOUBLE:
487 case LFUN_MOUSE_TRIPLE:
492 cur.selection() = true;
493 cur.pos() = cur.lastpos();
494 cur.idx() = cur.lastidx();
497 case LFUN_UP_PARAGRAPHSEL:
498 case LFUN_UP_PARAGRAPH:
499 case LFUN_DOWN_PARAGRAPHSEL:
500 case LFUN_DOWN_PARAGRAPH:
505 case LFUN_WORDLEFTSEL:
507 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
508 cur.macroModeClose();
509 if (cur.pos() != 0) {
511 } else if (cur.col() != 0) {
512 cur.idx() -= cur.col();
514 } else if (cur.idx() != 0) {
518 cmd = FuncRequest(LFUN_FINISHED_LEFT);
522 case LFUN_WORDRIGHTSEL:
526 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
527 cur.macroModeClose();
529 if (cur.pos() != cur.lastpos()) {
530 cur.pos() = cur.lastpos();
531 } else if (cur.col() != cur.lastcol()) {
532 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
533 cur.pos() = cur.lastpos();
534 } else if (cur.idx() != cur.lastidx()) {
535 cur.idx() = cur.lastidx();
536 cur.pos() = cur.lastpos();
538 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
544 case LFUN_BEGINNINGBUFSEL:
545 case LFUN_BEGINNINGBUF:
546 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:
572 recordUndo(cur, Undo::ATOMIC);
574 cmd = FuncRequest(LFUN_FINISHED_LEFT);
579 cur.clearSelection();
581 cmd = FuncRequest(LFUN_FINISHED_LEFT);
584 case LFUN_INSET_TOGGLE:
586 if (cur.pos() != cur.lastpos()) {
587 // toggle previous inset ...
588 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
589 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
590 // ... or enclosing inset if we are in the last inset position
591 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
596 case LFUN_SELFINSERT:
597 if (cmd.argument.empty()) {
598 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
601 recordUndo(cur, Undo::ATOMIC);
602 if (cmd.argument.size() != 1) {
603 cur.insert(cmd.argument);
606 if (!interpret(cur, cmd.argument[0]))
607 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
612 // this needs to be incorporated
614 // delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
615 bool remove_inset = false;
617 DispatchResult result(true);
618 bool was_macro = cur.inMacroMode();
625 // sprintf(dispatch_buffer, "%d %d",);
626 // DispatchResult= dispatch_buffer;
629 lyxerr << "LFUN_SETXY broken!" << endl;
632 istringstream is(cmd.argument.c_str());
634 cur.setScreenPos(x, y);
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);
963 cur.clearSelection();
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) {
986 //cur.setScreenPos(cmd.x + xo_, cmd.y + yo_);
987 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 cur.bv().cursor().setCursor(cur, true);
1014 bool MathNestInset::interpret(LCursor & cur, char c)
1016 lyxerr << "interpret 2: '" << c << "'" << endl;
1020 if (cur.inMacroMode()) {
1021 string name = cur.macroName();
1022 lyxerr << "interpret macro name: '" << name << "'" << endl;
1024 /// are we currently typing '#1' or '#2' or...?
1025 if (name == "\\#") {
1028 if (n >= 1 && n <= 9)
1029 cur.insert(new MathMacroArgument(n));
1034 cur.activeMacro()->setName(name + c);
1038 // handle 'special char' macros
1043 if (currentMode() == MathInset::TEXT_MODE)
1044 cur.niceInsert(createMathInset("textbackslash"));
1046 cur.niceInsert(createMathInset("backslash"));
1047 } else if (c == '{') {
1049 cur.niceInsert(MathAtom(new MathBraceInset));
1050 } else if (c == '#') {
1051 lyxerr << "setting name to " << name + c << endl;
1052 BOOST_ASSERT(cur.activeMacro());
1053 cur.activeMacro()->setName(name + c);
1054 lyxerr << "set name to " << name + c << endl;
1057 cur.niceInsert(createMathInset(string(1, c)));
1062 // leave macro mode and try again if necessary
1063 cur.macroModeClose();
1065 cur.niceInsert(MathAtom(new MathBraceInset));
1071 // This is annoying as one has to press <space> far too often.
1075 // leave autocorrect mode if necessary
1076 if (autocorrect() && c == ' ') {
1077 autocorrect() = false;
1082 // just clear selection on pressing the space bar
1083 if (cur.selection() && c == ' ') {
1084 cur.selection() = false;
1091 //lyxerr << "starting with macro" << endl;
1092 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1097 if (currentMode() == MathInset::TEXT_MODE)
1103 if (currentMode() == MathInset::TEXT_MODE) {
1104 // insert spaces in text mode,
1105 // but suppress direct insertion of two spaces in a row
1106 // the still allows typing '<space>a<space>' and deleting the 'a', but
1107 // it is better than nothing...
1108 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1112 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1113 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1118 // if are at the very end, leave the formula
1119 return cur.pos() != cur.lastpos();
1132 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#') {
1133 cur.niceInsert(createMathInset(string(1, c)));
1138 cur.niceInsert(MathAtom(new MathCommentInset));
1142 // try auto-correction
1143 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1146 // no special circumstances, so insert the character without any fuss
1148 cur.autocorrect() = true;
1153 bool MathNestInset::script(LCursor & cur, bool up)
1155 // Hack to get \\^ and \\_ working
1156 lyxerr << "handling script: up: " << up << endl;
1157 if (cur.inMacroMode() && cur.macroName() == "\\") {
1159 cur.niceInsert(createMathInset("mathcircumflex"));
1161 interpret(cur, '_');
1165 cur.macroModeClose();
1166 string safe = grabAndEraseSelection(cur);
1167 if (asScriptInset() && cur.idx() == 0) {
1168 // we are in a nucleus of a script inset, move to _our_ script
1169 MathScriptInset * inset = asScriptInset();
1170 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1172 cur.idx() = inset->idxOfScript(up);
1174 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1176 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1178 cur.idx() = inset->idxOfScript(up);
1179 cur.pos() = cur.lastpos();
1181 // convert the thing to our left to a scriptinset or create a new
1182 // one if in the very first position of the array
1183 if (cur.pos() == 0) {
1184 lyxerr << "new scriptinset" << endl;
1185 cur.insert(new MathScriptInset(up));
1187 lyxerr << "converting prev atom " << endl;
1188 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1190 lyxerr << "new scriptinset 2: cur:\n" << cur << endl;
1192 lyxerr << "new scriptinset 3: cur:\n" << cur << endl;
1193 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1194 lyxerr << "new scriptinset 3: inset:\n" << inset << endl;
1199 lyxerr << "pasting 1: safe:\n" << safe << endl;
1202 lyxerr << "pasting 2: safe:\n" << safe << endl;