On Sat, Apr 16, 2016 at 04:10:23PM -0400, Richard Heck wrote:

> On 04/16/2016 04:01 PM, Guillaume Munch wrote:
> > Le 24/01/2016 23:08, Enrico Forestieri a �crit :
> >> On Sun, Jan 24, 2016 at 10:41:39PM +0100, Enrico Forestieri wrote:
> >>> On Fri, Jan 22, 2016 at 06:36:03PM -0500, Guillaume Munch wrote:
> >>>>
> >>>> Maybe we can go with the improvements you already made for beta,
> >>>> and commit this particular patch to master after release.
> >>>
> >>> Fair enough. Please find attached the next iteration of the patch in
> >>> case you want to evaluate it. Note that I could not solve the problem
> >>> that a separator may be randomly selected after multiple clicks.
> >>> However, I think that this is a minor annoyance.
> >>
> >> I found the reason of this last quirk. The multiple clicks were not
> >> the real cause but the fact that, while clicking, the mouse could have
> >> been moved, even if slightly. Please try the attached patch. Now the
> >> separators should really be unselectable (by alone).
> >>
> >
> > I have been testing this patch for a while. I suggest that it is
> > committed to 2.3.0-staging and 2.2.2-staging, thanks.
> 
> Enrico, if you do want to commit this, do it first to 2.3-staging (which
> is open) and then I'll have a look. I'm sure it's fine for
> 2.2.2-staging, too, but I'd like to see it first before deciding....

I would be grateful if you can do that. I am attaching a patch updated
to account for 4bab2ab5.

-- 
Enrico
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 81ebe79..9d5f538 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -2203,9 +2203,14 @@ void BufferView::mouseEventDispatch(FuncRequest const & 
cmd0)
                // inset (depending on cmd.x(), cmd.y()). This is needed for
                // editing to fix bug 9628, but e.g. the context menu needs a
                // cursor in front of the inset.
-               if ((inset->hasSettings() || !inset->contextMenuName().empty()) 
&&
+               if ((inset->hasSettings() || !inset->contextMenuName().empty()
+                    || inset->lyxCode() == SEPARATOR_CODE) &&
                    cur.nextInset() != inset && cur.prevInset() == inset)
                        cur.posBackward();
+       } else if (cur.inTexted() && cur.pos()
+                       && cur.paragraph().isEnvSeparator(cur.pos() - 1)) {
+               // Always place cursor in front of a separator inset.
+               cur.posBackward();
        }
 
        // Put anchor at the same position.
@@ -2512,12 +2517,8 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool 
select)
        // FIXME: (2) if we had a working InsetText::notifyCursorLeaves,
        // the leftinset bool would not be necessary (badcursor instead).
        bool update = leftinset;
-       if (!do_selection && d->cursor_.inTexted()) {
+       if (!do_selection && d->cursor_.inTexted())
                update |= checkDepm(cur, d->cursor_);
-               if (cur.inTexted() && cur.pos()
-                       && cur.paragraph().isEnvSeparator(cur.pos() - 1))
-                   cur.posBackward();
-       }
 
        if (!do_selection)
                d->cursor_.resetAnchor();
diff --git a/src/Row.cpp b/src/Row.cpp
index 2bfe55a..fe3efbf 100644
--- a/src/Row.cpp
+++ b/src/Row.cpp
@@ -66,8 +66,7 @@ double Row::Element::pos2x(pos_type const i) const
 
        double w = 0;
        //handle first the two bounds of the element
-       if (i == endpos && type != VIRTUAL
-               && !(inset && inset->lyxCode() == SEPARATOR_CODE))
+       if (i == endpos && type != VIRTUAL)
                w = isRTL() ? 0 : full_width();
        else if (i == pos || type != STRING)
                w = isRTL() ? full_width() : 0;
diff --git a/src/Text.cpp b/src/Text.cpp
index 187e387..847fe88 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1110,7 +1110,7 @@ bool Text::cursorForwardOneWord(Cursor & cur)
        Paragraph const & par = cur.paragraph();
 
        // Paragraph boundary is a word boundary
-       if (pos == lastpos) {
+       if (pos == lastpos || (pos + 1 == lastpos && par.isEnvSeparator(pos))) {
                if (pit != cur.lastpit())
                        return setCursor(cur, pit + 1, 0);
                else
@@ -1143,6 +1143,10 @@ bool Text::cursorForwardOneWord(Cursor & cur)
                             ++pos;
        }
 
+       // Don't skip a separator inset at the end of a paragraph
+       if (pos == lastpos && pos && par.isEnvSeparator(pos - 1))
+               --pos;
+
        return setCursor(cur, pit, pos);
 }
 
@@ -1156,8 +1160,14 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
        Paragraph & par = cur.paragraph();
 
        // Paragraph boundary is a word boundary
-       if (pos == 0 && pit != 0)
-               return setCursor(cur, pit - 1, getPar(pit - 1).size());
+       if (pos == 0 && pit != 0) {
+               Paragraph & prevpar = getPar(pit - 1);
+               pos = prevpar.size();
+               // Don't stop after an environment separator
+               if (pos && prevpar.isEnvSeparator(pos - 1))
+                       --pos;
+               return setCursor(cur, pit - 1, pos);
+       }
 
        if (lyxrc.mac_like_cursor_movement) {
                // Skip through punctuation and spaces.
diff --git a/src/Text3.cpp b/src/Text3.cpp
index fbcd9b7..f68004b 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1661,6 +1661,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
                tm->setCursorFromCoordinates(cur, cmd.x(), y);
                cur.setTargetX(cmd.x());
+               // Don't allow selecting a separator inset
+               if (cur.pos() && cur.paragraph().isEnvSeparator(cur.pos() - 1))
+                       cur.posBackward();
                if (cmd.y() >= wh)
                        lyx::dispatch(FuncRequest(LFUN_DOWN_SELECT));
                else if (cmd.y() < 0)
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 325fb6c..9cd03b4 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1594,7 +1594,8 @@ bool TextMetrics::cursorEnd(Cursor & cur)
                        boundary = true;
                else
                        --end;
-       }
+       } else if (cur.paragraph().isEnvSeparator(end-1))
+               --end;
        return text_->setCursor(cur, cur.pit(), end, true, boundary);
 }
 

Reply via email to