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_boxinset.h"
17 #include "math_braceinset.h"
18 #include "math_commentinset.h"
19 #include "math_data.h"
20 #include "math_deliminset.h"
21 #include "math_factory.h"
22 #include "math_hullinset.h"
23 #include "math_mathmlstream.h"
24 #include "math_macroarg.h"
25 //#include "math_mboxinset.h"
26 #include "math_parser.h"
27 #include "math_scriptinset.h"
28 #include "math_spaceinset.h"
29 #include "math_symbolinset.h"
30 #include "math_support.h"
31 #include "math_unknowninset.h"
33 #include "BufferView.h"
34 #include "CutAndPaste.h"
35 #include "FuncStatus.h"
37 #include "bufferview_funcs.h"
38 #include "coordcache.h"
41 #include "dispatchresult.h"
42 #include "funcrequest.h"
44 #include "outputparams.h"
47 #include "support/lstrings.h"
49 #include "frontends/Dialogs.h"
50 #include "frontends/LyXView.h"
51 #include "frontends/Painter.h"
55 using lyx::cap::copySelection;
56 using lyx::cap::grabAndEraseSelection;
57 using lyx::cap::cutSelection;
58 using lyx::cap::pasteSelection;
59 using lyx::cap::replaceSelection;
60 using lyx::cap::selClearOrDel;
64 using std::istringstream;
67 MathNestInset::MathNestInset(idx_type nargs)
68 : cells_(nargs), lock_(false)
72 MathInset::idx_type MathNestInset::nargs() const
78 MathArray & MathNestInset::cell(idx_type i)
84 MathArray const & MathNestInset::cell(idx_type i) const
90 void MathNestInset::getCursorPos(CursorSlice const & sl,
91 int & x, int & y) const
93 // FIXME: This is a hack. Ideally, the coord cache should not store
94 // absolute positions, but relative ones. This would mean to call
95 // setXY() not in MathArray::draw(), but in the parent insets' draw()
96 // with the correctly adjusted x,y values. But this means that we'd have
97 // to touch all (math)inset's draw() methods. Right now, we'll store
98 // absolute value, and make them here relative, only to make them
99 // absolute again when actually drawing the cursor. What a mess.
100 BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
101 MathArray const & ar = sl.cell();
102 if (!theCoords.getArrays().has(&ar)) {
103 // this can (semi-)legally happen if we just created this cell
104 // and it never has been drawn before. So don't ASSERT.
105 //lyxerr << "no cached data for array " << &ar << endl;
110 Point const pt = theCoords.getArrays().xy(&ar);
111 if (!theCoords.getInsets().has(this)) {
113 //lyxerr << "no cached data for inset " << this << endl;
118 Point const pt2 = theCoords.getInsets().xy(this);
119 //lyxerr << "retrieving position cache for MathArray "
120 // << pt.x_ << ' ' << pt.y_ << std::endl;
121 x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
123 // lyxerr << "pt.y_ : " << pt.y_ << " pt2_.y_ : " << pt2.y_
124 // << " asc: " << ascent() << " des: " << descent()
125 // << " ar.asc: " << ar.ascent() << " ar.des: " << ar.descent() << endl;
126 // move cursor visually into empty cells ("blue rectangles");
132 void MathNestInset::metrics(MetricsInfo const & mi) const
135 for (idx_type i = 0, n = nargs(); i != n; ++i)
140 bool MathNestInset::idxNext(LCursor & cur) const
142 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
143 if (cur.idx() == cur.lastidx())
151 bool MathNestInset::idxRight(LCursor & cur) const
157 bool MathNestInset::idxPrev(LCursor & cur) const
159 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
163 cur.pos() = cur.lastpos();
168 bool MathNestInset::idxLeft(LCursor & cur) const
174 bool MathNestInset::idxFirst(LCursor & cur) const
176 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
185 bool MathNestInset::idxLast(LCursor & cur) const
187 BOOST_ASSERT(ptr_cmp(&cur.inset(), this));
190 cur.idx() = cur.lastidx();
191 cur.pos() = cur.lastpos();
196 void MathNestInset::dump() const
198 WriteStream os(lyxerr);
199 os << "---------------------------------------------\n";
202 for (idx_type i = 0, n = nargs(); i != n; ++i)
203 os << cell(i) << "\n";
204 os << "---------------------------------------------\n";
208 void MathNestInset::draw(PainterInfo & pi, int x, int y) const
212 pi.pain.fillRectangle(x, y - ascent(), width(), height(),
215 setPosCache(pi, x, y);
219 void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
221 // FIXME: hack to get position cache warm
224 // this should use the x/y values given, not the cached values
225 LCursor & cur = pi.base.bv->cursor();
226 if (!cur.selection())
228 if (!ptr_cmp(&cur.inset(), this))
231 CursorSlice s1 = cur.selBegin();
232 CursorSlice s2 = cur.selEnd();
233 //lyxerr << "MathNestInset::drawing selection: "
234 // << " s1: " << s1 << " s2: " << s2 << endl;
235 if (s1.idx() == s2.idx()) {
236 MathArray const & c = cell(s1.idx());
237 int x1 = c.xo() + c.pos2x(s1.pos());
238 int y1 = c.yo() - c.ascent();
239 int x2 = c.xo() + c.pos2x(s2.pos());
240 int y2 = c.yo() + c.descent();
241 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
242 //lyxerr << "MathNestInset::drawing selection 3: "
243 // << " x1: " << x1 << " x2: " << x2
244 // << " y1: " << y1 << " y2: " << y2 << endl;
246 for (idx_type i = 0; i < nargs(); ++i) {
247 if (idxBetween(i, s1.idx(), s2.idx())) {
248 MathArray const & c = cell(i);
250 int y1 = c.yo() - c.ascent();
251 int x2 = c.xo() + c.width();
252 int y2 = c.yo() + c.descent();
253 pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
260 void MathNestInset::validate(LaTeXFeatures & features) const
262 for (idx_type i = 0; i < nargs(); ++i)
263 cell(i).validate(features);
267 void MathNestInset::replace(ReplaceData & rep)
269 for (idx_type i = 0; i < nargs(); ++i)
270 cell(i).replace(rep);
274 bool MathNestInset::contains(MathArray const & ar) const
276 for (idx_type i = 0; i < nargs(); ++i)
277 if (cell(i).contains(ar))
283 bool MathNestInset::lock() const
289 void MathNestInset::lock(bool l)
295 bool MathNestInset::isActive() const
301 MathArray MathNestInset::glue() const
304 for (size_t i = 0; i < nargs(); ++i)
310 void MathNestInset::write(WriteStream & os) const
312 os << '\\' << name().c_str();
313 for (size_t i = 0; i < nargs(); ++i)
314 os << '{' << cell(i) << '}';
316 os.pendingSpace(true);
317 if (lock_ && !os.latex()) {
319 os.pendingSpace(true);
324 void MathNestInset::normalize(NormalStream & os) const
326 os << '[' << name().c_str();
327 for (size_t i = 0; i < nargs(); ++i)
328 os << ' ' << cell(i);
333 int MathNestInset::latex(Buffer const &, std::ostream & os,
334 OutputParams const & runparams) const
336 WriteStream wi(os, runparams.moving_arg, true);
342 void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/)
348 MathArray & ar = cur.cell();
349 // remove base-only "scripts"
350 for (pos_type i = 0; i + 1 < ar.size(); ++i) {
351 MathScriptInset * p = operator[](i).nucleus()->asScriptInset();
352 if (p && p->nargs() == 1) {
353 MathArray ar = p->nuc();
356 cur.adjust(i, ar.size() - 1);
360 // glue adjacent font insets of the same kind
361 for (pos_type i = 0; i + 1 < size(); ++i) {
362 MathFontInset * p = operator[](i).nucleus()->asFontInset();
363 MathFontInset const * q = operator[](i + 1)->asFontInset();
364 if (p && q && p->name() == q->name()) {
365 p->cell(0).append(q->cell(0));
374 void MathNestInset::handleFont
375 (LCursor & cur, string const & arg, string const & font)
377 // this whole function is a hack and won't work for incremental font
379 recordUndo(cur, Undo::ATOMIC);
381 if (cur.inset().asMathInset()->name() == font)
382 cur.handleFont(font);
384 cur.handleNest(createMathInset(font));
390 void MathNestInset::handleFont2(LCursor & cur, string const & arg)
392 recordUndo(cur, Undo::ATOMIC);
395 bv_funcs::string2font(arg, font, b);
396 if (font.color() != LColor::inherit) {
397 MathAtom at = createMathInset("color");
398 asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0));
399 cur.handleNest(at, 1);
404 void MathNestInset::doDispatch(LCursor & cur, FuncRequest & cmd)
406 //lyxerr << "MathNestInset: request: " << cmd << std::endl;
407 //CursorSlice sl = cur.current();
409 switch (cmd.action) {
413 cur.message(_("Paste"));
414 replaceSelection(cur);
416 istringstream is(cmd.argument);
418 pasteSelection(cur, n);
419 cur.clearSelection(); // bug 393
420 cur.bv().switchKeyMap();
426 cutSelection(cur, true, true);
427 cur.message(_("Cut"));
432 cur.message(_("Copy"));
435 case LFUN_MOUSE_PRESS:
436 lfunMousePress(cur, cmd);
439 case LFUN_MOUSE_MOTION:
440 lfunMouseMotion(cur, cmd);
443 case LFUN_MOUSE_RELEASE:
444 lfunMouseRelease(cur, cmd);
447 case LFUN_FINISHED_LEFT:
448 cur.bv().cursor() = cur;
451 case LFUN_FINISHED_RIGHT:
453 cur.bv().cursor() = cur;
456 case LFUN_FINISHED_UP:
457 cur.bv().cursor() = cur;
460 case LFUN_FINISHED_DOWN:
461 cur.bv().cursor() = cur;
466 cur.selHandle(cmd.action == LFUN_RIGHTSEL);
467 cur.autocorrect() = false;
469 cur.macroModeClose();
470 if (cur.pos() != cur.lastpos() && cur.openable(cur.nextAtom())) {
471 cur.pushLeft(*cur.nextAtom().nucleus());
472 cur.inset().idxFirst(cur);
473 } else if (cur.posRight() || idxRight(cur)
474 || cur.popRight() || cur.selection())
477 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
482 cur.selHandle(cmd.action == LFUN_LEFTSEL);
483 cur.autocorrect() = false;
485 cur.macroModeClose();
486 if (cur.pos() != 0 && cur.openable(cur.prevAtom())) {
488 cur.push(*cur.nextAtom().nucleus());
489 cur.inset().idxLast(cur);
490 } else if (cur.posLeft() || idxLeft(cur)
491 || cur.popLeft() || cur.selection())
494 cmd = FuncRequest(LFUN_FINISHED_LEFT);
499 // FIXME Tried to use clearTargetX and macroModeClose, crashed on cur.up()
500 if (cur.inMacroMode()) {
502 cur.macroModeClose();
505 cur.selHandle(cmd.action == LFUN_UPSEL);
507 cmd = FuncRequest(LFUN_FINISHED_UP);
508 // fixes bug 1598. Please check!
514 if (cur.inMacroMode()) {
515 cur.macroModeClose();
518 cur.selHandle(cmd.action == LFUN_DOWNSEL);
520 cmd = FuncRequest(LFUN_FINISHED_DOWN);
521 // fixes bug 1598. Please check!
525 case LFUN_MOUSE_DOUBLE:
526 case LFUN_MOUSE_TRIPLE:
531 cur.selection() = true;
532 cur.pos() = cur.lastpos();
533 cur.idx() = cur.lastidx();
536 case LFUN_UP_PARAGRAPHSEL:
537 case LFUN_UP_PARAGRAPH:
538 case LFUN_DOWN_PARAGRAPHSEL:
539 case LFUN_DOWN_PARAGRAPH:
544 case LFUN_WORDLEFTSEL:
546 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
547 cur.macroModeClose();
548 if (cur.pos() != 0) {
550 } else if (cur.col() != 0) {
551 cur.idx() -= cur.col();
553 } else if (cur.idx() != 0) {
557 cmd = FuncRequest(LFUN_FINISHED_LEFT);
561 case LFUN_WORDRIGHTSEL:
565 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
566 cur.macroModeClose();
568 if (cur.pos() != cur.lastpos()) {
569 cur.pos() = cur.lastpos();
570 } else if (ncols() && (cur.col() != cur.lastcol())) {
571 cur.idx() = cur.idx() - cur.col() + cur.lastcol();
572 cur.pos() = cur.lastpos();
573 } else if (cur.idx() != cur.lastidx()) {
574 cur.idx() = cur.lastidx();
575 cur.pos() = cur.lastpos();
577 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
583 cmd = FuncRequest(LFUN_FINISHED_LEFT);
588 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
591 case LFUN_CELL_FORWARD:
592 cur.inset().idxNext(cur);
595 case LFUN_CELL_BACKWARD:
596 cur.inset().idxPrev(cur);
599 case LFUN_DELETE_WORD_BACKWARD:
601 recordUndo(cur, Undo::ATOMIC);
605 case LFUN_DELETE_WORD_FORWARD:
609 cmd = FuncRequest(LFUN_FINISHED_LEFT);
614 cur.clearSelection();
616 cmd = FuncRequest(LFUN_FINISHED_LEFT);
619 case LFUN_INSET_TOGGLE:
622 if (cur.pos() != cur.lastpos()) {
623 // toggle previous inset ...
624 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
625 } else if (cur.popLeft() && cur.pos() != cur.lastpos()) {
626 // ... or enclosing inset if we are in the last inset position
627 cur.nextAtom().nucleus()->lock(!cur.nextAtom()->lock());
632 case LFUN_SELFINSERT:
634 if (cmd.argument.size() != 1) {
635 cur.insert(cmd.argument);
638 if (!interpret(cur, cmd.argument[0]))
639 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
643 // sprintf(dispatch_buffer, "%d %d",);
647 lyxerr << "LFUN_SETXY broken!" << endl;
650 istringstream is(cmd.argument);
652 cur.setScreenPos(x, y);
656 // Special casing for superscript in case of LyX handling
658 case LFUN_CIRCUMFLEX:
659 if (cmd.argument.empty()) {
660 // do superscript if LyX handles
662 recordUndo(cur, Undo::ATOMIC);
680 case LFUN_HUNG_UMLAUT:
684 case LFUN_FREEFONT_APPLY:
685 case LFUN_FREEFONT_UPDATE:
686 handleFont2(cur, cmd.argument);
690 handleFont(cur, cmd.argument, "mathbf");
693 handleFont(cur, cmd.argument, "mathsf");
696 handleFont(cur, cmd.argument, "mathcal");
699 handleFont(cur, cmd.argument, "mathrm");
702 handleFont(cur, cmd.argument, "texttt");
705 handleFont(cur, cmd.argument, "mathfrak");
708 handleFont(cur, cmd.argument, "mathit");
711 handleFont(cur, cmd.argument, "mathbb");
713 //case LFUN_FREEFONT_APPLY:
714 handleFont(cur, cmd.argument, "textrm");
717 handleFont(cur, cmd.argument, "textnormal");
722 // ignore math-mode on when already in math mode
723 if (currentMode() == InsetBase::MATH_MODE && cmd.argument == "on")
725 cur.macroModeClose();
727 //cur.plainInsert(MathAtom(new MathMBoxInset(cur.bv())));
728 cur.plainInsert(MathAtom(new MathBoxInset("mbox")));
730 cur.pushLeft(*cur.nextInset());
732 if (currentMode() == InsetBase::TEXT_MODE) {
733 cur.niceInsert(MathAtom(new MathHullInset("simple")));
734 cur.message(_("create new math text environment ($...$)"));
736 handleFont(cur, cmd.argument, "textrm");
737 cur.message(_("entered math text mode (textrm)"));
749 case LFUN_INSERT_MATRIX: {
750 recordUndo(cur, Undo::ATOMIC);
755 istringstream is(cmd.argument);
756 is >> m >> n >> v_align >> h_align;
763 MathAtom(new MathArrayInset("array", m, n, v_align[0], h_align)));
767 case LFUN_MATH_DELIM: {
768 lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
770 string rs = lyx::support::split(cmd.argument, ls, ' ');
771 // Reasonable default values
776 recordUndo(cur, Undo::ATOMIC);
777 cur.handleNest(MathAtom(new MathDelimInset(ls, rs)));
781 case LFUN_SPACE_INSERT:
782 case LFUN_MATH_SPACE:
783 recordUndo(cur, Undo::ATOMIC);
784 cur.insert(MathAtom(new MathSpaceInset(",")));
788 // interpret this as if a backslash was typed
789 recordUndo(cur, Undo::ATOMIC);
790 interpret(cur, '\\');
794 // interpret this as if a _ was typed
795 recordUndo(cur, Undo::ATOMIC);
799 case LFUN_SUPERSCRIPT:
800 // interpret this as if a ^ was typed
801 recordUndo(cur, Undo::ATOMIC);
805 // FIXME: We probably should swap parts of "math-insert" and "self-insert"
806 // handling such that "self-insert" works on "arbitrary stuff" too, and
807 // math-insert only handles special math things like "matrix".
808 case LFUN_INSERT_MATH: {
809 recordUndo(cur, Undo::ATOMIC);
811 asArray(cmd.argument, ar);
812 if (ar.size() == 1 && (ar[0].nucleus()->asNestInset())) {
813 cur.handleNest(ar[0]);
815 cur.niceInsert(cmd.argument);
819 case LFUN_DIALOG_SHOW_NEW_INSET: {
820 string const & name = cmd.argument;
825 data = tmp.createDialogStr(name);
828 cur.bv().owner()->getDialogs().show(name, data, 0);
832 case LFUN_INSET_APPLY: {
833 string const name = cmd.getArg(0);
834 InsetBase * base = cur.bv().owner()->getDialogs().getOpenInset(name);
837 FuncRequest fr(LFUN_INSET_MODIFY, cmd.argument);
838 base->dispatch(cur, fr);
842 if (createMathInset_fromDialogStr(cmd.argument, ar)) {
851 MathDimInset::doDispatch(cur, cmd);
857 bool MathNestInset::getStatus(LCursor & /*cur*/, FuncRequest const & cmd,
858 FuncStatus & flag) const
860 // the font related toggles
861 //string tc = "mathnormal";
863 switch (cmd.action) {
865 case LFUN_TABULAR_FEATURE:
866 // FIXME: check temporarily disabled
868 char align = mathcursor::valign();
873 if (cmd.argument.empty()) {
877 if (!contains("tcb", cmd.argument[0])) {
881 flag.setOnOff(cmd.argument[0] == align);
884 flag.setOnOff(tc == "mathbf");
887 flag.setOnOff(tc == "mathsf");
890 flag.setOnOff(tc == "mathcal");
893 flag.setOnOff(tc == "mathrm");
896 flag.setOnOff(tc == "mathtt");
899 flag.setOnOff(tc == "mathbb");
902 flag.setOnOff(tc == "mathnormal");
905 case LFUN_MATH_MUTATE:
906 //flag.setOnOff(mathcursor::formula()->hullType() == cmd.argument);
907 flag.setOnOff(false);
910 // we just need to be in math mode to enable that
912 case LFUN_MATH_SPACE:
913 case LFUN_MATH_LIMITS:
914 case LFUN_MATH_NONUMBER:
915 case LFUN_MATH_NUMBER:
916 case LFUN_MATH_EXTERN:
928 void MathNestInset::edit(LCursor & cur, bool left)
931 cur.idx() = left ? 0 : cur.lastidx();
932 cur.pos() = left ? 0 : cur.lastpos();
934 lyxerr << "MathNestInset::edit, cur:\n" << cur << endl;
938 InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) const
941 int dist_min = 1000000;
942 for (idx_type i = 0; i < nargs(); ++i) {
943 int d = cell(i).dist(x, y);
949 MathArray const & ar = cell(idx_min);
950 cur.push(const_cast<MathNestInset&>(*this));
952 cur.pos() = ar.x2pos(x - ar.xo());
953 lyxerr << "found cell : " << idx_min << " pos: " << cur.pos() << endl;
956 for (pos_type i = 0, n = ar.size(); i < n; ++i)
957 if (ar[i]->covers(x, y))
958 return ar[i].nucleus()->editXY(cur, x, y);
960 return const_cast<MathNestInset*>(this);
964 void MathNestInset::lfunMousePress(LCursor & cur, FuncRequest & cmd)
966 //lyxerr << "## lfunMousePress: buttons: " << cmd.button() << endl;
967 if (cmd.button() == mouse_button::button1) {
968 //lyxerr << "## lfunMousePress: setting cursor to: " << cur << endl;
970 cur.bv().cursor() = cur;
973 if (cmd.button() == mouse_button::button2) {
974 cur.dispatch(FuncRequest(LFUN_PASTESELECTION));
979 void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd)
981 // only select with button 1
982 if (cmd.button() == mouse_button::button1) {
983 LCursor & bvcur = cur.bv().cursor();
984 if (bvcur.anchor_.hasPart(cur)) {
985 //lyxerr << "## lfunMouseMotion: cursor: " << cur << endl;
986 bvcur.setCursor(cur);
987 bvcur.selection() = true;
988 //lyxerr << "MOTION " << bvcur << endl;
997 void MathNestInset::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
999 //lyxerr << "## lfunMouseRelease: buttons: " << cmd.button() << endl;
1001 if (cmd.button() == mouse_button::button1) {
1002 //cur.bv().stuffClipboard(cur.grabSelection());
1006 if (cmd.button() == mouse_button::button2) {
1008 asArray(cur.bv().getClipboard(), ar);
1009 cur.clearSelection();
1010 cur.setScreenPos(cmd.x, cmd.y);
1016 if (cmd.button() == mouse_button::button3) {
1017 // try to dispatch to enclosed insets first
1018 cur.bv().owner()->getDialogs().show("mathpanel");
1026 bool MathNestInset::interpret(LCursor & cur, char c)
1028 lyxerr << "interpret 2: '" << c << "'" << endl;
1032 if (cur.inMacroMode()) {
1033 string name = cur.macroName();
1035 /// are we currently typing '#1' or '#2' or...?
1036 if (name == "\\#") {
1039 if (n >= 1 && n <= 9)
1040 cur.insert(new MathMacroArgument(n));
1045 cur.activeMacro()->setName(name + c);
1049 // handle 'special char' macros
1054 if (currentMode() == MathInset::TEXT_MODE)
1055 cur.niceInsert(createMathInset("textbackslash"));
1057 cur.niceInsert(createMathInset("backslash"));
1058 } else if (c == '{') {
1060 cur.niceInsert(MathAtom(new MathBraceInset));
1061 } else if (c == '%') {
1063 cur.niceInsert(MathAtom(new MathCommentInset));
1064 } else if (c == '#') {
1065 BOOST_ASSERT(cur.activeMacro());
1066 cur.activeMacro()->setName(name + c);
1069 cur.niceInsert(createMathInset(string(1, c)));
1074 // leave macro mode and try again if necessary
1075 cur.macroModeClose();
1077 cur.niceInsert(MathAtom(new MathBraceInset));
1083 // This is annoying as one has to press <space> far too often.
1087 // leave autocorrect mode if necessary
1088 if (autocorrect() && c == ' ') {
1089 autocorrect() = false;
1094 // just clear selection on pressing the space bar
1095 if (cur.selection() && c == ' ') {
1096 cur.selection() = false;
1103 //lyxerr << "starting with macro" << endl;
1104 cur.insert(MathAtom(new MathUnknownInset("\\", false)));
1109 if (currentMode() == MathInset::TEXT_MODE)
1115 if (currentMode() == MathInset::TEXT_MODE) {
1116 // insert spaces in text mode,
1117 // but suppress direct insertion of two spaces in a row
1118 // the still allows typing '<space>a<space>' and deleting the 'a', but
1119 // it is better than nothing...
1120 if (!cur.pos() != 0 || cur.prevAtom()->getChar() != ' ')
1124 if (cur.pos() != 0 && cur.prevAtom()->asSpaceInset()) {
1125 cur.prevAtom().nucleus()->asSpaceInset()->incSpace();
1130 // if are at the very end, leave the formula
1131 return cur.pos() != cur.lastpos();
1144 if (c == '{' || c == '}' || c == '&' || c == '$' || c == '#' || c == '%') {
1145 cur.niceInsert(createMathInset(string(1, c)));
1150 cur.niceInsert(createMathInset("sim"));
1154 // try auto-correction
1155 //if (autocorrect() && hasPrevAtom() && math_autocorrect(prevAtom(), c))
1158 // no special circumstances, so insert the character without any fuss
1160 cur.autocorrect() = true;
1165 bool MathNestInset::script(LCursor & cur, bool up)
1167 // Hack to get \^ and \_ working
1168 lyxerr << "handling script: up: " << up << endl;
1169 if (cur.inMacroMode() && cur.macroName() == "\\") {
1171 cur.niceInsert(createMathInset("mathcircumflex"));
1173 interpret(cur, '_');
1177 cur.macroModeClose();
1178 string safe = grabAndEraseSelection(cur);
1179 if (asScriptInset() && cur.idx() == 0) {
1180 // we are in a nucleus of a script inset, move to _our_ script
1181 MathScriptInset * inset = asScriptInset();
1182 lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
1184 cur.idx() = inset->idxOfScript(up);
1186 } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
1188 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1190 cur.idx() = inset->idxOfScript(up);
1191 cur.pos() = cur.lastpos();
1193 // convert the thing to our left to a scriptinset or create a new
1194 // one if in the very first position of the array
1195 if (cur.pos() == 0) {
1196 lyxerr << "new scriptinset" << endl;
1197 cur.insert(new MathScriptInset(up));
1199 lyxerr << "converting prev atom " << endl;
1200 cur.prevAtom() = MathAtom(new MathScriptInset(cur.prevAtom(), up));
1203 MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
1208 lyxerr << "pasting 1: safe:\n" << safe << endl;
1211 lyxerr << "pasting 2: safe:\n" << safe << endl;