Skip to content
This repository has been archived by the owner on Jun 29, 2019. It is now read-only.

add command to run previously run editor #119

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions keymaps/atom-runner.cson
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
'.platform-darwin atom-text-editor':
'ctrl-r': 'run:file'
'ctrl-shift-r': 'run:selection'
'ctrl-q': 'run:prev'

'.platform-win32 atom-text-editor, .platform-linux atom-text-editor':
'alt-r': 'run:file'
'alt-shift-r': 'run:selection'
'alt-q': 'run:prev'

'.platform-darwin .atom-runner':
'cmd-c': 'run:copy'
Expand Down
7 changes: 6 additions & 1 deletion lib/atom-runner.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AtomRunner

extensionMap: null
scopeMap: null
prev: null

debug: (args...) ->
console.debug('[atom-runner]', args...)
Expand Down Expand Up @@ -70,11 +71,13 @@ class AtomRunner
atom.commands.add 'atom-workspace', 'run:selection', => @run(true)
atom.commands.add 'atom-workspace', 'run:stop', => @stop()
atom.commands.add 'atom-workspace', 'run:close', => @stopAndClose()
atom.commands.add 'atom-workspace', 'run:prev', => @run(false, true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the previous run was a run:selection? The implementation should be robust enough to support any previous execution.

atom.commands.add '.atom-runner', 'run:copy', =>
atom.clipboard.write(window.getSelection().toString())

run: (selection) ->
run: (selection, rerun=false) ->
editor = atom.workspace.getActiveTextEditor()
editor = @prev if rerun
return unless editor?

path = editor.getPath()
Expand Down Expand Up @@ -105,6 +108,8 @@ class AtomRunner
view.setTitle(editor.getTitle())
pane.activateItem(view)

@prev = editor

@execute(cmd, editor, view, selection)

stop: (view) ->
Expand Down