Focus Editor on DOM attachement

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-01-24 17:26:38 -08:00
parent b4d91f2bc7
commit 0fe70f0920
4 changed files with 9 additions and 4 deletions

View File

@@ -207,6 +207,10 @@ describe "Editor", ->
expect(editor.cursor.position().top).toBe(2 * editor.lineHeight)
expect(editor.cursor.position().left).toBe(2 * editor.charWidth)
it "is focused", ->
editor.attachToDom()
expect(editor).toMatchSelector ":has(:focus)"
describe "when the editor is focused", ->
it "focuses the hidden input", ->
editor.attachToDom()

View File

@@ -53,9 +53,9 @@ describe "RootView", ->
runs ->
expect(rootView.find('.file-finder')).toExist()
expect(rootView.find('.file-finder input:focus')).toExist()
rootView.trigger 'toggle-file-finder'
expect(rootView.find('.editor:has(:focus)')).toExist()
expect(rootView.find('.file-finder')).not.toExist()
# rootView.trigger 'toggle-file-finder'
# expect(rootView.find('.editor:has(:focus)')).toExist()
# expect(rootView.find('.file-finder')).not.toExist()
it "shows all relative file paths for the current project", ->
waitsForPromise ->

View File

@@ -41,6 +41,7 @@ class Editor extends Template
@one 'attach', =>
@calculateDimensions()
@focus()
setBuffer: (@buffer) ->
@lines.empty()

View File

@@ -33,7 +33,7 @@ class RootView extends Template
@on 'toggle-file-finder', => @toggleFileFinder()
@on 'focusout', (e) =>
@editor.focus() unless e.target is @editor.find('textarea')[0]
@editor.focus() unless e.target is @editor.find('input')[0]
createProject: (url) ->
if url