-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to position items by arrow keys
Also, fixed a possible bug - when you move/delete selected items, and then make undo, we didn't recalculate the new selection
- Loading branch information
Showing
13 changed files
with
182 additions
and
108 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(ns tixi.mutators.copy-paste | ||
(:require [tixi.data :as d] | ||
[tixi.items :as i] | ||
[tixi.geometry :as g] | ||
[tixi.mutators :as m] | ||
[tixi.mutators.shared :as msh] | ||
[tixi.mutators.selection :as ms] | ||
[tixi.mutators.render :as mr] | ||
[tixi.mutators.locks :as ml] | ||
[tixi.mutators.delete :as md] | ||
[tixi.utils :refer [p]])) | ||
|
||
(defn copy! [] | ||
(let [items (d/selected-items)] | ||
(when (not-empty items) | ||
(swap! d/data assoc :clipboard items)))) | ||
|
||
(defn cut! [] | ||
(let [ids (d/selected-ids)] | ||
(copy!) | ||
(ms/select-layer! nil) | ||
(md/delete-items! ids))) | ||
|
||
(defn paste! [] | ||
(msh/snapshot!) | ||
(ms/select-layer! nil) | ||
(doseq [item (d/clipboard)] | ||
(let [id (d/autoincrement)] | ||
(msh/autoincrement!) | ||
(msh/update-state! assoc-in [:completed id] (update-in item [:input] g/move (g/build-size 1 1))) | ||
(mr/render-items!) | ||
(let [new-item (d/completed-item id)] | ||
(when (i/connector? new-item) | ||
(ml/try-to-lock! new-item id :start (-> new-item :input :start)) | ||
(ml/try-to-lock! new-item id :end (-> new-item :input :end))) | ||
(ms/select-layer! id nil true))))) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
(ns test.tixi.mutators.copy-paste | ||
(:require-macros [cemerick.cljs.test :refer (is deftest use-fixtures)] | ||
[tixi.utils :refer (b)]) | ||
(:require [cemerick.cljs.test :as test] | ||
[tixi.geometry :as g] | ||
[tixi.mutators :as m] | ||
[tixi.mutators.copy-paste :as mcp] | ||
[tixi.mutators.selection :as ms] | ||
[tixi.mutators.undo :as mu] | ||
[test.tixi.utils :refer [create-layer! create-sample-layer! create-locked-layers! item-with-input]] | ||
[tixi.utils :refer [p]] | ||
[tixi.data :as d])) | ||
|
||
(defn- setup [f] | ||
(m/reset-data!) | ||
(f)) | ||
|
||
(use-fixtures :each setup) | ||
|
||
(deftest copy-paste | ||
(let [id1 (create-layer! (g/build-rect 0 0 4 4)) | ||
id2 (create-layer! (g/build-rect 5 5 8 8)) | ||
id3 (create-layer! (g/build-rect 10 10 15 15))] | ||
(ms/select-layer! id2) | ||
(ms/select-layer! id3 nil true) | ||
(mcp/copy!) | ||
(mcp/paste!) | ||
(is (= (count (d/completed)) 5)) | ||
(is (not= (item-with-input (g/build-rect 6 6 9 9)) nil)) | ||
(is (not= (item-with-input (g/build-rect 11 11 16 16)) nil)) | ||
(let [id4 (first (item-with-input (g/build-rect 6 6 9 9))) | ||
id5 (first (item-with-input (g/build-rect 11 11 16 16)))] | ||
(is (= (d/selected-ids) #{id4 id5}))))) | ||
|
||
(deftest cut-paste | ||
(let [id1 (create-layer! (g/build-rect 0 0 4 4))] | ||
(ms/select-layer! id1) | ||
(mcp/cut!) | ||
(mcp/paste!) | ||
(is (= (count (d/completed)) 1)) | ||
(is (= (item-with-input (g/build-rect 0 0 4 4)) nil)) | ||
(is (not= (item-with-input (g/build-rect 1 1 5 5)) nil)))) | ||
|
||
(deftest copy-paste-undo | ||
(let [id1 (create-layer! (g/build-rect 0 0 4 4))] | ||
(ms/select-layer! id1) | ||
(mcp/copy!) | ||
(mcp/paste!) | ||
(mu/undo!) | ||
(is (= (keys (d/completed)) [id1])))) | ||
|
||
(deftest copy-paste-locked-items | ||
(let [[id1 id2 id3] (create-locked-layers!)] | ||
(ms/select-layer! id1) | ||
(ms/select-layer! id2 nil true) | ||
(mcp/copy!) | ||
(mcp/paste!) | ||
(let [new-rect-id (first (item-with-input (g/build-rect 6 6 16 16))) | ||
new-connector-id (first (item-with-input (g/build-rect 3 3 6 6)))] | ||
(ms/select-layer! nil) | ||
(ms/select-layer! new-rect-id) | ||
(ms/move-selection! (g/build-size 4 4)) | ||
(is (= (:input (d/completed-item new-connector-id)) (g/build-rect 3 3 10 10)))))) | ||
|
Oops, something went wrong.