From 6c38a862abdfd6d317d4995809a9a830683abeec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 17 Nov 2003 14:28:18 +0000 Subject: [PATCH] move some cursor handling from insettext.C to text2.C git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8094 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 9 +++- src/insets/insettext.C | 88 ++------------------------------ src/insets/insettext.h | 22 -------- src/lyxtext.h | 22 +++++++- src/text2.C | 112 +++++++++++++++++++++++++++++++++++++---- 5 files changed, 133 insertions(+), 120 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 71ccf663c0..5a284698f8 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -872,16 +872,21 @@ namespace { theTempCursor = LCursor(bv); while (true) { InsetOld * inset_hit = text->checkInsetHit(x, y); - if (!inset_hit) + if (!inset_hit) { + lyxerr << "no further inset hit" << endl; break; + } inset = inset_hit; - if (!inset_hit->descendable()) + if (!inset_hit->descendable()) { + lyxerr << "not descendable" << endl; break; + } text = inset_hit->getText(0); lyxerr << "Hit inset: " << inset << " at x: " << x << " text: " << text << " y: " << y << endl; theTempCursor.push(static_cast(inset)); } + lyxerr << "theTempCursor: " << theTempCursor << endl; return inset; } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 61d647abe2..f0992c4fe3 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -462,23 +462,23 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, break; case LFUN_RIGHT: - result = moveRight(bv); + result = text_.moveRight(); finishUndo(); break; case LFUN_LEFT: finishUndo(); - result = moveLeft(bv); + result = text_.moveLeft(); break; case LFUN_DOWN: finishUndo(); - result = moveDown(bv); + result = text_.moveDown(); break; case LFUN_UP: finishUndo(); - result = moveUp(bv); + result = text_.moveUp(); break; case LFUN_PRIOR: @@ -674,73 +674,6 @@ int InsetText::insetInInsetY() const } -DispatchResult InsetText::moveRight(BufferView * bv) -{ - if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params())) - return moveLeftIntern(bv, false, true, false); - else - return moveRightIntern(bv, true, true, false); -} - - -DispatchResult InsetText::moveLeft(BufferView * bv) -{ - if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params())) - return moveRightIntern(bv, true, true, false); - else - return moveLeftIntern(bv, false, true, false); -} - - -DispatchResult InsetText::moveRightIntern(BufferView * bv, bool front, - bool activate_inset, bool selecting) -{ - ParagraphList::iterator c_par = cpar(); - if (boost::next(c_par) == paragraphs.end() && cpos() >= c_par->size()) - return DispatchResult(false, FINISHED_RIGHT); - if (activate_inset && checkAndActivateInset(bv, front)) - return DispatchResult(true, true); - text_.cursorRight(bv); - if (!selecting) - text_.clearSelection(); - return DispatchResult(true); -} - - -DispatchResult InsetText::moveLeftIntern(BufferView * bv, bool front, - bool activate_inset, bool selecting) -{ - if (cpar() == paragraphs.begin() && cpos() <= 0) - return DispatchResult(false, FINISHED); - text_.cursorLeft(bv); - if (!selecting) - text_.clearSelection(); - if (activate_inset && checkAndActivateInset(bv, front)) - return DispatchResult(true, true); - return DispatchResult(true); -} - - -DispatchResult InsetText::moveUp(BufferView * bv) -{ - if (crow() == text_.firstRow()) - return DispatchResult(false, FINISHED_UP); - text_.cursorUp(bv); - text_.clearSelection(); - return DispatchResult(true); -} - - -DispatchResult InsetText::moveDown(BufferView * bv) -{ - if (crow() == text_.lastRow()) - return DispatchResult(false, FINISHED_DOWN); - text_.cursorDown(bv); - text_.clearSelection(); - return DispatchResult(true); -} - - bool InsetText::insertInset(BufferView * bv, InsetOld * inset) { inset->setOwner(this); @@ -817,19 +750,6 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall, } -bool InsetText::checkAndActivateInset(BufferView * bv, bool front) -{ - if (cpos() == cpar()->size()) - return false; - InsetOld * inset = cpar()->getInset(cpos()); - if (!isHighlyEditableInset(inset)) - return false; - inset->edit(bv, front); - updateLocal(bv, false); - return true; -} - - void InsetText::markNew(bool track_changes) { ParagraphList::iterator pit = paragraphs.begin(); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 2a355a9279..b0f63ea5af 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -186,31 +186,9 @@ private: // If the inset is empty set the language of the current font to the // language to the surronding text (if different). void sanitizeEmptyText(BufferView *); - - /// - DispatchResult moveRight(BufferView *); - /// - DispatchResult moveLeft(BufferView *); - /// - DispatchResult moveRightIntern(BufferView *, bool front, - bool activate_inset = true, - bool selecting = false); - /// - DispatchResult moveLeftIntern(BufferView *, bool front, - bool activate_inset = true, - bool selecting = false); - - /// - DispatchResult moveUp(BufferView *); - /// - DispatchResult moveDown(BufferView *); /// void setCharFont(Buffer const &, int pos, LyXFont const & font); /// - bool checkAndActivateInset(BufferView * bv, bool front); - /// - bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0); - /// void removeNewlines(); /// lyx::pos_type cpos() const; diff --git a/src/lyxtext.h b/src/lyxtext.h index b662e08594..1ad4c89d76 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -227,9 +227,9 @@ public: /// void cursorDown(bool selecting = false); /// - void cursorLeft(bool internal = true); + bool cursorLeft(bool internal = true); /// - void cursorRight(bool internal = true); + bool cursorRight(bool internal = true); /// void cursorLeftOneWord(); /// @@ -444,6 +444,24 @@ public: /// void cursorRightOneWord(LyXCursor &); + /// + DispatchResult moveRight(); + /// + DispatchResult moveLeft(); + /// + DispatchResult moveRightIntern(bool front, + bool activate_inset, bool selecting); + /// + DispatchResult moveLeftIntern(bool front, + bool activate_inset, bool selecting); + /// + DispatchResult moveUp(); + /// + DispatchResult moveDown(); + /// + bool checkAndActivateInset(bool front); + + private: /** Cursor related data. Later this variable has to be removed. There should be now internal diff --git a/src/text2.C b/src/text2.C index 386df5e419..58ca5969be 100644 --- a/src/text2.C +++ b/src/text2.C @@ -1580,7 +1580,87 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) } -void LyXText::cursorLeft(bool internal) + +bool LyXText::checkAndActivateInset(bool front) +{ + if (cursor.pos() == cursorPar()->size()) + return false; + InsetOld * inset = cursorPar()->getInset(cursor.pos()); + if (!isHighlyEditableInset(inset)) + return false; + inset->edit(bv(), front); + return true; +} + + +DispatchResult LyXText::moveRight() +{ + if (cursorPar()->isRightToLeftPar(bv()->buffer()->params())) + return moveLeftIntern(false, true, false); + else + return moveRightIntern(true, true, false); +} + + +DispatchResult LyXText::moveLeft() +{ + if (cursorPar()->isRightToLeftPar(bv()->buffer()->params())) + return moveRightIntern(true, true, false); + else + return moveLeftIntern(false, true, false); +} + + +DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool selecting) +{ + ParagraphList::iterator c_par = cursorPar(); + if (boost::next(c_par) == ownerParagraphs().end() + && cursor.pos() >= c_par->size()) + return DispatchResult(false, FINISHED_RIGHT); + if (activate_inset && checkAndActivateInset(front)) + return DispatchResult(true, true); + cursorRight(bv()); + if (!selecting) + clearSelection(); + return DispatchResult(true); +} + + +DispatchResult LyXText::moveLeftIntern(bool front, + bool activate_inset, bool selecting) +{ + if (cursor.par() == 0 && cursor.pos() <= 0) + return DispatchResult(false, FINISHED); + cursorLeft(bv()); + if (!selecting) + clearSelection(); + if (activate_inset && checkAndActivateInset(front)) + return DispatchResult(true, true); + return DispatchResult(true); +} + + +DispatchResult LyXText::moveUp() +{ + if (cursorRow() == firstRow()) + return DispatchResult(false, FINISHED_UP); + cursorUp(bv()); + clearSelection(); + return DispatchResult(true); +} + + +DispatchResult LyXText::moveDown() +{ + if (cursorRow() == lastRow()) + return DispatchResult(false, FINISHED_DOWN); + cursorDown(bv()); + clearSelection(); + return DispatchResult(true); +} + + +bool LyXText::cursorLeft(bool internal) { if (cursor.pos() > 0) { bool boundary = cursor.boundary(); @@ -1588,28 +1668,40 @@ void LyXText::cursorLeft(bool internal) if (!internal && !boundary && bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos() + 1)) setCursor(cursor.par(), cursor.pos() + 1, true, true); - } else if (cursor.par() != 0) { + return true; + } + + if (cursor.par() != 0) { // steps into the paragraph above setCursor(cursor.par() - 1, boost::prior(cursorPar())->size()); + return true; } + + return false; } -void LyXText::cursorRight(bool internal) +bool LyXText::cursorRight(bool internal) { - bool const at_end = (cursor.pos() == cursorPar()->size()); - bool const at_newline = !at_end && - cursorPar()->isNewline(cursor.pos()); - - if (!internal && cursor.boundary() && !at_newline) + if (!internal && cursor.boundary()) { setCursor(cursor.par(), cursor.pos(), true, false); - else if (!at_end) { + return true; + } + + if (cursor.pos() != cursorPar()->size()) { setCursor(cursor.par(), cursor.pos() + 1, true, false); if (!internal && bidi.isBoundary(*bv()->buffer(), *cursorPar(), cursor.pos())) setCursor(cursor.par(), cursor.pos(), true, true); - } else if (cursor.par() + 1 != int(ownerParagraphs().size())) + return true; + } + + if (cursor.par() + 1 != int(ownerParagraphs().size())) { setCursor(cursor.par() + 1, 0); + return true; + } + + return false; } -- 2.39.2