The attached patch is an attempt to only show the "Accept Change" and "Reject Change" options in the context menu when there is a change in the selection.
It works well except if the selection is inside an inset. For example, when in a LyX Note, ppos_beg and ppos_end refer to the position within the note. Does each inset have its own ParagraphList? If so, how do I access it? In addition to the above problem, any other comments are welcome, since I don't know this code well. Scott
From 22ea8d15753e15c124f73b929348da42daee3431 Mon Sep 17 00:00:00 2001 From: Scott Kostyshak <skost...@lyx.org> Date: Fri, 4 May 2018 18:21:54 -0400 Subject: [PATCH] Only show Accept/Reject Change options if relevant In the context menu for a selection, we now only show the options "Accept Change" and "Reject Change" if there are actually changes in the selection. --- src/Text3.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index 572e4bd..8c2bd00 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -3191,17 +3191,32 @@ 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 { + // enable if there is a change in the selection + enable = false; + ParagraphList & pars = cur.buffer()->text().paragraphs(); + pit_type const pars_begin = cur.selectionBegin().bottom().pit(); + pit_type const pars_end = cur.selectionEnd().bottom().pit(); + for (pit_type pit = pars_begin; pit <= pars_end; ++pit) { + pos_type ppos_beg, ppos_end; + if (pit == pars_begin) + ppos_beg = cur.selBegin().pos(); + else + ppos_beg = 0; + if (pit == pars_end) + ppos_end = cur.selEnd().pos(); + else + ppos_end = pars[pit].size(); + + if (ppos_beg != ppos_end && + pars[pit].isChanged(ppos_beg, ppos_end)) { + enable = true; + break; + } + } + } break; case LFUN_OUTLINE_UP: -- 2.7.4
signature.asc
Description: PGP signature