X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathNest.cpp;h=a03aaefb168a38304e91042f1d076bc59d1a13bd;hb=9296344b9a26191a2092d175a51e357ecc35145d;hp=bdcd8a9a4c0cfeaf7eee8fdae6fd4ceba8e00504;hpb=6763301c05f4447936490d3478ca428c5fc19e21;p=lyx.git diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index bdcd8a9a4c..a03aaefb16 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -32,8 +32,8 @@ #include "MathCompletionList.h" #include "MathData.h" #include "MathFactory.h" -#include "MathMacro.h" -#include "MathMacroArgument.h" +#include "InsetMathMacro.h" +#include "InsetMathMacroArgument.h" #include "MathParser.h" #include "MathStream.h" #include "MathSupport.h" @@ -173,7 +173,7 @@ void InsetMathNest::cursorPos(BufferView const & bv, // move cursor visually into empty cells ("blue rectangles"); if (ar.empty()) { Dimension const dim = coord_cache.getArrays().dim(&ar); - x += dim.wid / 2; + x += dim.wid / 3; } } @@ -277,54 +277,6 @@ void InsetMathNest::draw(PainterInfo &, int, int) const } -void InsetMathNest::drawSelection(PainterInfo & pi, int x, int y) const -{ - BufferView & bv = *pi.base.bv; - // this should use the x/y values given, not the cached values - Cursor & cur = bv.cursor(); - if (!cur.selection()) - return; - if (&cur.inset() != this) - return; - - // FIXME: hack to get position cache warm - bool const original_drawing_state = pi.pain.isDrawingEnabled(); - pi.pain.setDrawingEnabled(false); - draw(pi, x, y); - pi.pain.setDrawingEnabled(original_drawing_state); - - CursorSlice s1 = cur.selBegin(); - CursorSlice s2 = cur.selEnd(); - - //lyxerr << "InsetMathNest::drawing selection: " - // << " s1: " << s1 << " s2: " << s2 << endl; - if (s1.idx() == s2.idx()) { - MathData const & c = cell(s1.idx()); - Geometry const & g = bv.coordCache().getArrays().geometry(&c); - int x1 = g.pos.x_ + c.pos2x(pi.base.bv, s1.pos()); - int y1 = g.pos.y_ - g.dim.ascent(); - int x2 = g.pos.x_ + c.pos2x(pi.base.bv, s2.pos()); - int y2 = g.pos.y_ + g.dim.descent(); - pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection); - //lyxerr << "InsetMathNest::drawing selection 3: " - // << " x1: " << x1 << " x2: " << x2 - // << " y1: " << y1 << " y2: " << y2 << endl; - } else { - for (idx_type i = 0; i < nargs(); ++i) { - if (idxBetween(i, s1.idx(), s2.idx())) { - MathData const & c = cell(i); - Geometry const & g = bv.coordCache().getArrays().geometry(&c); - int x1 = g.pos.x_; - int y1 = g.pos.y_ - g.dim.ascent(); - int x2 = g.pos.x_ + g.dim.width(); - int y2 = g.pos.y_ + g.dim.descent(); - pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, Color_selection); - } - } - } -} - - void InsetMathNest::validate(LaTeXFeatures & features) const { for (idx_type i = 0; i < nargs(); ++i) @@ -783,20 +735,18 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_MOUSE_DOUBLE: case LFUN_WORD_SELECT: cur.pos() = 0; - cur.resetAnchor(); - cur.selection(true); + cur.bv().mouseSetCursor(cur); cur.pos() = cur.lastpos(); - cur.bv().cursor() = cur; + cur.bv().mouseSetCursor(cur, true); break; case LFUN_MOUSE_TRIPLE: cur.idx() = 0; cur.pos() = 0; - cur.resetAnchor(); - cur.selection(true); + cur.bv().mouseSetCursor(cur); cur.idx() = cur.lastidx(); cur.pos() = cur.lastpos(); - cur.bv().cursor() = cur; + cur.bv().mouseSetCursor(cur, true); break; case LFUN_LINE_BEGIN: @@ -862,9 +812,9 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) else if (!cur.inMacroMode()) cur.recordUndoSelection(); // if the inset can not be removed from within, delete it - if (!cur.backspace()) { - FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD); - cur.innerText()->dispatch(cur, cmd); + if (!cur.backspace(cmd.getArg(0) == "force")) { + FuncRequest newcmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD, "force"); + cur.innerText()->dispatch(cur, newcmd); } break; @@ -876,9 +826,9 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) else cur.recordUndoSelection(); // if the inset can not be removed from within, delete it - if (!cur.erase()) { - FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD); - cur.innerText()->dispatch(cur, cmd); + if (!cur.erase(cmd.getArg(0) == "force")) { + FuncRequest newcmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD, "force"); + cur.innerText()->dispatch(cur, newcmd); } break; @@ -886,8 +836,12 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) if (cur.selection()) cur.clearSelection(); else { - cmd = FuncRequest(LFUN_FINISHED_FORWARD); - cur.undispatched(); + if (cur.inMacroMode()) + cur.macroModeClose(true); + else { + cmd = FuncRequest(LFUN_FINISHED_FORWARD); + cur.undispatched(); + } } break; @@ -946,7 +900,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) int y = 0; istringstream is(to_utf8(cmd.argument())); is >> x >> y; - cur.setScreenPos(x, y); + cur.setTargetX(x); break; } @@ -1256,7 +1210,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd) bool fold = act == LFUN_MATH_MACRO_FOLD; bool found = findMacroToFoldUnfold(it, fold); if (found) { - MathMacro * macro = it.nextInset()->asInsetMath()->asMacro(); + InsetMathMacro * macro = it.nextInset()->asInsetMath()->asMacro(); cur.recordUndoInset(); if (fold) macro->fold(cur); @@ -1352,7 +1306,7 @@ bool InsetMathNest::findMacroToFoldUnfold(Cursor & it, bool fold) const { // go backward through the current cell Inset * inset = it.nextInset(); while (inset && inset->asInsetMath()) { - MathMacro * macro = inset->asInsetMath()->asMacro(); + InsetMathMacro * macro = inset->asInsetMath()->asMacro(); if (macro) { // found the an macro to open/close? if (macro->folded() != fold) @@ -1543,7 +1497,7 @@ void InsetMathNest::edit(Cursor & cur, bool front, EntryDirection entry_from) Inset * InsetMathNest::editXY(Cursor & cur, int x, int y) { - int idx_min = 0; + int idx_min = -1; int dist_min = 1000000; for (idx_type i = 0, n = nargs(); i != n; ++i) { int const d = cell(i).dist(cur.bv(), x, y); @@ -1552,6 +1506,9 @@ Inset * InsetMathNest::editXY(Cursor & cur, int x, int y) idx_min = i; } } + if (idx_min == -1) + return this; + MathData & ar = cell(idx_min); cur.push(*this); cur.idx() = idx_min; @@ -1581,6 +1538,10 @@ void InsetMathNest::lfunMousePress(Cursor & cur, FuncRequest & cmd) return; } } + + // set cursor after the inset if x is nearer to that position (bug 9748) + cur.moveToClosestEdge(cmd.x(), true); + bool do_selection = cmd.button() == mouse_button::button1 && cmd.modifier() == ShiftModifier; bv.mouseSetCursor(cur, do_selection); @@ -1625,6 +1586,9 @@ void InsetMathNest::lfunMouseMotion(Cursor & cur, FuncRequest & cmd) return; } + // set cursor after the inset if x is nearer to that position (bug 9748) + cur.moveToClosestEdge(cmd.x()); + CursorSlice old = bvcur.top(); // We continue with our existing selection or start a new one, so don't @@ -1677,7 +1641,7 @@ bool InsetMathNest::interpretChar(Cursor & cur, char_type const c) cur.backspace(); int n = c - '0'; if (n >= 1 && n <= 9) - cur.insert(new MathMacroArgument(n)); + cur.insert(new InsetMathMacroArgument(n)); return true; } @@ -2071,8 +2035,7 @@ bool InsetMathNest::insertCompletion(Cursor & cur, docstring const & s, #if 0 // FIXME: this creates duplicates in the completion popup // which looks ugly. Moreover the changes the list lengths - // which seems to - confuse the popup as well. + // which seems to confuse the popup as well. MathCompletionList::addToFavorites(inset->name()); #endif lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, " "));