X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FDocIterator.cpp;h=5cd1c0eac3c0e84f199e6ce12cce830c4b14bc73;hb=4d5bef1bdcbe7a20d67613a793acb89f0e583bf6;hp=51433d47814b617463aa30273e78d02b75c2a7f6;hpb=1ec0b390f5eab86253f121e5a098ce4f3c97a98b;p=lyx.git diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp index 51433d4781..5cd1c0eac3 100644 --- a/src/DocIterator.cpp +++ b/src/DocIterator.cpp @@ -72,10 +72,30 @@ DocIterator doc_iterator_end(const Buffer * buf0, const Inset * inset0) } +DocIterator DocIterator::clone(Buffer * buffer) const +{ + LASSERT(buffer->isClone(), return DocIterator()); + Inset * inset = &buffer->inset(); + DocIterator dit(buffer); + size_t const n = slices_.size(); + for (size_t i = 0 ; i != n; ++i) { + LASSERT(inset, /**/); + dit.push_back(slices_[i]); + dit.top().inset_ = inset; + if (i + 1 != n) + inset = dit.nextInset(); + } + return dit; +} + + bool DocIterator::inRegexped() const { - InsetMathHull * i = dynamic_cast(inset().asInsetMath()); - return i && i->getType() == hullRegexp; + InsetMath * im = inset().asInsetMath(); + if (!im) + return false; + InsetMathHull * hull = im->asHullInset(); + return hull && hull->getType() == hullRegexp; } @@ -92,7 +112,8 @@ Inset * DocIterator::nextInset() const if (pos() == lastpos()) return 0; if (pos() > lastpos()) { - LYXERR0("Should not happen, but it does. "); + LYXERR0("Should not happen, but it does: pos() = " + << pos() << ", lastpos() = " << lastpos()); return 0; } if (inMathed()) @@ -110,7 +131,7 @@ Inset * DocIterator::prevInset() const if (cell().empty()) // FIXME: this should not happen but it does. // See bug 3189 - // http://bugzilla.lyx.org/show_bug.cgi?id=3189 + // http://www.lyx.org/trac/ticket/3189 return 0; else return prevAtom().nucleus(); @@ -124,8 +145,8 @@ Inset * DocIterator::realInset() const LASSERT(inTexted(), /**/); // if we are in a tabular, we need the cell if (inset().lyxCode() == TABULAR_CODE) { - InsetTabular & tabular = static_cast(inset()); - return tabular.cell(idx()).get(); + InsetTabular * tabular = inset().asInsetTabular(); + return tabular->cell(idx()).get(); } return &inset(); } @@ -171,6 +192,18 @@ Paragraph & DocIterator::innerParagraph() const } +FontSpan DocIterator::locateWord(word_location const loc) const +{ + FontSpan f = FontSpan(); + + if (!top().text()->empty()) { + f.first = pos(); + top().paragraph().locateWord(f.first, f.last, loc); + } + return f; +} + + CursorSlice const & DocIterator::innerTextSlice() const { LASSERT(!empty(), /**/); @@ -249,12 +282,7 @@ MathData & DocIterator::cell() const Text * DocIterator::innerText() const { LASSERT(!empty(), /**/); - // go up until first non-0 text is hit - // (innermost text is 0 in mathed) - for (int i = depth() - 1; i >= 0; --i) - if (slices_[i].text()) - return slices_[i].text(); - return 0; + return innerTextSlice().text(); } @@ -315,7 +343,7 @@ void DocIterator::forwardPosIgnoreCollapsed() // FIXME: the check for asInsetMath() shouldn't be necessary // but math insets do not return a sensible editable() state yet. if (nextinset && !nextinset->asInsetMath() - && nextinset->editable() != Inset::HIGHLY_EDITABLE) { + && !nextinset->editable()) { ++top().pos(); return; } @@ -502,6 +530,35 @@ bool DocIterator::fixIfBroken() } +void DocIterator::sanitize() +{ + // this function re-creates the cache of inset pointers + //lyxerr << "converting:\n" << *this << endl; + if (buffer_) + inset_ = &buffer_->inset(); + Inset * inset = inset_; + for (size_t i = 0, n = slices_.size(); i != n; ++i) { + if (inset == 0) { + // FIXME + LYXERR0(" Should not happen, but does e.g. after " + "C-n C-l C-z S-C-z\n" + << " or when a Buffer has been concurrently edited by two views" + << '\n' << "dit: " << *this << '\n' + << " lastpos: " << slices_[i].lastpos()); + fixIfBroken(); + break; + } + slices_[i].inset_ = inset; + if (fixIfBroken()) + break; + if (i + 1 != n) + inset = slices_[i].inset().inMathed() ? slices_[i].cell()[slices_[i].pos()].nucleus() + : slices_[i].paragraph().getInset(pos()); + } + //lyxerr << "convert:\n" << *this << " to:\n" << dit << endl; +} + + int DocIterator::find(MathData const & cell) const { for (size_t l = 0; l != slices_.size(); ++l) { @@ -569,29 +626,9 @@ StableDocIterator::StableDocIterator(DocIterator const & dit) DocIterator StableDocIterator::asDocIterator(Buffer * buf) const { - // this function re-creates the cache of inset pointers - //lyxerr << "converting:\n" << *this << endl; - Inset * inset = &buf->inset(); - DocIterator dit = DocIterator(buf, inset); - for (size_t i = 0, n = data_.size(); i != n; ++i) { - if (inset == 0) { - // FIXME - LYXERR0(" Should not happen, but does e.g. after " - "C-n C-l C-z S-C-z\n" - << " or when a Buffer has been concurrently edited by two views" - << '\n' << "dit: " << dit << '\n' - << " lastpos: " << dit.lastpos()); - dit.fixIfBroken(); - break; - } - dit.push_back(data_[i]); - dit.top().inset_ = inset; - if (dit.fixIfBroken()) - break; - if (i + 1 != n) - inset = dit.nextInset(); - } - //lyxerr << "convert:\n" << *this << " to:\n" << dit << endl; + DocIterator dit = DocIterator(buf); + dit.slices_ = data_; + dit.sanitize(); return dit; } @@ -610,16 +647,4 @@ bool operator==(StableDocIterator const & dit1, StableDocIterator const & dit2) } -bool isLetter(DocIterator const & dit) -{ - return dit.inTexted() - && dit.inset().allowSpellCheck() - && dit.pos() != dit.lastpos() - && (dit.paragraph().isLetter(dit.pos()) - // We want to pass the ' and escape chars to ispell - || contains(from_utf8(lyxrc.spellchecker_esc_chars + '\''), - dit.paragraph().getChar(dit.pos()))) - && !dit.paragraph().isDeleted(dit.pos()); -} - } // namespace lyx