X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathNest.cpp;h=1f0adda5045a15428e02745687eeed430d2c8dfc;hb=25d64bf43aba78a1ed20c88dfdc4cac269b53985;hp=1da75468d218533b93c527aefe5b5b58d0daa99b;hpb=f6d4bce12303a2f30ea129ee86e7f7d879668260;p=lyx.git diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 1da75468d2..1f0adda504 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -171,17 +171,19 @@ void InsetMathNest::cursorPos(BufferView const & bv, // << " asc: " << ascent() << " des: " << descent() // << " ar.asc: " << ar.ascent() << " ar.des: " << ar.descent() << endl; // move cursor visually into empty cells ("blue rectangles"); - if (ar.empty()) - x += 2; + if (ar.empty()) { + Dimension const dim = coord_cache.getArrays().dim(&ar); + x += dim.wid / 3; + } } -void InsetMathNest::metrics(MetricsInfo const & mi) const +void InsetMathNest::cellsMetrics(MetricsInfo const & mi) const { MetricsInfo m = mi; - for (idx_type i = 0, n = nargs(); i != n; ++i) { + for (auto const & cell : cells_) { Dimension dim; - cell(i).metrics(m, dim); + cell.metrics(m, dim); } } @@ -275,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) @@ -860,8 +814,8 @@ 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); + if (!cur.backspace(cmd.getArg(0) == "force")) { + FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD, "force"); cur.innerText()->dispatch(cur, cmd); } break; @@ -874,8 +828,8 @@ 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); + if (!cur.erase(cmd.getArg(0) == "force")) { + FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD, "force"); cur.innerText()->dispatch(cur, cmd); } break; @@ -1579,6 +1533,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); @@ -1623,6 +1581,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