From 108a67ed433821fba346ddc0adb28483a0154e2a Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Thu, 15 Apr 2010 18:16:07 +0000 Subject: [PATCH] Make Cursor::anchor_ private and make an access function Cursor::realAnchor() to stress the fact that this is thus not the normalAnchor(). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34146 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 4 ++-- src/Cursor.cpp | 8 +++++++- src/Cursor.h | 8 ++++++-- src/Text3.cpp | 14 +++++++------- src/insets/InsetTabular.cpp | 4 ++-- src/mathed/InsetMathNest.cpp | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 9a922f997f..d237e6d416 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1859,10 +1859,10 @@ docstring const BufferView::requestSelection() LYXERR(Debug::SELECTION, "requestSelection: xsel_cache.set: " << d->xsel_cache_.set); if (!d->xsel_cache_.set || cur.top() != d->xsel_cache_.cursor || - cur.anchor_.top() != d->xsel_cache_.anchor) + cur.realAnchor().top() != d->xsel_cache_.anchor) { d->xsel_cache_.cursor = cur.top(); - d->xsel_cache_.anchor = cur.anchor_.top(); + d->xsel_cache_.anchor = cur.realAnchor().top(); d->xsel_cache_.set = cur.selection(); return cur.selectionAsString(false); } diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 185d866950..33536fae07 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -214,7 +214,7 @@ 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_))) { + && (!cur.selection() || positionable(it, cur.realAnchor()))) { Point p = bv.getPos(it, false); int xo = p.x_; int yo = p.y_; @@ -994,6 +994,12 @@ CursorSlice Cursor::normalAnchor() const } +DocIterator & Cursor::realAnchor() +{ + return anchor_; +} + + CursorSlice Cursor::selBegin() const { if (!selection()) diff --git a/src/Cursor.h b/src/Cursor.h index 5747d31ce4..eb268a371a 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -202,6 +202,10 @@ public: /// access to normalized selection anchor CursorSlice normalAnchor() const; + // FIXME: this can't be a const & and a const function because + // LFUN_TAB_* wants to move the real anchor. + /// access to real selection anchor + DocIterator & realAnchor(); /// sets anchor to cursor position void resetAnchor(); /// access to owning BufferView @@ -288,8 +292,6 @@ public: /// BufferView * bv_; //private: - /// the anchor position - DocIterator anchor_; /// DocIterator const & beforeDispatchCursor() const { return beforeDispatchCursor_; } @@ -297,6 +299,8 @@ public: void saveBeforeDispatchPosXY(); private: + /// the anchor position + DocIterator anchor_; /// mutable DispatchResult disp_; /** diff --git a/src/Text3.cpp b/src/Text3.cpp index 04de6b7bc2..69015cac62 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -885,8 +885,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) bv->buffer().params().trackChanges); // Update the selection pos to make sure the selection does not // change as the inserted tab will increase the logical pos. - if (cur.anchor_.pit() == pit) - cur.anchor_.forwardPos(); + if (cur.realAnchor().pit() == pit) + cur.realAnchor().forwardPos(); if (cur.pit() == pit) cur.forwardPos(); } @@ -912,8 +912,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) if (par.getChar(0) == '\t') { if (cur.pit() == pit) cur.posBackward(); - if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 ) - cur.anchor_.backwardPos(); + if (cur.realAnchor().pit() == pit && cur.realAnchor().pos() > 0 ) + cur.realAnchor().backwardPos(); par.eraseChar(0, tc); } else @@ -922,8 +922,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) par.getChar(0) == ' ' && n_spaces < 4; ++n_spaces) { if (cur.pit() == pit) cur.posBackward(); - if (cur.anchor_.pit() == pit && cur.anchor_.pos() > 0 ) - cur.anchor_.backwardPos(); + if (cur.realAnchor().pit() == pit && cur.realAnchor().pos() > 0 ) + cur.realAnchor().backwardPos(); par.eraseChar(0, tc); } @@ -1403,7 +1403,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd) } // ignore motions deeper nested than the real anchor Cursor & bvcur = cur.bv().cursor(); - if (!bvcur.anchor_.hasPart(cur)) { + if (!bvcur.realAnchor().hasPart(cur)) { cur.undispatched(); break; } diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index d75e2a6ffe..55476b4c5b 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -3560,7 +3560,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) //lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl; if (cmd.button() == mouse_button::button1) { // only accept motions to places not deeper nested than the real anchor - if (!bvcur.anchor_.hasPart(cur)) { + if (!bvcur.realAnchor().hasPart(cur)) { cur.undispatched(); break; } @@ -3590,7 +3590,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) } // only update if selection changes if (bvcur.idx() == cur.idx() && - !(bvcur.anchor_.idx() == cur.idx() && bvcur.pos() != cur.pos())) + !(bvcur.realAnchor().idx() == cur.idx() && bvcur.pos() != cur.pos())) cur.noUpdate(); setCursorFromCoordinates(cur, cmd.x(), cmd.y()); bvcur.setCursor(cur); diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index 21721eb3b6..151690f654 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1454,7 +1454,7 @@ void InsetMathNest::lfunMouseMotion(Cursor & cur, FuncRequest & cmd) // only select with button 1 if (cmd.button() == mouse_button::button1) { Cursor & bvcur = cur.bv().cursor(); - if (bvcur.anchor_.hasPart(cur)) { + if (bvcur.realAnchor().hasPart(cur)) { //lyxerr << "## lfunMouseMotion: cursor: " << cur << endl; bvcur.setCursor(cur); bvcur.setSelection(true);