Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
})
atom.commands.dispatch(workspaceElement, 'key-binding-resolver:toggle')
// Not partial because it dispatches the command for `x` immediately due to only having keyup events in remainder of partial match
document.dispatchEvent(atom.keymaps.constructor.buildKeydownEvent('x', {target: workspaceElement}))
await etch.getScheduler().getNextUpdatePromise()
expect(workspaceElement.querySelector('.key-binding-resolver .keystroke').textContent).toBe('x')
expect(workspaceElement.querySelectorAll('.key-binding-resolver .used')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unused')).toHaveLength(0)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unmatched')).toHaveLength(1)
// It should not render the keyup event data because there is no match
document.dispatchEvent(atom.keymaps.constructor.buildKeyupEvent('x', {target: workspaceElement}))
await etch.getScheduler().getNextUpdatePromise()
expect(workspaceElement.querySelector('.key-binding-resolver .keystroke').textContent).toBe('x ^x')
expect(workspaceElement.querySelectorAll('.key-binding-resolver .used')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unused')).toHaveLength(0)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unmatched')).toHaveLength(0)
document.dispatchEvent(atom.keymaps.constructor.buildKeydownEvent('a', {target: workspaceElement}))
await etch.getScheduler().getNextUpdatePromise()
expect(workspaceElement.querySelector('.key-binding-resolver .keystroke').textContent).toBe('a (partial)')
expect(workspaceElement.querySelectorAll('.key-binding-resolver .used')).toHaveLength(0)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unused')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unmatched')).toHaveLength(0)
document.dispatchEvent(atom.keymaps.constructor.buildKeyupEvent('a', {target: workspaceElement}))
await etch.getScheduler().getNextUpdatePromise()
expect(workspaceElement.querySelector('.key-binding-resolver .keystroke').textContent).toBe('a ^a')
expect(workspaceElement.querySelectorAll('.key-binding-resolver .used')).toHaveLength(1)
'.never-again': {
'x': 'unmatch-2'
}
})
atom.commands.dispatch(workspaceElement, 'key-binding-resolver:toggle')
document.dispatchEvent(atom.keymaps.constructor.buildKeydownEvent('x', {target: workspaceElement}))
await etch.getScheduler().getNextUpdatePromise()
expect(workspaceElement.querySelector('.key-binding-resolver .keystroke').textContent).toBe('x')
expect(workspaceElement.querySelectorAll('.key-binding-resolver .used')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unused')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unmatched')).toHaveLength(1)
// It should not render the keyup event data because there is no match
spyOn(etch.getScheduler(), 'updateDocument').andCallThrough()
document.dispatchEvent(atom.keymaps.constructor.buildKeyupEvent('x', {target: workspaceElement}))
expect(etch.getScheduler().updateDocument).not.toHaveBeenCalled()
expect(workspaceElement.querySelector('.key-binding-resolver .keystroke').textContent).toBe('x')
expect(workspaceElement.querySelectorAll('.key-binding-resolver .used')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unused')).toHaveLength(1)
expect(workspaceElement.querySelectorAll('.key-binding-resolver .unmatched')).toHaveLength(1)
})
renderItems () {
if (this.items.length > 0) {
const className = ['list-group'].concat(this.props.itemsClassList || []).join(' ')
if (this.visibilityObserver) {
etch.getScheduler().updateDocument(() => {
Array.from(this.refs.items.children).slice(this.props.initiallyVisibleItemCount).forEach(element => {
this.visibilityObserver.observe(element)
})
})
}
this.listItems = this.items.map((item, index) => {
const selected = this.getSelectedItem() === item
const visible = !this.props.initiallyVisibleItemCount || index < this.props.initiallyVisibleItemCount
return $(ListItemView, {
element: this.props.elementForItem(item, { selected, index, visible }),
selected: selected,
onclick: () => this.didClickItem(index)
})
})
this.element.removeEventListener('mousedown', this.mouseDown)
this.element.removeEventListener('mouseup', this.mouseUp)
this.element.removeEventListener('click', this.didClick)
this.element.parentNode.replaceChild(props.element, this.element)
this.element = props.element
this.element.addEventListener('mousedown', this.mouseDown)
this.element.addEventListener('mouseup', this.mouseUp)
this.element.addEventListener('click', this.didClick)
if (props.selected) {
this.element.classList.add('selected')
}
this.selected = props.selected
this.onclick = props.onclick
etch.getScheduler().updateDocument(this.scrollIntoViewIfNeeded.bind(this))
}
this.element.removeEventListener('mousedown', this.mouseDown)
this.element.removeEventListener('mouseup', this.mouseUp)
this.element.removeEventListener('click', this.didClick)
this.element.parentNode.replaceChild(props.element, this.element)
this.element = props.element
this.element.addEventListener('mousedown', this.mouseDown)
this.element.addEventListener('mouseup', this.mouseUp)
this.element.addEventListener('click', this.didClick)
if (props.selected) {
this.element.classList.add('selected')
}
this.selected = props.selected
this.onclick = props.onclick
etch.getScheduler().updateDocument(this.scrollIntoViewIfNeeded.bind(this))
}
const getNextUpdatePromise = () => etch.getScheduler().nextUpdatePromise;
scheduleUpdate (nextUpdateOnlyBlinksCursors = false) {
if (!this.visible) return
this.nextUpdateOnlyBlinksCursors =
this.nextUpdateOnlyBlinksCursors !== false && nextUpdateOnlyBlinksCursors === true
if (this.updatedSynchronously) {
this.updateSync()
} else if (!this.updateScheduled) {
this.updateScheduled = true
etch.getScheduler().updateDocument(() => {
if (this.updateScheduled) this.updateSync(true)
})
}
}
renderItems () {
if (this.items.length > 0) {
const className = ['list-group'].concat(this.props.itemsClassList || []).join(' ')
if (this.visibilityObserver) {
etch.getScheduler().updateDocument(() => {
Array.from(this.refs.items.children).slice(this.props.initiallyVisibleItemCount).forEach(element => {
this.visibilityObserver.observe(element)
})
})
}
this.listItems = this.items.map((item, index) => {
const selected = this.getSelectedItem() === item
const visible = !this.props.initiallyVisibleItemCount || index < this.props.initiallyVisibleItemCount
return $(ListItemView, {
element: this.props.elementForItem(item, {selected, index, visible}),
selected: selected,
onclick: () => this.didClickItem(index)
})
})
this.didClick = this.didClick.bind(this)
this.selected = props.selected
this.onclick = props.onclick
this.element = props.element
this.element.addEventListener('mousedown', this.mouseDown)
this.element.addEventListener('mouseup', this.mouseUp)
this.element.addEventListener('click', this.didClick)
if (this.selected) {
this.element.classList.add('selected')
}
this.domEventsDisposable = new Disposable(() => {
this.element.removeEventListener('mousedown', this.mouseDown)
this.element.removeEventListener('mouseup', this.mouseUp)
this.element.removeEventListener('click', this.didClick)
})
etch.getScheduler().updateDocument(this.scrollIntoViewIfNeeded.bind(this))
}
static getScheduler () {
return etch.getScheduler()
}