From 5238faf6da457b3396fce42330b8f1b2a6303e92 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Mon, 7 Oct 2019 19:36:52 +0200 Subject: [PATCH] Loki: Fix lookup for label key token (#19579) --- .../features/explore/slate-plugins/suggestions.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/public/app/features/explore/slate-plugins/suggestions.tsx b/public/app/features/explore/slate-plugins/suggestions.tsx index 60e55cbbdfa..1f99640da5b 100644 --- a/public/app/features/explore/slate-plugins/suggestions.tsx +++ b/public/app/features/explore/slate-plugins/suggestions.tsx @@ -225,14 +225,16 @@ const handleTypeahead = debounce( ) .toArray(); + // Find the first label key to the left of the cursor const labelKeyDec = decorations - .filter( - decoration => - decoration.end.offset === myOffset && + .filter(decoration => { + return ( + decoration.end.offset <= myOffset && decoration.type === TOKEN_MARK && decoration.data.get('className').includes('label-key') - ) - .first(); + ); + }) + .last(); const labelKey = labelKeyDec && value.focusText.text.slice(labelKeyDec.start.offset, labelKeyDec.end.offset);