X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursor.cpp;h=b20e981b32c506cab09c2e7cc34e1989bc0a55b9;hb=ab8a290040dc28f39ebb230ab4b8a43467df0906;hp=59d2dd78c9db2d44fca1820d30ea7b6ff20646f4;hpb=f361c26a0522059556b550cd0f468794af2ad301;p=lyx.git diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 59d2dd78c9..b20e981b32 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -95,20 +95,18 @@ DocIterator bruteFind2(Cursor const & c, int x, int y) int xo; int yo; Inset const * inset = &it.inset(); - map const & data = - c.bv().coordCache().getInsets().getData(); - map::const_iterator I = data.find(inset); + CoordCache const & cache = c.bv().coordCache(); // FIXME: in the case where the inset is not in the cache, this // means that no part of it is visible on screen. In this case // we don't do elaborate search and we just return the forwarded // DocIterator at its beginning. - if (I == data.end()) { + if (!cache.getInsets().has(inset)) { it.top().pos() = 0; return it; } - Point o = I->second.pos; + Point const o = cache.getInsets().xy(inset); inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo); // Convert to absolute xo += o.x_; @@ -402,7 +400,7 @@ void Cursor::dispatch(FuncRequest const & cmd0) bool badcursor = notifyCursorLeavesOrEnters(old, *this); if (badcursor) { fixIfBroken(); - bv().fixInlineCompletionPos(); + bv().resetInlineCompletionPos(); } old.endUndoGroup(); } @@ -520,14 +518,14 @@ void Cursor::setCursorToAnchor() } -void Cursor::markEditPosition() +void Cursor::markNewWordPosition() { - if (inTexted() && new_word_.empty()) { - FontSpan ow = locateWord(WHOLE_WORD); - if (ow.size() == 1) { + if (lyxrc.spellcheck_continuously && inTexted() && new_word_.empty()) { + FontSpan nw = locateWord(WHOLE_WORD); + if (nw.size() == 1) { LYXERR(Debug::DEBUG, "start new word: " << " par: " << pit() - << " pos: " << ow.first); + << " pos: " << nw.first); new_word_ = *this; } } @@ -547,22 +545,35 @@ void Cursor::clearNewWordPosition() void Cursor::checkNewWordPosition() { - if (new_word_.empty()) + if (!lyxrc.spellcheck_continuously || new_word_.empty()) return ; if (!inTexted()) clearNewWordPosition(); else { - if (paragraph().id() != new_word_.paragraph().id()) + // forget the position of the current new word if + // 1) the paragraph changes or + // 2) the count of nested insets changes or + // 3) the cursor pos is out of paragraph bound + if (pit() != new_word_.pit() || + depth() != new_word_.depth() || + new_word_.pos() > new_word_.lastpos()) { + clearNewWordPosition(); + } else if (new_word_.fixIfBroken()) + // 4) or the remembered position was "broken" clearNewWordPosition(); else { - FontSpan ow = new_word_.locateWord(WHOLE_WORD); FontSpan nw = locateWord(WHOLE_WORD); - if (nw.intersect(ow).empty()) + if (nw.size()) { + FontSpan ow = new_word_.locateWord(WHOLE_WORD); + if (nw.intersect(ow).empty()) + clearNewWordPosition(); + else + LYXERR(Debug::DEBUG, "new word: " + << " par: " << pit() + << " pos: " << nw.first << ".." << nw.last); + } else { clearNewWordPosition(); - else - LYXERR(Debug::DEBUG, "new word: " - << " par: " << pit() - << " pos: " << nw.first << ".." << nw.last); + } } } } @@ -2264,6 +2275,7 @@ bool Cursor::fixIfBroken() bool const broken_anchor = anchor_.fixIfBroken(); if (broken_cursor || broken_anchor) { + clearNewWordPosition(); clearSelection(); return true; }