diff --git a/lib/keymaps/autocomplete-xml.cson b/lib/keymaps/autocomplete-xml.cson new file mode 100644 index 0000000..26e8020 --- /dev/null +++ b/lib/keymaps/autocomplete-xml.cson @@ -0,0 +1,11 @@ +# Keybindings require three things to be fully defined: A selector that is +# matched against the focused element, the keystroke and the command to +# execute. +# +# Below is a basic keybinding which registers on all platforms by applying to +# the root workspace element. + +# For more detailed documentation see +# https://atom.io/docs/latest/behind-atom-keymaps-in-depth +'atom-workspace': + 'ctrl-alt-c': 'main:copyXpathToClipboard' diff --git a/lib/main.coffee b/lib/main.coffee index 95c1c08..3ceb550 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -1,4 +1,6 @@ provider = require './provider' +utils = require './xml-utils' +{CompositeDisposable} = require 'atom' module.exports = xpathView: null @@ -18,6 +20,13 @@ module.exports = getProvider: -> provider + activate: (state) -> + # Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable + @subscriptions = new CompositeDisposable + # Register command that toggles this view + @subscriptions.add atom.commands.add 'atom-workspace', 'main:copyXpathToClipboard': => @copyXpathToClipboard() + @subscriptions.dispose() + deactivate: -> @xpathView?.destroy() @xpathView = null @@ -26,3 +35,11 @@ module.exports = XPathStatusBarView = require './xpath-statusbar-view' @xpathView = new XPathStatusBarView().initialize(statusBar) @xpathView.attach() + + copyXpathToClipboard: -> + editor = atom.workspace.getActiveTextEditor() + if editor + buffer = editor.getBuffer() + bufferPosition = editor.getCursorBufferPosition() + xpath = utils.getXPath buffer, bufferPosition, '' + atom.clipboard.write(xpath.join '/')