From 2bbc420032a3ec293aff5465473d05171254a72e Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 18 Jun 2023 12:45:25 +0200 Subject: [PATCH] Disable LFUN_INDEX_TAG_ALL if there is noting to tag (#12812) --- src/BufferView.cpp | 6 ++++++ src/insets/InsetIndex.cpp | 28 ++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 913c4598d3..15911e8ff3 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -1759,6 +1759,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) } case LFUN_INDEX_TAG_ALL: { + if (cur.pos() == 0) + // nothing precedes + break; + Inset * ins = cur.nextInset(); if (!ins || ins->lyxCode() != INDEX_CODE) // not at index inset @@ -1795,6 +1799,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr) // Get word or selection cur.text()->selectWord(cur, WHOLE_WORD); docstring const searched_string = cur.selectionAsString(false); + if (searched_string.empty()) + break; // Start from the beginning lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN)); while (findOne(this, searched_string, diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index f494b07695..536288d68a 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -27,6 +27,7 @@ #include "IndicesList.h" #include "InsetList.h" #include "Language.h" +#include "Paragraph.h" #include "LaTeX.h" #include "LaTeXFeatures.h" #include "Lexer.h" @@ -693,8 +694,31 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_INDEXMACRO_INSERT: return macrosPossible(cmd.getArg(0)); - case LFUN_INDEX_TAG_ALL: - return true; + case LFUN_INDEX_TAG_ALL: { + if (cur.pos() == 0) + // nothing to tag + return false; + // move backwards into preceding word + // skip over other index insets + DocIterator dit(cur); + dit.backwardPosIgnoreCollapsed(); + while (true) { + if (dit.inset().lyxCode() == INDEX_CODE) + dit.pop_back(); + else if (dit.prevInset() && dit.prevInset()->lyxCode() == INDEX_CODE) + dit.backwardPosIgnoreCollapsed(); + else + break; + } + if (!dit.inTexted()) + // action not possible + return false; + // Check if we actually have a word to tag + FontSpan tw = dit.locateWord(WHOLE_WORD); + + // action possible if we have a word of at least one char + return (tw.size() > 0); + } default: return InsetCollapsible::getStatus(cur, cmd, flag); -- 2.39.5