]> git.lyx.org Git - lyx.git/commitdiff
* dispatchresult.h: rename 'FINISHED' to 'FINISHED_LEFT'
authorAndré Pönitz <poenitz@gmx.net>
Fri, 20 Feb 2004 17:19:53 +0000 (17:19 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 20 Feb 2004 17:19:53 +0000 (17:19 +0000)
* cursor.[Ch]: prepare for localized getStatus()

* lyxtext.h:
* tabular.C:
* text.C:
* text2.C:
* text3.C:  streamlines the LyXText cursor movement handlers a bit.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8453 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/cursor.C
src/cursor.h
src/dispatchresult.h
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insettabular.C
src/lyxtext.h
src/mathed/math_gridinset.C
src/mathed/math_nestinset.C
src/tabular.C
src/text.C
src/text2.C
src/text3.C

index f318697064d7eb458a64d272a77f97043232b5c9..b64e9a0f92a74e38f2f264d7f59ea9d7ff51378e 100644 (file)
@@ -981,15 +981,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
 
        switch (cmd.action) {
 
-       case LFUN_ESCAPE: {
-               if (bv_->cursor().depth() > 1) {
-                       bv_->cursor().pop();
-                       // Tell the paragraph dialog that we changed paragraph
-                       dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
-               }
-               break;
-       }
-
        case LFUN_UNDO:
                if (available()) {
                        cur.message(_("Undo"));
index 13956e8bfda180b9e930ea2dc17471c39fe30d93..0179a4656a0bb4b301e63feab1ba54cc37e95acb 100644 (file)
@@ -2,6 +2,19 @@
 
        * text3.C: fixed LFUN_QUOTE and add lfun arguments single/double.
 
+2004-02-20  André Pönitz  <poenitz@gmx.net>
+
+       * dispatchresult.h: rename 'FINISHED' to 'FINISHED_LEFT'
+
+       * cursor.[Ch]: prepare for localized getStatus()
+
+       * lyxtext.h:
+       * tabular.C:
+       * text.C:
+       * text2.C:
+       * text3.C:  streamlines the LyXText cursor movement handlers a bit.
+
+
 2004-02-20  André Pönitz  <poenitz@gmx.net>
 
        * lyxfunc.[Ch]: rename view_status_message() to viewStatusMessage()
index df64bb4eda42b0734eedb3cde98d64df7c05afed..99119245a59e194f1b03224d66898619d981de4c 100644 (file)
@@ -98,7 +98,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
                                // the inset handled the event fully
                                current_ = cursor_.size() - 1;
                                return DispatchResult(true, true);
-                       case FINISHED:
+                       case FINISHED_LEFT:
                                // the inset handled the event partially
                                cmd = FuncRequest(LFUN_FINISHED_LEFT);
                                break;
@@ -125,6 +125,30 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
 }
 
 
+bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
+{
+       lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
+       BOOST_ASSERT(pos() <= lastpos());
+       BOOST_ASSERT(idx() <= lastidx());
+       BOOST_ASSERT(par() <= lastpar());
+       for (current_ = cursor_.size() - 1; current_ >= 1; --current_) {
+               // the inset's getStatus() will return 'true' if it made
+               // a definitive decision on whether it want to handle the
+               // request or not. The result of this decision is put into
+               // the 'status' parameter.
+               bool const res = inset()->getStatus(*this, cmd, status);
+               if (res) {
+                       current_ = cursor_.size() - 1;
+                       return true;
+               }
+       }
+       BOOST_ASSERT(current_ == 0);
+       bool const res = bv_->text()->getStatus(*this, cmd, status);
+       current_ = cursor_.size() - 1;
+       return res;
+}
+
+
 void LCursor::push(InsetBase * inset)
 {
        lyxerr << "LCursor::push()  inset: " << inset << endl;
@@ -1936,7 +1960,7 @@ void LCursor::replaceWord(string const & replacestring)
 
        // Go back so that replacement string is also spellchecked
        for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
-               t->cursorLeft(*this, true);
+               t->cursorLeft(*this);
 }
 
 
index 91e169f5f142a4464bdd4d6fcdc22da6bc675ce4..9fc092b126d09cf11fc932fd7ca46c690cdeac89 100644 (file)
@@ -22,6 +22,7 @@ class BufferView;
 class UpdatableInset;
 class MathAtom;
 class DispatchResult;
+class FuncStatus;
 class FuncRequest;
 class InsetTabular;
 class LyXText;
@@ -74,6 +75,9 @@ public:
        explicit LCursor(BufferView & bv);
        /// dispatch from innermost inset upwards
        DispatchResult dispatch(FuncRequest const & cmd);
+       /// are we willing to handle this event?
+       bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
+
        /// add a new cursor slice
        void push(InsetBase * inset);
        /// add a new cursor slice, place cursor on left end
index 70760b33d0b1f045b7915e93d990c38323922f43..d5492172fab02784edae953e571e8b71ae3ca6a1 100644 (file)
 #define DISPATCH_RESULT_H
 
 /** Dispatch result codes
-       DISPATCHED          = the inset caught the action
-       DISPATCHED_NOUPDATE = the inset caught the action and no update
-                       is needed to redraw the inset
-       FINISHED            = the inset must be unlocked as a result
-                       of the action
+       NONE                = no special action required
+       FINISHED_LEFT       = the cursor leaves the inset to the LEFT
+                             as consequence of this action
        FINISHED_RIGHT      = FINISHED, but move the cursor RIGHT from
                        the inset.
        FINISHED_UP         = FINISHED, but move the cursor UP from
                        the inset.
        FINISHED_DOWN       = FINISHED, but move the cursor DOWN from
                        the inset.
-       FINISHED_POP       = FINISHED, but move the cursor out the inset
-                       (possibly more than one level)
-       UNDISPATCHED        = the action was not caught, it should be
-                       dispatched by lower level insets
 */
 enum dispatch_result_t {
        NONE = 0,
-       FINISHED,
+       FINISHED_LEFT,
        FINISHED_RIGHT,
        FINISHED_UP,
        FINISHED_DOWN
index 07a27dbdc5d472a84c744ee09edab1ef6c2ab392..53b749e730ca376d7e46d96f91ef5ad58ccdce51 100644 (file)
@@ -40,6 +40,12 @@ void InsetBase::priv_dispatch(LCursor & cur, FuncRequest const &)
 }
 
 
+bool InsetBase::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
+{
+       return false;
+}
+
+
 void InsetBase::edit(LCursor &, bool)
 {
        lyxerr << "InsetBase: edit left/right" << std::endl;
index aceaf310c334492c8f6bce6184c900aead6c0187..77115c1bf5fffa09c7f039c75f05060766c0785f 100644 (file)
@@ -21,6 +21,7 @@ class BufferView;
 class CursorSlice;
 class DispatchResult;
 class FuncRequest;
+class FuncStatus;
 class LaTeXFeatures;
 class LCursor;
 class LyXLex;
@@ -69,6 +70,9 @@ public:
 
        // the real dispatcher
        void dispatch(LCursor & cur, FuncRequest const & cmd);
+       /// do we want to handle this event?
+       virtual bool getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & status);
 
        /// cursor enters
        virtual void edit(LCursor & cur, bool left);
index 62d0f14bb979a02c5d13f62220c2844e1887bbba..36344554f23757df320f3cf3e6dafb600a98e22b 100644 (file)
@@ -470,6 +470,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_RIGHTSEL:
        case LFUN_RIGHT:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
                if (sl == cur.current())
@@ -479,15 +480,17 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_LEFTSEL: 
        case LFUN_LEFT:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
                if (sl == cur.current())
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_DOWNSEL:
        case LFUN_DOWN:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
                                cur.idx() = tabular.getCellBelow(cur.idx());
@@ -502,6 +505,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_UPSEL:
        case LFUN_UP:
                cell(cur.idx()).dispatch(cur, cmd);
+               cur.dispatched(NONE); // override the cell's result
                if (sl == cur.current())
                        if (tabular.row_of_cell(cur.idx()) != 0) {
                                cur.idx() = tabular.getCellAbove(cur.idx());
index a569a2dd280e8eda2e502d393185fa0acfe372f5..bafa53b3ef78b7aaba0f9b5d67c26e888617c1b8 100644 (file)
@@ -33,6 +33,7 @@ class Dimension;
 class InsetBase;
 class InsetOld_code;
 class FuncRequest;
+class FuncStatus;
 class LColor_color;
 class LCursor;
 class LyXTextClass;
@@ -129,7 +130,10 @@ public:
        int dist(int x, int y) const;
 
        /// try to handle that request
-       DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
+       void dispatch(LCursor & cur, FuncRequest const & cmd);
+       /// do we want to handle this event?
+       bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status);
+
        /// access to out BufferView. This should go...
        BufferView * bv();
        /// access to out BufferView. This should go...
@@ -194,13 +198,13 @@ public:
        ///
        InsetBase * editXY(LCursor & cur, int x, int y);
        ///
-       void cursorUp(LCursor & cur, bool selecting = false);
+       void cursorUp(LCursor & cur);
        ///
-       void cursorDown(LCursor & cur, bool selecting = false);
+       void cursorDown(LCursor & cur);
        ///
-       bool cursorLeft(LCursor & cur, bool internal = true);
+       void cursorLeft(LCursor & cur);
        ///
-       bool cursorRight(LCursor & cur, bool internal = true);
+       void cursorRight(LCursor & cur);
        ///
        void cursorLeftOneWord(LCursor & cur);
        ///
@@ -347,21 +351,6 @@ public:
        std::string getPossibleLabel(LCursor & cur) const;
        /// is this paragraph right-to-left?
        bool isRTL(Paragraph const & par) const;
-
-       ///
-       DispatchResult moveRight(LCursor & cur);
-       ///
-       DispatchResult moveLeft(LCursor & cur);
-       ///
-       DispatchResult moveRightIntern(LCursor & cur, bool front,
-               bool activate_inset, bool selecting);
-       ///
-       DispatchResult moveLeftIntern(LCursor & cur, bool front,
-               bool activate_inset, bool selecting);
-       ///
-       DispatchResult moveUp(LCursor & cur);
-       ///
-       DispatchResult moveDown(LCursor & cur);
        ///
        bool checkAndActivateInset(LCursor & cur, bool front);
 
index 5a8c3faded3cb023c046cfd7a161f19be72d217b..ac2664752f3b672ac06d4525bd99982a048863e0 100644 (file)
@@ -1031,7 +1031,7 @@ int MathGridInset::border() const
 
 void MathGridInset::splitCell(LCursor & cur)
 {
-       if (cur.idx() + 1 == nargs())
+       if (cur.idx() == cur.lastidx())
                return;
        MathArray ar = cur.cell();
        ar.erase(0, cur.pos());
@@ -1097,7 +1097,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                        cur.idx() = cur.lastpos();
 
                        //mathcursor->normalize();
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                        return;
                }
 
@@ -1156,7 +1156,7 @@ void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
                                cur.notdispatched();
                                return;
                        }
-                       lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
+                       lyxerr << "returning FINISHED_LEFT" << endl;
                        return;
                }
 
