X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FDocIterator.cpp;h=38f2393224b1e37b1839537f12ea6b85008ec8d8;hb=7309ae50b4c40bdbd5c4e45962f132ec0e1a4249;hp=e574115c31be85de4349a1ef7ab1e60db2e19f2a;hpb=17e435c47e36effd36d25cec900369e04f6acb4e;p=lyx.git diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp index e574115c31..38f2393224 100644 --- a/src/DocIterator.cpp +++ b/src/DocIterator.cpp @@ -26,6 +26,7 @@ #include "insets/InsetTabular.h" +#include "support/convert.h" #include "support/debug.h" #include "support/ExceptionMessage.h" #include "support/gettext.h" @@ -59,7 +60,7 @@ DocIterator::DocIterator(Buffer * buf, Inset * inset) DocIterator doc_iterator_begin(const Buffer * buf0, const Inset * inset0) { - Buffer * buf = const_cast(buf0); + Buffer * buf = const_cast(buf0); Inset * inset = const_cast(inset0); DocIterator dit(buf, inset ? inset : &buf->inset()); dit.forwardPos(); @@ -69,7 +70,7 @@ DocIterator doc_iterator_begin(const Buffer * buf0, const Inset * inset0) DocIterator doc_iterator_end(const Buffer * buf0, const Inset * inset0) { - Buffer * buf = const_cast(buf0); + Buffer * buf = const_cast(buf0); Inset * inset = const_cast(inset0); return DocIterator(buf, inset ? inset : &buf->inset()); } @@ -95,7 +96,7 @@ DocIterator DocIterator::clone(Buffer * buffer) const bool DocIterator::inRegexped() const { InsetMath * im = inset().asInsetMath(); - if (!im) + if (!im) return false; InsetMathHull * hull = im->asHullInset(); return hull && hull->getType() == hullRegexp; @@ -207,7 +208,7 @@ FontSpan DocIterator::locateWord(word_location const loc) const return f; } - + CursorSlice const & DocIterator::innerTextSlice() const { LBUFERR(!empty()); @@ -226,6 +227,23 @@ CursorSlice const & DocIterator::innerTextSlice() const } +docstring DocIterator::paragraphGotoArgument() const +{ + CursorSlice const & s = innerTextSlice(); + return convert(s.paragraph().id()) + ' ' + + convert(s.pos()); +} + + +DocIterator DocIterator::getInnerText() const +{ + DocIterator texted = *this; + while (!texted.inTexted()) + texted.pop_back(); + return texted; +} + + pit_type DocIterator::lastpit() const { return inMathed() ? 0 : text()->paragraphs().size() - 1; @@ -300,6 +318,24 @@ Inset * DocIterator::innerInsetOfType(int code) const } +bool DocIterator::posBackward() +{ + if (pos() == 0) + return false; + --pos(); + return true; +} + + +bool DocIterator::posForward() +{ + if (pos() == lastpos()) + return false; + ++pos(); + return true; +} + + // This duplicates code above, but is in the critical path. // So please think twice before adding stuff void DocIterator::forwardPos() @@ -449,6 +485,28 @@ void DocIterator::backwardPos() } +#if 0 +// works, but currently not needed +void DocIterator::backwardInset() +{ + backwardPos(); + + while (!empty() && !nextInset()) { + if (inTexted()) { + pos_type const lastp = lastpos(); + Paragraph const & par = paragraph(); + pos_type & pos = top().pos(); + while (pos > 0 && (pos == lastp || !par.isInset(pos))) + --pos; + if (pos > 0) + break; + } + backwardPos(); + } +} +#endif + + bool DocIterator::hasPart(DocIterator const & it) const { // it can't be a part if it is larger @@ -460,6 +518,19 @@ bool DocIterator::hasPart(DocIterator const & it) const } +bool DocIterator::allowSpellCheck() const +{ + /// spell check is disabled if the iterator position + /// is inside of an inset which disables the spell checker + size_t const n = depth(); + for (size_t i = 0; i < n; ++i) { + if (!slices_[i].inset_->allowSpellCheck()) + return false; + } + return true; +} + + void DocIterator::updateInsets(Inset * inset) { // this function re-creates the cache of inset pointers. @@ -483,7 +554,7 @@ bool DocIterator::fixIfBroken() if (empty()) return false; - // Go through the slice stack from the bottom. + // Go through the slice stack from the bottom. // Check that all coordinates (idx, pit, pos) are correct and // that the inset is the one which is claimed to be there Inset * inset = &slices_[0].inset(); @@ -491,7 +562,7 @@ bool DocIterator::fixIfBroken() size_t n = slices_.size(); for (; i != n; ++i) { CursorSlice & cs = slices_[i]; - if (&cs.inset() != inset) { + if (&cs.inset() != inset || ! cs.inset().isActive()) { // the whole slice is wrong, chop off this as well --i; LYXERR(Debug::DEBUG, "fixIfBroken(): inset changed"); @@ -555,8 +626,8 @@ void DocIterator::sanitize() fixIfBroken(); break; } - if (!inset->editable()) { - LYXERR0("Inset found on cursor stack is not editable."); + if (!inset->isActive()) { + LYXERR0("Inset found on cursor stack is not active."); fixIfBroken(); break; } @@ -580,7 +651,7 @@ int DocIterator::find(MathData const & cell) const } -int DocIterator::find(Inset const * inset) const +int DocIterator::find(Inset const * inset) const { for (size_t l = 0; l != slices_.size(); ++l) { if (&slices_[l].inset() == inset) @@ -603,13 +674,13 @@ void DocIterator::cutOff(int above) } -void DocIterator::append(vector const & x) +void DocIterator::append(vector const & x) { slices_.insert(slices_.end(), x.begin(), x.end()); } -void DocIterator::append(DocIterator::idx_type idx, pos_type pos) +void DocIterator::append(DocIterator::idx_type idx, pos_type pos) { slices_.push_back(CursorSlice()); top().idx() = idx; @@ -627,9 +698,9 @@ ostream & operator<<(ostream & os, DocIterator const & dit) /////////////////////////////////////////////////////// -StableDocIterator::StableDocIterator(DocIterator const & dit) +StableDocIterator::StableDocIterator(DocIterator const & dit) : + data_(dit.internalData()) { - data_ = dit.internalData(); for (size_t i = 0, n = data_.size(); i != n; ++i) data_[i].inset_ = 0; }