Merge pull request #17124 from atom/aw/keyboard-enablement

Separate keyboard enablement from read-only editor state
This commit is contained in:
Ash Wilson
2018-04-13 07:51:38 -04:00
committed by GitHub
2 changed files with 29 additions and 5 deletions

View File

@@ -477,7 +477,7 @@ class TextEditorComponent {
attributes.mini = ''
}
if (!this.isInputEnabled()) {
if (model.isReadOnly()) {
attributes.readonly = ''
}
@@ -2965,11 +2965,11 @@ class TextEditorComponent {
}
setInputEnabled (inputEnabled) {
this.props.model.update({readOnly: !inputEnabled})
this.props.model.update({keyboardInputEnabled: inputEnabled})
}
isInputEnabled (inputEnabled) {
return !this.props.model.isReadOnly()
isInputEnabled () {
return !this.props.model.isReadOnly() && this.props.model.isKeyboardInputEnabled()
}
getHiddenInput () {

View File

@@ -107,6 +107,13 @@ class TextEditor {
}
state.assert = atomEnvironment.assert.bind(atomEnvironment)
// Semantics of the readOnly flag have changed since its introduction.
// Only respect readOnly2, which has been set with the current readOnly semantics.
delete state.readOnly
state.readOnly = state.readOnly2
delete state.readOnly2
const editor = new TextEditor(state)
if (state.registered) {
const disposable = atomEnvironment.textEditors.add(editor)
@@ -130,6 +137,7 @@ class TextEditor {
this.decorationManager = params.decorationManager
this.selectionsMarkerLayer = params.selectionsMarkerLayer
this.mini = (params.mini != null) ? params.mini : false
this.keyboardInputEnabled = (params.keyboardInputEnabled != null) ? params.keyboardInputEnabled : true
this.readOnly = (params.readOnly != null) ? params.readOnly : false
this.placeholderText = params.placeholderText
this.showLineNumbers = params.showLineNumbers
@@ -416,6 +424,15 @@ class TextEditor {
}
break
case 'keyboardInputEnabled':
if (value !== this.keyboardInputEnabled) {
this.keyboardInputEnabled = value
if (this.component != null) {
this.component.scheduleUpdate()
}
}
break
case 'placeholderText':
if (value !== this.placeholderText) {
this.placeholderText = value
@@ -546,7 +563,8 @@ class TextEditor {
softWrapAtPreferredLineLength: this.softWrapAtPreferredLineLength,
preferredLineLength: this.preferredLineLength,
mini: this.mini,
readOnly: this.readOnly,
readOnly2: this.readOnly, // readOnly encompassed both readOnly and keyboardInputEnabled
keyboardInputEnabled: this.keyboardInputEnabled,
editorWidthInChars: this.editorWidthInChars,
width: this.width,
maxScreenLineLength: this.maxScreenLineLength,
@@ -988,6 +1006,12 @@ class TextEditor {
isReadOnly () { return this.readOnly }
enableKeyboardInput (enabled) {
this.update({keyboardInputEnabled: enabled})
}
isKeyboardInputEnabled () { return this.keyboardInputEnabled }
onDidChangeMini (callback) {
return this.emitter.on('did-change-mini', callback)
}