index 90a3f74b4dfc5fb790b22e8e66de53b9082f9e78..57694909010b248c072b0fbe3778f5ffe29e4a50 100644 (file)
@@ -432,7 +432,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_LEFT:
                cur.selHandle(cmd.action == LFUN_LEFTSEL);
                if (!cur.left())
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_UPSEL:
@@ -466,7 +466,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_WORDLEFT:
                cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
                if (!cur.home())
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_WORDRIGHTSEL:
@@ -480,7 +480,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_HOME:
                cur.selHandle(cmd.action == LFUN_HOMESEL);
                if (!cur.home())
-                       cur.dispatched(FINISHED_RIGHT);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_ENDSEL:
@@ -494,7 +494,7 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_PRIOR:
        case LFUN_BEGINNINGBUFSEL:
        case LFUN_BEGINNINGBUF:
-               cur.dispatched(FINISHED);
+               cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_NEXTSEL:
@@ -522,14 +522,14 @@ void MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_DELETE:
                //recordUndo(cur, Undo::ATOMIC);
                cur.erase();
-               cur.dispatched(FINISHED);
+               cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_ESCAPE:
                if (cur.selection()) 
                        cur.selClear();
                else 
-                       cur.dispatched(FINISHED);
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
        case LFUN_INSET_TOGGLE:
