Created
April 24, 2024 15:04
-
-
Save LouDnl/29911e3f53a93bdbc17834fa2587705a to your computer and use it in GitHub Desktop.
adapted version of ignore_form.cljs for Joyride
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn get-position | |
[movement | |
& {:keys [steps] :or {steps 2}}] | |
(p/let [editor ^js vscode/window.activeTextEditor | |
_ (vscode/commands.executeCommand movement) | |
insert-position (.-active (eu/current-selection)) | |
insert-position-2 (.with insert-position (.-line insert-position) (max 0 (- (.-character insert-position) steps))) | |
range-before-insert-position (.with (eu/current-selection) insert-position-2 insert-position) | |
text-before-insert-position (.getText (.-document editor) range-before-insert-position) | |
position-after (.with insert-position (.-line insert-position) (max 0 (+ (.-character insert-position) 1))) | |
position-after-extended (.with insert-position (.-line insert-position) (max 0 (+ (.-character insert-position) 4))) | |
range-after (.with (eu/current-selection) insert-position position-after) | |
range-after-extended (.with (eu/current-selection) insert-position position-after-extended) | |
char-after (when-let [r (.getText (.-document editor) range-after)] | |
(if (or (= r "t") (= r "f")) | |
(.getText (.-document editor) range-after-extended) | |
r))] | |
(cond | |
(some #{text-before-insert-position} [" \"" "_\""]) | |
(get-position "paredit.backwardUpSexp") | |
(not-any? #{char-after} ["\"" "[" "{" "(" ":" "true" "fals"]) | |
(get-position "paredit.backwardSexpOrUp" #_{:steps 1}) | |
:else | |
[insert-position | |
range-before-insert-position | |
text-before-insert-position]))) | |
(defn main | |
[] | |
(p/let [editor ^js vscode/window.activeTextEditor | |
original-selection (eu/current-selection) | |
[insert-position | |
range-before-insert-position | |
text-before-insert-position] | |
(get-position "paredit.backwardSexpOrUp")] | |
(aset editor "selection" original-selection) | |
(if (= "#_" text-before-insert-position) | |
(p/do! (eu/delete-range! editor range-before-insert-position)) | |
(p/do! (eu/insert-text!+ "#_" editor insert-position))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment