Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 706bc26

Browse files
committed
Use new bulk spell-checking method in task handler
1 parent b106c48 commit 706bc26

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lib/spell-check-handler.coffee

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
SpellChecker = require 'spellchecker'
22

3-
wordRegex = /(?:^|[\s\[\]"'])([a-zA-Z]+([a-zA-Z']+[a-zA-Z])?)(?=[\s\.\[\]:,"']|$)/g
4-
53
module.exports = ({id, text}) ->
4+
misspelledCharacterRanges = SpellChecker.checkSpelling(text)
5+
66
row = 0
7+
rangeIndex = 0
8+
characterIndex = 0
79
misspellings = []
8-
for line in text.split('\n')
9-
while matches = wordRegex.exec(line)
10-
word = matches[1]
11-
continue if word in ['GitHub', 'github']
12-
continue unless SpellChecker.isMisspelled(word)
10+
while characterIndex < text.length and rangeIndex < misspelledCharacterRanges.length
11+
lineBreakIndex = text.indexOf('\n', characterIndex)
12+
if lineBreakIndex is -1
13+
lineBreakIndex = Infinity
1314

14-
startColumn = matches.index + matches[0].length - word.length
15-
endColumn = startColumn + word.length
16-
misspellings.push([[row, startColumn], [row, endColumn]])
15+
loop
16+
range = misspelledCharacterRanges[rangeIndex]
17+
if range and range.start < lineBreakIndex
18+
misspellings.push([
19+
[row, range.start - characterIndex],
20+
[row, range.end - characterIndex]
21+
])
22+
rangeIndex++
23+
else
24+
break
25+
26+
characterIndex = lineBreakIndex + 1
1727
row++
28+
1829
{id, misspellings}

0 commit comments

Comments
 (0)