<commit_before>StepperView = require './stepper-view'
views = require '../util/views'
{focusEditorPane} = require '../util/pane-item'
{span} = views.tags

module.exports =
class Stepper

  constructor: ({@buttons}) ->
    @views = []
    @text = "Grand Steppin'"
    @buttons ?= [
      {icon: 'arrow-down'}
      {icon: 'link-external'}
      {icon: 'chevron-right'}
    ]

  attach: (ed) ->
    @views.push new StepperView ed, @line

  setText: (@text) ->
    for view in @views
      view.clear()
      view.appendChild views.render span 'stepper-label', @text
      view.appendChild view.buttonGroup @buttons

  edsForFile: (file) ->
    atom.workspace.getTextEditors()
      .filter((x)->x.getPath() is file)

  activate: (file, line) ->
    active = atom.workspace.getActiveTextEditor()
    if active?.getPath() is file
      active.setCursorBufferPosition [line, 0]
      Promise.resolve()
    else
      focusEditorPane()
      atom.workspace.open file,
        initialLine: line
        searchAllPanes: true
        # TODO: This causes Atom to hang when the current stepper-enabled
        # editor is also marked pending.
        # pending: true

  goto: (file, @line) ->
    @listener ?= atom.workspace.observeTextEditors (ed) =>
      @attach(ed) if ed.getPath() is @file

    @activate(file, @line).then =>
      if file == @file
        view.goto @line for view in @views
      else
        @file = file
        @detach()
        @attach(ed) for ed in @edsForFile file
        @setText @text

  detach: ->
    view?.destroy() for view in @views
    @views = []
<commit_msg>destroy out of date views<commit_after>StepperView = require './stepper-view'
views = require '../util/views'
{focusEditorPane} = require '../util/pane-item'
{span} = views.tags

module.exports =
class Stepper

  constructor: ({@buttons}) ->
    @views = []
    @text = "Grand Steppin'"
    @buttons ?= [
      {icon: 'arrow-down'}
      {icon: 'link-external'}
      {icon: 'chevron-right'}
    ]

  attach: (ed) ->
    s = new StepperView ed, @line
    @views.push s
    ed.onDidDestroy =>
      s.destroy()
      @views = @views.filter((x) => x != s)

  setText: (@text) ->
    for view in @views
      view.clear()
      view.appendChild views.render span 'stepper-label', @text
      view.appendChild view.buttonGroup @buttons

  edsForFile: (file) ->
    atom.workspace.getTextEditors()
      .filter((x)->x.getPath() is file)

  activate: (file, line) ->
    active = atom.workspace.getActiveTextEditor()
    if active?.getPath() is file
      active.setCursorBufferPosition [line, 0]
      Promise.resolve()
    else
      focusEditorPane()
      atom.workspace.open file,
        initialLine: line
        searchAllPanes: true
        # TODO: This causes Atom to hang when the current stepper-enabled
        # editor is also marked pending.
        # pending: true

  goto: (file, @line) ->
    @listener ?= atom.workspace.observeTextEditors (ed) =>
      @attach(ed) if ed.getPath() is @file

    @activate(file, @line).then =>
      if file == @file
        view.goto @line for view in @views
      else
        @file = file
        @detach()
        @attach(ed) for ed in @edsForFile file
        @setText @text

  detach: ->
    view.destroy() for view in @views
    @views = []

{'fraction_non_alphanumeric': 0.13719512195121952, 'fraction_numerical': 0.0006097560975609756, 'mean_word_length': 2.4356020942408376, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '3191630', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1026, 'n_words': 280}