X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ftext2.C;h=673287fbbb595796f0fedb4242fbf7cb15b9ebde;hb=3c851f1f7951f3a24b57826f3e580e4318b5e6c4;hp=44e897db0fae661c17a8c4ec35b665381cc095fd;hpb=2aa786c65225add27f3157a6e77faf728405e9ef;p=lyx.git diff --git a/src/text2.C b/src/text2.C index 44e897db0f..673287fbbb 100644 --- a/src/text2.C +++ b/src/text2.C @@ -58,7 +58,7 @@ #include "support/lstrings.h" #include "support/textutils.h" -#include "support/tostr.h" +#include "support/convert.h" #include @@ -119,7 +119,7 @@ InsetBase * LyXText::checkInsetHit(int x, int y) const InsetBase * inset = iit->inset; #if 1 lyxerr << "examining inset " << inset << endl; - if (theCoords.insets_.has(inset)) + if (theCoords.getInsets().has(inset)) lyxerr << " xo: " << inset->xo() << "..." << inset->xo() + inset->width() @@ -440,7 +440,9 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) // Don't use forwardChar here as ditend might have // pos() == lastpos() and forwardChar would miss it. - for (; dit != ditend; dit.forwardPos()) { + // Can't use forwardPos either as this descends into + // nested insets. + for (; dit != ditend; dit.forwardPosNoDescend()) { if (dit.pos() != dit.lastpos()) { LyXFont f = getFont(dit.paragraph(), dit.pos()); f.update(font, params.language, toggleall); @@ -791,8 +793,10 @@ void LyXText::setCounter(Buffer const & buf, pit_type pit) bool isOK = false; while (tmppit != end) { in = pars_[tmppit].inInset(); - if (in->lyxCode() == InsetBase::FLOAT_CODE || - in->lyxCode() == InsetBase::WRAP_CODE) { + // FIXME: in should be always valid. + if (in && + (in->lyxCode() == InsetBase::FLOAT_CODE || + in->lyxCode() == InsetBase::WRAP_CODE)) { isOK = true; break; } @@ -1122,8 +1126,8 @@ pos_type LyXText::getColumnNearX(pit_type const pit, pit_type LyXText::getPitNearY(int y) const { BOOST_ASSERT(!paragraphs().empty()); - BOOST_ASSERT(theCoords.pars_.find(this) != theCoords.pars_.end()); - CoordCache::InnerParPosCache const & cc = theCoords.pars_[this]; + BOOST_ASSERT(theCoords.getParPos().find(this) != theCoords.getParPos().end()); + CoordCache::InnerParPosCache const & cc = theCoords.getParPos().find(this)->second; lyxerr << "LyXText::getPitNearY: y: " << y << " cache size: " << cc.size() << endl; @@ -1159,6 +1163,7 @@ Row const & LyXText::getRowNearY(int y, pit_type pit) const return *rit; } + // x,y are absolute screen coordinates // sets cursor recursively descending into nested editable insets InsetBase * LyXText::editXY(LCursor & cur, int x, int y) const @@ -1179,12 +1184,12 @@ InsetBase * LyXText::editXY(LCursor & cur, int x, int y) const InsetBase * inset = checkInsetHit(x, y); lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl; if (!inset) { - //either we deconst editXY or better we move current_font - //and real_current_font to LCursor + // Either we deconst editXY or better we move current_font + // and real_current_font to LCursor const_cast(this)->setCurrentFont(cur); return 0; } - + // This should be just before or just behind the // cursor position set above. BOOST_ASSERT((pos != 0 && inset == pars_[pit].getInset(pos - 1)) @@ -1214,49 +1219,52 @@ bool LyXText::checkAndActivateInset(LCursor & cur, bool front) } -void LyXText::cursorLeft(LCursor & cur) +bool LyXText::cursorLeft(LCursor & cur) { if (cur.pos() != 0) { bool boundary = cur.boundary(); - setCursor(cur, cur.pit(), cur.pos() - 1, true, false); + bool updateNeeded = setCursor(cur, cur.pit(), cur.pos() - 1, true, false); if (!checkAndActivateInset(cur, false)) { if (false && !boundary && bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1)) - setCursor(cur, cur.pit(), cur.pos() + 1, true, true); + updateNeeded |= + setCursor(cur, cur.pit(), cur.pos() + 1, true, true); } - return; + return updateNeeded; } if (cur.pit() != 0) { - // steps into the paragraph above - setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size()); + // Steps into the paragraph above + return setCursor(cur, cur.pit() - 1, getPar(cur.pit() - 1).size()); } + return false; } -void LyXText::cursorRight(LCursor & cur) +bool LyXText::cursorRight(LCursor & cur) { if (false && cur.boundary()) { - setCursor(cur, cur.pit(), cur.pos(), true, false); - return; + return setCursor(cur, cur.pit(), cur.pos(), true, false); } if (cur.pos() != cur.lastpos()) { + bool updateNeeded = false; if (!checkAndActivateInset(cur, true)) { - setCursor(cur, cur.pit(), cur.pos() + 1, true, false); + updateNeeded |= setCursor(cur, cur.pit(), cur.pos() + 1, true, false); if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos())) - setCursor(cur, cur.pit(), cur.pos(), true, true); + updateNeeded |= setCursor(cur, cur.pit(), cur.pos(), true, true); } - return; + return updateNeeded; } if (cur.pit() != cur.lastpit()) - setCursor(cur, cur.pit() + 1, 0); + return setCursor(cur, cur.pit() + 1, 0); + return false; } -void LyXText::cursorUp(LCursor & cur) +bool LyXText::cursorUp(LCursor & cur) { Paragraph const & par = cur.paragraph(); int const row = par.pos2row(cur.pos()); @@ -1264,62 +1272,102 @@ void LyXText::cursorUp(LCursor & cur) if (!cur.selection()) { int const y = bv_funcs::getPos(cur).y_; + LCursor old = cur; editXY(cur, x, y - par.rows()[row].ascent() - 1); - return; + + // This happens when you move out of an inset. + // And to give the DEPM the possibility of doing + // something we must provide it with two different + // cursors. (Lgb) + LCursor dummy = cur; + if (dummy == old) + ++dummy.pos(); + + return deleteEmptyParagraphMechanism(dummy, old); } + bool updateNeeded = false; + if (row > 0) { - setCursor(cur, cur.pit(), x2pos(cur.pit(), row - 1, x)); + updateNeeded |= setCursor(cur, cur.pit(), + x2pos(cur.pit(), row - 1, x)); } else if (cur.pit() > 0) { --cur.pit(); - setCursor(cur, cur.pit(), x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x)); - + updateNeeded |= setCursor(cur, cur.pit(), + x2pos(cur.pit(), par.rows().size() - 1, x)); } cur.x_target() = x; + + return updateNeeded; } -void LyXText::cursorDown(LCursor & cur) +bool LyXText::cursorDown(LCursor & cur) { - - Paragraph const & par = cur.paragraph(); int const row = par.pos2row(cur.pos()); int const x = cur.targetX(); if (!cur.selection()) { int const y = bv_funcs::getPos(cur).y_; + LCursor old = cur; editXY(cur, x, y + par.rows()[row].descent() + 1); - return; + + // This happens when you move out of an inset. + // And to give the DEPM the possibility of doing + // something we must provide it with two different + // cursors. (Lgb) + LCursor dummy = cur; + if (dummy == old) + ++dummy.pos(); + + bool const changed = deleteEmptyParagraphMechanism(dummy, old); + + // Make sure that cur gets back whatever happened to dummy(Lgb) + if (changed) + cur = dummy; + + return changed; + } - + + bool updateNeeded = false; + if (row + 1 < int(par.rows().size())) { - setCursor(cur, cur.pit(), x2pos(cur.pit(), row + 1, x)); + updateNeeded |= setCursor(cur, cur.pit(), + x2pos(cur.pit(), row + 1, x)); } else if (cur.pit() + 1 < int(paragraphs().size())) { ++cur.pit(); - setCursor(cur, cur.pit(), x2pos(cur.pit(), 0, x)); + updateNeeded |= setCursor(cur, cur.pit(), + x2pos(cur.pit(), 0, x)); } - + cur.x_target() = x; + + return updateNeeded; } -void LyXText::cursorUpParagraph(LCursor & cur) +bool LyXText::cursorUpParagraph(LCursor & cur) { + bool updated = false; if (cur.pos() > 0) - setCursor(cur, cur.pit(), 0); + updated = setCursor(cur, cur.pit(), 0); else if (cur.pit() != 0) - setCursor(cur, cur.pit() - 1, 0); + updated = setCursor(cur, cur.pit() - 1, 0); + return updated; } -void LyXText::cursorDownParagraph(LCursor & cur) +bool LyXText::cursorDownParagraph(LCursor & cur) { + bool updated = false; if (cur.pit() != cur.lastpit()) - setCursor(cur, cur.pit() + 1, 0); + updated = setCursor(cur, cur.pit() + 1, 0); else - setCursor(cur, cur.pit(), cur.lastpos()); + updated = setCursor(cur, cur.pit(), cur.lastpos()); + return updated; } @@ -1327,16 +1375,16 @@ void LyXText::cursorDownParagraph(LCursor & cur) // position. Called by deleteEmptyParagraphMechanism void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where) { - // do notheing if cursor is not in the paragraph where the + // Do nothing if cursor is not in the paragraph where the // deletion occured, if (cur.pit() != where.pit()) return; - // if cursor position is after the deletion place update it + // If cursor position is after the deletion place update it if (cur.pos() > where.pos()) --cur.pos(); - // check also if we don't want to set the cursor on a spot behind the + // Check also if we don't want to set the cursor on a spot behind the // pagragraph because we erased the last character. if (cur.pos() > cur.lastpos()) cur.pos() = cur.lastpos(); @@ -1345,7 +1393,6 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where) bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old) { - BOOST_ASSERT(cur.size() == old.size()); // Would be wrong to delete anything if we have a selection. if (cur.selection()) return false; @@ -1401,7 +1448,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old) #warning DEPM, look here #endif //fixCursorAfterDelete(cur.anchor(), old.top()); - return false; + return true; } }