Enhance highlight parsing logic with priority handling and improve repeat match extraction in CustomParsers

This commit is contained in:
Mo Tarbin
2025-04-24 19:50:47 -04:00
parent c1f2c062fe
commit f537a00409

View File

@@ -190,23 +190,41 @@ const TaskInput = ({ autoFocus, onChoreUpdate, isModalOpen, onClose }) => {
// Combine all highlight ranges and sort them by their start index // Combine all highlight ranges and sort them by their start index
const allHighlights = [] const allHighlights = []
if (repeatHighlight) { if (repeatHighlight) {
repeatHighlight.forEach(h => allHighlights.push({ ...h, type: 'repeat' })) repeatHighlight.forEach(h =>
allHighlights.push({ ...h, type: 'repeat', priority: 40 }),
)
} }
if (priorityHighlight) { if (priorityHighlight) {
priorityHighlight.forEach(h => priorityHighlight.forEach(h =>
allHighlights.push({ ...h, type: 'priority' }), allHighlights.push({ ...h, type: 'priority', priority: 30 }),
) )
} }
if (labelsHighlight) { if (labelsHighlight) {
labelsHighlight.forEach(h => allHighlights.push({ ...h, type: 'label' })) labelsHighlight.forEach(h =>
allHighlights.push({ ...h, type: 'label', priority: 20 }),
)
} }
if (dueDateHighlight) { if (dueDateHighlight) {
allHighlights.push({ ...dueDateHighlight, type: 'dueDate' }) allHighlights.push({ ...dueDateHighlight, type: 'dueDate', priority: 10 })
} }
allHighlights.sort((a, b) => a.start - b.start) allHighlights.sort((a, b) => a.start - b.start)
const resolvedHighlights = []
for (let i = 0; i < allHighlights.length; i++) {
const current = allHighlights[i]
const previous = resolvedHighlights[resolvedHighlights.length - 1]
for (const highlight of allHighlights) { if (previous && current.start < previous.end) {
if (current.priority > previous.priority) {
resolvedHighlights.pop()
resolvedHighlights.push(current)
}
} else {
// No overlap, add the current highlight
resolvedHighlights.push(current)
}
}
for (const highlight of resolvedHighlights) {
// Add the text before the highlight // Add the text before the highlight
if (highlight.start > lastIndex) { if (highlight.start > lastIndex) {
parts.push(sentence.substring(lastIndex, highlight.start)) parts.push(sentence.substring(lastIndex, highlight.start))