Add API for enabling/disabling input to support vim-mode's insert mode

This commit is contained in:
Nathan Sobo
2014-06-11 06:07:41 -06:00
parent 9e7e77bdf8
commit 64870c733b
3 changed files with 19 additions and 0 deletions

View File

@@ -1175,6 +1175,12 @@ describe "EditorComponent", ->
inputNode.dispatchEvent(new Event('input'))
expect(editor.lineForBufferRow(0)).toBe 'üvar quicksort = function () {'
it "does not handle input events when input is disabled", ->
component.setInputEnabled(false)
inputNode.value = 'x'
inputNode.dispatchEvent(new Event('input'))
expect(editor.lineForBufferRow(0)).toBe 'var quicksort = function () {'
describe "commands", ->
describe "editor:consolidate-selections", ->
it "consolidates selections on the editor model, aborting the key binding if there is only one selection", ->

View File

@@ -37,6 +37,7 @@ EditorComponent = React.createClass
overflowChangedEventsPaused: false
overflowChangedWhilePaused: false
measureLineHeightAndDefaultCharWidthWhenShown: false
inputEnabled: true
render: ->
{focused, fontSize, lineHeight, fontFamily, showIndentGuide, showInvisibles, visible} = @state
@@ -456,6 +457,8 @@ EditorComponent = React.createClass
scrollViewNode.scrollLeft = 0
onInput: (char, replaceLastCharacter) ->
return unless @inputEnabled
{editor} = @props
if replaceLastCharacter
@@ -760,6 +763,10 @@ EditorComponent = React.createClass
getModel: ->
@props.editor
isInputEnabled: -> @inputEnabled
setInputEnabled: (@inputEnabled) -> @inputEnabled
runScrollBenchmark: ->
unless process.env.NODE_ENV is 'production'
ReactPerf = require 'react-atom-fork/lib/ReactDefaultPerf'

View File

@@ -197,6 +197,12 @@ class ReactEditorView extends View
insertText: (text) ->
@editor.insertText(text)
isInputEnabled: ->
@component.isInputEnabled()
setInputEnabled: (inputEnabled) ->
@component.setInputEnabled(inputEnabled)
requestDisplayUpdate: -> # No-op shim for find-and-replace
updateDisplay: -> # No-op shim for package specs