Skip to content

Commit 9c002d2

Browse files
authored
Fix caps, keyboard group logic
Closes GH-37. Closes GH-39. Closes GH-41.
1 parent bd92048 commit 9c002d2

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lib/suggest.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function suggest(value) {
1818
var replacementTable = self.replacementTable
1919
var conversion = self.conversion
2020
var groups = self.flags.KEY
21+
var charAdded = {}
2122
var suggestions = []
2223
var weighted = {}
2324
var memory
@@ -77,8 +78,12 @@ function suggest(value) {
7778

7879
while (++index < length) {
7980
character = value.charAt(index)
81+
before = value.slice(0, index)
82+
after = value.slice(index + 1)
8083
insensitive = character.toLowerCase()
8184
upper = insensitive !== character
85+
charAdded = {}
86+
8287
offset = -1
8388
count = groups.length
8489

@@ -90,15 +95,19 @@ function suggest(value) {
9095
continue
9196
}
9297

93-
before = value.slice(0, position)
94-
after = value.slice(position + 1)
9598
otherOffset = -1
9699
otherCount = group.length
97100

98101
while (++otherOffset < otherCount) {
99102
if (otherOffset !== position) {
100103
otherCharacter = group.charAt(otherOffset)
101104

105+
if (charAdded[otherCharacter]) {
106+
continue
107+
}
108+
109+
charAdded[otherCharacter] = true
110+
102111
if (upper) {
103112
otherCharacter = otherCharacter.toUpperCase()
104113
}

test/index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ test('NSpell()', function (t) {
257257

258258
st.deepEqual(
259259
us.suggest('propper'),
260-
['dropper', 'proper', 'cropper', 'popper', 'propped', 'prosper'],
260+
['proper', 'propped', 'cropper', 'dropper', 'popper', 'prosper'],
261261
'should suggest alternatives'
262262
)
263263

264264
st.deepEqual(
265265
us.suggest('Ghandi'),
266-
['shandy', 'Brandi', 'Ghana', 'Grand', 'Grandee', 'Grands', 'handy'],
266+
['Brandi', 'Ghana', 'Grandee', 'Shanxi', 'hand', 'hands', 'handy'],
267267
'should suggest alternatives'
268268
)
269269

@@ -301,7 +301,7 @@ test('NSpell()', function (t) {
301301

302302
st.deepEqual(
303303
us.suggest('collor'),
304-
['color', 'collar', 'colloq'],
304+
['color', 'colloq', 'collar'],
305305
'should suggest removals'
306306
)
307307

@@ -478,17 +478,17 @@ test('NSpell()', function (t) {
478478
st.deepEqual(
479479
us.suggest('dont'),
480480
[
481-
'dent',
482481
'cont',
483482
'font',
484-
'wont',
483+
'dent',
485484
'dint',
485+
'done',
486+
'dong',
487+
'wont',
486488
'dolt',
487489
'don',
488490
"don't",
489491
'dona',
490-
'done',
491-
'dong',
492492
'dons',
493493
'dost',
494494
'dot',
@@ -499,6 +499,12 @@ test('NSpell()', function (t) {
499499
'should suggest alternatives including correct conjunction'
500500
)
501501

502+
st.deepEqual(
503+
us.suggest('TODO'),
504+
[`DODO`, `TOD`, `TODD`, `TOGO`, `TOJO`, `TOO`, `TOTO`],
505+
'should suggest alternatives for uppercase input'
506+
)
507+
502508
st.end()
503509
})
504510

0 commit comments

Comments
 (0)