]> git.lyx.org Git - features.git/commitdiff
Disable LFUN_INDEX_TAG_ALL if there is noting to tag (#12812)
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 18 Jun 2023 10:45:25 +0000 (12:45 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 18 Jun 2023 10:45:25 +0000 (12:45 +0200)
src/BufferView.cpp
src/insets/InsetIndex.cpp

index 913c4598d37937ad00e8d82cc1d312a320522b6a..15911e8ff3a651745e28dbfbd8e392a26435a707 100644 (file)
@@ -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,
index f494b076954e1bce0f582aa9ddf377b513ab7a4d..536288d68a3a181c8c758e1ba6117beaf6082bd0 100644 (file)
@@ -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);