Skip to content

Commit

Permalink
Merge pull request pleonex#22 from easycheese/master
Browse files Browse the repository at this point in the history
Added hotkey for copying xPath
Fix pleonex#19
  • Loading branch information
pleonex committed Jun 3, 2016
2 parents 319fa18 + 5e98a6f commit 426ce1d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/keymaps/autocomplete-xml.cson
Original file line number Diff line number Diff line change
@@ -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'
17 changes: 17 additions & 0 deletions lib/main.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
provider = require './provider'
utils = require './xml-utils'
{CompositeDisposable} = require 'atom'

module.exports =
xpathView: null
Expand All @@ -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
Expand All @@ -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 '/')

0 comments on commit 426ce1d

Please sign in to comment.