<commit_before>import { Command } from 'substance'

export default class ToggleCodeCommand extends Command {

  /*
    Always enabled
  */
  getCommandState() {
    return {
      disabled: false,
      active: false
    }
  }

  /*
    Returns all cell components found in the document
  */
  _getCellComponents(params) {
    let editor = params.editorSession.getEditor()
    return editor.findAll('.sc-cell')
  }

  execute(params) {
    let cellComponents = this._getCellComponents(params)
    cellComponents.forEach((cellComponent) => {
      cellComponent.extendState({
        showMenu: false,
        showCode: this.config.showCode
      })
    })
    params.editorSession.setSelection(null)
  }
}<commit_msg>Preserve selection on show/hide code.<commit_after>import { Command } from 'substance'

export default class ToggleCodeCommand extends Command {

  /*
    Always enabled
  */
  getCommandState() {
    return {
      disabled: false,
      active: false
    }
  }

  /*
    Returns all cell components found in the document
  */
  _getCellComponents(params) {
    let editor = params.editorSession.getEditor()
    return editor.findAll('.sc-cell')
  }

  execute(params) {
    let cellComponents = this._getCellComponents(params)
    let sel = params.editorSession.getSelection()
    cellComponents.forEach((cellComponent) => {
      cellComponent.extendState({
        showMenu: false,
        showCode: this.config.showCode
      })
    })
    params.editorSession.setSelection(sel)
  }
}
{'fraction_non_alphanumeric': 0.10166112956810631, 'fraction_numerical': 0.0, 'mean_word_length': 2.911688311688312, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7129564', 'n_tokens_mistral': 433, 'n_tokens_neox': 425, 'n_words': 93}