fix(filter): don't crash when filtering for labels in (#1333)
This commit is contained in:
parent
07d6630891
commit
4c9f112103
|
|
@ -83,64 +83,9 @@ function decorateDocument(doc: Node) {
|
|||
while ((labelMatch = pattern.exec(text)) !== null) {
|
||||
const labelValue = labelMatch[4]?.trim()
|
||||
const operator = labelMatch[2]?.trim()
|
||||
if (labelValue) { // If there's a value
|
||||
const valueStart = labelMatch.index + labelMatch[0].lastIndexOf(labelValue)
|
||||
const valueEnd = valueStart + labelValue.length
|
||||
|
||||
const addLabelDecoration = (labelValue: string, start: number, end: number) => {
|
||||
const label = labelStore.getLabelByExactTitle(labelValue)
|
||||
|
||||
const from = findPosForIndex(doc, start)
|
||||
const to = findPosForIndex(doc, end)
|
||||
|
||||
if (from === null || to === null) {
|
||||
return
|
||||
}
|
||||
|
||||
valueRanges.push({start, end})
|
||||
|
||||
if (label) {
|
||||
// Use label color if found
|
||||
decorations.push(
|
||||
Decoration.inline(from, to, {
|
||||
class: 'label-value',
|
||||
style: `background-color: ${label.hexColor}; color: ${label.hexColor && colorIsDark(label.hexColor) ? 'white' : 'black'};`,
|
||||
}),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Fallback to generic value styling
|
||||
decorations.push(
|
||||
Decoration.inline(from, to, {class: 'value'}),
|
||||
)
|
||||
}
|
||||
|
||||
// Check if this is a multi-value operator and the value contains commas
|
||||
const isMultiValueOperator = ['in', '?=', 'not in', '?!='].includes(operator)
|
||||
if (isMultiValueOperator && labelValue.includes(',')) {
|
||||
// Split by commas and create decorations for each individual label
|
||||
const labels = labelValue.split(',').map(l => l.trim()).filter(l => l.length > 0)
|
||||
let currentOffset = 0
|
||||
|
||||
labels.forEach(individualLabel => {
|
||||
// Find the position of this individual label within the full value
|
||||
const labelIndex = labelValue.indexOf(individualLabel, currentOffset)
|
||||
if (labelIndex !== -1) {
|
||||
const individualStart = valueStart + labelIndex
|
||||
const individualEnd = individualStart + individualLabel.length
|
||||
|
||||
addLabelDecoration(individualLabel, individualStart, individualEnd)
|
||||
|
||||
currentOffset = labelIndex + individualLabel.length
|
||||
}
|
||||
})
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
addLabelDecoration(labelValue, valueStart, valueEnd)
|
||||
if(!labelValue) {
|
||||
continue
|
||||
}
|
||||
|
||||
const valueStart = labelMatch.index + labelMatch[0].lastIndexOf(labelValue)
|
||||
|
|
|
|||
Loading…
Reference in New Issue