X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursor.cpp;h=f6d10cbc972ab2ca43f0180943e645f791c933c3;hb=a3c84666b2dbfc75c9a80cf4f94612149cb2b570;hp=0e1a51e351998eca7a307f1dc9b186cb0c307983;hpb=b79d8e5e2d20e8f294d47fe924c20de17dbd5c0b;p=lyx.git diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 0e1a51e351..f6d10cbc97 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -49,11 +49,12 @@ #include "mathed/MathData.h" #include "mathed/MathMacro.h" -#include +#include "support/bind.h" #include #include #include +#include using namespace std; @@ -214,8 +215,10 @@ bool bruteFind3(Cursor & cur, int x, int y, bool up) for ( ; it != et; it.forwardPos()) { // avoid invalid nesting when selecting if (bv.cursorStatus(it) == CUR_INSIDE - && (!cur.selection() || positionable(it, cur.anchor_))) { - Point p = bv.getPos(it, false); + && (!cur.selection() || positionable(it, cur.realAnchor()))) { + // If this function is ever used again, check whether this + // is the same as "bv.getPos(it, false)" with boundary = false. + Point p = bv.getPos(it); int xo = p.x_; int yo = p.y_; if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { @@ -329,19 +332,20 @@ void Cursor::dispatch(FuncRequest const & cmd0) fixIfBroken(); FuncRequest cmd = cmd0; Cursor safe = *this; + disp_ = DispatchResult(); buffer()->undo().beginUndoGroup(); // Is this a function that acts on inset at point? if (lyxaction.funcHasFlag(cmd.action(), LyXAction::AtPoint) && nextInset()) { - result().dispatched(true); - result().update(Update::FitCursor | Update::Force); + disp_.dispatched(true); + disp_.screenUpdate(Update::FitCursor | Update::Force); FuncRequest tmpcmd = cmd; LYXERR(Debug::DEBUG, "Cursor::dispatch: (AtPoint) cmd: " << cmd0 << endl << *this); nextInset()->dispatch(*this, tmpcmd); - if (result().dispatched()) { + if (disp_.dispatched()) { buffer()->undo().endUndoGroup(); return; } @@ -359,7 +363,7 @@ void Cursor::dispatch(FuncRequest const & cmd0) // The common case is 'LFUN handled, need update', so make the // LFUN handler's life easier by assuming this as default value. // The handler can reset the update and val flags if necessary. - disp_.update(Update::FitCursor | Update::Force); + disp_.screenUpdate(Update::FitCursor | Update::Force); disp_.dispatched(true); inset().dispatch(*this, cmd); if (disp_.dispatched()) @@ -380,7 +384,7 @@ void Cursor::dispatch(FuncRequest const & cmd0) safe.pos() = safe.lastpos(); } operator=(safe); - disp_.update(Update::None); + disp_.screenUpdate(Update::None); disp_.dispatched(false); } else { // restore the previous one because nested Cursor::dispatch calls @@ -391,7 +395,7 @@ void Cursor::dispatch(FuncRequest const & cmd0) } -DispatchResult Cursor::result() const +DispatchResult const & Cursor::result() const { return disp_; } @@ -467,7 +471,7 @@ int Cursor::currentMode() void Cursor::getPos(int & x, int & y) const { - Point p = bv().getPos(*this, boundary()); + Point p = bv().getPos(*this); x = p.x_; y = p.y_; } @@ -980,7 +984,7 @@ void Cursor::posVisToRowExtremity(bool left) } -CursorSlice Cursor::anchor() const +CursorSlice Cursor::normalAnchor() const { if (!selection()) return top(); @@ -994,11 +998,17 @@ CursorSlice Cursor::anchor() const } +DocIterator & Cursor::realAnchor() +{ + return anchor_; +} + + CursorSlice Cursor::selBegin() const { if (!selection()) return top(); - return anchor() < top() ? anchor() : top(); + return normalAnchor() < top() ? normalAnchor() : top(); } @@ -1006,7 +1016,7 @@ CursorSlice Cursor::selEnd() const { if (!selection()) return top(); - return anchor() > top() ? anchor() : top(); + return normalAnchor() > top() ? normalAnchor() : top(); } @@ -1018,10 +1028,10 @@ DocIterator Cursor::selectionBegin() const DocIterator di; // FIXME: This is a work-around for the problem that // CursorSlice doesn't keep track of the boundary. - if (anchor() == top()) + if (normalAnchor() == top()) di = anchor_.boundary() > boundary() ? anchor_ : *this; else - di = anchor() < top() ? anchor_ : *this; + di = normalAnchor() < top() ? anchor_ : *this; di.resize(depth()); return di; } @@ -1035,10 +1045,10 @@ DocIterator Cursor::selectionEnd() const DocIterator di; // FIXME: This is a work-around for the problem that // CursorSlice doesn't keep track of the boundary. - if (anchor() == top()) + if (normalAnchor() == top()) di = anchor_.boundary() < boundary() ? anchor_ : *this; else - di = anchor() > top() ? anchor_ : *this; + di = normalAnchor() > top() ? anchor_ : *this; if (di.depth() > depth()) { di.resize(depth()); @@ -1053,9 +1063,9 @@ void Cursor::setSelection() setSelection(true); // A selection with no contents is not a selection // FIXME: doesnt look ok - if (idx() == anchor().idx() && - pit() == anchor().pit() && - pos() == anchor().pos()) + if (idx() == normalAnchor().idx() && + pit() == normalAnchor().pit() && + pos() == normalAnchor().pos()) setSelection(false); } @@ -1267,13 +1277,14 @@ void Cursor::plainInsert(MathAtom const & t) ++pos(); inset().setBuffer(bv_->buffer()); inset().initView(); + forceBufferUpdate(); } void Cursor::insert(docstring const & str) { for_each(str.begin(), str.end(), - boost::bind(static_cast + bind(static_cast (&Cursor::insert), this, _1)); } @@ -1304,11 +1315,13 @@ void Cursor::insert(Inset * inset0) { LASSERT(inset0, /**/); if (inMathed()) - insert(MathAtom(inset0)); + insert(MathAtom(inset0->asInsetMath())); else { text()->insertInset(*this, inset0); inset0->setBuffer(bv_->buffer()); inset0->initView(); + if (inset0->isLabeled()) + forceBufferUpdate(); } } @@ -1350,7 +1363,7 @@ void Cursor::insert(MathData const & ar) cap::eraseSelection(*this); cell().insert(pos(), ar); pos() += ar.size(); - // FIXME audit setBuffer/updateBuffer calls + // FIXME audit setBuffer calls inset().setBuffer(bv_->buffer()); } @@ -1501,7 +1514,7 @@ bool Cursor::macroModeClose() // trigger updates of macros, at least, if no full // updates take place anyway - updateFlags(Update::Force); + screenUpdateFlags(Update::Force); docstring const name = s.substr(1); InsetMathNest * const in = inset().asInsetMath()->asNestInset(); @@ -1874,13 +1887,15 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded) updateNeeded |= bv().checkDepm(dummy, *this); updateTextTargetOffset(); + if (updateNeeded) + forceBufferUpdate(); } return false; } // with and without selection are handled differently if (!selection()) { - int yo = bv().getPos(*this, boundary()).y_; + int yo = bv().getPos(*this).y_; Cursor old = *this; // To next/previous row if (up) @@ -1898,7 +1913,7 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded) ++dummy.pos(); if (bv().checkDepm(dummy, old)) { updateNeeded = true; - // Make sure that cur gets back whatever happened to dummy(Lgb) + // Make sure that cur gets back whatever happened to dummy (Lgb) operator=(dummy); } } else { @@ -1943,6 +1958,8 @@ bool Cursor::upDownInText(bool up, bool & updateNeeded) updateNeeded |= bv().checkDepm(*this, old); } + if (updateNeeded) + forceBufferUpdate(); updateTextTargetOffset(); return true; } @@ -2104,15 +2121,33 @@ void Cursor::dispatched() } -void Cursor::updateFlags(Update::flags f) +void Cursor::screenUpdateFlags(Update::flags f) +{ + disp_.screenUpdate(f); +} + + +void Cursor::forceBufferUpdate() +{ + disp_.forceBufferUpdate(); +} + + +void Cursor::clearBufferUpdate() +{ + disp_.clearBufferUpdate(); +} + + +bool Cursor::needBufferUpdate() const { - disp_.update(f); + return disp_.needBufferUpdate(); } -void Cursor::noUpdate() +void Cursor::noScreenUpdate() { - disp_.update(Update::None); + disp_.screenUpdate(Update::None); }