     (clear-preview-canvas)
     (set! (.-fillStyle preview-context) preview-color)
     (let [line-coords (bresenham/bresenham mouse-down-x mouse-down-y doc-x doc-y)]
-      (paint-pixels-for-pencil-tool line-coords pixel-size)))
+      (paint-pixels-for-pencil-tool line-coords pixel-size doc-canvas-width)))
 
   (when (= paint-tool :box)
     (set! (.-width preview-canvas-elem) (.-width preview-canvas-elem))

        flat-coords (vec (map #(geometry/flatten-point-to-index % doc-width) coords))]
    (reset! visited-pixels (vec (concat @visited-pixels flat-coords)))))

(defn paint-pixel [coord pixel-size]
  (let [[x y] coord
        preview-context (.getContext preview-canvas-elem "2d")]
    (.fillRect preview-context
               (* x pixel-size)
               (* y pixel-size)
               pixel-size pixel-size)))

(defn paint-pixels-for-pencil-tool [coords pixel-size]
  (dorun (map #(paint-pixel % pixel-size) coords)))


;; =============================================================================

  (when (= paint-tool :brush)
    (let [active-pixels-since-last-event (bresenham/bresenham doc-x doc-y last-x last-y)]
      (set! (.-fillStyle preview-context) preview-color)
      (paint-pixels-for-pencil-tool active-pixels-since-last-event pixel-size doc-canvas-width)
      (visit-pixels-for-line-segment doc-x doc-y last-x last-y doc-canvas-width)
      (reset! guistate/transient-state
              (assoc @guistate/transient-state :last-mouse-pos [doc-x doc-y]))))
