Skip to content

Commit

Permalink
Merge pull request #72 from geksilla/feature/pane-focus-keybindings
Browse files Browse the repository at this point in the history
Added pane focus specific keybindings. refs #65
  • Loading branch information
dvcrn committed Dec 23, 2015
2 parents 6ff9391 + 1344241 commit 8577585
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugin/styles/proton.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


.proton-which-key {
font-size: 15px;
font-size: 13px;
font-family: Courier New;
}

Expand Down
25 changes: 23 additions & 2 deletions src/cljs/proton/layers/core/keybindings.cljs
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
(ns proton.layers.core.keybindings
(:require [proton.layers.core.actions :as actions :refer [state]]
[proton.lib.pane_manager :as panes]
[proton.lib.proton :as proton]))

(defn select-window-fn [n]
(fn []
(panes/focus-on-item n)))

(def keybindings
(atom { :0 {:action "tree-view:toggle-focus"
:title "focus tree-view"}
(atom { :0 {:fx (select-window-fn 0)
:title "window 0"}
:1 {:fx (select-window-fn 1)
:title "window 1"}
:2 {:fx (select-window-fn 2)
:title "window 2"}
:3 {:fx (select-window-fn 3)
:title "window 3"}
:5 {:fx (select-window-fn 4)
:title "window 4"}
:6 {:fx (select-window-fn 6)
:title "window 6"}
:7 {:fx (select-window-fn 7)
:title "window 7"}
:8 {:fx (select-window-fn 8)
:title "window 8"}
:9 {:fx (select-window-fn 9)
:title "window 9"}
:j {:action "window:focus-pane-below"
:target actions/get-active-pane
:title "focus below pane"}
Expand Down
30 changes: 30 additions & 0 deletions src/cljs/proton/lib/pane_manager.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns proton.lib.pane_manager)

(defn get-panes []
"Returns list of panes."
(.getPanes js/atom.workspace))

(defn get-panels
"Returns list of panels by location.
Possible locations: left, right, top, bottom, modal"
[location]
(seq (.getPanels js/atom.workspace location)))

(defn focus-on-panel [panel]
(if-let [item (.getItem panel)]
(.focus item)))

(defn focus-on-pane [pane]
(when-not (nil? pane)
(.activate pane)))

(defn focus-on-item [n]
(let [panels-left (get-panels "left")
panels-left-count (count panels-left)
panels-right (get-panels "right")
panels-right-count (count panels-right)
panes (get-panes)
panes-count (count panes)]
(cond (> panels-left-count n) (focus-on-panel (nth panels-left n))
(> (+ panels-left-count panes-count) n) (focus-on-pane (nth panes (- n panels-left-count)))
(> (+ panels-right-count panels-left-count panes-count) n) (focus-on-panel (nth panels-right (- n (+ panes-count panels-left-count)))))))

0 comments on commit 8577585

Please sign in to comment.