mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-19 22:50:13 +08:00
feat(contenteditable): add bold, underline, etc keymaps
This commit is contained in:
parent
9f309d399b
commit
09728d8cbc
1 changed files with 19 additions and 8 deletions
|
@ -2,6 +2,7 @@ _ = require 'underscore'
|
||||||
React = require 'react'
|
React = require 'react'
|
||||||
|
|
||||||
{Utils, DOMUtils} = require 'nylas-exports'
|
{Utils, DOMUtils} = require 'nylas-exports'
|
||||||
|
{KeyCommandsRegion} = require 'nylas-component-kit'
|
||||||
ClipboardService = require './clipboard-service'
|
ClipboardService = require './clipboard-service'
|
||||||
FloatingToolbarContainer = require './floating-toolbar-container'
|
FloatingToolbarContainer = require './floating-toolbar-container'
|
||||||
|
|
||||||
|
@ -137,7 +138,8 @@ class Contenteditable extends React.Component
|
||||||
onDomMutator={@_onDomMutator} />
|
onDomMutator={@_onDomMutator} />
|
||||||
|
|
||||||
render: =>
|
render: =>
|
||||||
<div className="contenteditable-container">
|
<KeyCommandsRegion className="contenteditable-container"
|
||||||
|
localHandlers={@_keymapHandlers()}>
|
||||||
{@_renderFloatingToolbar()}
|
{@_renderFloatingToolbar()}
|
||||||
|
|
||||||
<div className="contenteditable"
|
<div className="contenteditable"
|
||||||
|
@ -146,7 +148,21 @@ class Contenteditable extends React.Component
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
dangerouslySetInnerHTML={__html: @props.value}
|
dangerouslySetInnerHTML={__html: @props.value}
|
||||||
{...@_eventHandlers()}></div>
|
{...@_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: =>
|
_eventHandlers: =>
|
||||||
onBlur: @_onBlur
|
onBlur: @_onBlur
|
||||||
|
@ -252,11 +268,6 @@ class Contenteditable extends React.Component
|
||||||
|
|
||||||
if event.key is "Tab"
|
if event.key is "Tab"
|
||||||
@_onTabDownDefaultBehavior(event)
|
@_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
|
# Every time the contents of the contenteditable DOM node change, the
|
||||||
|
|
Loading…
Reference in a new issue