On Sat, May 05, 2018 at 04:05:49PM +0000, Richard Kimberly Heck wrote: > On 05/05/2018 11:56 AM, Scott Kostyshak wrote: > > 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? > > If it's an InsetText, then it has its own Text object, which has paragraphs: > ParagraphList const & pars = theInset.text().paragraphs();
Thanks, Riki. that's exactly what I needed. New patch attached. The next problem is that I need to check all paragraphs on all depths. For example, if there is a change inside a LyX Note, and I select the LyX Note from the outside of the inset, isChanged() is false because I guess it checks whether the entire note was changed, not the contents of the note. I'll look into this. Scott
From 335f461c26d7aa64c01f7e1f9722d4007e983ce2 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 9b0f50c..f0d488b 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -3185,17 +3185,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 const & pars = cur.text()->paragraphs(); + pit_type const pars_begin = cur.selectionBegin().pit(); + pit_type const pars_end = cur.selectionEnd().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