|
2 | 2 | #_(:require [proton.core])
|
3 | 3 | (:require [cljs.reader :as reader]
|
4 | 4 | [cljs.nodejs :as node]
|
5 |
| - [clojure.string :as string :refer [upper-case join]] |
| 5 | + [clojure.string :as string :refer [upper-case join starts-with?]] |
6 | 6 | [proton.lib.mode :as mode-manager]
|
7 | 7 | [proton.lib.helpers :as helpers]
|
8 | 8 | [proton.lib.atom :as atom-env]
|
|
90 | 90 | ret-map (reduce #(assoc %1 %2 command) {} (map identity ret))]
|
91 | 91 | (atom-env/set-keymap! selector ret-map 100)))
|
92 | 92 |
|
| 93 | +(defn- vim-input? [provider] (some #{provider} [:vim-mode :vim-mode-plus])) |
| 94 | + |
| 95 | +(defn- configure-leader-keys [config-map] |
| 96 | + (let [vim-provider? (vim-input? (config-map "proton.core.inputProvider")) |
| 97 | + current-keys [(config-map "proton.core.leaderKey") (config-map "proton.core.modeKey")] |
| 98 | + vim-keys ["space" ","] |
| 99 | + non-vim-keys ["alt-m" "ctrl-alt-m"]] |
| 100 | + (cond |
| 101 | + (and vim-provider? (= non-vim-keys current-keys)) vim-keys |
| 102 | + (and (not vim-provider?) (= vim-keys current-keys)) non-vim-keys |
| 103 | + :else current-keys))) |
| 104 | + |
| 105 | +(defn- clear-conflicted-keystrokes! [keystrokes] |
| 106 | + (let [reg (re-pattern (str "^(" (join "|" keystrokes) ")"))] |
| 107 | + (set! (.-keyBindings atom-env/keymaps) |
| 108 | + (clj->js |
| 109 | + (filter |
| 110 | + #(not (and (re-find reg (.-keystrokes %)) (not (re-find (re-pattern "^proton:") (.-command %))))) |
| 111 | + (array-seq atom-env/keymaps.keyBindings)))))) |
| 112 | + |
93 | 113 | (defn init-proton-leader-keys! [configs]
|
94 | 114 | (let [config-map (into (hash-map) configs)
|
95 |
| - selectors ["body atom-workspace:not(.proton-mode) atom-text-editor:not([mini]):not(.insert-mode)" |
96 |
| - "body atom-workspace:not(.proton-mode) atom-panel-container.left" |
97 |
| - "body atom-workspace:not(.proton-mode) atom-panel-container.right" |
98 |
| - "body atom-workspace:not(.proton-mode) atom-panel-container.bottom" |
99 |
| - "atom-workspace:not(.proton-mode)"] |
| 115 | + vim-provider? (vim-input? (config-map "proton.core.inputProvider")) |
| 116 | + selectors (conj |
| 117 | + ["body atom-workspace:not(.proton-mode) atom-panel-container.left" |
| 118 | + "body atom-workspace:not(.proton-mode) atom-panel-container.right" |
| 119 | + "body atom-workspace:not(.proton-mode) atom-panel-container.bottom" |
| 120 | + "atom-workspace:not(.proton-mode)"] |
| 121 | + (if vim-provider? |
| 122 | + "body atom-workspace:not(.proton-mode) atom-text-editor:not([mini]):not(.insert-mode)" |
| 123 | + "body atom-workspace:not(.proton-mode) atom-text-editor:not([mini])")) |
100 | 124 | selector (string/join ", " selectors)
|
101 | 125 | leader-command "proton:toggle"
|
102 |
| - proton-leader-key "space" |
103 |
| - proton-mode-key (name (nth proton.core/mode-keys 1)) |
| 126 | + proton-keys (configure-leader-keys config-map) |
| 127 | + proton-leader-key (proton-keys 0) |
| 128 | + proton-mode-key (proton-keys 1) |
104 | 129 | mode-command "proton:toggleMode"
|
105 | 130 | keymap (hash-map proton-leader-key leader-command proton-mode-key mode-command)]
|
| 131 | + (when (not vim-provider?) |
| 132 | + (clear-conflicted-keystrokes! [proton-leader-key proton-mode-key])) |
106 | 133 | (atom-env/set-keymap! selector keymap 100)))
|
| 134 | + |
| 135 | +(defn show-deprecated-configs [configs] |
| 136 | + (let [config-map (into (hash-map) configs)] |
| 137 | + (when (config-map "proton.core.vim-provider") |
| 138 | + (.addInfo atom-env/notifications "proton-mode: deprecated config <strong>proton.core.vim-provider</strong>" |
| 139 | + (clj->js {:detail "Please use proton.core.inputProvider" |
| 140 | + :dismissable true}))))) |
0 commit comments