From 6c1b63d3521a999dc36f7bd69c5b8028bfa4e8c7 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Thu, 21 Nov 2013 17:49:07 -0500 Subject: [PATCH 01/16] Pass originalEvent property on command events vim-mode needs access to the original keystroke that triggered the event. --- src/keymap.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/keymap.coffee b/src/keymap.coffee index 41beffad5..71d04abd0 100644 --- a/src/keymap.coffee +++ b/src/keymap.coffee @@ -159,15 +159,16 @@ class Keymap else if keyBinding.command is 'native!' shouldBubble = true - else if @triggerCommandEvent(element, keyBinding.command) + else if @triggerCommandEvent(element, keyBinding.command, event) shouldBubble = false break if shouldBubble? shouldBubble ? true - triggerCommandEvent: (element, commandName) -> + triggerCommandEvent: (element, commandName, event) -> commandEvent = $.Event(commandName) + commandEvent.originalEvent = event commandEvent.abortKeyBinding = -> commandEvent.stopImmediatePropagation() $(element).trigger(commandEvent) not commandEvent.isImmediatePropagationStopped() From d093d5cc06669eeca48c5c28afdbedbe552a2bce Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 14:21:06 -0800 Subject: [PATCH 02/16] Check selectors using webkitMatchesSelector --- src/menu-manager.coffee | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 0ae3f26d8..51bc745a3 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -27,11 +27,27 @@ class MenuManager @merge(@template, item) for item in items @update() + # Private: Should the binding for the given selector be included in the menu + # commands. + # + # * selector: A String selector to check. + # + # Returns true to include the selector, false otherwise. + includeSelector: (selector) -> + unless @testEditor? + @testEditor = document.createElement('div') + @testEditor.classList.add('editor') + testBody = document.createElement('body') + testBody.classList.add(document.body.classList.toString().split(' ')...) + testBody.appendChild(@testEditor) + + document.body.webkitMatchesSelector(selector) or @testEditor.webkitMatchesSelector(selector) + # Public: Refreshes the currently visible menu. update: -> keystrokesByCommand = {} - selectors = ['body', ".platform-#{process.platform}", '.editor', '.editor:not(.mini)'] - for binding in atom.keymap.getKeyBindings() when binding.selector in selectors + for binding in atom.keymap.getKeyBindings() when @includeSelector(binding.selector) + console.log binding.selector keystrokesByCommand[binding.command] ?= [] keystrokesByCommand[binding.command].push binding.keystroke @sendToBrowserProcess(@template, keystrokesByCommand) @@ -40,8 +56,8 @@ class MenuManager loadPlatformItems: -> menusDirPath = path.join(@resourcePath, 'menus') platformMenuPath = fs.resolve(menusDirPath, process.platform, ['cson', 'json']) - data = CSON.readFileSync(platformMenuPath) - @add(data.menu) + {menu} = CSON.readFileSync(platformMenuPath) + @add(menu) # Private: Merges an item in a submenu aware way such that new items are always # appended to the bottom of existing menus where possible. From c4dec72dcd8d618ee60ec39e9b047903c9835a7f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 14:32:28 -0800 Subject: [PATCH 03/16] Return early when document.body matches selector --- src/menu-manager.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 51bc745a3..5b5fd868d 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -34,6 +34,8 @@ class MenuManager # # Returns true to include the selector, false otherwise. includeSelector: (selector) -> + return true if document.body.webkitMatchesSelector(selector) + unless @testEditor? @testEditor = document.createElement('div') @testEditor.classList.add('editor') @@ -41,7 +43,7 @@ class MenuManager testBody.classList.add(document.body.classList.toString().split(' ')...) testBody.appendChild(@testEditor) - document.body.webkitMatchesSelector(selector) or @testEditor.webkitMatchesSelector(selector) + @testEditor.webkitMatchesSelector(selector) # Public: Refreshes the currently visible menu. update: -> From a9887b500733901073e503405d599121f9a2a1f5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 14:32:45 -0800 Subject: [PATCH 04/16] Remove logging --- src/menu-manager.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 5b5fd868d..6a918f1ec 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -49,7 +49,6 @@ class MenuManager update: -> keystrokesByCommand = {} for binding in atom.keymap.getKeyBindings() when @includeSelector(binding.selector) - console.log binding.selector keystrokesByCommand[binding.command] ?= [] keystrokesByCommand[binding.command].push binding.keystroke @sendToBrowserProcess(@template, keystrokesByCommand) From 7d9d0c715c5affdf1c34bbe0bb047e8cb1639b9e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 14:33:58 -0800 Subject: [PATCH 05/16] :memo: Mention what testEditor simulates --- src/menu-manager.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/menu-manager.coffee b/src/menu-manager.coffee index 6a918f1ec..4850e040b 100644 --- a/src/menu-manager.coffee +++ b/src/menu-manager.coffee @@ -36,6 +36,8 @@ class MenuManager includeSelector: (selector) -> return true if document.body.webkitMatchesSelector(selector) + # Simulate an .editor element attached to a body element that has the same + # classes as the current body element. unless @testEditor? @testEditor = document.createElement('div') @testEditor.classList.add('editor') From 2f46fee1cad24c0c025a60db841bac8d1cf38a93 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 14:55:25 -0800 Subject: [PATCH 06/16] Use resource path from load settings --- spec/spec-helper.coffee | 8 ++++---- spec/spec-suite.coffee | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 3fcbf8263..65da40e5d 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -39,7 +39,9 @@ specPackageName = null specPackagePath = null specProjectPath = null -if specDirectory = atom.getLoadSettings().specDirectory +{specDirectory, resourcePath} = atom.getLoadSettings() + +if specDirectory specPackagePath = path.resolve(specDirectory, '..') try specPackageName = fs.readObjectSync(path.join(specPackagePath, 'package.json'))?.name @@ -68,9 +70,7 @@ beforeEach -> spyOn(atom.menu, 'sendToBrowserProcess') # reset config before each spec; don't load or save from/to `config.json` - config = new Config - resourcePath: window.resourcePath - configDirPath: atom.getConfigDirPath() + config = new Config({resourcePath, configDirPath: atom.getConfigDirPath()}) spyOn(config, 'load') spyOn(config, 'save') config.setDefaults('core', RootView.configDefaults) diff --git a/spec/spec-suite.coffee b/spec/spec-suite.coffee index 82dc95070..6beade358 100644 --- a/spec/spec-suite.coffee +++ b/spec/spec-suite.coffee @@ -23,9 +23,10 @@ setSpecDirectory = (specDirectory) -> setSpecField('specDirectory', specDirectory) runAllSpecs = -> + {resourcePath} = atom.getLoadSettings() # Only run core specs when resource path is the Atom repository - if Git.exists(window.resourcePath) - requireSpecs(path.join(window.resourcePath, 'spec')) + if Git.exists(resourcePath) + requireSpecs(path.join(resourcePath, 'spec')) setSpecType('core') fixturesPackagesPath = path.join(__dirname, 'fixtures', 'packages') @@ -34,7 +35,7 @@ runAllSpecs = -> packagePaths = _.groupBy packagePaths, (packagePath) -> if packagePath.indexOf("#{fixturesPackagesPath}#{path.sep}") is 0 'fixtures' - else if packagePath.indexOf("#{window.resourcePath}#{path.sep}") is 0 + else if packagePath.indexOf("#{resourcePath}#{path.sep}") is 0 'bundled' else 'user' From 87b530140bf65315493d4c15ace908523582987d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 14:59:53 -0800 Subject: [PATCH 07/16] Remove window.resourcePath --- src/window.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/window.coffee b/src/window.coffee index 014f745fa..e8f50d644 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -11,7 +11,6 @@ windowEventHandler = null # This method is called in any window needing a general environment, including specs window.setUpEnvironment = (windowMode) -> atom.windowMode = windowMode - window.resourcePath = atom.getLoadSettings().resourcePath atom.initialize() # Set up the default event handlers and menus for a non-editor windows. From dd9aa2d02fbac6775ff002a4c21079faac9a6dca Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 15:25:51 -0800 Subject: [PATCH 08/16] :lipstick: Remove extra space --- spec/spec-helper.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 65da40e5d..6181e9f7c 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -70,7 +70,7 @@ beforeEach -> spyOn(atom.menu, 'sendToBrowserProcess') # reset config before each spec; don't load or save from/to `config.json` - config = new Config({resourcePath, configDirPath: atom.getConfigDirPath()}) + config = new Config({resourcePath, configDirPath: atom.getConfigDirPath()}) spyOn(config, 'load') spyOn(config, 'save') config.setDefaults('core', RootView.configDefaults) From 5d717eb7bd51aebe62257a7eeccff49cf990c57a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 15:44:36 -0800 Subject: [PATCH 09/16] Load ~/.atom/user.js when available --- src/atom.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 39841c266..65a764747 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -307,11 +307,11 @@ class Atom @rootView.trigger 'beep' requireUserInitScript: -> - userInitScriptPath = path.join(@getConfigDirPath(), "user.coffee") - try - require userInitScriptPath if fs.isFileSync(userInitScriptPath) - catch error - console.error "Failed to load `#{userInitScriptPath}`", error.stack, error + if userInitScriptPath = fs.resolve(@getConfigDirPath(), 'user', ['js', 'coffee']) + try + require userInitScriptPath + catch error + console.error "Failed to load `#{userInitScriptPath}`", error.stack, error requireWithGlobals: (id, globals={}) -> existingGlobals = {} From 2a5f3937128cbdd9a85d7ac205ca669ea17fb7a0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 16:32:12 -0800 Subject: [PATCH 10/16] Use resource path from atom.getLoadSettings() --- src/window.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/window.coffee b/src/window.coffee index e8f50d644..2da308cfd 100644 --- a/src/window.coffee +++ b/src/window.coffee @@ -64,11 +64,13 @@ window.unloadEditorWindow = -> windowEventHandler?.unsubscribe() installAtomCommand = (callback) -> - commandPath = path.join(window.resourcePath, 'atom.sh') + {resourcePath} = atom.getLoadSettings() + commandPath = path.join(resourcePath, 'atom.sh') require('./command-installer').install(commandPath, callback) installApmCommand = (callback) -> - commandPath = path.join(window.resourcePath, 'node_modules', '.bin', 'apm') + {resourcePath} = atom.getLoadSettings() + commandPath = path.join(resourcePath, 'node_modules', '.bin', 'apm') require('./command-installer').install(commandPath, callback) window.deserializeEditorWindow = -> From e623ef4232fbfcc4512eda73efde764ed0cdaa33 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 16:56:24 -0800 Subject: [PATCH 11/16] Upgrade to exception-reporting@0.8.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0d26d3f31..406ac66d4 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "command-palette": "0.10.0", "dev-live-reload": "0.17.0", "editor-stats": "0.7.0", - "exception-reporting": "0.7.0", + "exception-reporting": "0.8.0", "find-and-replace": "0.48.0", "fuzzy-finder": "0.25.0", "gists": "0.9.0", From 3e7a517c2546ea456fa5549e88a293451dc355d1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 17:03:10 -0800 Subject: [PATCH 12/16] Add missing @ before lessCache lazy initialization --- src/theme-manager.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 67248e2a3..3e6f75d70 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -146,7 +146,7 @@ class ThemeManager # Internal-only: loadLessStylesheet: (lessStylesheetPath) -> - unless lessCache? + unless @lessCache? LessCompileCache = require './less-compile-cache' @lessCache = new LessCompileCache({@resourcePath}) From 7a6c75a83ea653a2a90e28af7cbb8c7db0284bf3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 21 Nov 2013 17:44:57 -0800 Subject: [PATCH 13/16] Refresh cache when core.themes changes Previously this wasn't needed because a new cache was created for each stylesheet loaded. --- src/less-compile-cache.coffee | 14 +++++++++----- src/theme-manager.coffee | 7 ++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/less-compile-cache.coffee b/src/less-compile-cache.coffee index ac965b4f5..935f53339 100644 --- a/src/less-compile-cache.coffee +++ b/src/less-compile-cache.coffee @@ -11,21 +11,25 @@ class LessCompileCache @cacheDir: path.join(tmpDir, 'atom-compile-cache', 'less') - constructor: ({resourcePath}) -> + constructor: ({resourcePath, importPaths}) -> @lessSearchPaths = [ path.join(resourcePath, 'static', 'variables') path.join(resourcePath, 'static') ] + if importPaths? + importPaths = importPaths.concat(@lessSearchPaths) + else + importPaths = @lessSearchPaths + @cache = new LessCache cacheDir: @constructor.cacheDir - importPaths: @getImportPaths() + importPaths: importPaths resourcePath: resourcePath fallbackDir: path.join(resourcePath, 'less-compile-cache') - @subscribe atom.themes, 'reloaded', => @cache.setImportPaths(@getImportPaths()) - - getImportPaths: -> atom.themes.getImportPaths().concat(@lessSearchPaths) + setImportPaths: (importPaths=[]) -> + @cache.setImportPaths(importPaths.concat(@lessSearchPaths)) read: (stylesheetPath) -> @cache.readFileSync(stylesheetPath) diff --git a/src/theme-manager.coffee b/src/theme-manager.coffee index 3e6f75d70..aedffae3a 100644 --- a/src/theme-manager.coffee +++ b/src/theme-manager.coffee @@ -56,6 +56,7 @@ class ThemeManager themeNames = _.clone(themeNames).reverse() @packageManager.activatePackage(themeName) for themeName in themeNames + @refreshLessCache() @loadUserStylesheet() @reloadBaseStylesheets() @emit('reloaded') @@ -66,6 +67,10 @@ class ThemeManager @packageManager.deactivatePackage(pack.name) for pack in @getActiveThemes() null + # Internal-only: + refreshLessCache: -> + @lessCache?.setImportPaths(@getImportPaths()) + # Public: Set the list of enabled themes. # # * enabledThemeNames: An {Array} of {String} theme names. @@ -148,7 +153,7 @@ class ThemeManager loadLessStylesheet: (lessStylesheetPath) -> unless @lessCache? LessCompileCache = require './less-compile-cache' - @lessCache = new LessCompileCache({@resourcePath}) + @lessCache = new LessCompileCache({@resourcePath, importPaths: @getImportPaths()}) try @lessCache.read(lessStylesheetPath) From ca8be839034c9204cdb7fbce95d8216c234bab0d Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Fri, 22 Nov 2013 09:46:59 -0500 Subject: [PATCH 14/16] Upgrade terminal@0.20.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 406ac66d4..918792322 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "styleguide": "0.15.0", "symbols-view": "0.24.0", "tabs": "0.11.0", - "terminal": "0.19.0", + "terminal": "0.20.0", "timecop": "0.10.0", "to-the-hubs": "0.13.0", "tree-view": "0.38.0", From 085806f97f51bcb020bb1a5d9a45d959a59c63db Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Fri, 22 Nov 2013 10:12:19 -0500 Subject: [PATCH 15/16] Upgrade terminal@0.21.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 918792322..7c103f9cf 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "styleguide": "0.15.0", "symbols-view": "0.24.0", "tabs": "0.11.0", - "terminal": "0.20.0", + "terminal": "0.21.0", "timecop": "0.10.0", "to-the-hubs": "0.13.0", "tree-view": "0.38.0", From 74decbd18a7a0ba3f4b2dae34158b9af1754aa3e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 22 Nov 2013 09:33:17 -0800 Subject: [PATCH 16/16] Upgrade to terminal@0.22.0 refs #1150 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7c103f9cf..dec13378a 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "styleguide": "0.15.0", "symbols-view": "0.24.0", "tabs": "0.11.0", - "terminal": "0.21.0", + "terminal": "0.22.0", "timecop": "0.10.0", "to-the-hubs": "0.13.0", "tree-view": "0.38.0",