index 4dc6cb787d2454b2cfd525297093d553c61901d6..66e09284dcdaf973d6834ae878d29e321aa3d376 100644 (file)
@@ -1999,7 +1999,6 @@ int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
 {
        int ret = 0;
        int cell = getCellNumber(i, 0);
-       BufferParams const & bufferparams = buf.params();
 
        ret += TeXTopHLine(os, i);
        for (int j = 0; j < columns_; ++j) {
index deab330d9228038702da5f64e1c556ae6dd7fbdf..9a17b781d3997042f3da0fafc63f57797ce5f77d 100644 (file)
@@ -877,7 +877,7 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
        if (cur.pos() != 0 && cur.textRow().pos() == cur.pos()
            && !cpit->isNewline(cur.pos() - 1))
        {
-               cursorLeft(cur, true);
+               cursorLeft(cur);
        }
 
        while (!next_par->empty() && next_par->isNewline(0))
@@ -1254,7 +1254,7 @@ void LyXText::deleteWordForward(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0)
-               cursorRight(cur, true);
+               cursorRight(cur);
        else {
                cur.resetAnchor();
                cur.selection() = true;
@@ -1270,7 +1270,7 @@ void LyXText::deleteWordBackward(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0)
-               cursorLeft(cur, true);
+               cursorLeft(cur);
        else {
                cur.resetAnchor();
                cur.selection() = true;
@@ -1287,7 +1287,7 @@ void LyXText::deleteLineForward(LCursor & cur)
        BOOST_ASSERT(this == cur.text());
        if (cur.lastpos() == 0) {
                // Paragraph is empty, so we just go to the right
-               cursorRight(cur, true);
+               cursorRight(cur);
        } else {
                cur.resetAnchor();
                cur.selection() = true; // to avoid deletion
@@ -1355,12 +1355,11 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
 void LyXText::Delete(LCursor & cur)
 {
        BOOST_ASSERT(this == cur.text());
-       // this is a very simple implementation
-       // just move to the right
-       // if you had success make a backspace
-       size_t oldpar = cur.par();
-       if (cursorRight(cur, true)) {
-               recordUndo(cur, Undo::DELETE, oldpar);
+       // just move to the right, if we had success make a backspace
+       CursorSlice sl = cur.current();
+       cursorRight(cur);
+       if (sl == cur.current()) {
+               recordUndo(cur, Undo::DELETE, cur.par(), max(0, cur.par() - 1));
                backspace(cur);
        }
 }
@@ -1390,7 +1389,7 @@ void LyXText::backspace(LCursor & cur)
                        // handle the actual deletion of the paragraph.
 
                        if (cur.par() != 0) {
-                               cursorLeft(cur, true);
+                               cursorLeft(cur);
                                // the layout things can change the height of a row !
                                redoParagraph(cur);
                                return;
index 6000d2f04277c7222747428c2970a0029543f5ee..0a46ae2e639e0056de62209b79ba170810a06e8e 100644 (file)
@@ -878,7 +878,7 @@ void LyXText::insertInset(LCursor & cur, InsetBase * inset)
        // and fails if the cursor is behind the inset and getInset
        // does not return the inset!
        if (isHighlyEditableInset(inset))
-               cursorLeft(cur, true);
+               cursorLeft(cur);
        unFreezeUndo();
 }
 
@@ -1007,7 +1007,7 @@ void LyXText::setSelectionRange(LCursor & cur, lyx::pos_type length)
                return;
        cur.resetAnchor();
        while (length--)
-               cursorRight(cur, true);
+               cursorRight(cur);
        cur.setSelection();
 }
 
@@ -1344,6 +1344,8 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y)
 
 bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
 {
+       if (cur.selection())
+               return false;
        if (cur.pos() == cur.lastpos())
                return false;
        InsetBase * inset = cur.nextInset();
@@ -1354,125 +1356,56 @@ bool LyXText::checkAndActivateInset(LCursor & cur, bool front)
 }
 
 
-DispatchResult LyXText::moveRight(LCursor & cur)
-{
-       if (isRTL(cur.paragraph()))
-               return moveLeftIntern(cur, false, true, false);
-       else
-               return moveRightIntern(cur, true, true, false);
-}
-
-
-DispatchResult LyXText::moveLeft(LCursor & cur)
-{
-       if (isRTL(cur.paragraph()))
-               return moveRightIntern(cur, true, true, false);
-       else
-               return moveLeftIntern(cur, false, true, false);
-}
-
-
-DispatchResult LyXText::moveRightIntern(LCursor & cur, 
-       bool front, bool activate_inset, bool selecting)
-{
-       if (cur.par() == cur.lastpar() && cur.pos() == cur.lastpos())
-               return DispatchResult(false, FINISHED_RIGHT);
-       if (activate_inset && checkAndActivateInset(cur, front))
-               return DispatchResult(true, true);
-       cursorRight(cur, true);
-       if (!selecting)
-               cur.clearSelection();
-       return DispatchResult(true);
-}
-
-
-DispatchResult LyXText::moveLeftIntern(LCursor & cur,
-       bool front, bool activate_inset, bool selecting)
-{
-       if (cur.par() == 0 && cur.pos() == 0)
-               return DispatchResult(false, FINISHED);
-       cursorLeft(cur, true);
-       if (!selecting)
-               cur.clearSelection();
-       if (activate_inset && checkAndActivateInset(cur, front))
-               return DispatchResult(true, true);
-       return DispatchResult(true);
-}
-
-
-DispatchResult LyXText::moveUp(LCursor & cur)
-{
-       if (cur.par() == 0 && cur.crow() == 0)
-               return DispatchResult(false, FINISHED_UP);
-       cursorUp(cur, false);
-       cur.clearSelection();
-       return DispatchResult(true);
-}
-
-
-DispatchResult LyXText::moveDown(LCursor & cur)
-{
-       if (cur.par() == cur.lastpar() && cur.textRow().endpos() == cur.lastpos())
-               return DispatchResult(false, FINISHED_DOWN);
-       cursorDown(cur, false);
-       cur.clearSelection();
-       return DispatchResult(true);
-}
-
-
-bool LyXText::cursorLeft(LCursor & cur, bool internal)
+void LyXText::cursorLeft(LCursor & cur)
 {
        if (cur.pos() != 0) {
                bool boundary = cur.boundary();
                setCursor(cur, cur.par(), cur.pos() - 1, true, false);
-               if (!internal && !boundary &&
-                   bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
-                       setCursor(cur, cur.par(), cur.pos() + 1, true, true);
-               return true;
+               if (!checkAndActivateInset(cur, false)) {
+                       if (false && !boundary &&
+                                       bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
+                               setCursor(cur, cur.par(), cur.pos() + 1, true, true);
+                       return;
+               }
        }
 
        if (cur.par() != 0) {
                // steps into the paragraph above
                setCursor(cur, cur.par() - 1, getPar(cur.par() - 1)->size());
-               return true;
        }
-
-       return false;
 }
 
 
-bool LyXText::cursorRight(LCursor & cur, bool internal)
+void LyXText::cursorRight(LCursor & cur)
 {
-       if (!internal && cur.boundary()) {
+       if (false && cur.boundary()) {
                setCursor(cur, cur.par(), cur.pos(), true, false);
-               return true;
+               return;
        }
 
        if (cur.pos() != cur.lastpos()) {
-               setCursor(cur, cur.par(), cur.pos() + 1, true, false);
-               if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
-                                                cur.pos()))
-                       setCursor(cur, cur.par(), cur.pos(), true, true);
-               return true;
+               if (!checkAndActivateInset(cur, true)) { 
+                       setCursor(cur, cur.par(), cur.pos() + 1, true, false);
+                       if (false && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
+                                                        cur.pos()))
+                               setCursor(cur, cur.par(), cur.pos(), true, true);
+               }
+               return;
        }
 
-       if (cur.par() != cur.lastpar()) {
+       if (cur.par() != cur.lastpar())
                setCursor(cur, cur.par() + 1, 0);
-               return true;
-       }
-
-       return false;
 }
 
 
-void LyXText::cursorUp(LCursor & cur, bool selecting)
+void LyXText::cursorUp(LCursor & cur)
 {
        Row const & row = cur.textRow();
        int x = cur.x_target();
        int y = cursorY(cur.current()) - row.baseline() - 1;
        setCursorFromCoordinates(cur, x, y);
 
-       if (!selecting) {
+       if (!cur.selection()) {
                InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->editXY(cur, cur.x_target(), y);
@@ -1480,14 +1413,14 @@ void LyXText::cursorUp(LCursor & cur, bool selecting)
 }
 
 
-void LyXText::cursorDown(LCursor & cur, bool selecting)
+void LyXText::cursorDown(LCursor & cur)
 {
        Row const & row = cur.textRow();
        int x = cur.x_target();
        int y = cursorY(cur.current()) - row.baseline() + row.height() + 1;
        setCursorFromCoordinates(cur, x, y);
 
-       if (!selecting) {
+       if (!cur.selection()) {
                InsetBase * inset_hit = checkInsetHit(cur.x_target(), y);
                if (inset_hit && isHighlyEditableInset(inset_hit))
                        inset_hit->editXY(cur, cur.x_target(), y);
index f07306eaf9d4085039367459ebd6a3857f032f67..d4e39fc9fd5416af4d389981fc9f79c445bc62f3 100644 (file)
@@ -299,7 +299,7 @@ void LyXText::cursorPrevious(LCursor & cur)
        if (cpar == cur.par() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
-               cursorUp(cur, true);
+               cursorUp(cur);
        }
 
        bv()->updateScrollbar();
@@ -319,7 +319,7 @@ void LyXText::cursorNext(LCursor & cur)
        if (cpar == cur.par() && cpos == cur.pos()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
-               cursorDown(cur, true);
+               cursorDown(cur);
        }
 
        bv()->updateScrollbar();
@@ -373,12 +373,13 @@ bool LyXText::isRTL(Paragraph const & par) const
 }
 
 
-DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
+void LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
        //lyxerr << "*** LyXText::dispatch: cmd: " << cmd << endl;
 
        BufferView * bv = &cur.bv();
+       CursorSlice sl = cur.current();
 
        switch (cmd.action) {
 
@@ -461,38 +462,42 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                finishChange(cur);
                break;
 
+       case LFUN_RIGHT:
        case LFUN_RIGHTSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_RIGHTSEL);
                if (isRTL(cur.paragraph()))
-                       cursorLeft(cur, true);
+                       cursorLeft(cur);
                else
-                       cursorRight(cur, true);
-               finishChange(cur, true);
+                       cursorRight(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_RIGHT);
                break;
 
+       case LFUN_LEFT:
        case LFUN_LEFTSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
+               cur.selHandle(cmd.action == LFUN_LEFTSEL);
                if (isRTL(cur.paragraph()))
-                       cursorRight(cur, true);
+                       cursorRight(cur);
                else
-                       cursorLeft(cur, true);
-               finishChange(cur, true);
+                       cursorLeft(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_LEFT);
                break;
 
+       case LFUN_UP:
        case LFUN_UPSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorUp(cur, true);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_UPSEL);
+               cursorUp(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_UP);
                break;
 
+       case LFUN_DOWN:
        case LFUN_DOWNSEL:
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorDown(cur, true);
-               finishChange(cur, true);
+               cur.selHandle(cmd.action == LFUN_DOWNSEL);
+               cursorDown(cur);
+               if (sl == cur.current())
+                       cur.dispatched(FINISHED_DOWN);
                break;
 
        case LFUN_UP_PARAGRAPHSEL:
@@ -563,22 +568,6 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
        }
 
-       case LFUN_RIGHT:
-               finishChange(cur);
-               return moveRight(cur);
-
-       case LFUN_LEFT:
-               finishChange(cur);
-               return moveLeft(cur);
-
-       case LFUN_UP:
-               finishChange(cur);
-               return moveUp(cur);
-
-       case LFUN_DOWN:
-               finishChange(cur);
-               return moveDown(cur);
-
        case LFUN_UP_PARAGRAPH:
                if (!cur.mark())
                        cur.clearSelection();
@@ -598,8 +587,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                        cur.clearSelection();
                finishChange(cur, false);
                if (cur.par() == 0 && cur.textRow().pos() == 0)
-                       return DispatchResult(false, FINISHED_UP);
-               cursorPrevious(cur);
+                       cur.dispatched(FINISHED_UP);
+               else
+                       cursorPrevious(cur);
                break;
 
        case LFUN_NEXT:
@@ -608,8 +598,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                finishChange(cur, false);
                if (cur.par() == cur.lastpar()
                          && cur.textRow().endpos() == cur.lastpos())
-                       return DispatchResult(false, FINISHED_DOWN);
-               cursorNext(cur);
+                       cur.dispatched(FINISHED_DOWN);
+               else
+                       cursorNext(cur);
                break;
 
        case LFUN_HOME:
@@ -653,8 +644,8 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                // Reverse the effect of LFUN_BREAKPARAGRAPH_SKIP.
                if (!cur.selection()) {
                        if (cur.pos() == cur.lastpos()) {
-                               cursorRight(cur, true);
-                               cursorLeft(cur, true);
+                               cursorRight(cur);
+                               cursorLeft(cur);
                        }
                        Delete(cur);
                        cur.resetAnchor();
@@ -800,9 +791,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_INSET_TOGGLE:
                cur.clearSelection();
                if (!toggleInset(cur))
-                       return DispatchResult(false);
-               cur.update();
-               bv->switchKeyMap();
+                       cur.notdispatched();
+               else
+                       bv->switchKeyMap();
                break;
 
        case LFUN_SPACE_INSERT:
@@ -880,21 +871,25 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
 
        case LFUN_BEGINNINGBUFSEL:
-               if (in_inset_)
-                       return DispatchResult(false);
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorTop(cur);
-               finishChange(cur, true);
+               if (in_inset_) {
+                       cur.notdispatched();
+               } else {
+                       if (!cur.selection())
+                               cur.resetAnchor();
+                       cursorTop(cur);
+                       finishChange(cur, true);
+               }
                break;
 
        case LFUN_ENDBUFSEL:
-               if (in_inset_)
-                       return DispatchResult(false);
-               if (!cur.selection())
-                       cur.resetAnchor();
-               cursorBottom(cur);
-               finishChange(cur, true);
+               if (in_inset_) {
+                       cur.notdispatched();
+               } else {
+                       if (!cur.selection())
+                               cur.resetAnchor();
+                       cursorBottom(cur);
+                       finishChange(cur, true);
+               }
                break;
 
        case LFUN_GETXY:
@@ -1110,9 +1105,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                // FIXME: shouldn't be top-text-specific
                if (!in_inset_ && cur.current() == old) {
                        if (cmd.y - bv->top_y() >= bv->workHeight())
-                               cursorDown(cur, true);
+                               cursorDown(cur);
                        else if (cmd.y - bv->top_y() < 0)
-                               cursorUp(cur, true);
+                               cursorUp(cur);
                }
 
                // don't set anchor_
@@ -1186,8 +1181,10 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
        case LFUN_MOUSE_RELEASE: {
                // do nothing if we used the mouse wheel
                if (cmd.button() == mouse_button::button4
-                || cmd.button() == mouse_button::button5)
-                       return DispatchResult(true, false);
+                || cmd.button() == mouse_button::button5) {
+                       cur.notdispatched();
+                       break;
+               }
 
                selection_possible = false;
 
@@ -1452,7 +1449,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
                cur.pop(cur.currentDepth());
                if (isRTL(cur.paragraph()))
-                       cursorLeft(cur, true);
+                       cursorLeft(cur);
                cur.bv().cursor() = cur;
                break;
 
@@ -1460,21 +1457,21 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
                cur.pop(cur.currentDepth());
                if (!isRTL(cur.paragraph()))
-                       cursorRight(cur, true);
+                       cursorRight(cur);
                cur.bv().cursor() = cur;
                break;
 
        case LFUN_FINISHED_UP:
                lyxerr << "handle LFUN_FINISHED_UP" << endl;
                cur.pop(cur.currentDepth());
-               cursorUp(cur, true);
+               cursorUp(cur);
                cur.bv().cursor() = cur;
                break;
 
        case LFUN_FINISHED_DOWN:
                lyxerr << "handle LFUN_FINISHED_DOWN" << endl;
                cur.pop(cur.currentDepth());
-               cursorDown(cur, true);
+               cursorDown(cur);
                cur.bv().cursor() = cur;
                break;
 
@@ -1535,7 +1532,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                        breakParagraph(cur);
 
                        if (cur.lastpos() != 0) {
-                               cursorLeft(cur, true);
+                               cursorLeft(cur);
                                breakParagraph(cur);
                        }
 
@@ -1596,9 +1593,21 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
                break;
        }
 
+       case LFUN_ESCAPE:
+               if (cur.selection())
+                       cur.selection() = false;
+               else
+                       cur.dispatched(FINISHED_LEFT);
+               break;
+
        default:
-               return DispatchResult(false);
+               cur.notdispatched();
+               break;
        }
+}
+
 
-       return DispatchResult(true, true);
+bool LyXText::getStatus(LCursor &, FuncRequest const &, FuncStatus &)
+{
+       return false;
 }