import Tool from '../tools/Tool'

class CorrectionTool extends Tool {

  render($$) {
    let node = this.props.node
    let Button = this.getComponent('button')
    let el = $$('div').addClass('sc-correction-tool')

    if (node && node.suggestions.length > 0) {
      node.suggestions.forEach((s) => {
        el.append(
          $$(Button, {
            label: s,
            style: this.props.style
          }).attr('title', this.getLabel('open-link'))
            .attr('data-correction', s)
            .on('click', this._applyCorrection.bind(this, s))
        )
      })
    } else {
      el.append(
        $$(Button, {
          label: 'No suggestions',
          style: this.props.style,
          disabled: true
        })
      )
    }
    return el
  }

  _applyCorrection(suggestion) {
    let editorSession = this.context.editorSession
    editorSession.transaction(function(tx) {
      tx.insertText(tx, suggestion)
    })
  }
}

export default CorrectionTool

@@ -881,20 +881,15 @@
 ion(
-function
 (tx)
+ =%3E
  %7B%0A 
@@ -911,12 +911,8 @@
 ext(
-tx, 
 sugg

Fix bug in CorrectionTool