Repository: atom/atom
File: src/text-editor.js (JavaScript)

Code before:

  // Essential: Returns {Boolean} `true` if this editor has been modified.
  isModified () { return this.buffer.isModified() }

  // Essential: Returns {Boolean} `true` if this editor has no content.
  isEmpty () { return this.buffer.isEmpty() }

  /*
  Section: File Operations
  */

  // Essential: Saves the editor's text buffer.
  //
  // See {TextBuffer::save} for more details.
  save () { return this.buffer.save() }

  // Essential: Saves the editor's text buffer as the given path.
  //
  // See {TextBuffer::saveAs} for more details.
  //
  // * `filePath` A {String} path.
  saveAs (filePath) { return this.buffer.saveAs(filePath) }

  // Determine whether the user should be prompted to save before closing
  // this editor.
  shouldPromptToSave ({windowCloseRequested, projectHasPaths} = {}) {
    if (windowCloseRequested && projectHasPaths && atom.stateStore.isConnected()) {
      return this.buffer.isInConflict()
    } else {
      return this.isModified() && !this.buffer.hasMultipleEditors()
    }
  }

  // Returns an {Object} to configure dialog shown when this editor is saved
  // via {Pane::saveItemAs}.
  getSaveDialogOptions () { return {} }

  /*
  Section: Reading Text
  */

  // Essential: Returns a {String} representing the entire contents of the editor.
  getText () { return this.buffer.getText() }

  // Essential: Get the text in the given {Range} in buffer coordinates.
  //
  // * `range` A {Range} or range-compatible {Array}.
  //
  // Returns a {String}.
  getTextInBufferRange (range) {
    return this.buffer.getTextInRange(range)

Review comment (suggestion):
I don't want this unnecessary guard. If readonly really disallow buffer modification, just returning `buffer.isModified()` should be enough.
This method should be just proxy of `this.buffer.isModified()` for clarity, and remove possibility of inconsistency   when it become `this.isReadonly !== this.buffer.isModifed()`.
Also this breaks https://github.com/t9md/atom-narrow pkg's important feature.

Code after:
  getPath () {
    return this.buffer.getPath()
  }

  getFileName () {
    const fullPath = this.getPath()
    if (fullPath) return path.basename(fullPath)
  }

  getDirectoryPath () {
    const fullPath = this.getPath()
    if (fullPath) return path.dirname(fullPath)
  }

  // Extended: Returns the {String} character set encoding of this editor's text
  // buffer.
  getEncoding () { return this.buffer.getEncoding() }

  // Extended: Set the character set encoding to use in this editor's text
  // buffer.
  //
  // * `encoding` The {String} character set encoding name such as 'utf8'
  setEncoding (encoding) { this.buffer.setEncoding(encoding) }

  // Essential: Returns {Boolean} `true` if this editor has been modified.
  isModified () { return this.isReadOnly() ? false : this.buffer.isModified() }

  // Essential: Returns {Boolean} `true` if this editor has no content.
  isEmpty () { return this.buffer.isEmpty() }

  /*
  Section: File Operations
  */

  // Essential: Saves the editor's text buffer.
  //
  // See {TextBuffer::save} for more details.
  save () { return this.buffer.save() }

  // Essential: Saves the editor's text buffer as the given path.
  //
  // See {TextBuffer::saveAs} for more details.
  //
  // * `filePath` A {String} path.
  saveAs (filePath) { return this.buffer.saveAs(filePath) }

  // Determine whether the user should be prompted to save before closing
  // this editor.
  shouldPromptToSave ({windowCloseRequested, projectHasPaths} = {}) {
    if (windowCloseRequested && projectHasPaths && atom.stateStore.isConnected()) {
      return this.buffer.isInConflict()