]> git.lyx.org Git - lyx.git/commitdiff
Let getPosNearX take horizontal scrolling into account
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 30 Apr 2016 23:27:13 +0000 (01:27 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 3 May 2016 08:53:10 +0000 (10:53 +0200)
If we do not do that, it is not possible to position the cursor after
a long inset with the mouse.

To do this, it is necessary to add the pit information to the Row
object. This is a good idea in any case, and will allow to simplify
some code later on.

Fixes bug #10094.
(cherry picked from commit 8851645799ef67015e49fd75b9dfeed65d685e85)

src/Row.cpp
src/Row.h
src/TextMetrics.cpp
src/TextMetrics.h
status.22x

index d0694f7d2e8539ffd328127786274eb97355beab..58a23805f2ff35491df7fe56d265fcda40e85b52 100644 (file)
@@ -148,7 +148,8 @@ Row::Row()
        : separator(0), label_hfill(0), left_margin(0), right_margin(0),
          sel_beg(-1), sel_end(-1),
          begin_margin_sel(false), end_margin_sel(false),
-         changed_(false), crc_(0), pos_(0), end_(0), right_boundary_(false)
+         changed_(false), crc_(0),
+         pit_(0), pos_(0), end_(0), right_boundary_(false)
 {}
 
 
index f0c5b72ca1125aaef0c6ee784c7747ac0866fb4c..0bd4597746616ac5dd03fb3f2a6b57a226f933f4 100644 (file)
--- a/src/Row.h
+++ b/src/Row.h
@@ -144,6 +144,10 @@ public:
        void setSelectionAndMargins(DocIterator const & beg,
                DocIterator const & end) const;
 
+       ///
+       void pit(pit_type p) { pit_ = p; }
+       ///
+       pit_type pit() const { return pit_; }
        ///
        void pos(pos_type p) { pos_ = p; }
        ///
@@ -286,6 +290,8 @@ private:
        mutable bool changed_;
        /// CRC of row contents.
        mutable size_type crc_;
+       /// Index of the paragraph that contains this row
+       pit_type pit_;
        /// first pos covered by this row
        pos_type pos_;
        /// one behind last pos covered by this row
index 816f4bacd6115d741dce60cee8a3b7dee569900c..fdf0da692672c78798b2feb956187108df06c0b8 100644 (file)
@@ -443,6 +443,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                if (row_index == pm.rows().size())
                        pm.rows().push_back(Row());
                Row & row = pm.rows()[row_index];
+               row.pit(pit);
                row.pos(first);
                breakRow(row, right_margin, pit);
                setRowHeight(row, pit);
@@ -1113,6 +1114,16 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
        int const xo = origin_.x_;
        x -= xo;
 
+       int offset = 0;
+       CursorSlice rowSlice(const_cast<InsetText &>(text_->inset()));
+       rowSlice.pit() = row.pit();
+       rowSlice.pos() = row.pos();
+
+       // Adapt to cursor row scroll offset if applicable.
+       if (bv_->currentRowSlice() == rowSlice)
+               offset = bv_->horizScrollOffset();
+       x += offset;
+
        pos_type pos = row.pos();
        boundary = false;
        if (row.empty())
@@ -1166,8 +1177,10 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
                else
                        boundary = row.right_boundary();
        }
-       x += xo;
+
+       x += xo - offset;
        //LYXERR0("getPosNearX ==> pos=" << pos << ", boundary=" << boundary);
+
        return pos;
 }
 
index f0abcb520185a1ed4fd4daf721f0f1e16db008f8..6f5cf687336514ca747e6d298f557d5812bd59ed 100644 (file)
@@ -150,7 +150,7 @@ private:
 public:
        /// returns the position near the specified x-coordinate of the row.
        /// x is an absolute screen coord, it is set to the real beginning
-       /// of this column.
+       /// of this column. This takes in account horizontal cursor row scrolling.
        pos_type getPosNearX(Row const & row, int & x, bool & boundary) const;
 
        /// returns pos in given par at given x coord.
index 4321008e0ef2bbdfb539a405a10a5093d8568454..cfe0a4de626becc77e848cd98b54da84d094c6ca 100644 (file)
@@ -57,6 +57,9 @@ What's new
 - Fix horizontal scrolling feature when inside a collapsable inset
   with several paragraphs.
 
+- Fix selection of large formula with the mouse when horizontal
+  scrolling kicks in (but 10094).
+
 - Fix display of collapsable insets when the same document is shown in
   two views with different width (bug 9756).