mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Ensure read-only text editors are not considered 'modified'. Also clear read-only flag on successful save.
This commit is contained in:
@@ -85,6 +85,23 @@ describe('TextEditor', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the editor is readonly', () => {
|
||||
it('overrides TextBuffer.isModified to return false', async () => {
|
||||
const editor = await atom.workspace.open(null, {readOnly: true})
|
||||
editor.setText('I am altering the buffer, pray I do not alter it any further')
|
||||
expect(editor.isModified()).toBe(false)
|
||||
editor.setReadOnly(false)
|
||||
expect(editor.isModified()).toBe(true)
|
||||
})
|
||||
it('clears the readonly status when saved', async () => {
|
||||
const editor = await atom.workspace.open(null, {readOnly: true})
|
||||
editor.setText('I am altering the buffer, pray I do not alter it any further')
|
||||
expect(editor.isReadOnly()).toBe(true)
|
||||
await editor.saveAs(temp.openSync('was-readonly').path)
|
||||
expect(editor.isReadOnly()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when the editor is constructed with the largeFileMode option set to true', () => {
|
||||
it("loads the editor but doesn't tokenize", async () => {
|
||||
editor = await atom.workspace.openTextFile('sample.js', {largeFileMode: true})
|
||||
|
||||
@@ -411,6 +411,7 @@ class TextEditor {
|
||||
if (this.component != null) {
|
||||
this.component.scheduleUpdate()
|
||||
}
|
||||
this.buffer.emitModifiedStatusChanged(this.isModified())
|
||||
}
|
||||
break
|
||||
|
||||
@@ -575,6 +576,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 () {
|
||||
@@ -1126,7 +1132,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() }
|
||||
|
||||
Reference in New Issue
Block a user