]> git.lyx.org Git - features.git/commitdiff
Only show Accept/Reject Change options if relevant
authorScott Kostyshak <skostysh@lyx.org>
Fri, 4 May 2018 22:21:54 +0000 (18:21 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Thu, 10 May 2018 16:58:44 +0000 (12:58 -0400)
In the context menu for a selection, we now only show the options
"Accept Change" and "Reject Change" if there is actually a change in
the selection. Similarly, in the toolbar, the buttons are only
enabled when there is a change in the selection.

This fixes #10338.

src/Paragraph.h
src/Text3.cpp

index 450dfe3265f19e5e94250c1375b7d5030dc2144b..b81832259ffe383f3d8ce5c89c6de2b87b810fd2 100644 (file)
@@ -263,10 +263,12 @@ public:
        /// look up change at given pos
        Change const & lookupChange(pos_type pos) const;
 
-       /// is there a change within the given range ?
+       /// is there a change within the given range (does not
+       /// check contained paragraphs)
        bool isChanged(pos_type start, pos_type end) const;
        /// is there an unchanged char at the given pos ?
        bool isChanged(pos_type pos) const;
+
        /// is there an insertion at the given pos ?
        bool isInserted(pos_type pos) const;
        /// is there a deletion at the given pos ?
index 9b0f50cc91ef7601894c464d8983555151a940e3..4172b3dc317eaadc4ba76a43c5284792e05fc154 100644 (file)
@@ -3185,17 +3185,31 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_CHANGE_ACCEPT:
        case LFUN_CHANGE_REJECT:
-               // In principle, these LFUNs should only be enabled if there
-               // is a change at the current position/in the current selection.
-               // However, without proper optimizations, this will inevitably
-               // result in unacceptable performance - just imagine a user who
-               // wants to select the complete content of a long document.
                if (!cur.selection())
                        enable = cur.paragraph().isChanged(cur.pos());
-               else
-                       // TODO: context-sensitive enabling of LFUN_CHANGE_ACCEPT/REJECT
-                       // for selections.
-                       enable = true;
+               else {
+                       // will enable if there is a change in the selection
+                       enable = false;
+
+                       // cheap improvement for efficiency: using cached
+                       // buffer variable, if there is no change in the
+                       // document, no need to check further.
+                       if (!cur.buffer()->areChangesPresent())
+                               break;
+
+                       for (DocIterator it = cur.selectionBegin(); it < cur.selectionEnd(); it.forwardPar()) {
+                               pos_type const beg = it.pos();
+                               pos_type end;
+                               if (it.paragraph().id() == cur.selectionEnd().paragraph().id())
+                                       end = cur.selectionEnd().pos();
+                               else
+                                       end = it.paragraph().size();
+                               if (beg != end && it.paragraph().isChanged(beg, end)) {
+                                       enable = true;
+                                       break;
+                               }
+                       }
+               }
                break;
 
        case LFUN_OUTLINE_UP: