mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge branch 'master' into mb-tree-sitter-parsers
This commit is contained in:
@@ -56,7 +56,7 @@ class TextEditorComponent {
|
||||
this.props = props
|
||||
|
||||
if (!props.model) {
|
||||
props.model = new TextEditor({mini: props.mini})
|
||||
props.model = new TextEditor({mini: props.mini, readOnly: props.readOnly})
|
||||
}
|
||||
this.props.model.component = this
|
||||
|
||||
@@ -460,9 +460,13 @@ class TextEditorComponent {
|
||||
}
|
||||
}
|
||||
|
||||
let attributes = null
|
||||
let attributes = {}
|
||||
if (model.isMini()) {
|
||||
attributes = {mini: ''}
|
||||
attributes.mini = ''
|
||||
}
|
||||
|
||||
if (!this.isInputEnabled()) {
|
||||
attributes.readonly = ''
|
||||
}
|
||||
|
||||
const dataset = {encoding: model.getEncoding()}
|
||||
@@ -819,7 +823,7 @@ class TextEditorComponent {
|
||||
|
||||
const oldClassList = this.classList
|
||||
const newClassList = ['editor']
|
||||
if (this.focused) newClassList.push('is-focused')
|
||||
if (this.focused && this.isInputEnabled()) newClassList.push('is-focused')
|
||||
if (model.isMini()) newClassList.push('mini')
|
||||
for (var i = 0; i < model.selections.length; i++) {
|
||||
if (!model.selections[i].isEmpty()) {
|
||||
@@ -2962,11 +2966,11 @@ class TextEditorComponent {
|
||||
}
|
||||
|
||||
setInputEnabled (inputEnabled) {
|
||||
this.props.inputEnabled = inputEnabled
|
||||
this.props.model.update({readOnly: !inputEnabled})
|
||||
}
|
||||
|
||||
isInputEnabled (inputEnabled) {
|
||||
return this.props.inputEnabled != null ? this.props.inputEnabled : true
|
||||
return !this.props.model.isReadOnly()
|
||||
}
|
||||
|
||||
getHiddenInput () {
|
||||
|
||||
@@ -59,6 +59,9 @@ class TextEditorElement extends HTMLElement {
|
||||
case 'gutter-hidden':
|
||||
this.getModel().update({lineNumberGutterVisible: newValue == null})
|
||||
break
|
||||
case 'readonly':
|
||||
this.getModel().update({readOnly: newValue != null})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,7 +278,8 @@ class TextEditorElement extends HTMLElement {
|
||||
this.component = new TextEditorComponent({
|
||||
element: this,
|
||||
mini: this.hasAttribute('mini'),
|
||||
updatedSynchronously: this.updatedSynchronously
|
||||
updatedSynchronously: this.updatedSynchronously,
|
||||
readOnly: this.hasAttribute('readonly')
|
||||
})
|
||||
this.updateModelFromAttributes()
|
||||
}
|
||||
|
||||
@@ -124,6 +124,7 @@ class TextEditor {
|
||||
this.decorationManager = params.decorationManager
|
||||
this.selectionsMarkerLayer = params.selectionsMarkerLayer
|
||||
this.mini = (params.mini != null) ? params.mini : false
|
||||
this.readOnly = (params.readOnly != null) ? params.readOnly : false
|
||||
this.placeholderText = params.placeholderText
|
||||
this.showLineNumbers = params.showLineNumbers
|
||||
this.assert = params.assert || (condition => condition)
|
||||
@@ -400,6 +401,16 @@ class TextEditor {
|
||||
}
|
||||
break
|
||||
|
||||
case 'readOnly':
|
||||
if (value !== this.readOnly) {
|
||||
this.readOnly = value
|
||||
if (this.component != null) {
|
||||
this.component.scheduleUpdate()
|
||||
}
|
||||
this.buffer.emitModifiedStatusChanged(this.isModified())
|
||||
}
|
||||
break
|
||||
|
||||
case 'placeholderText':
|
||||
if (value !== this.placeholderText) {
|
||||
this.placeholderText = value
|
||||
@@ -530,6 +541,7 @@ class TextEditor {
|
||||
softWrapAtPreferredLineLength: this.softWrapAtPreferredLineLength,
|
||||
preferredLineLength: this.preferredLineLength,
|
||||
mini: this.mini,
|
||||
readOnly: this.readOnly,
|
||||
editorWidthInChars: this.editorWidthInChars,
|
||||
width: this.width,
|
||||
maxScreenLineLength: this.maxScreenLineLength,
|
||||
@@ -556,6 +568,11 @@ class TextEditor {
|
||||
this.disposables.add(this.buffer.onDidChangeModified(() => {
|
||||
if (!this.hasTerminatedPendingState && this.buffer.isModified()) this.terminatePendingState()
|
||||
}))
|
||||
this.disposables.add(this.buffer.onDidSave(() => {
|
||||
if (this.isReadOnly()) {
|
||||
this.setReadOnly(false)
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
terminatePendingState () {
|
||||
@@ -965,6 +982,12 @@ class TextEditor {
|
||||
|
||||
isMini () { return this.mini }
|
||||
|
||||
setReadOnly (readOnly) {
|
||||
this.update({readOnly})
|
||||
}
|
||||
|
||||
isReadOnly () { return this.readOnly }
|
||||
|
||||
onDidChangeMini (callback) {
|
||||
return this.emitter.on('did-change-mini', callback)
|
||||
}
|
||||
@@ -1106,7 +1129,7 @@ class TextEditor {
|
||||
setEncoding (encoding) { this.buffer.setEncoding(encoding) }
|
||||
|
||||
// Essential: Returns {Boolean} `true` if this editor has been modified.
|
||||
isModified () { return this.buffer.isModified() }
|
||||
isModified () { return this.isReadOnly() ? false : this.buffer.isModified() }
|
||||
|
||||
// Essential: Returns {Boolean} `true` if this editor has no content.
|
||||
isEmpty () { return this.buffer.isEmpty() }
|
||||
@@ -4552,8 +4575,7 @@ class TextEditor {
|
||||
? minBlankIndentLevel
|
||||
: 0
|
||||
|
||||
const tabLength = this.getTabLength()
|
||||
const indentString = ' '.repeat(tabLength * minIndentLevel)
|
||||
const indentString = this.buildIndentString(minIndentLevel)
|
||||
for (let row = start; row <= end; row++) {
|
||||
const line = this.buffer.lineForRow(row)
|
||||
if (NON_WHITESPACE_REGEXP.test(line)) {
|
||||
|
||||
@@ -497,6 +497,9 @@ module.exports = class Workspace extends Model {
|
||||
this.textEditorRegistry.maintainConfig(item),
|
||||
item.observeGrammar(this.handleGrammarUsed.bind(this))
|
||||
)
|
||||
if (!this.project.findBufferForId(item.buffer.id)) {
|
||||
this.project.addBuffer(item.buffer)
|
||||
}
|
||||
item.onDidDestroy(() => { subscriptions.dispose() })
|
||||
this.emitter.emit('did-add-text-editor', {textEditor: item, pane, index})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user