From 2ad9bd1e7d0c18b70a277bd6c807a05356f767b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 6 Nov 2003 16:43:12 +0000 Subject: [PATCH] more global cursor work git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8059 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/cursor.C | 15 ++++++++----- src/insets/insetbase.C | 6 ++++- src/insets/insetcollapsable.C | 10 +++++---- src/insets/insetcollapsable.h | 2 ++ src/insets/insettabular.C | 37 ++++++++++++++++++++++++------- src/insets/insettabular.h | 2 ++ src/insets/insettext.C | 41 ++++++++++++++++++++++++----------- src/insets/insettext.h | 2 ++ src/insets/updatableinset.h | 2 ++ src/lyxfunc.C | 15 +++++++++---- src/text2.C | 8 ++----- src/text3.C | 16 +++++++------- 12 files changed, 106 insertions(+), 50 deletions(-) diff --git a/src/cursor.C b/src/cursor.C index e6c8973008..0f40029809 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -41,8 +41,9 @@ std::ostream & operator<<(std::ostream & os, CursorItem const & item) std::ostream & operator<<(std::ostream & os, LCursor const & cursor) { + os << "\n"; for (size_t i = 0, n = cursor.data_.size(); i != n; ++i) - os << " " << cursor.data_[i]; + os << " " << cursor.data_[i] << "\n"; return os; } @@ -68,11 +69,11 @@ bool LCursor::handleResult(DispatchResult const & res) lyxerr << "LCursor::handleResult: " << res.val() << endl; switch (res.val()) { case FINISHED: - pop(); + ///pop(); return true; case FINISHED_RIGHT: { - pop(); + ///pop(); //InsetText * inset = static_cast(innerInset()); //if (inset) // inset->moveRightIntern(bv_, false, false); @@ -83,7 +84,7 @@ bool LCursor::handleResult(DispatchResult const & res) } case FINISHED_UP: { - pop(); + ///pop(); //InsetText * inset = static_cast(inset()); //if (inset) // result = inset->moveUp(bv); @@ -91,7 +92,7 @@ bool LCursor::handleResult(DispatchResult const & res) } case FINISHED_DOWN: { - pop(); + ///pop(); //InsetText * inset = static_cast(inset()); //if (inset) // result = inset->moveDown(bv); @@ -99,7 +100,6 @@ bool LCursor::handleResult(DispatchResult const & res) } default: - break; lyxerr << "# unhandled result: " << res.val() << endl; return false; } @@ -114,12 +114,15 @@ LCursor::LCursor(BufferView * bv) void LCursor::push(InsetOld * inset, LyXText * text) { + lyxerr << "LCursor::push() inset: " << inset << " text: " << text + << endl; data_.push_back(CursorItem(inset, text)); } void LCursor::pop() { + lyxerr << "LCursor::pop() " << endl; //BOOST_ASSERT(!data_.empty()); if (data_.empty()) lyxerr << "### TRYING TO POP FROM EMPTY CURSOR" << endl; diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 051e2fdff3..fea008ea8b 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -11,6 +11,7 @@ #include #include "insetbase.h" +#include "debug.h" #include "dispatchresult.h" @@ -38,10 +39,13 @@ InsetBase::priv_dispatch(FuncRequest const &, idx_type &, pos_type &) void InsetBase::edit(BufferView *, bool) -{} +{ + lyxerr << "InsetBase: edit left/right" << std::endl; +} void InsetBase::edit(BufferView * bv, int, int) { + lyxerr << "InsetBase: edit xy" << std::endl; edit(bv, true); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 4e105fe9ce..a525d20181 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -16,6 +16,7 @@ #include "buffer.h" #include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "dispatchresult.h" #include "LColor.h" @@ -276,9 +277,10 @@ bool InsetCollapsable::hitButton(FuncRequest const & cmd) const void InsetCollapsable::edit(BufferView * bv, bool left) { - lyxerr << "InsetCollapsable: edit" << endl; + lyxerr << "InsetCollapsable: edit left/right" << endl; if (!bv->lockInset(this)) lyxerr << "InsetCollapsable: can't lock" << endl; + bv->cursor().push(this, inset.getText(0)); inset.edit(bv, left); first_after_edit = true; open(bv); @@ -309,6 +311,7 @@ void InsetCollapsable::edit(BufferView * bv, bool left) void InsetCollapsable::edit(BufferView * bv, int x, int y) { + lyxerr << "InsetCollapsable: edit xy" << endl; if (collapsed_) { collapsed_ = false; // set this only here as it should be recollapsed only if @@ -328,16 +331,15 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) inset.edit(bv, x, ascent() + y - (height_collapsed() + inset.ascent())); } + bv->cursor().push(this, inset.getText(0)); } DispatchResult -InsetCollapsable::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) { //lyxerr << "InsetCollapsable::localDispatch: " // << cmd.action << " '" << cmd.argument << "'\n"; - BufferView * bv = cmd.view(); switch (cmd.action) { case LFUN_MOUSE_PRESS: if (!collapsed_ && cmd.y > button_dim.y2) diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index cae30c8954..689b562155 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -157,6 +157,8 @@ protected: void edit(BufferView *, bool); /// void edit(BufferView *, int, int); + /// + UpdatableInset * lockingInset() const { return inset.lockingInset(); } private: /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index a28ee59e9d..72cfc70916 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -15,6 +15,7 @@ #include "buffer.h" #include "bufferparams.h" #include "BufferView.h" +#include "cursor.h" #include "debug.h" #include "dispatchresult.h" #include "funcrequest.h" @@ -641,8 +642,9 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd) void InsetTabular::edit(BufferView * bv, bool left) { - lyxerr << "InsetTabular::edit: " << this << " first cell: " - << &tabular.cell_info[0][0].inset << endl; + lyxerr << "InsetTabular::edit: " << this + << " first text: " << tabular.cell_info[0][0].inset.getText(0) + << " first cell: " << &tabular.cell_info[0][0].inset << endl; if (!bv->lockInset(this)) { lyxerr << "InsetTabular::Cannot lock inset" << endl; @@ -669,6 +671,7 @@ void InsetTabular::edit(BufferView * bv, bool left) clearSelection(); resetPos(bv); bv->fitCursor(); + bv->cursor().push(this, 0); } @@ -696,6 +699,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y) inset_y = cursory_; activateCellInset(bv, x - inset_x, y - inset_y); } + bv->cursor().push(this, tabular.getCellInset(actcell).getText(0)); } @@ -714,8 +718,11 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, return result; } - if (cmd.action < 0 && cmd.argument.empty()) + if (cmd.action < 0 && cmd.argument.empty()) { + lyxerr << "InsetTabular: cursor pop 2" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED); + } bool hs = hasSelection(); @@ -1107,8 +1114,9 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, break; } - if (result.val() >= FINISHED) + if (result.val() >= FINISHED) { bv->unlockInset(this); + } else if (!the_locking_inset && bv->fitCursor()) updateLocal(bv); @@ -1403,8 +1411,11 @@ DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock) } else { bool moved = isRightToLeft(bv) ? movePrevCell(bv) : moveNextCell(bv); - if (!moved) + if (!moved) { + lyxerr << "InsetTabular: cursor pop 3" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED_RIGHT); + } if (lock && activateCellInset(bv)) return DispatchResult(true, true); } @@ -1416,8 +1427,11 @@ DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock) DispatchResult InsetTabular::moveLeft(BufferView * bv, bool lock) { bool moved = isRightToLeft(bv) ? moveNextCell(bv) : movePrevCell(bv); - if (!moved) + if (!moved) { + lyxerr << "InsetTabular: cursor pop 4" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED); + } // behind the inset if (lock && activateCellInset(bv, 0, 0, true)) return DispatchResult(true, true); @@ -1430,8 +1444,11 @@ DispatchResult InsetTabular::moveUp(BufferView * bv, bool lock) { int const ocell = actcell; actcell = tabular.getCellAbove(actcell); - if (actcell == ocell) // we moved out of the inset + if (actcell == ocell) { // we moved out of the inset + lyxerr << "InsetTabular: cursor pop 5" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED_UP); + } resetPos(bv); if (lock) { int x = 0; @@ -1451,8 +1468,11 @@ DispatchResult InsetTabular::moveDown(BufferView * bv, bool lock) { int const ocell = actcell; actcell = tabular.getCellBelow(actcell); - if (actcell == ocell) // we moved out of the inset + if (actcell == ocell) { // we moved out of the inset + lyxerr << "InsetTabular: cursor pop 6" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED_DOWN); + } resetPos(bv); if (lock) { int x = 0; @@ -1986,6 +2006,7 @@ bool InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind) //inset_x = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); //inset_y = cursory_; inset.edit(bv, x, y); + bv->cursor().push(&inset, inset.getText(0)); if (!the_locking_inset) return false; updateLocal(bv); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index f449498bf3..e846d153c9 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -273,6 +273,8 @@ private: int & srow, int & erow) const; /// bool insertAsciiString(BufferView *, std::string const & buf, bool usePaste); + /// + UpdatableInset * lockingInset() const { return the_locking_inset; } // // Private structures and variables diff --git a/src/insets/insettext.C b/src/insets/insettext.C index e90fcb85ae..beaf1ab70a 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -584,9 +584,10 @@ void InsetText::edit(BufferView * bv, bool left) setViewCache(bv); if (!bv->lockInset(this)) { - lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; + lyxerr << "Cannot lock inset" << endl; return; } + lyxerr << "InsetText: edit left/right" << endl; locked = true; the_locking_inset = 0; @@ -620,9 +621,10 @@ void InsetText::edit(BufferView * bv, bool left) void InsetText::edit(BufferView * bv, int x, int y) { if (!bv->lockInset(this)) { - lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; + lyxerr << "Cannot lock inset" << endl; return; } + lyxerr << "InsetText: edit xy" << endl; locked = true; the_locking_inset = 0; @@ -720,7 +722,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd, if (result.val() >= FINISHED) { updateLocal(bv, false); bv->unlockInset(this); - bv->cursor().pop(); } break; case FINISHED_DOWN: @@ -728,7 +729,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd, if (result.val() >= FINISHED) { updateLocal(bv, false); bv->unlockInset(this); - bv->cursor().pop(); } break; default: @@ -795,9 +795,11 @@ InsetText::priv_dispatch(FuncRequest const & cmd, break; case LFUN_PRIOR: - if (crow() == text_.firstRow()) + if (crow() == text_.firstRow()) { result.val(FINISHED_UP); - else { + lyxerr << "InsetText: cursor pop 1" << endl; + bv->cursor().pop(); + } else { text_.cursorPrevious(); text_.clearSelection(); result.dispatched(true); @@ -805,9 +807,11 @@ InsetText::priv_dispatch(FuncRequest const & cmd, break; case LFUN_NEXT: - if (crow() == text_.lastRow()) + if (crow() == text_.lastRow()) { result.val(FINISHED_DOWN); - else { + lyxerr << "InsetText: cursor pop 2" << endl; + bv->cursor().pop(); + } else { text_.cursorNext(); text_.clearSelection(); result.dispatched(true); @@ -954,7 +958,6 @@ InsetText::priv_dispatch(FuncRequest const & cmd, if (result.val() >= FINISHED) { result.val(NONE); bv->unlockInset(this); - bv->cursor().pop(); } return result; @@ -1078,8 +1081,11 @@ InsetText::moveRightIntern(BufferView * bv, bool front, { ParagraphList::iterator c_par = cpar(); - if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size()) + if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size()) { + lyxerr << "InsetText: cursor pop 3" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED_RIGHT); + } if (activate_inset && checkAndActivateInset(bv, front)) return DispatchResult(true, true); text_.cursorRight(bv); @@ -1093,8 +1099,11 @@ DispatchResult InsetText::moveLeftIntern(BufferView * bv, bool front, bool activate_inset, bool selecting) { - if (cpar() == paragraphs.begin() && cpos() <= 0) + if (cpar() == paragraphs.begin() && cpos() <= 0) { + lyxerr << "InsetText: cursor pop 4" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED); + } text_.cursorLeft(bv); if (!selecting) text_.clearSelection(); @@ -1106,8 +1115,11 @@ InsetText::moveLeftIntern(BufferView * bv, bool front, DispatchResult InsetText::moveUp(BufferView * bv) { - if (crow() == text_.firstRow()) + if (crow() == text_.firstRow()) { + lyxerr << "InsetText: cursor pop 5" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED_UP); + } text_.cursorUp(bv); text_.clearSelection(); return DispatchResult(true); @@ -1116,8 +1128,11 @@ DispatchResult InsetText::moveUp(BufferView * bv) DispatchResult InsetText::moveDown(BufferView * bv) { - if (crow() == text_.lastRow()) + if (crow() == text_.lastRow()) { + lyxerr << "InsetText: cursor pop 6" << endl; + bv->cursor().pop(); return DispatchResult(false, FINISHED_DOWN); + } text_.cursorDown(bv); text_.clearSelection(); return DispatchResult(true); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index d9ea980c4d..db8617cf9e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -183,6 +183,8 @@ public: void edit(BufferView *, bool); /// void edit(BufferView *, int, int); + /// + UpdatableInset * lockingInset() const { return the_locking_inset; } /// int numParagraphs() const { return 1; } diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 058db608dd..26ec8b9346 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -88,6 +88,8 @@ public: virtual bool showInsetDialog(BufferView *) const { return false; } /// virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {} + /// + virtual UpdatableInset * lockingInset() const { return 0; } protected: /// An updatable inset could handle lyx editing commands diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 4e20c5fc58..19cbed4590 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -882,10 +882,17 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) view()->hideCursor(); #if 1 - if (view()->cursor().innerInset() != view()->theLockingInset()) { - lyxerr << "### CURSOR OUT OF SYNC: tli: " - << view()->theLockingInset() - << "\ncursor: " << view()->cursor() << endl; + { + UpdatableInset * innerinset = view()->theLockingInset(); + for (UpdatableInset * tmp = innerinset; tmp; tmp = tmp->lockingInset()) + innerinset = tmp; + + if (view()->cursor().innerInset() != innerinset) { + lyxerr << "### CURSOR OUT OF SYNC: tli: " + << view()->theLockingInset() << " inner: " + << innerinset + << "\ncursor: " << view()->cursor() << endl; + } } if (0) { diff --git a/src/text2.C b/src/text2.C index 9d025b5918..f958261c16 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1629,10 +1629,8 @@ void LyXText::cursorUp(bool selecting) int y2 = y1; y -= topy; InsetOld * inset_hit = checkInsetHit(x, y1); - if (inset_hit && isHighlyEditableInset(inset_hit)) { + if (inset_hit && isHighlyEditableInset(inset_hit)) inset_hit->edit(bv(), x, y - (y2 - y1)); - bv()->cursor().push(inset_hit, inset_hit->getText(0)); - } } #else lyxerr << "cursorUp: y " << cursor.y() << " bl: " << @@ -1657,10 +1655,8 @@ void LyXText::cursorDown(bool selecting) int y2 = y1; y -= topy; InsetOld * inset_hit = checkInsetHit(x, y1); - if (inset_hit && isHighlyEditableInset(inset_hit)) { - bv()->cursor().push(inset_hit, inset_hit->getText(0)); + if (inset_hit && isHighlyEditableInset(inset_hit)) inset_hit->edit(bv(), x, y - (y2 - y1)); - } } #else setCursorFromCoordinates(bv()->x_target(), diff --git a/src/text3.C b/src/text3.C index 4fdef9729f..7c761bfb40 100644 --- a/src/text3.C +++ b/src/text3.C @@ -376,10 +376,8 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd, gotsel = true; } if (bv->insertInset(inset)) { - if (edit) { + if (edit) inset->edit(bv, true); - bv->cursor().push(inset, inset->getText(0)); - } if (gotsel && pastesel) bv->owner()->dispatch(FuncRequest(LFUN_PASTE)); } @@ -596,7 +594,6 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) InsetOld * tmpinset = cursorPar()->getInset(cursor.pos()); cmd.message(tmpinset->editMessage()); tmpinset->edit(bv, !is_rtl); - bv->cursor().push(tmpinset, tmpinset->getText(0)); break; } if (!is_rtl) @@ -1247,8 +1244,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) } // Single-click on work area - case LFUN_MOUSE_PRESS: - { + case LFUN_MOUSE_PRESS: { if (!bv->buffer()) break; @@ -1292,6 +1288,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; } bv->unlockInset(bv->theLockingInset()); + lyxerr << "Re-initializing cursor" << endl; + bv->cursor() = LCursor(bv); } if (!inset_hit) @@ -1304,13 +1302,15 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) // Single left click in math inset? if (isHighlyEditableInset(inset_hit)) { - // Highly editable inset, like math + lyxerr << "click on highly editable inset, like math" << endl; UpdatableInset * inset = static_cast(inset_hit); selection_possible = false; bv->owner()->message(inset->editMessage()); // We just have to lock the inset before calling a PressEvent on it! if (!bv->lockInset(inset)) - lyxerr[Debug::INSETS] << "Cannot lock inset" << endl; + lyxerr << "Cannot lock inset" << endl; +#warning cell 0 is certainly not always good. + bv->cursor().push(inset, inset->getText(0)); FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button()); inset->dispatch(cmd1); break; -- 2.39.2