]> git.lyx.org Git - lyx.git/blobdiff - src/Compare.cpp
Fix text direction issue for InsetInfo in RTL context
[lyx.git] / src / Compare.cpp
index 1cdffcba250b17fa1169449e3675803eee50308e..214f25cc7f7d6dee5b45abf3c8934902a4c2eab2 100644 (file)
 #include "Author.h"
 #include "BufferParams.h"
 #include "Changes.h"
+#include "CutAndPaste.h"
+#include "ErrorList.h"
 #include "Font.h"
 
 #include "insets/InsetText.h"
 
+#include "support/docstream.h"
 #include "support/lassert.h"
+#include "support/lyxalgo.h"
 #include "support/qstring_helpers.h"
 
-#include <boost/next_prior.hpp>
-
 using namespace std;
 using namespace lyx::support;
 
@@ -62,10 +64,10 @@ public:
                : from(from_), to(to_)
        {}
 
-       DocRange(Buffer const * buf)
+       DocRange(Buffer const * buf) :
+               from(doc_iterator_begin(buf)),
+               to(doc_iterator_end(buf))
        {
-               from = doc_iterator_begin(buf);
-               to = doc_iterator_end(buf);
                to.backwardPos();
        }
 
@@ -229,7 +231,10 @@ class Compare::Impl {
 public:
        ///
        Impl(Compare const & compare)
-               : abort_(false), compare_(compare), recursion_level_(0), D_(0)
+               : abort_(false), n_(0), m_(0), offset_reverse_diagonal_(0),
+                 odd_offset_(0), compare_(compare),
+                 old_buf_(0), new_buf_(0), dest_buf_(0), dest_pars_(0),
+                 recursion_level_(0), nested_inset_level_(0), D_(0)
        {}
 
        ///
@@ -304,9 +309,9 @@ private:
        void writeToDestBuffer(ParagraphList const & copy_pars) const;
 
        /// The length of the old chunk currently processed
-       int N_;
+       int n_;
        /// The length of the new chunk currently processed
-       int M_;
+       int m_;
        /// The offset diagonal of the reverse path of the
        /// currently processed chunk
        int offset_reverse_diagonal_;
@@ -379,7 +384,6 @@ void Compare::run()
        // Copy the buffer params to the destination buffer
        dest_buffer->params() = options_.settings_from_new
                ? new_buffer->params() : old_buffer->params();
-
        // Copy extra authors to the destination buffer
        AuthorList const & extra_authors = options_.settings_from_new ?
                old_buffer->params().authors() : new_buffer->params().authors();
@@ -387,12 +391,27 @@ void Compare::run()
        for (; it != extra_authors.end(); ++it)
                dest_buffer->params().authors().record(*it);
 
-       doStatusMessage();
+       // We will need this later
+       DocumentClassConstPtr const olddc =
+               dest_buffer->params().documentClassPtr();
+       // We do not want to share the DocumentClass with the other Buffer.
+       // See bug #10295.
+       dest_buffer->params().makeDocumentClass();
 
-       // do the real work
+       doStatusMessage();
+       // Do the real work
        if (!doCompare())
                return;
 
+       // The comparison routine simply copies the paragraphs over into the
+       // new buffer with the document class from wherever they came from.
+       // So we need to reset the document class of all the paragraphs.
+       // See bug #10295.
+       ErrorList el;
+       cap::switchBetweenClasses(
+                       olddc, dest_buffer->params().documentClassPtr(),
+                       static_cast<InsetText &>(dest_buffer->inset()), el);
+
        finished(pimpl_->abort_);
        return;
 }
@@ -420,8 +439,8 @@ static void getParagraphList(DocRange const & range,
        pit_type startpit = range.from.pit();
        pit_type endpit = range.to.pit();
        ParagraphList const & ps_ = range.text()->paragraphs();
-       ParagraphList tmp_pars(boost::next(ps_.begin(), startpit),
-               boost::next(ps_.begin(), endpit + 1));
+       ParagraphList tmp_pars(lyx::next(ps_.begin(), startpit),
+               lyx::next(ps_.begin(), endpit + 1));
 
        // Remove the end of the last paragraph; afterwards, remove the
        // beginning of the first paragraph. Keep this order - there may only
@@ -610,7 +629,7 @@ Compare::Impl::SnakeResult Compare::Impl::retrieveMiddleSnake(
        if (os[k].empty() && os_r[kk].empty()) {
                // No, there is no snake at all, in which case
                // the length of the shortest edit script is M+N.
-               LATTEST(2 * D - odd_offset_ == M_ + N_);
+               LATTEST(2 * D - odd_offset_ == m_ + n_);
                return NoSnake;
        }
 
@@ -632,12 +651,12 @@ int Compare::Impl::findMiddleSnake(DocRangePair const & rp,
        DocPair & middle_snake)
 {
        // The lengths of the old and new chunks.
-       N_ = rp.o.length();
-       M_ = rp.n.length();
+       n_ = rp.o.length();
+       m_ = rp.n.length();
 
        // Forward paths are centered around the 0-diagonal; reverse paths
        // are centered around the diagonal N - M. (Delta in the article)
-       offset_reverse_diagonal_ = N_ - M_;
+       offset_reverse_diagonal_ = n_ - m_;
 
        // If the offset is odd, only check for overlap while extending forward
     // paths, otherwise only check while extending reverse paths.
@@ -653,7 +672,7 @@ int Compare::Impl::findMiddleSnake(DocRangePair const & rp,
        nrs.reset(DocIterator());
 
        // In the formula below, the "+ 1" ensures we round like ceil()
-       int const D_max = (M_ + N_ + 1)/2;
+       int const D_max = (m_ + n_ + 1)/2;
        // D is the number of horizontal and vertical steps, i.e.
        // different characters in the old and new chunk.
        for (int D = 0; D <= D_max; ++D) {
@@ -717,7 +736,7 @@ bool Compare::Impl::diff(Buffer const * new_buf, Buffer const * old_buf,
                diff_i(rp_new);
 
        for (pit_type p = 0; p < (pit_type)dest_pars_->size(); ++p) {
-               (*dest_pars_)[p].setBuffer(const_cast<Buffer &>(*dest_buf));
+               (*dest_pars_)[p].setInsetBuffers(const_cast<Buffer &>(*dest_buf));
                (*dest_pars_)[p].setInsetOwner(&dest_buf_->inset());
        }