mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge branch 'dev' into editor-stats
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
DeferredAtomPackage = require 'deferred-atom-package'
|
||||
$ = require 'jquery'
|
||||
|
||||
module.exports =
|
||||
class CommandLogger extends DeferredAtomPackage
|
||||
@@ -7,4 +8,25 @@ class CommandLogger extends DeferredAtomPackage
|
||||
|
||||
instanceClass: 'command-logger/src/command-logger-view'
|
||||
|
||||
onLoadEvent: (event, instance) -> instance.toggle()
|
||||
activate: (rootView, state={})->
|
||||
super
|
||||
|
||||
@eventLog = state.eventLog ? {}
|
||||
rootView.command 'command-logger:clear-data', => @eventLog = {}
|
||||
|
||||
registerTriggeredEvent = (eventName) =>
|
||||
eventNameLog = @eventLog[eventName]
|
||||
unless eventNameLog
|
||||
eventNameLog =
|
||||
count: 0
|
||||
name: eventName
|
||||
@eventLog[eventName] = eventNameLog
|
||||
eventNameLog.count++
|
||||
eventNameLog.lastRun = new Date().getTime()
|
||||
originalTrigger = $.fn.trigger
|
||||
$.fn.trigger = (eventName) ->
|
||||
eventName = eventName.type if eventName.type
|
||||
registerTriggeredEvent(eventName) if $(this).events()[eventName]
|
||||
originalTrigger.apply(this, arguments)
|
||||
|
||||
onLoadEvent: (event, instance) -> instance.toggle(@eventLog)
|
||||
|
||||
@@ -6,9 +6,8 @@ describe "CommandLogger", ->
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
atom.loadPackage('command-logger').getInstance()
|
||||
commandLogger = atom.loadPackage('command-logger')
|
||||
editor = rootView.getActiveEditor()
|
||||
commandLogger = CommandLogger.instance
|
||||
|
||||
afterEach ->
|
||||
rootView.deactivate()
|
||||
@@ -44,9 +43,11 @@ describe "CommandLogger", ->
|
||||
|
||||
describe "when an event is ignored", ->
|
||||
it "does not create a node for that event", ->
|
||||
commandLogger.ignoredEvents.push 'editor:delete-line'
|
||||
commandLoggerView = commandLogger.getInstance()
|
||||
commandLoggerView.ignoredEvents.push 'editor:delete-line'
|
||||
editor.trigger 'editor:delete-line'
|
||||
nodes = commandLogger.createNodes()
|
||||
commandLoggerView.eventLog = commandLogger.eventLog
|
||||
nodes = commandLoggerView.createNodes()
|
||||
for node in nodes
|
||||
continue unless node.name is 'Editor'
|
||||
for child in node.children
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
{$$$} = require 'space-pen'
|
||||
ScrollView = require 'scroll-view'
|
||||
$ = require 'jquery'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class CommandLoggerView extends ScrollView
|
||||
@activate: (rootView, state) ->
|
||||
@instance = new CommandLoggerView(rootView, state?.eventLog)
|
||||
@instance = new CommandLoggerView(rootView)
|
||||
|
||||
@content: (rootView) ->
|
||||
@div class: 'command-logger', tabindex: -1, =>
|
||||
@@ -31,29 +30,13 @@ class CommandLoggerView extends ScrollView
|
||||
'tree-view:directory-modified'
|
||||
]
|
||||
|
||||
initialize: (@rootView, @eventLog={}) ->
|
||||
initialize: (@rootView) ->
|
||||
super
|
||||
|
||||
@rootView.command 'command-logger:clear-data', => @eventLog = {}
|
||||
@command 'core:cancel', => @detach()
|
||||
@on 'blur', => @detach() unless document.activeElement is this[0]
|
||||
|
||||
registerEvent = (eventName) =>
|
||||
eventNameLog = @eventLog[eventName]
|
||||
unless eventNameLog
|
||||
eventNameLog =
|
||||
count: 0
|
||||
name: eventName
|
||||
@eventLog[eventName] = eventNameLog
|
||||
eventNameLog.count++
|
||||
eventNameLog.lastRun = new Date().getTime()
|
||||
|
||||
originalTrigger = $.fn.trigger
|
||||
$.fn.trigger = (eventName) ->
|
||||
eventName = eventName.type if eventName.type
|
||||
registerEvent(eventName) if $(this).events()[eventName]
|
||||
originalTrigger.apply(this, arguments)
|
||||
|
||||
toggle: ->
|
||||
toggle: (@eventLog={}) ->
|
||||
if @hasParent()
|
||||
@detach()
|
||||
else
|
||||
@@ -198,8 +181,11 @@ class CommandLoggerView extends ScrollView
|
||||
@focus()
|
||||
|
||||
detach: ->
|
||||
super()
|
||||
return if @detaching
|
||||
@detaching = true
|
||||
super
|
||||
@rootView.focus()
|
||||
@detaching = false
|
||||
|
||||
serialize: ->
|
||||
eventLog: @eventLog
|
||||
|
||||
@@ -438,13 +438,13 @@ describe "CommandPanel", ->
|
||||
expect(previewList.getSelectedOperation()).toBe previewList.getOperations()[0]
|
||||
|
||||
describe "when core:confirm is triggered on the preview list", ->
|
||||
it "opens the operation's buffer, selects and scrolls to the search result, and focuses the active editor", ->
|
||||
it "opens the operation's buffer, selects and scrolls to the search result, and refocuses the preview list", ->
|
||||
rootView.height(200)
|
||||
rootView.attachToDom()
|
||||
|
||||
waitsForPromise -> commandPanel.execute('X x/apply/') # use apply because it is at the end of the file
|
||||
runs ->
|
||||
spyOn(rootView, 'focus')
|
||||
spyOn(previewList, 'focus')
|
||||
executeHandler = jasmine.createSpy('executeHandler')
|
||||
commandPanel.on 'core:confirm', executeHandler
|
||||
|
||||
@@ -458,13 +458,13 @@ describe "CommandPanel", ->
|
||||
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
|
||||
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
|
||||
expect(editor.isScreenRowVisible(editor.getCursorScreenRow())).toBeTruthy()
|
||||
expect(rootView.focus).toHaveBeenCalled()
|
||||
expect(previewList.focus).toHaveBeenCalled()
|
||||
|
||||
expect(executeHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "when an operation in the preview list is clicked", ->
|
||||
it "opens the operation's buffer, selects the search result, and focuses the active editor", ->
|
||||
spyOn(rootView, 'focus')
|
||||
it "opens the operation's buffer, selects the search result, and refocuses the preview list", ->
|
||||
spyOn(previewList, 'focus')
|
||||
operation = previewList.getOperations()[4]
|
||||
|
||||
previewList.find('li.operation:eq(4) span').mousedown()
|
||||
@@ -473,4 +473,4 @@ describe "CommandPanel", ->
|
||||
editSession = rootView.getActiveEditSession()
|
||||
expect(editSession.buffer.getPath()).toBe project.resolve(operation.getPath())
|
||||
expect(editSession.getSelectedBufferRange()).toEqual operation.getBufferRange()
|
||||
expect(rootView.focus).toHaveBeenCalled()
|
||||
expect(previewList.focus).toHaveBeenCalled()
|
||||
|
||||
@@ -51,7 +51,7 @@ class CommandPanelView extends View
|
||||
@previewList.hide()
|
||||
@previewCount.hide()
|
||||
@errorMessages.hide()
|
||||
@prompt.iconSize(@miniEditor.fontSize)
|
||||
@prompt.iconSize(@miniEditor.getFontSize())
|
||||
|
||||
serialize: ->
|
||||
text: @miniEditor.getText()
|
||||
|
||||
@@ -83,7 +83,7 @@ class PreviewList extends ScrollView
|
||||
editSession = @rootView.open(operation.getPath())
|
||||
bufferRange = operation.execute(editSession)
|
||||
editSession.setSelectedBufferRange(bufferRange, autoscroll: true) if bufferRange
|
||||
@rootView.focus()
|
||||
@focus()
|
||||
false
|
||||
|
||||
getPathCount: ->
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
window.keymap.bindKeys '.editor'
|
||||
'.editor':
|
||||
'tab': 'snippets:expand'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# it's critical that these bindings be loaded after those snippets-1 so they
|
||||
# are later in the cascade, hence breaking the keymap into 2 files
|
||||
|
||||
window.keymap.bindKeys '.editor'
|
||||
'.editor':
|
||||
'tab': 'snippets:next-tab-stop'
|
||||
'shift-tab': 'snippets:previous-tab-stop'
|
||||
|
||||
@@ -277,6 +277,7 @@ describe "Snippets extension", ->
|
||||
|
||||
it "terminates the worker when loading completes", ->
|
||||
jasmine.unspy(LoadSnippetsTask.prototype, 'loadAtomSnippets')
|
||||
spyOn(console, "warn")
|
||||
spyOn(Worker.prototype, 'terminate').andCallThrough()
|
||||
snippets.loaded = false
|
||||
snippets.loadAll()
|
||||
@@ -284,6 +285,8 @@ describe "Snippets extension", ->
|
||||
waitsFor "all snippets to load", 5000, -> snippets.loaded
|
||||
|
||||
runs ->
|
||||
expect(console.warn).toHaveBeenCalled()
|
||||
expect(console.warn.argsForCall[0]).toMatch /Error reading snippets file '.*?\/spec\/fixtures\/packages\/package-with-snippets\/snippets\/junk-file'/
|
||||
expect(Worker.prototype.terminate).toHaveBeenCalled()
|
||||
expect(Worker.prototype.terminate.calls.length).toBe 1
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Task = require 'Task'
|
||||
Task = require 'task'
|
||||
TextMatePackage = require 'text-mate-package'
|
||||
|
||||
module.exports =
|
||||
|
||||
@@ -5,7 +5,7 @@ Tabs = require 'tabs'
|
||||
fs = require 'fs'
|
||||
|
||||
describe "Tabs", ->
|
||||
[rootView, editor, statusBar, buffer, tabs] = []
|
||||
[rootView, editor, buffer, tabs] = []
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView(require.resolve('fixtures/sample.js'))
|
||||
@@ -118,3 +118,21 @@ describe "Tabs", ->
|
||||
tabs.find('.tab .close-icon:eq(1)').click()
|
||||
expect(editor.getActiveEditSessionIndex()).toBe 0
|
||||
expect(editor.activeEditSession).toBe firstSession
|
||||
|
||||
describe "when two tabs have the same file name", ->
|
||||
[tempPath] = []
|
||||
|
||||
beforeEach ->
|
||||
tempPath = '/tmp/sample.js'
|
||||
fs.write(tempPath, 'sample')
|
||||
|
||||
afterEach ->
|
||||
fs.remove(tempPath) if fs.exists(tempPath)
|
||||
|
||||
it "displays the parent folder name after the file name", ->
|
||||
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.js'
|
||||
rootView.open(tempPath)
|
||||
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.js - fixtures'
|
||||
expect(tabs.find('.tab:last .file-name').text()).toBe 'sample.js - tmp'
|
||||
editor.destroyActiveEditSession()
|
||||
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.js'
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{View} = require 'space-pen'
|
||||
fs = require 'fs'
|
||||
|
||||
module.exports =
|
||||
class Tab extends View
|
||||
@@ -7,12 +8,14 @@ class Tab extends View
|
||||
@span class: 'file-name', outlet: 'fileName'
|
||||
@span class: 'close-icon'
|
||||
|
||||
initialize: (@editSession) ->
|
||||
initialize: (@editSession, @editor) ->
|
||||
@buffer = @editSession.buffer
|
||||
@subscribe @buffer, 'path-changed', => @updateFileName()
|
||||
@subscribe @buffer, 'contents-modified', => @updateModifiedStatus()
|
||||
@subscribe @buffer, 'saved', => @updateModifiedStatus()
|
||||
@subscribe @buffer, 'git-status-changed', => @updateModifiedStatus()
|
||||
@subscribe @editor, 'editor:edit-session-added', => @updateFileName()
|
||||
@subscribe @editor, 'editor:edit-session-removed', => @updateFileName()
|
||||
@updateFileName()
|
||||
@updateModifiedStatus()
|
||||
|
||||
@@ -25,4 +28,14 @@ class Tab extends View
|
||||
@isModified = false
|
||||
|
||||
updateFileName: ->
|
||||
@fileName.text(@editSession.buffer.getBaseName() ? 'untitled')
|
||||
fileNameText = @editSession.buffer.getBaseName()
|
||||
if fileNameText?
|
||||
duplicates = @editor.getEditSessions().filter (session) -> fileNameText is session.buffer.getBaseName()
|
||||
if duplicates.length > 1
|
||||
directory = fs.base(fs.directory(@editSession.getPath()))
|
||||
fileNameText = "#{fileNameText} - #{directory}" if directory
|
||||
else
|
||||
fileNameText = 'untitled'
|
||||
|
||||
@fileName.text(fileNameText)
|
||||
@fileName.attr('title', @editSession.getPath())
|
||||
|
||||
@@ -34,7 +34,7 @@ class Tabs extends View
|
||||
false
|
||||
|
||||
addTabForEditSession: (editSession) ->
|
||||
@append(new Tab(editSession))
|
||||
@append(new Tab(editSession, @editor))
|
||||
|
||||
setActiveTab: (index) ->
|
||||
@find(".tab.active").removeClass('active')
|
||||
|
||||
@@ -761,7 +761,7 @@ describe "TreeView", ->
|
||||
|
||||
expect(addDialog.miniEditor.getText().length).toBe 0
|
||||
|
||||
describe "tree-view:move", ->
|
||||
fdescribe "tree-view:move", ->
|
||||
describe "when a file is selected", ->
|
||||
moveDialog = null
|
||||
|
||||
@@ -770,6 +770,9 @@ describe "TreeView", ->
|
||||
treeView.trigger "tree-view:move"
|
||||
moveDialog = rootView.find(".tree-view-dialog").view()
|
||||
|
||||
afterEach ->
|
||||
waits 50 # The move specs cause too many false positives because of their async nature, so wait a little bit before we cleanup
|
||||
|
||||
it "opens a move dialog with the file's current path (excluding extension) populated", ->
|
||||
extension = fs.extension(filePath)
|
||||
fileNameWithoutExtension = fs.base(filePath, extension)
|
||||
|
||||
Reference in New Issue
Block a user