mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Use closure wrapper with current event name
This commit is contained in:
@@ -114,12 +114,14 @@ describe "EditorCommand", ->
|
||||
|
||||
it "registers all keymaps", ->
|
||||
callbackCount = 0
|
||||
eventName = null
|
||||
class CustomCommand extends EditorCommand
|
||||
@getKeymaps: (editor) ->
|
||||
'meta-V': 'custom1'
|
||||
'meta-B': 'custom2'
|
||||
|
||||
@execute: (editor, event) ->
|
||||
eventName = event
|
||||
@replaceSelectedText editor, (text) ->
|
||||
callbackCount++
|
||||
text
|
||||
@@ -129,7 +131,9 @@ describe "EditorCommand", ->
|
||||
editor.selectToEndOfLine()
|
||||
editor.trigger 'custom1'
|
||||
expect(callbackCount).toBe 1
|
||||
expect(eventName).toBe 'custom1'
|
||||
editor.trigger 'custom2'
|
||||
expect(eventName).toBe 'custom2'
|
||||
expect(callbackCount).toBe 2
|
||||
|
||||
describe "LowerCaseCommand", ->
|
||||
|
||||
@@ -18,7 +18,9 @@ class EditorCommand
|
||||
return unless keymaps
|
||||
|
||||
for key, event of keymaps
|
||||
editor.on event, => @execute(editor, event)
|
||||
do (event) =>
|
||||
editor.on event, =>
|
||||
@execute(editor, event)
|
||||
|
||||
@replaceSelectedText: (editor, replace) ->
|
||||
selection = editor.getSelection()
|
||||
|
||||
Reference in New Issue
Block a user