<commit_before>###
@module emberella
@submodule emberella-mixins
###

Emberella = window.Emberella
get = Ember.get
set = Ember.set
guidFor = Ember.guidFor
typeOf = Ember.typeOf

###
  `Emberella.SelectableMixin` adds selection support to array controllers.

  This mixin is rough around the edges and is not verified to work
  across browsers.

  @class SelectableMixin
  @namespace Emberella
###

Emberella.SelectableMixin = Ember.Mixin.create
  ###
    @property isSelectable
    @type Boolean
    @default true
    @final
  ###
  isSelectable: true #quack like a duck

  init: ->
    set @, '_selection', new Emberella.SelectionSet()
    @_super()

  # allowsSelection: true #TODO: Enable this setting

  # allowsMultipleSelection: true #TODO: Enable this setting

  # allowsEmptySelection: true #TODO: Enable this setting

  ###
    A member of the content array. When expanding the selection, the selection
    will typically expand using the index of this object.

    @property cursor
    @type Object
    @default null
  ###
  cursor: null

  ###
    @private

    The complete set of all currently selected items.

    @property _selection
    @type Set
    @default null
  ###
  _selection: null

  ###
    The "active" selection: an array of items selected by the user that are
    also present in the content array. This allows the selection to be retained
    even if, for example, a filter removes a selected object from the `content`
    property. When the filter is removed, the previously selected object will,
    once again, appear to be selected.

    @property selection
    @type Array
    @default []
  ###
  # TODO: Fix excessive array creation
  selection: Ember.computed ->
    content = @getActiveContent()
    selection = get(@, '_selection')
    selection.filter((item) -> content.contains(item))
  .property('_selection.[]', 'content.[]', 'arrangedContent.[]')

  ###
    The first member of the content array that would be a valid selection. The
    default behavior is to simply use the first item in the content array.
    Override this property with validation checks as needed.

    @property firstSelectableObject
    @type Object
  ###
  firstSelectableObject: Ember.computed ->
    get(@, 'firstObject')
  .property 'firstObject'

  ###
    The last member of the content array that would be a valid selection. The
    default behavior is to simply use the last item in the content array.
    Override this property with validation checks as needed.

    @property firstSelectableObject
    @type Object
  ###
  lastSelectableObject: Ember.computed ->
    get(@, 'lastObject')
  .property 'lastObject'

  ###
    Retrieve an array of items that could appear in the active selection.

    The default behavior is simply to return the `content` array. Override this
    method to intorduce custom retrieval or assembly of the array of
    potentially selectable items.

    @method getActiveContent
    @return Array
  ###
  getActiveContent: ->
    get(@, 'content')

  ###
    Manipulate the selection set.

    Typically, this method will empty the selection set and add the specified
    item to the selection.

    Optionally, the selection status of a given item can be toggled or all
    items between the cursor and the specified item can be selected.

    @method select
    @param {Object|Integer} item The object or index to select
    @param {Object} [options] Expand or toggle the selection
      @param {Boolean} [options.toggle]
        If true, the item's selection state will be toggled.
      @param {Boolean} [options.range]
        If true, all items between the item and the cursor (inclusive) will be
        added to the selection.
    @chainable<commit_msg>Adjusted computation of current selection to favor arrangedContent<commit_after>###
@module emberella
@submodule emberella-mixins
###

Emberella = window.Emberella
get = Ember.get
set = Ember.set
guidFor = Ember.guidFor
typeOf = Ember.typeOf

###
  `Emberella.SelectableMixin` adds selection support to array controllers.

  This mixin is rough around the edges and is not verified to work
  across browsers.

  @class SelectableMixin
  @namespace Emberella
###

Emberella.SelectableMixin = Ember.Mixin.create
  ###
    @property isSelectable
    @type Boolean
    @default true
    @final
  ###
  isSelectable: true #quack like a duck

  init: ->
    set @, '_selection', new Emberella.SelectionSet()
    @_super()

  # allowsSelection: true #TODO: Enable this setting

  # allowsMultipleSelection: true #TODO: Enable this setting

  # allowsEmptySelection: true #TODO: Enable this setting

  ###
    A member of the content array. When expanding the selection, the selection
    will typically expand using the index of this object.

    @property cursor
    @type Object
    @default null
  ###
  cursor: null

  ###
    @private

    The complete set of all currently selected items.

    @property _selection
    @type Set
    @default null
  ###
  _selection: null

  ###
    The "active" selection: an array of items selected by the user that are
    also present in the content array. This allows the selection to be retained
    even if, for example, a filter removes a selected object from the `content`
    property. When the filter is removed, the previously selected object will,
    once again, appear to be selected.

    @property selection
    @type Array
    @default []
  ###
  # TODO: Fix excessive array creation
  selection: Ember.computed ->
    content = @getActiveContent()
    selection = get(@, '_selection')
    selection.filter((item) -> content.contains(item))
  .property('_selection.[]', 'content', 'arrangedContent.[]')

  ###
    The first member of the content array that would be a valid selection. The
    default behavior is to simply use the first item in the content array.
    Override this property with validation checks as needed.

    @property firstSelectableObject
    @type Object
  ###
  firstSelectableObject: Ember.computed ->
    get(@, 'firstObject')
  .property 'firstObject'

  ###
    The last member of the content array that would be a valid selection. The
    default behavior is to simply use the last item in the content array.
    Override this property with validation checks as needed.

    @property firstSelectableObject
    @type Object
  ###
  lastSelectableObject: Ember.computed ->
    get(@, 'lastObject')
  .property 'lastObject'

  ###
    Retrieve an array of items that could appear in the active selection.

    The default behavior is simply to return the `arrangedContent` array.
    Override this method to intorduce custom retrieval or assembly of the
    array of potentially selectable items.

    @method getActiveContent
    @return Array
  ###
  getActiveContent: ->
    get(@, 'arrangedContent')

  ###
    Manipulate the selection set.

    Typically, this method will empty the selection set and add the specified
    item to the selection.

    Optionally, the selection status of a given item can be toggled or all
    items between the cursor and the specified item can be selected.

    @method select
    @param {Object|Integer} item The object or index to select
    @param {Object} [options] Expand or toggle the selection
      @param {Boolean} [options.toggle]
        If true, the item's selection state will be toggled.
      @param {Boolean} [options.range]
        If true, all items between the item and the cursor (inclusive) will be
        added to the selection.
    @chainable
{'fraction_non_alphanumeric': 0.07453333333333333, 'fraction_numerical': 0.0, 'mean_word_length': 3.259511641113004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3397134', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1979, 'n_words': 876}