diff --git a/src/text-editor-component.js b/src/text-editor-component.js index fe6b9db44..2579bcfd0 100644 --- a/src/text-editor-component.js +++ b/src/text-editor-component.js @@ -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 () { diff --git a/src/text-editor.js b/src/text-editor.js index 2490ab94b..b1e0980f8 100644 --- a/src/text-editor.js +++ b/src/text-editor.js @@ -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) }