Commit ·
08ba334
1
Parent(s): 3f4dd4a
fix: Re-index suggestion spans after dismiss (keep as-is) - After filtering dismissed suggestion from array, span data-suggestion-id indices became stale - Adjacent error words became unclickable because findSuggestionById used wrong index - Now re-indexes all remaining spans to match updated array positions
Browse files- src/js/editor.js +13 -0
src/js/editor.js
CHANGED
|
@@ -508,6 +508,19 @@ function dismissSuggestion(suggestion) {
|
|
| 508 |
s => !(s.start === suggestion.start && s.end === suggestion.end)
|
| 509 |
);
|
| 510 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
const spellingCount = window.currentSuggestions.filter(s => s.type === 'spelling').length;
|
| 512 |
const grammarCount = window.currentSuggestions.filter(s => s.type === 'grammar').length;
|
| 513 |
const punctuationCount = window.currentSuggestions.filter(s => s.type === 'punctuation').length;
|
|
|
|
| 508 |
s => !(s.start === suggestion.start && s.end === suggestion.end)
|
| 509 |
);
|
| 510 |
|
| 511 |
+
// Re-index remaining error spans to match updated array indices
|
| 512 |
+
const remainingSpans = document.querySelectorAll('.spelling-error, .grammar-error, .punctuation-suggestion');
|
| 513 |
+
remainingSpans.forEach(span => {
|
| 514 |
+
const oldId = parseInt(span.dataset.suggestionId, 10);
|
| 515 |
+
// Find this span's suggestion in the updated array by matching start/end
|
| 516 |
+
const newIdx = window.currentSuggestions.findIndex(s => {
|
| 517 |
+
return span.textContent === s.original;
|
| 518 |
+
});
|
| 519 |
+
if (newIdx >= 0) {
|
| 520 |
+
span.dataset.suggestionId = newIdx;
|
| 521 |
+
}
|
| 522 |
+
});
|
| 523 |
+
|
| 524 |
const spellingCount = window.currentSuggestions.filter(s => s.type === 'spelling').length;
|
| 525 |
const grammarCount = window.currentSuggestions.filter(s => s.type === 'grammar').length;
|
| 526 |
const punctuationCount = window.currentSuggestions.filter(s => s.type === 'punctuation').length;
|