          (* (- adjusted-doc-y mouse-down-y) zoom-factor))))
 
   (when (= paint-tool :selection)
-    (let [user-is-moving-selection (om/get-state owner :user-is-moving-selection)]
+    (let [user-is-moving-selection (om/get-state owner :user-is-moving-selection)
+          selection-was-pasted (om/get-state owner :selection-was-pasted)]
       (when (not user-is-moving-selection)
         (clear-preview-canvas)
         (set! (.-fillStyle preview-context) "rgba(127,127,127,0.3)")

              [x1 y1 x2 y2] (om/get-state owner :selection)
              paste-x (- doc-x xOff)
              paste-y (- doc-y yOff)
              backfill (create-sub-image-for-rect (om/get-state owner :selection)
                                                  (get-in @app [:tools :paint-color]))]
        (paste-image app owner x1 y1 backfill)
        (paste-image app owner paste-x paste-y (om/get-state owner :selection-image)))
        (clear-selection-state owner)
        (om/transact! app

  (om/set-state! owner :selection [0 0 0 0])
  (om/set-state! owner :mouse-offset-in-selection [0 0])
  (om/set-state! owner :selection-image {})
  (om/set-state! owner :user-is-moving-selection false)
  (om/set-state! owner :selection-was-pasted false))


(defn make-selection [app owner doc-x doc-y doc-width]
  (let [[orig-x orig-y] (get-in @guistate/transient-state [:mouse-down-pos])
        selection-rect (geometry/normalize-rect orig-x orig-y doc-x doc-y)
        main-image (canvas/get-current-pixels @app)]
    (clear-selection-state owner)
    (om/set-state! owner :selection selection-rect)
    (om/set-state! owner :selection-image (clip-sub-image main-image selection-rect doc-width))))

