mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Clear multiple selections on escape
The binding uses the `!important` selector to ensure that the editor always gets a chance to clear multiple selections before other bindings for escape are processed.
This commit is contained in:
@@ -2472,3 +2472,19 @@ describe "Editor", ->
|
||||
expect(fsUtils.write).toHaveBeenCalled()
|
||||
expect(fsUtils.write.argsForCall[0][0]).toBe '/tmp/state'
|
||||
expect(typeof fsUtils.write.argsForCall[0][1]).toBe 'string'
|
||||
|
||||
describe "when the escape key is pressed on the editor", ->
|
||||
it "clears multiple selections if there are any, and otherwise allows other bindings to be handled", ->
|
||||
keymap.bindKeys '.editor', 'escape': 'test-event'
|
||||
testEventHandler = jasmine.createSpy("testEventHandler")
|
||||
|
||||
editor.on 'test-event', testEventHandler
|
||||
editor.activeEditSession.addSelectionForBufferRange([[3, 0], [3, 0]])
|
||||
expect(editor.activeEditSession.getSelections().length).toBe 2
|
||||
|
||||
editor.trigger(keydownEvent('escape'))
|
||||
expect(editor.activeEditSession.getSelections().length).toBe 1
|
||||
expect(testEventHandler).not.toHaveBeenCalled()
|
||||
|
||||
editor.trigger(keydownEvent('escape'))
|
||||
expect(testEventHandler).toHaveBeenCalled()
|
||||
|
||||
@@ -104,6 +104,7 @@ class Editor extends View
|
||||
'editor:move-to-previous-word': @moveCursorToPreviousWord
|
||||
'editor:select-word': @selectWord
|
||||
'editor:newline': @insertNewline
|
||||
'editor:consolidate-selections': @consolidateSelections
|
||||
'editor:indent': @indent
|
||||
'editor:auto-indent': @autoIndent
|
||||
'editor:indent-selected-rows': @indentSelectedRows
|
||||
@@ -164,7 +165,7 @@ class Editor extends View
|
||||
documentation = {}
|
||||
for name, method of editorBindings
|
||||
do (name, method) =>
|
||||
@command name, => method.call(this); false
|
||||
@command name, (e) => method.call(this, e); false
|
||||
|
||||
getCursor: -> @activeEditSession.getCursor()
|
||||
getCursors: -> @activeEditSession.getCursors()
|
||||
@@ -232,6 +233,7 @@ class Editor extends View
|
||||
cutToEndOfLine: -> @activeEditSession.cutToEndOfLine()
|
||||
insertText: (text, options) -> @activeEditSession.insertText(text, options)
|
||||
insertNewline: -> @activeEditSession.insertNewline()
|
||||
consolidateSelections: (e) -> e.abortKeyBinding() unless @activeEditSession.consolidateSelections()
|
||||
insertNewlineBelow: -> @activeEditSession.insertNewlineBelow()
|
||||
insertNewlineAbove: -> @activeEditSession.insertNewlineAbove()
|
||||
indent: (options) -> @activeEditSession.indent(options)
|
||||
|
||||
@@ -31,3 +31,6 @@
|
||||
'enter': 'core:confirm',
|
||||
'escape': 'core:cancel'
|
||||
'meta-w': 'core:cancel'
|
||||
|
||||
'.editor !important':
|
||||
'escape': 'editor:consolidate-selections'
|
||||
|
||||
Reference in New Issue
Block a user