atom-select-list
Advanced tools
Comparing version 0.3.2 to 0.4.0
{ | ||
"name": "atom-select-list", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "A general-purpose select list for use in Atom packages", | ||
@@ -5,0 +5,0 @@ "main": "./src/select-list-view.js", |
@@ -52,2 +52,3 @@ # atom-select-list | ||
* (Optional) `itemsClassList: [String]`: an array of strings that will be added as class names to the items element. | ||
* (Optional) `initialSelectionIndex: Number`: the index of the item to initially select and automatically select after query changes; defaults to 0. | ||
* (Optional) `didChangeQuery: (query: String) -> Void`: a function that is called when the query changes. | ||
@@ -54,0 +55,0 @@ * (Optional) `didChangeSelection: (item: Object) -> Void`: a function that is called when the selected item changes. |
@@ -17,2 +17,5 @@ const {Disposable, CompositeDisposable, TextEditor} = require('atom') | ||
this.props = props | ||
if (!this.props.hasOwnProperty('initialSelectionIndex')) { | ||
this.props.initialSelectionIndex = 0 | ||
} | ||
this.computeItems(false) | ||
@@ -140,2 +143,6 @@ this.disposables = new CompositeDisposable() | ||
if (props.hasOwnProperty('initialSelectionIndex')) { | ||
this.props.initialSelectionIndex = props.initialSelectionIndex | ||
} | ||
if (shouldComputeItems) { | ||
@@ -244,3 +251,3 @@ this.computeItems() | ||
this.selectIndex(0, updateComponent) | ||
this.selectIndex(this.props.initialSelectionIndex, updateComponent) | ||
} | ||
@@ -266,2 +273,3 @@ | ||
getSelectedItem () { | ||
if (this.selectionIndex === undefined) return null | ||
return this.items[this.selectionIndex] | ||
@@ -271,2 +279,3 @@ } | ||
selectPrevious () { | ||
if (this.selectionIndex === undefined) return this.selectLast() | ||
return this.selectIndex(this.selectionIndex - 1) | ||
@@ -276,2 +285,3 @@ } | ||
selectNext () { | ||
if (this.selectionIndex === undefined) return this.selectFirst() | ||
return this.selectIndex(this.selectionIndex + 1) | ||
@@ -288,2 +298,6 @@ } | ||
selectNone () { | ||
return this.selectIndex(undefined) | ||
} | ||
selectIndex (index, updateComponent = true) { | ||
@@ -297,3 +311,3 @@ if (index >= this.items.length) { | ||
this.selectionIndex = index | ||
if (this.props.didChangeSelection) { | ||
if (index !== undefined && this.props.didChangeSelection) { | ||
this.props.didChangeSelection(this.getSelectedItem()) | ||
@@ -300,0 +314,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37336
5
794
58