Disable LFUN_INDEX_TAG_ALL if there is noting to tag (#12812)

This commit is contained in:
Juergen Spitzmueller 2023-06-18 12:45:25 +02:00
parent ca5a75b23e
commit 2bbc420032
2 changed files with 32 additions and 2 deletions

View File

@ -1759,6 +1759,10 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
} }
case LFUN_INDEX_TAG_ALL: { case LFUN_INDEX_TAG_ALL: {
if (cur.pos() == 0)
// nothing precedes
break;
Inset * ins = cur.nextInset(); Inset * ins = cur.nextInset();
if (!ins || ins->lyxCode() != INDEX_CODE) if (!ins || ins->lyxCode() != INDEX_CODE)
// not at index inset // not at index inset
@ -1795,6 +1799,8 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
// Get word or selection // Get word or selection
cur.text()->selectWord(cur, WHOLE_WORD); cur.text()->selectWord(cur, WHOLE_WORD);
docstring const searched_string = cur.selectionAsString(false); docstring const searched_string = cur.selectionAsString(false);
if (searched_string.empty())
break;
// Start from the beginning // Start from the beginning
lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN)); lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
while (findOne(this, searched_string, while (findOne(this, searched_string,

View File

@ -27,6 +27,7 @@
#include "IndicesList.h" #include "IndicesList.h"
#include "InsetList.h" #include "InsetList.h"
#include "Language.h" #include "Language.h"
#include "Paragraph.h"
#include "LaTeX.h" #include "LaTeX.h"
#include "LaTeXFeatures.h" #include "LaTeXFeatures.h"
#include "Lexer.h" #include "Lexer.h"
@ -693,8 +694,31 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_INDEXMACRO_INSERT: case LFUN_INDEXMACRO_INSERT:
return macrosPossible(cmd.getArg(0)); return macrosPossible(cmd.getArg(0));
case LFUN_INDEX_TAG_ALL: case LFUN_INDEX_TAG_ALL: {
return true; 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: default:
return InsetCollapsible::getStatus(cur, cmd, flag); return InsetCollapsible::getStatus(cur, cmd, flag);