commit 2bbc420032a3ec293aff5465473d05171254a72e
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sun Jun 18 12:45:25 2023 +0200

    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 913c459..15911e8 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 f494b07..536288d 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);
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to