mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 10:12:00 +08:00
feat(contenteditable): add bold, underline, etc keymaps
This commit is contained in:
parent
cfdc401c54
commit
3eb12507f1
1 changed files with 19 additions and 8 deletions
|
@ -2,6 +2,7 @@ _ = require 'underscore'
|
|||
React = require 'react'
|
||||
|
||||
{Utils, DOMUtils} = require 'nylas-exports'
|
||||
{KeyCommandsRegion} = require 'nylas-component-kit'
|
||||
ClipboardService = require './clipboard-service'
|
||||
FloatingToolbarContainer = require './floating-toolbar-container'
|
||||
|
||||
|
@ -137,7 +138,8 @@ class Contenteditable extends React.Component
|
|||
onDomMutator={@_onDomMutator} />
|
||||
|
||||
render: =>
|
||||
<div className="contenteditable-container">
|
||||
<KeyCommandsRegion className="contenteditable-container"
|
||||
localHandlers={@_keymapHandlers()}>
|
||||
{@_renderFloatingToolbar()}
|
||||
|
||||
<div className="contenteditable"
|
||||
|
@ -146,7 +148,21 @@ class Contenteditable extends React.Component
|
|||
spellCheck={false}
|
||||
dangerouslySetInnerHTML={__html: @props.value}
|
||||
{...@_eventHandlers()}></div>
|
||||
</div>
|
||||
</KeyCommandsRegion>
|
||||
|
||||
_keymapHandlers: ->
|
||||
'contenteditable:underline': @_execCommandWrap("underline")
|
||||
'contenteditable:bold': @_execCommandWrap("bold")
|
||||
'contenteditable:italic': @_execCommandWrap("italic")
|
||||
'contenteditable:numbered-list': @_execCommandWrap("insertOrderedList")
|
||||
'contenteditable:bulleted-list': @_execCommandWrap("insertUnorderedList")
|
||||
'contenteditable:outdent': @_execCommandWrap("outdent")
|
||||
'contenteditable:indent': @_execCommandWrap("indent")
|
||||
|
||||
_execCommandWrap: (command) => (e) =>
|
||||
@atomicEdit =>
|
||||
document.execCommand(command)
|
||||
, e
|
||||
|
||||
_eventHandlers: =>
|
||||
onBlur: @_onBlur
|
||||
|
@ -252,12 +268,7 @@ class Contenteditable extends React.Component
|
|||
|
||||
if event.key is "Tab"
|
||||
@_onTabDownDefaultBehavior(event)
|
||||
|
||||
U = 85
|
||||
if event.which is U and (event.metaKey or event.ctrlKey)
|
||||
event.preventDefault()
|
||||
document.execCommand("underline")
|
||||
return
|
||||
return
|
||||
|
||||
# Every time the contents of the contenteditable DOM node change, the
|
||||
# `onInput` event gets fired.
|
||||
|
|
Loading…
Reference in a new issue