mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-10 14:44:52 +08:00
feat(spellcheck): Turn on atom spellchecker, new contextual menu
Summary: Pending issues: - As you're typing, Atom Shell says the word you're currently typing is misspelled until you finish it. I will need to patch Atom Shell to fix this. Test Plan: Run tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1358
This commit is contained in:
parent
5bcefd23ba
commit
a0d2cc1785
3 changed files with 59 additions and 1 deletions
|
@ -27,6 +27,7 @@ ContenteditableComponent = React.createClass
|
|||
toolbarVisible: false
|
||||
|
||||
componentDidMount: ->
|
||||
@_editableNode().addEventListener('contextmenu', @_onShowContextualMenu)
|
||||
@_setupSelectionListeners()
|
||||
@_setupLinkHoverListeners()
|
||||
@_setupGlobalMouseListener()
|
||||
|
@ -47,6 +48,7 @@ ContenteditableComponent = React.createClass
|
|||
}
|
||||
|
||||
componentWillUnmount: ->
|
||||
@_editableNode().removeEventListener('contextmenu', @_onShowContextualMenu)
|
||||
@_teardownSelectionListeners()
|
||||
@_teardownLinkHoverListeners()
|
||||
@_teardownGlobalMouseListener()
|
||||
|
@ -256,6 +258,54 @@ ContenteditableComponent = React.createClass
|
|||
window.removeEventListener("mousedown", @__onMouseDown)
|
||||
window.removeEventListener("mouseup", @__onMouseUp)
|
||||
|
||||
_onShowContextualMenu: (event) ->
|
||||
@_hideToolbar()
|
||||
event.preventDefault()
|
||||
|
||||
selection = document.getSelection()
|
||||
range = selection.getRangeAt(0)
|
||||
text = range.toString()
|
||||
|
||||
remote = require('remote')
|
||||
clipboard = require('clipboard')
|
||||
Menu = remote.require('menu')
|
||||
MenuItem = remote.require('menu-item')
|
||||
spellchecker = require('spellchecker')
|
||||
|
||||
apply = (newtext) ->
|
||||
range.deleteContents()
|
||||
node = document.createTextNode(newtext)
|
||||
range.insertNode(node)
|
||||
range.selectNode(node)
|
||||
selection.removeAllRanges()
|
||||
selection.addRange(range)
|
||||
|
||||
cut = ->
|
||||
clipboard.writeText(text)
|
||||
apply('')
|
||||
|
||||
copy = ->
|
||||
clipboard.writeText(text)
|
||||
|
||||
paste = ->
|
||||
apply(clipboard.readText())
|
||||
|
||||
menu = new Menu()
|
||||
|
||||
if spellchecker.isMisspelled(text)
|
||||
corrections = spellchecker.getCorrectionsForMisspelling(text)
|
||||
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' }))
|
||||
|
||||
menu.append(new MenuItem({ label: 'Cut', click:cut}))
|
||||
menu.append(new MenuItem({ label: 'Copy', click:copy}))
|
||||
menu.append(new MenuItem({ label: 'Paste', click:paste}))
|
||||
menu.popup(remote.getCurrentWindow())
|
||||
|
||||
_onMouseDown: (event) ->
|
||||
@_mouseDownEvent = event
|
||||
@_mouseHasMoved = false
|
||||
|
|
|
@ -76,7 +76,8 @@
|
|||
"text-buffer": "^4.1",
|
||||
"theorist": "^1.0",
|
||||
"underscore-plus": "^1.6",
|
||||
"vm-compatibility-layer": "0.1.0"
|
||||
"vm-compatibility-layer": "0.1.0",
|
||||
"spellchecker": "2.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"proxyquire": "git+https://github.com/bengotow/proxyquire",
|
||||
|
|
|
@ -196,6 +196,7 @@ class Atom extends Model
|
|||
# Add 'exports' to module search path.
|
||||
exportsPath = path.join(resourcePath, 'exports')
|
||||
require('module').globalPaths.push(exportsPath)
|
||||
|
||||
# Still set NODE_PATH since tasks may need it.
|
||||
process.env.NODE_PATH = exportsPath
|
||||
|
||||
|
@ -234,6 +235,12 @@ class Atom extends Model
|
|||
# Edgehill-specific
|
||||
@inbox = new InboxAPI()
|
||||
|
||||
# initialize spell checking
|
||||
require('web-frame').setSpellCheckProvider("en-US", false, {
|
||||
spellCheck: (text) ->
|
||||
!(require('spellchecker').isMisspelled(text))
|
||||
})
|
||||
|
||||
@subscribe @packages.onDidActivateInitialPackages => @watchThemes()
|
||||
@windowEventHandler = new WindowEventHandler
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue