Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pane focus specific keybindings. refs #65 #72

Merged
merged 1 commit into from
Dec 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this to be its own function, or could we jsut use panes/focus-on-item in place of select-window-fn in the keybindings map?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

:fx should be a function, so I wrap panes/focus-on-item into function that returns function + window number as argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't panes/focus-on-item a function though?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh I see it. Nevermind. Haha sorry for being slow here

(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)))))))