From 25bafa277251eaf01e3068921442b1584ce77975 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 13 Jan 2004 18:08:13 +0000 Subject: [PATCH] Anchor globalization git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8340 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 46 +++++++++++++++++++++--- src/BufferView.h | 21 ++++++++--- src/BufferView_pimpl.C | 35 ++++++++++--------- src/bufferview_funcs.C | 2 +- src/cursor.C | 66 ++++++++++++++++++++--------------- src/cursor.h | 15 ++++++-- src/cursor_slice.C | 22 +++++++++--- src/cursor_slice.h | 8 +++-- src/frontends/screen.C | 6 ++-- src/insets/insetcollapsable.C | 4 +-- src/insets/insettabular.C | 28 +++++++-------- src/insets/insettext.C | 2 +- src/iterators.C | 2 +- src/lyxfunc.C | 20 +++++------ src/mathed/formulabase.C | 8 ++--- src/rowpainter.C | 2 +- src/text.C | 20 +++++------ src/text2.C | 16 ++++----- src/text3.C | 54 ++++++++++++++-------------- src/undo.C | 2 +- 20 files changed, 233 insertions(+), 146 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 062bd2854d..d75d6c1960 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -316,7 +316,7 @@ void BufferView::gotoLabel(string const & label) text()->setCursor( std::distance(text()->paragraphs().begin(), it.getPar()), it.getPos()); - text()->anchor() = text()->cursor(); + resetAnchor(); update(); return; } @@ -393,13 +393,13 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to) UpdatableInset * BufferView::innerInset() const { - return static_cast(cursor().innerInset()); + return static_cast(fullCursor().innerInset()); } LyXText * BufferView::getLyXText() const { - return cursor().innerText(); + return fullCursor().innerText(); } @@ -436,18 +436,48 @@ int BufferView::workHeight() const } -LCursor & BufferView::cursor() +void BufferView::fullCursor(LCursor const & cur) +{ + pimpl_->cursor_ = cur; +} + + +LCursor & BufferView::fullCursor() { return pimpl_->cursor_; } -LCursor const & BufferView::cursor() const +LCursor const & BufferView::fullCursor() const { return pimpl_->cursor_; } +CursorSlice & BufferView::cursor() +{ + return fullCursor().cursor_.back(); +} + + +CursorSlice const & BufferView::cursor() const +{ + return fullCursor().cursor_.back(); +} + + +CursorSlice & BufferView::anchor() +{ + return fullCursor().anchor_.back(); +} + + +CursorSlice const & BufferView::anchor() const +{ + return fullCursor().anchor_.back(); +} + + void BufferView::x_target(int x) { x_target_ = x; @@ -470,3 +500,9 @@ LyXText * BufferView::text() const { return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0; } + + +void BufferView::resetAnchor() +{ + return fullCursor().resetAnchor(); +} diff --git a/src/BufferView.h b/src/BufferView.h index 47f2da3b3c..8781866c5e 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -21,6 +21,7 @@ class Buffer; class Change; +class CursorSlice; class Encoding; class ErrorList; class FuncRequest; @@ -185,14 +186,26 @@ public: /// clear the X selection void unsetXSel(); - /// access to cursor - LCursor & cursor(); - /// access to cursor - LCursor const & cursor() const; + /// access to full cursor + LCursor & fullCursor(); + /// access to full cursor + void fullCursor(LCursor const &); + /// access to full cursor + LCursor const & fullCursor() const; + /// access to topmost cursor slice + CursorSlice & cursor(); + /// access to topmost cursor slice + CursorSlice const & cursor() const; + /// access to selection anchor + CursorSlice & anchor(); + /// access to selection anchor + CursorSlice const & anchor() const; /// UpdatableInset * innerInset() const; /// LyXText * text() const; + /// + void resetAnchor(); private: /// diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 9e8bb28013..59f74f27d3 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -393,8 +393,8 @@ void BufferView::Pimpl::resizeCurrentBuffer() if (!text) return; - par = text->cursor().par(); - pos = text->cursor().pos(); + par = bv_->cursor().par(); + pos = bv_->cursor().pos(); selstartpar = text->selStart().par(); selstartpos = text->selStart().pos(); selendpar = text->selEnd().par(); @@ -412,13 +412,13 @@ void BufferView::Pimpl::resizeCurrentBuffer() text->selection.mark(mark_set); if (selection) { text->setCursor(selstartpar, selstartpos); - text->anchor() = text->cursor(); + bv_->resetAnchor(); text->setCursor(selendpar, selendpos); text->setSelection(); text->setCursor(par, pos); } else { text->setCursor(par, pos); - text->anchor() = text->cursor(); + bv_->resetAnchor(); text->selection.set(false); } } @@ -537,11 +537,11 @@ void BufferView::Pimpl::selectionRequested() } if (!xsel_cache_.set || - text->cursor() != xsel_cache_.cursor || - text->anchor() != xsel_cache_.anchor) + bv_->cursor() != xsel_cache_.cursor || + bv_->anchor() != xsel_cache_.anchor) { - xsel_cache_.cursor = text->cursor(); - xsel_cache_.anchor = text->anchor(); + xsel_cache_.cursor = bv_->cursor(); + xsel_cache_.anchor = bv_->anchor(); xsel_cache_.set = text->selection.set(); sel = text->selectionAsString(*bv_->buffer(), false); if (!sel.empty()) @@ -915,7 +915,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) if (!available()) return false; FuncRequest cmd1(cmd, bv_); - UpdatableInset * inset = bv_->cursor().innerInset(); + UpdatableInset * inset = bv_->fullCursor().innerInset(); DispatchResult res; if (inset) { cmd1.x -= inset->x(); @@ -923,12 +923,12 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) res = inset->dispatch(cmd1); } else { cmd1.y += bv_->top_y(); - res = bv_->cursor().innerText()->dispatch(cmd1); + res = bv_->fullCursor().innerText()->dispatch(cmd1); } if (bv_->fitCursor() || res.update()) { bv_->update(); - bv_->cursor().updatePos(); + bv_->fullCursor().updatePos(); } return true; @@ -968,7 +968,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) res = inset->dispatch(cmd2); if (res.update()) { bv_->update(); - bv_->cursor().updatePos(); + bv_->fullCursor().updatePos(); } res.update(false); switch (res.val()) { @@ -977,8 +977,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) case FINISHED_UP: case FINISHED_DOWN: theTempCursor.pop(); - bv_->cursor() = theTempCursor; - bv_->cursor().innerText()->setCursorFromCoordinates(cmd.x, top_y() + cmd.y); + bv_->fullCursor(theTempCursor); + bv_->fullCursor().innerText() + ->setCursorFromCoordinates(cmd.x, top_y() + cmd.y); if (bv_->fitCursor()) bv_->update(); return true; @@ -994,9 +995,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) lyxerr << "dispatching " << cmd1 << " to surrounding LyXText " << theTempCursor.innerText() << endl; - bv_->cursor() = theTempCursor; + bv_->fullCursor(theTempCursor); cmd1.y += bv_->top_y(); - res = bv_->cursor().innerText()->dispatch(cmd1); + res = bv_->fullCursor().innerText()->dispatch(cmd1); if (bv_->fitCursor() || res.update()) bv_->update(); @@ -1276,7 +1277,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) bv_->text()->setLayout(hasLayout ? lres : tclass.defaultLayoutName()); bv_->text()->setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0); } - bv_->cursor().innerText()->insertInset(inset); + bv_->fullCursor().innerText()->insertInset(inset); unFreezeUndo(); return true; } diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index c8445a2935..13383258d6 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -295,7 +295,7 @@ void put_selection_at(BufferView * bv, PosIterator const & cur, bv->top_y(par.outerPar()->y); bv->update(); text->setCursor(cur.pit(), cur.pos()); - bv->cursor().updatePos(); + bv->fullCursor().updatePos(); if (length) { text->setSelectionRange(length); diff --git a/src/cursor.C b/src/cursor.C index 13f1bc2420..9af49d4638 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -32,17 +32,17 @@ using std::vector; using std::endl; -std::ostream & operator<<(std::ostream & os, LCursor const & cursor) +std::ostream & operator<<(std::ostream & os, LCursor const & cur) { os << "\n"; - for (size_t i = 0, n = cursor.data_.size(); i != n; ++i) - os << " " << cursor.data_[i] << "\n"; + for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i) + os << " (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n"; return os; } LCursor::LCursor(BufferView * bv) - : data_(1), bv_(bv) + : cursor_(1), anchor_(1), bv_(bv) {} @@ -51,8 +51,8 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) lyxerr << "\nLCursor::dispatch: " << *this << endl; FuncRequest cmd = cmd0; - for (int i = data_.size() - 1; i >= 1; --i) { - CursorSlice const & citem = data_[i]; + for (int i = cursor_.size() - 1; i >= 1; --i) { + CursorSlice const & citem = cursor_[i]; lyxerr << "trying to dispatch to inset " << citem.inset_ << endl; DispatchResult res = citem.inset_->dispatch(cmd); if (res.dispatched()) { @@ -100,7 +100,8 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0) void LCursor::push(UpdatableInset * inset) { lyxerr << "LCursor::push() inset: " << inset << endl; - data_.push_back(CursorSlice(inset)); + cursor_.push_back(CursorSlice(inset)); + anchor_.push_back(CursorSlice(inset)); updatePos(); } @@ -109,9 +110,10 @@ void LCursor::push(UpdatableInset * inset) void LCursor::pop(int depth) { lyxerr << "LCursor::pop() to " << depth << endl; - while (data_.size() > 1 && depth < data_.size()) { + while (cursor_.size() > 1 && depth < cursor_.size()) { lyxerr << "LCursor::pop a level " << endl; - data_.pop_back(); + cursor_.pop_back(); + anchor_.pop_back(); } } @@ -119,28 +121,30 @@ void LCursor::pop(int depth) void LCursor::pop() { lyxerr << "LCursor::pop() " << endl; - //BOOST_ASSERT(!data_.empty()); - if (data_.size() <= 1) + //BOOST_ASSERT(!cursor_.empty()); + if (cursor_.size() <= 1) lyxerr << "### TRYING TO POP FROM EMPTY CURSOR" << endl; - else - data_.pop_back(); + else { + cursor_.pop_back(); + anchor_.pop_back(); + } } UpdatableInset * LCursor::innerInset() const { - return data_.size() <= 1 ? 0 : data_.back().asUpdatableInset(); + return cursor_.size() <= 1 ? 0 : cursor_.back().asUpdatableInset(); } LyXText * LCursor::innerText() const { - if (data_.size() > 1) { + if (cursor_.size() > 1) { // go up until first non-0 text is hit // (innermost text is 0 e.g. for mathed and the outer tabular level) - for (int i = data_.size() - 1; i >= 1; --i) - if (data_[i].text()) - return data_[i].text(); + for (int i = cursor_.size() - 1; i >= 1; --i) + if (cursor_[i].text()) + return cursor_[i].text(); } return bv_->text(); } @@ -148,7 +152,7 @@ LyXText * LCursor::innerText() const void LCursor::updatePos() { - if (data_.size() > 1) + if (cursor_.size() > 1) cached_y_ = bv_->top_y() + innerInset()->y(); } @@ -168,7 +172,7 @@ void LCursor::getDim(int & asc, int & desc) const void LCursor::getPos(int & x, int & y) const { - if (data_.size() <= 1) { + if (cursor_.size() <= 1) { x = bv_->text()->cursorX(); y = bv_->text()->cursorY(); // y -= bv_->top_y(); @@ -182,7 +186,7 @@ void LCursor::getPos(int & x, int & y) const // inset->draw() is not called: this doesn't update // inset.top_baseline, so getCursor() returns an old value. // Ugly as you like. - inset->getCursorPos(data_.back().idx_, x, y); + inset->getCursorPos(cursor_.back().idx_, x, y); x += inset->x(); y += cached_y_; } @@ -191,9 +195,9 @@ void LCursor::getPos(int & x, int & y) const UpdatableInset * LCursor::innerInsetOfType(int code) const { - for (int i = data_.size() - 1; i >= 1; --i) - if (data_[i].asUpdatableInset()->lyxCode() == code) - return data_[i].asUpdatableInset(); + for (int i = cursor_.size() - 1; i >= 1; --i) + if (cursor_[i].asUpdatableInset()->lyxCode() == code) + return cursor_[i].asUpdatableInset(); return 0; } @@ -207,13 +211,19 @@ InsetTabular * LCursor::innerInsetTabular() const void LCursor::cell(int idx) { - BOOST_ASSERT(!data_.empty()); - data_.back().idx_ = idx; + BOOST_ASSERT(!cursor_.empty()); + cursor_.back().idx_ = idx; } int LCursor::cell() const { - BOOST_ASSERT(!data_.empty()); - return data_.back().idx_; + BOOST_ASSERT(!cursor_.empty()); + return cursor_.back().idx_; +} + + +void LCursor::resetAnchor() +{ + anchor_ = cursor_; } diff --git a/src/cursor.h b/src/cursor.h index 689f84ee4c..704544cf95 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -49,9 +49,9 @@ public: /// pop one level off the cursor void pop(); /// access to cursor 'tip' - CursorSlice & top() { return data_.back(); } + CursorSlice & top() { return cursor_.back(); } /// access to cursor 'tip' - CursorSlice const & top() const { return data_.back(); } + CursorSlice const & top() const { return cursor_.back(); } /// set the cell the cursor is in void cell(int); @@ -71,11 +71,15 @@ public: void getDim(int & asc, int & desc) const; /// cache the absolute coordinate from the top inset void updatePos(); + /// sets anchor to cursor position + void resetAnchor(); /// friend std::ostream & operator<<(std::ostream &, LCursor const &); public: /// mainly used as stack, but wee need random access - std::vector data_; + std::vector cursor_; + /// The + std::vector anchor_; /// BufferView * bv_; private: @@ -83,4 +87,9 @@ private: int cached_y_; }; + +class LCursorS +{ +}; + #endif // LYXCURSOR_H diff --git a/src/cursor_slice.C b/src/cursor_slice.C index 5956907b7e..7094014d89 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -36,25 +36,37 @@ CursorSlice::CursorSlice(InsetBase * p) } -void CursorSlice::par(lyx::paroffset_type par) +void CursorSlice::idx(idx_type idx) +{ + idx_ = idx; +} + + +CursorSlice::idx_type CursorSlice::idx() const +{ + return idx_; +} + + +void CursorSlice::par(par_type par) { par_ = par; } -lyx::paroffset_type CursorSlice::par() const +CursorSlice::par_type CursorSlice::par() const { return par_; } -void CursorSlice::pos(lyx::pos_type pos) +void CursorSlice::pos(pos_type pos) { pos_ = pos; } -lyx::pos_type CursorSlice::pos() const +CursorSlice::pos_type CursorSlice::pos() const { return pos_; } @@ -87,6 +99,7 @@ UpdatableInset * CursorSlice::asUpdatableInset() const MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const { BOOST_ASSERT(inset_); + BOOST_ASSERT(asMathInset()); return asMathInset()->cell(idx); } @@ -100,6 +113,7 @@ MathArray & CursorSlice::cell() const void CursorSlice::getPos(int & x, int & y) const { + BOOST_ASSERT(inset_); asMathInset()->getPos(idx_, pos_, x, y); } diff --git a/src/cursor_slice.h b/src/cursor_slice.h index 84b63f8181..5655a8fa7b 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -51,11 +51,15 @@ public: explicit CursorSlice(InsetBase *); /// set the paragraph that contains this cursor - void par(par_type pit); + void idx(idx_type idx); + /// return the paragraph this cursor is in + idx_type idx() const; + /// set the paragraph that contains this cursor + void par(par_type par); /// return the paragraph this cursor is in par_type par() const; /// set the position within the paragraph - void pos(pos_type p); + void pos(pos_type pos); /// return the position within the paragraph pos_type pos() const; diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 68da7ca38d..7b06eabb3f 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -172,7 +172,7 @@ void LyXScreen::showCursor(BufferView & bv) int h = ascent + descent; int x = 0; int y = 0; - bv.cursor().getPos(x, y); + bv.fullCursor().getPos(x, y); y -= ascent + bv.top_y(); //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl; @@ -211,8 +211,8 @@ bool LyXScreen::fitCursor(BufferView * bv) int newtop = top_y; int x, y, asc, desc; - bv->cursor().getPos(x, y); - bv->cursor().getDim(asc, desc); + bv->fullCursor().getPos(x, y); + bv->fullCursor().getDim(asc, desc); bool const big_row = h / 4 < asc + desc && asc + desc < h; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 40b580c572..1f1620982b 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -308,7 +308,7 @@ void InsetCollapsable::edit(BufferView * bv, bool left) lyxerr << "InsetCollapsable: edit left/right" << endl; inset.edit(bv, left); open(); - bv->cursor().push(this); + bv->fullCursor().push(this); } @@ -324,7 +324,7 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) y += inset.ascent() - height_collapsed(); } inset.edit(bv, x, y); - bv->cursor().push(this); + bv->fullCursor().push(this); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 4a6cf02f3c..ad7754429c 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -398,14 +398,14 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd) lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl; if (cell == -1) { tablemode = true; - bv->cursor() = theTempCursor; - bv->cursor().data_.push_back(CursorSlice(this)); - bv->cursor().cell(cell); + bv->fullCursor(theTempCursor); + bv->fullCursor().push(this); + bv->fullCursor().cell(cell); } else { tablemode = false; setPos(bv, cmd.x, cmd.y); - bv->cursor() = theTempCursor; - bv->cursor().cell(cell); + bv->fullCursor(theTempCursor); + bv->fullCursor().cell(cell); } lyxerr << bv->cursor() << endl; @@ -461,8 +461,8 @@ void InsetTabular::edit(BufferView * bv, bool left) clearSelection(); resetPos(bv); bv->fitCursor(); - bv->cursor().push(this); - bv->cursor().cell(cell); + bv->fullCursor().push(this); + bv->fullCursor().cell(cell); lyxerr << bv->cursor() << endl; } @@ -477,7 +477,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y) clearSelection(); finishUndo(); //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell); - bv->cursor().push(this); + bv->fullCursor().push(this); //if (x > xx) // activateCellInset(bv, cell, x - xx, y - cursory_); } @@ -511,7 +511,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, break; } - CursorSlice & cur = bv->cursor().data_.back(); + CursorSlice & cur = bv->cursor(); if (!tablemode) { @@ -677,7 +677,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_NEXT: { if (hasSelection()) clearSelection(); - int actcell = bv->cursor().cell(); + int actcell = bv->cursor().idx(); int actcol = tabular.column_of_cell(actcell); int column = actcol; if (bv->top_y() + bv->painter().paperHeight() @@ -695,7 +695,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, case LFUN_PRIOR: { if (hasSelection()) clearSelection(); - int actcell = bv->cursor().cell(); + int actcell = bv->cursor().idx(); int actcol = tabular.column_of_cell(actcell); int column = actcol; if (yo_ < 0) { @@ -1278,7 +1278,7 @@ void checkLongtableSpecial(LyXTabular::ltType & ltt, void InsetTabular::tabularFeatures(BufferView * bv, LyXTabular::Feature feature, string const & value) { - int actcell = bv->cursor().cell(); + int actcell = bv->cursor().idx(); int sel_col_start; int sel_col_end; int sel_row_start; @@ -1881,7 +1881,7 @@ bool InsetTabular::pasteSelection(BufferView * bv) { if (!paste_tabular) return false; - int actcell = bv->cursor().cell(); + int actcell = bv->cursor().idx(); int actcol = tabular.column_of_cell(actcell); int actrow = tabular.row_of_cell(actcell); for (int r1 = 0, r2 = actrow; @@ -2019,7 +2019,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, string::size_type len = buf.length(); string::size_type p = 0; - int actcell = bv->cursor().cell(); + int actcell = bv->cursor().idx(); int actcol = tabular.column_of_cell(actcell); int actrow = tabular.row_of_cell(actcell); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index f1287bf7b1..065c68a672 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -314,7 +314,7 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, switch (cmd.action) { case LFUN_MOUSE_PRESS: - bv->cursor() = theTempCursor; + bv->fullCursor(theTempCursor); // fall through default: result = text_.dispatch(cmd); diff --git a/src/iterators.C b/src/iterators.C index e5e8633e1e..fda9d6c5d8 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -401,7 +401,7 @@ ParIterator::ParIterator(PosIterator const & pos) void ParIterator::lockPath(BufferView * bv) const { - bv->cursor() = LCursor(bv); + bv->fullCursor() = LCursor(bv); int last = size() - 1; #warning this seems to create just one entry for InsetTabulars for (int i = 0; i < last; ++i) diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 1c036ced63..cb4485b587 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -157,8 +157,8 @@ void LyXFunc::handleKeyFunc(kb_action action) // actions keyseq.clear(); // copied verbatim from do_accent_char + view()->resetAnchor(); view()->update(); - view()->getLyXText()->anchor() = view()->getLyXText()->cursor(); } @@ -322,8 +322,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const } } - UpdatableInset * tli = view()->cursor().innerInset(); - InsetTabular * tab = view()->cursor().innerInsetTabular(); + UpdatableInset * tli = view()->fullCursor().innerInset(); + InsetTabular * tab = view()->fullCursor().innerInsetTabular(); // I would really like to avoid having this switch and rather try to // encode this in the function itself. @@ -356,7 +356,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; case LFUN_LAYOUT_TABULAR: - disable = !view()->cursor().innerInsetTabular(); + disable = !view()->fullCursor().innerInsetTabular(); break; case LFUN_DEPTH_MIN: @@ -471,7 +471,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const case LFUN_INSET_SETTINGS: { disable = true; - UpdatableInset * inset = view()->cursor().innerInset(); + UpdatableInset * inset = view()->fullCursor().innerInset(); if (!inset) break; @@ -543,7 +543,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = !Exporter::IsExportable(*buf, "dvi") || lyxrc.print_command == "none"; } else if (name == "character") { - UpdatableInset * tli = view()->cursor().innerInset(); + UpdatableInset * tli = view()->fullCursor().innerInset(); disable = tli && tli->lyxCode() == InsetOld::ERT_CODE; } else if (name == "vclog") { disable = !buf->lyxvc().inUse(); @@ -866,7 +866,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) case LFUN_ESCAPE: { if (!view()->available()) break; - view()->cursor().pop(); + view()->fullCursor().pop(); // Tell the paragraph dialog that we changed paragraph dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE)); break; @@ -1101,7 +1101,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) break; case LFUN_LAYOUT_TABULAR: - if (InsetTabular * tab = view()->cursor().innerInsetTabular()) + if (InsetTabular * tab = view()->fullCursor().innerInsetTabular()) tab->openLayoutDialog(view()); break; @@ -1449,7 +1449,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) default: { DispatchResult result = - view()->cursor().dispatch(FuncRequest(func, view())); + view()->fullCursor().dispatch(FuncRequest(func, view())); if (result.dispatched()) lyxerr << "dispatched by Cursor::dispatch()" << endl; else @@ -1464,7 +1464,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) if (view()->available()) { view()->fitCursor(); view()->update(); - view()->cursor().updatePos(); + view()->fullCursor().updatePos(); // if we executed a mutating lfun, mark the buffer as dirty if (!getStatus(func).disabled() && !lyxaction.funcHasFlag(func.action, LyXAction::NoBuffer) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index cdcf532a29..5e9d215b3d 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -313,7 +313,7 @@ void InsetFormulaBase::edit(BufferView * bv, bool left) lyxerr << "Called FormulaBase::edit" << endl; releaseMathCursor(bv); mathcursor = new MathCursor(this, left); - bv->cursor().push(this); + bv->fullCursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time bv->update(); @@ -327,7 +327,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int y) mathcursor = new MathCursor(this, true); //metrics(bv); mathcursor->setPos(x + xo_, y + yo_); - bv->cursor().push(this); + bv->fullCursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time bv->update(); @@ -901,7 +901,7 @@ void mathDispatchCreation(FuncRequest const & cmd, bool display) if (sel.empty()) { InsetFormula * f = new InsetFormula(bv); if (openNewInset(bv, f)) { - bv->cursor().innerInset()-> + bv->fullCursor().innerInset()-> dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); // don't do that also for LFUN_MATH_MODE unless you want end up with // always changing to mathrm when opening an inlined inset @@ -964,7 +964,7 @@ void mathDispatch(FuncRequest const & cmd) case LFUN_MATH_DELIM: { InsetFormula * f = new InsetFormula(bv); if (openNewInset(bv, f)) { - UpdatableInset * inset = bv->cursor().innerInset(); + UpdatableInset * inset = bv->fullCursor().innerInset(); inset->dispatch(FuncRequest(bv, LFUN_MATH_MUTATE, "simple")); inset->dispatch(cmd); } diff --git a/src/rowpainter.C b/src/rowpainter.C index f77fd18915..12b40d365a 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -132,7 +132,7 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text, paintBackground(); // paint the selection background - if (text_.selection.set() && &text_ == bv_.cursor().innerText()) + if (text_.selection.set() && &text_ == bv_.fullCursor().innerText()) paintSelection(); // vertical lines for appendix diff --git a/src/text.C b/src/text.C index 781772a33e..82eb64ec91 100644 --- a/src/text.C +++ b/src/text.C @@ -1104,7 +1104,7 @@ void LyXText::selectWord(word_location loc) setCursor(from.par(), from.pos()); if (to == from) return; - anchor() = cursor(); + bv()->resetAnchor(); setCursor(to.par(), to.pos()); setSelection(); } @@ -1170,7 +1170,7 @@ void LyXText::deleteWordForward() selection.set(true); // to avoid deletion cursorRightOneWord(); setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos()); - anchor() = cursor(); + bv()->resetAnchor(); cursor() = tmpcursor; setSelection(); cutSelection(true, false); @@ -1188,7 +1188,7 @@ void LyXText::deleteWordBackward() selection.set(true); // to avoid deletion cursorLeftOneWord(); setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos()); - anchor() = cursor(); + bv()->resetAnchor(); cursor() = tmpcursor; setSelection(); cutSelection(true, false); @@ -1207,7 +1207,7 @@ void LyXText::deleteLineForward() selection.set(true); // to avoid deletion cursorEnd(); setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos()); - anchor() = cursor(); + bv()->resetAnchor(); cursor() = tmpcursor; setSelection(); // What is this test for ??? (JMarc) @@ -1601,7 +1601,7 @@ void LyXText::redoParagraph(ParagraphList::iterator pit) void LyXText::fullRebreak() { redoParagraphs(paragraphs().begin(), paragraphs().end()); - anchor() = cursor(); + bv()->resetAnchor(); } @@ -1937,25 +1937,25 @@ int LyXText::cursorY(CursorSlice const & cur) const CursorSlice & LyXText::cursor() { - return bv()->cursor().top(); + return bv()->cursor(); } CursorSlice const & LyXText::cursor() const { - return bv()->cursor().top(); + return bv()->cursor(); } CursorSlice & LyXText::anchor() { - return anchor_; + return bv()->anchor(); } CursorSlice const & LyXText::anchor() const { - return anchor_; + return bv()->anchor(); } @@ -2005,7 +2005,7 @@ void LyXText::clearSelection() { selection.set(false); selection.mark(false); - anchor() = cursor(); + bv()->resetAnchor(); // reset this in the bv()! if (bv() && bv()->text()) bv()->unsetXSel(); diff --git a/src/text2.C b/src/text2.C index 263ddfa46d..1d5dc716a7 100644 --- a/src/text2.C +++ b/src/text2.C @@ -95,7 +95,7 @@ void LyXText::init(BufferView * bview) redoParagraphs(beg, end); setCursorIntern(0, 0); - anchor() = cursor(); + bv()->resetAnchor(); updateCounters(); } @@ -532,7 +532,7 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall) if (implicitSelection) { clearSelection(); cursor() = resetCursor; - anchor() = cursor(); + bv()->resetAnchor(); } } @@ -556,7 +556,7 @@ string LyXText::getStringToIndex() // Reset cursors to their original position. cursor() = reset_cursor; - anchor() = cursor(); + bv()->resetAnchor(); // Clear the implicit selection. if (implicitSelection) @@ -1026,7 +1026,7 @@ void LyXText::pasteSelection(size_t sel_index) clearSelection(); - anchor() = cursor(); + bv()->resetAnchor(); setCursor(ppp.first, ppp.second); setSelection(); updateCounters(); @@ -1038,7 +1038,7 @@ void LyXText::setSelectionRange(lyx::pos_type length) if (!length) return; - anchor() = cursor(); + bv()->resetAnchor(); while (length--) cursorRight(true); setSelection(); @@ -1087,7 +1087,7 @@ void LyXText::insertStringAsLines(string const & str) bv()->buffer()->insertStringAsLines(pit, pos, current_font, str); redoParagraphs(cursorPar(), endpit); - anchor() = cursor(); + bv()->resetAnchor(); setCursor(pit, pos); setSelection(); } @@ -1673,7 +1673,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor) if (selection_position_was_oldcursor_position) { // correct selection - anchor() = cursor(); + bv()->resetAnchor(); } } @@ -1682,7 +1682,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor) if (old_pit->stripLeadingSpaces()) { redoParagraph(old_pit); - anchor() = cursor(); + bv()->resetAnchor(); } return false; } diff --git a/src/text3.C b/src/text3.C index 7850838a6a..bfd7fe5341 100644 --- a/src/text3.C +++ b/src/text3.C @@ -349,7 +349,7 @@ void LyXText::gotoInset(vector const & codes, } } bv()->update(); - anchor() = cursor(); + bv()->resetAnchor(); } @@ -543,7 +543,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_RIGHTSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); if (rtl()) cursorLeft(bv); else @@ -553,7 +553,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_LEFTSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); if (rtl()) cursorRight(bv); else @@ -563,56 +563,56 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_UPSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorUp(true); finishChange(bv, true); break; case LFUN_DOWNSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorDown(true); finishChange(bv, true); break; case LFUN_UP_PARAGRAPHSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorUpParagraph(); finishChange(bv, true); break; case LFUN_DOWN_PARAGRAPHSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorDownParagraph(); finishChange(bv, true); break; case LFUN_PRIORSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorPrevious(); finishChange(bv, true); break; case LFUN_NEXTSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorNext(); finishChange(bv, true); break; case LFUN_HOMESEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorHome(); finishChange(bv, true); break; case LFUN_ENDSEL: if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorEnd(); finishChange(bv, true); break; @@ -722,7 +722,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_DELETE: if (!selection.set()) { Delete(); - anchor() = cursor(); + bv->resetAnchor(); // It is possible to make it a lot faster still // just comment out the line below... } else { @@ -739,10 +739,10 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) cursorRight(bv); cursorLeft(bv); Delete(); - anchor() = cursor(); + bv->resetAnchor(); } else { Delete(); - anchor() = cursor(); + bv->resetAnchor(); } } else { cutSelection(true, false); @@ -755,7 +755,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) if (!selection.set()) { if (bv->owner()->getIntl().getTransManager().backspace()) { backspace(); - anchor() = cursor(); + bv->resetAnchor(); // It is possible to make it a lot faster still // just comment out the line below... } @@ -783,7 +783,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) replaceSelection(bv->getLyXText()); breakParagraph(bv->buffer()->paragraphs(), 0); bv->update(); - anchor() = cursor(); + bv->resetAnchor(); bv->switchKeyMap(); bv->owner()->view_state_changed(); break; @@ -792,7 +792,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) replaceSelection(bv->getLyXText()); breakParagraph(bv->buffer()->paragraphs(), 1); bv->update(); - anchor() = cursor(); + bv->resetAnchor(); bv->switchKeyMap(); bv->owner()->view_state_changed(); break; @@ -882,7 +882,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } case LFUN_INSET_SETTINGS: - bv->cursor().innerInset()->showInsetDialog(bv); + bv->fullCursor().innerInset()->showInsetDialog(bv); break; case LFUN_INSET_TOGGLE: @@ -924,7 +924,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_MARK_OFF: clearSelection(); bv->update(); - anchor() = cursor(); + bv->resetAnchor(); cmd.message(N_("Mark off")); break; @@ -932,7 +932,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) clearSelection(); selection.mark(true); bv->update(); - anchor() = cursor(); + bv->resetAnchor(); cmd.message(N_("Mark on")); break; @@ -944,7 +944,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) selection.mark(true); cmd.message(N_("Mark set")); } - anchor() = cursor(); + bv->resetAnchor(); bv->update(); break; @@ -998,7 +998,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) if (in_inset_) return DispatchResult(false); if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorTop(); finishChange(bv, true); break; @@ -1007,7 +1007,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) if (in_inset_) return DispatchResult(false); if (!selection.set()) - anchor() = cursor(); + bv->resetAnchor(); cursorBottom(); finishChange(bv, true); break; @@ -1171,7 +1171,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) for (int i = 0; i < datetmp_len; i++) insertChar(datetmp[i]); - anchor() = cursor(); + bv->resetAnchor(); moveCursor(bv, false); break; } @@ -1182,7 +1182,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) if (cmd.button() == mouse_button::button1) { selection_possible = true; cursorHome(); - anchor() = cursor(); + bv->resetAnchor(); cursorEnd(); setSelection(); bv->haveSelection(selection.set()); @@ -1270,7 +1270,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } setCursorFromCoordinates(cmd.x, cmd.y); - anchor() = cursor(); + bv->resetAnchor(); finishUndo(); bv->x_target(cursorX() + xo_); @@ -1340,7 +1340,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) bv->owner()->getIntl().getTransManager(). TranslateAndInsert(*cit, this); - anchor() = cursor(); + bv->resetAnchor(); moveCursor(bv, false); // real_current_font.number can change so we need to diff --git a/src/undo.C b/src/undo.C index 0238286533..7bcf23b74a 100644 --- a/src/undo.C +++ b/src/undo.C @@ -183,7 +183,7 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) // clear any selection text->clearSelection(); - text->anchor() = text->cursor(); + bv->resetAnchor(); text->updateCounters(); // rebreak the entire lyxtext -- 2.39.2