fix(composer): Show "No Guesses Found" for misspellings without corrections, invalidate cache when learning spelling

This commit is contained in:
Ben Gotow 2015-09-08 17:52:26 -07:00
parent 089aba0b22
commit 53252fcb97
2 changed files with 18 additions and 3 deletions

View file

@ -19,6 +19,12 @@ class SpellcheckDraftStoreExtension extends DraftStoreExtension
@walkTreeNodes.push(editableNode)
@walkTreesDebounced()
@onLearnSpelling: (editableNode, word) ->
delete SpellcheckCache[word]
@ensureSetup()
@walkTreeNodes.push(editableNode)
@walkTreesDebounced()
@onSubstitutionPerformed: (editableNode) ->
@ensureSetup()
@walkTreeNodes.push(editableNode)

View file

@ -646,6 +646,12 @@ class ContenteditableComponent extends React.Component
if extension.onSubstitutionPerformed
extension.onSubstitutionPerformed(@_editableNode())
learnSpelling = =>
spellchecker.add(text)
for extension in DraftStore.extensions()
if extension.onLearnSpelling
extension.onLearnSpelling(@_editableNode(), text)
cut = =>
clipboard.writeText(text)
apply('')
@ -663,9 +669,12 @@ class ContenteditableComponent extends React.Component
if corrections.length > 0
corrections.forEach (correction) ->
menu.append(new MenuItem({ label: correction, click:( -> apply(correction))}))
menu.append(new MenuItem({ type: 'separator' }))
menu.append(new MenuItem({ label: 'Learn Spelling', click:( -> spellchecker.add(text))}))
menu.append(new MenuItem({ type: 'separator' }))
else
menu.append(new MenuItem({ label: 'No Guesses Found', enabled: false}))
menu.append(new MenuItem({ type: 'separator' }))
menu.append(new MenuItem({ label: 'Learn Spelling', click: learnSpelling}))
menu.append(new MenuItem({ type: 'separator' }))
menu.append(new MenuItem({ label: 'Cut', click:cut}))
menu.append(new MenuItem({ label: 'Copy', click:copy}))