mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Merge branch 'master' of github.com:github/atom
This commit is contained in:
@@ -17,20 +17,15 @@ describe "Autocomplete", ->
|
||||
afterEach ->
|
||||
autocomplete.remove()
|
||||
|
||||
describe 'autocomplete:toggle event', ->
|
||||
describe 'autocomplete:show event', ->
|
||||
it "shows autocomplete view and focuses its mini-editor", ->
|
||||
expect($(document).find('#autocomplete')).not.toExist()
|
||||
|
||||
editor.trigger "autocomplete:toggle"
|
||||
editor.trigger "autocomplete:attach"
|
||||
expect($(document).find('#autocomplete')).toExist()
|
||||
expect(autocomplete.editor.isFocused).toBeFalsy()
|
||||
expect(autocomplete.miniEditor.isFocused).toBeTruthy()
|
||||
|
||||
miniEditor.trigger "autocomplete:toggle"
|
||||
expect($(document).find('#autocomplete')).not.toExist()
|
||||
expect(autocomplete.editor.isFocused).toBeTruthy()
|
||||
expect(autocomplete.miniEditor.isFocused).toBeFalsy()
|
||||
|
||||
describe "when no text is selected", ->
|
||||
it 'autocompletes word when there is only a prefix', ->
|
||||
editor.buffer.insert([10,0] ,"extra:s:extra")
|
||||
@@ -186,7 +181,19 @@ describe "Autocomplete", ->
|
||||
expect(autocomplete.find('li:eq(0)')).toHaveClass('selected')
|
||||
expect(autocomplete.find('li:eq(1)')).not.toHaveClass('selected')
|
||||
|
||||
describe "when the mini-editor receives text input", ->
|
||||
describe "when the mini-editor's buffer changes", ->
|
||||
describe "when text is removed from the mini-editor", ->
|
||||
it "reloads the match list based on the mini-editor's text", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
editor.setCursorBufferPosition([10,0])
|
||||
autocomplete.attach()
|
||||
|
||||
expect(autocomplete.matchesList.find('li').length).toBe 8
|
||||
miniEditor.textInput('c')
|
||||
expect(autocomplete.matchesList.find('li').length).toBe 3
|
||||
miniEditor.backspace()
|
||||
expect(autocomplete.matchesList.find('li').length).toBe 8
|
||||
|
||||
describe "when the text contains only word characters", ->
|
||||
it "narrows the list of completions with the fuzzy match algorithm", ->
|
||||
editor.buffer.insert([10,0] ,"t")
|
||||
|
||||
@@ -51,6 +51,20 @@ describe "Editor", ->
|
||||
expect(newEditor.editSessions[0]).toEqual(editor.editSessions[0])
|
||||
expect(newEditor.editSessions[0]).not.toBe(editor.editSessions[0])
|
||||
|
||||
describe "editor-open event", ->
|
||||
it 'only triggers an editor-open event when it is first added to the DOM', ->
|
||||
openHandler = jasmine.createSpy('openHandler')
|
||||
editor.on 'editor-open', openHandler
|
||||
|
||||
editor.simulateDomAttachment()
|
||||
expect(openHandler).toHaveBeenCalled()
|
||||
[event, eventEditor] = openHandler.argsForCall[0]
|
||||
expect(eventEditor).toBe editor
|
||||
|
||||
openHandler.reset()
|
||||
editor.simulateDomAttachment()
|
||||
expect(openHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "text rendering", ->
|
||||
it "creates a line element for each line in the buffer with the html-escaped text of the line", ->
|
||||
expect(editor.lines.find('.line').length).toEqual(buffer.numLines())
|
||||
|
||||
@@ -131,3 +131,5 @@ $.fn.textInput = (data) ->
|
||||
event = jQuery.event.fix(event)
|
||||
$(this).trigger(event)
|
||||
|
||||
$.fn.simulateDomAttachment = ->
|
||||
$('<html>').append(this)
|
||||
@@ -33,13 +33,13 @@ class Autocomplete extends View
|
||||
@editor.on 'buffer-path-change', => @setCurrentBuffer(@editor.buffer)
|
||||
@editor.on 'before-remove', => @currentBuffer?.off '.autocomplete'
|
||||
|
||||
@editor.on 'autocomplete:toggle', => @attach()
|
||||
@on 'autocomplete:toggle', => @detach()
|
||||
@editor.on 'autocomplete:attach', => @attach()
|
||||
@on 'autocomplete:confirm', => @confirm()
|
||||
@on 'autocomplete:cancel', => @cancel()
|
||||
|
||||
@miniEditor.buffer.on 'change', =>
|
||||
@filterMatchList() if @parent()[0]
|
||||
@miniEditor.buffer.on 'change', (e) =>
|
||||
return unless @parent()[0]
|
||||
@filterMatchList()
|
||||
|
||||
@miniEditor.preempt 'move-up', =>
|
||||
@selectPreviousMatch()
|
||||
@@ -122,13 +122,14 @@ class Autocomplete extends View
|
||||
|
||||
if (prefix.length + suffix.length) > 0
|
||||
currentWord = prefix + @editor.getSelectedText() + suffix
|
||||
@matches = (match for match in @wordMatches(prefix, suffix) when match.word != currentWord)
|
||||
@baseMatches = (match for match in @wordMatches(prefix, suffix) when match.word != currentWord)
|
||||
else
|
||||
@matches = []
|
||||
@renderMatchList()
|
||||
@baseMatches = []
|
||||
|
||||
@filterMatchList()
|
||||
|
||||
filterMatchList: ->
|
||||
@matches = fuzzyFilter(@matches, @miniEditor.buffer.getText(), key: 'word')
|
||||
@matches = fuzzyFilter(@baseMatches, @miniEditor.getText(), key: 'word')
|
||||
@renderMatchList()
|
||||
|
||||
renderMatchList: ->
|
||||
|
||||
@@ -201,11 +201,14 @@ class Editor extends View
|
||||
else
|
||||
@gutter.addClass('drop-shadow')
|
||||
|
||||
@on 'attach', =>
|
||||
@on 'attach', (e) =>
|
||||
return if @attached
|
||||
@attached = true
|
||||
@calculateDimensions()
|
||||
@hiddenInput.width(@charWidth)
|
||||
@setMaxLineLength() if @softWrap
|
||||
@focus() if @isFocused
|
||||
@trigger 'editor-open', [this]
|
||||
|
||||
rootView: ->
|
||||
@parents('#root-view').view()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
window.keymap.bindKeys '.editor',
|
||||
'escape': 'autocomplete:toggle'
|
||||
'escape': 'autocomplete:attach'
|
||||
|
||||
window.keymap.bindKeys '#autocomplete .editor',
|
||||
'enter': 'autocomplete:confirm'
|
||||
|
||||
@@ -21,8 +21,8 @@ windowAdditions =
|
||||
$(document).on 'keydown', @_handleKeyEvent
|
||||
|
||||
startup: (path) ->
|
||||
@attachRootView(path)
|
||||
@loadUserConfiguration()
|
||||
@attachRootView(path)
|
||||
$(window).on 'close', => @close()
|
||||
$(window).on 'beforeunload', =>
|
||||
@shutdown()
|
||||
@@ -53,7 +53,7 @@ windowAdditions =
|
||||
try
|
||||
require atom.userConfigurationPath if fs.exists(atom.userConfigurationPath)
|
||||
catch error
|
||||
console.error "Failed to load `#{atom.userConfigurationPath}`", error
|
||||
console.error "Failed to load `#{atom.userConfigurationPath}`", error.message, error
|
||||
@showConsole()
|
||||
|
||||
requireStylesheet: (path) ->
|
||||
|
||||
Reference in New Issue
Block a user