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

Code before:
  //
  // Returns a {Range}.
  bufferRangeForScopeAtCursor (scopeSelector) {
    return this.bufferRangeForScopeAtPosition(scopeSelector, this.getCursorBufferPosition())
  }

  bufferRangeForScopeAtPosition (scopeSelector, position) {
    return this.buffer.getLanguageMode().bufferRangeForScopeAtPosition(scopeSelector, position)
  }

  // Extended: Determine if the given row is entirely a comment
  isBufferRowCommented (bufferRow) {
    const match = this.lineTextForBufferRow(bufferRow).match(/\S/)
    if (match) {
      if (!this.commentScopeSelector) this.commentScopeSelector = new TextMateScopeSelector('comment.*')
      return this.commentScopeSelector.matches(this.scopeDescriptorForBufferPosition([bufferRow, match.index]).scopes)
    }
  }

  // Get the scope descriptor at the cursor.
  getCursorScope () {
    return this.getLastCursor().getScopeDescriptor()
  }

  // Get the syntax nodes at the cursor.
  getSyntaxTree () {
    return this.getLastCursor().getSyntaxTree()
  }

  tokenForBufferPosition (bufferPosition) {
    return this.buffer.getLanguageMode().tokenForPosition(bufferPosition)
  }

  /*
  Section: Clipboard Operations
  */

  // Essential: For each selection, copy the selected text.
  copySelectedText () {
    let maintainClipboard = false
    for (let selection of this.getSelectionsOrderedByBufferPosition()) {
      if (selection.isEmpty()) {
        const previousRange = selection.getBufferRange()
        selection.selectLine()
        selection.copy(maintainClipboard, true)
        selection.setBufferRange(previousRange)
      } else {
        selection.copy(maintainClipboard, false)
      }
      maintainClipboard = true
    }

Review comment (suggestion):
This method name should probably start with `getCursor`, to make it clear that the positioning is derived from the cursor. Maybe `getCursorSyntaxTreePath`.

Code after:
  //
  // Returns a {Range}.
  bufferRangeForScopeAtCursor (scopeSelector) {
    return this.bufferRangeForScopeAtPosition(scopeSelector, this.getCursorBufferPosition())
  }

  bufferRangeForScopeAtPosition (scopeSelector, position) {
    return this.buffer.getLanguageMode().bufferRangeForScopeAtPosition(scopeSelector, position)
  }

  // Extended: Determine if the given row is entirely a comment
  isBufferRowCommented (bufferRow) {
    const match = this.lineTextForBufferRow(bufferRow).match(/\S/)
    if (match) {
      if (!this.commentScopeSelector) this.commentScopeSelector = new TextMateScopeSelector('comment.*')
      return this.commentScopeSelector.matches(this.scopeDescriptorForBufferPosition([bufferRow, match.index]).scopes)
    }
  }

  // Get the scope descriptor at the cursor.
  getCursorScope () {
    return this.getLastCursor().getScopeDescriptor()
  }

  // Get the syntax nodes at the cursor.
  getCursorSyntaxTreeScope () {
    return this.getLastCursor().getSyntaxTreeScopeDescriptor()
  }

  tokenForBufferPosition (bufferPosition) {
    return this.buffer.getLanguageMode().tokenForPosition(bufferPosition)
  }

  /*
  Section: Clipboard Operations
  */

  // Essential: For each selection, copy the selected text.
  copySelectedText () {
    let maintainClipboard = false
    for (let selection of this.getSelectionsOrderedByBufferPosition()) {
      if (selection.isEmpty()) {
        const previousRange = selection.getBufferRange()
        selection.selectLine()
        selection.copy(maintainClipboard, true)
        selection.setBufferRange(previousRange)
      } else {
        selection.copy(maintainClipboard, false)
      }
      maintainClipboard = true
    }