diff --git a/src/bean/functions.cljs b/src/bean/functions.cljs index e615c1e..0d03d1b 100644 --- a/src/bean/functions.cljs +++ b/src/bean/functions.cljs @@ -40,7 +40,7 @@ (remove #(every? nil? %) matrix)) (defn minimum-matrix [matrix] - (if (not (first (first matrix))) + (if (zero? (count (first matrix))) [[nil]] matrix)) @@ -124,7 +124,13 @@ new-selection (->> (util/map-on-matrix - #(get first-match (:representation (util/get-cell (:grid sheet) %))) + #(let [value (:representation (util/get-cell (:grid sheet) %))] + (if (empty? value) + ;; Hack for null references cells (to make it work like a left join) + ;; return a null cell + ;; but this breaks the renderer etc so we'll fix this later + [79 15] + (get first-match value))) (:selection from-frame)) remove-nil-columns remove-nil-rows)] @@ -147,7 +153,11 @@ (and (contains? (:skips frame-result) %) (contains? (:skips label-cells) %))) %)) remove-nil-columns - remove-nil-rows)] + remove-nil-rows + ;; Hack for null references cells + ;; these come from top left labels + (util/map-on-matrix + #(if-not % [79 15] %)))] {:matrix (address-matrix->cells-matrix sheet (minimum-matrix new-selection)) :frame (merge frame-result {:selection new-selection})}) (errors/label-not-found diff --git a/src/bean/grid.cljs b/src/bean/grid.cljs index 1a58325..96a848f 100644 --- a/src/bean/grid.cljs +++ b/src/bean/grid.cljs @@ -307,7 +307,7 @@ (let [existing-cell (util/get-cell (:grid sheet*) address) new-cell (-> existing-cell (assoc :content (:content attrs)) - (assoc :style (merge (:style existing-cell) (:style attrs)))) + (assoc :style (:style attrs))) new-sheet (eval-cell address sheet* new-cell true)] (if (:merge-until attrs) (merge-cells new-sheet @@ -387,7 +387,7 @@ (defn clear-area [sheet {:keys [start end]}] (->> (util/addresses-matrix start end) (mapcat identity) - (map #(do [% {:content ""}])) + (map #(do [% {:content "" :style {}}])) (into {}) (update-cells-bulk sheet start))) diff --git a/src/bean/ui/db.cljs b/src/bean/ui/db.cljs index 7788a28..7347967 100644 --- a/src/bean/ui/db.cljs +++ b/src/bean/ui/db.cljs @@ -55,7 +55,8 @@ average:{x.sum() / x.count()}")) (assoc :grid-dimensions {:num-rows num-rows :num-cols num-cols :row-heights (vec (repeat num-rows (:cell-h styles/sizes))) - :col-widths (vec (repeat num-cols (:cell-w styles/sizes)))})) + :col-widths (vec (repeat num-cols (:cell-w styles/sizes)))}) + (assoc :frames {})) :ui {:help-display false :grid {:editing-cell nil :selection nil diff --git a/src/bean/ui/events.cljs b/src/bean/ui/events.cljs index e7b0e2b..40f3f03 100644 --- a/src/bean/ui/events.cljs +++ b/src/bean/ui/events.cljs @@ -10,7 +10,8 @@ [bean.ui.util :as util] [day8.re-frame.undo :as undo :refer [undoable]] [re-frame.core :as rf] - [reagent.core :as rc])) + [reagent.core :as rc] + [bean.area :as area])) (rf/reg-event-db ::initialize-db @@ -51,6 +52,13 @@ (fn clear-area [db [_ area]] (update-in db [:sheet] #(grid/clear-area % area)))) +(rf/reg-event-fx + ::save-to-slot + ;; for repl usage only + (fn set-demo [{:keys [db]} [_ frame-name]] + {:db (assoc-in db [:ui :current-demo-name] frame-name) + :fx [[:dispatch [::export-demos]]]})) + (rf/reg-event-fx ::export-demos (fn [{:keys [db]} [_]] @@ -254,12 +262,6 @@ (fn [db [_]] (assoc-in db [:ui :grid :selection] nil))) -(rf/reg-event-fx - ::select-frame - (fn select-frame [{:keys [db]} [_ frame-name]] - (let [{:keys [start]} (get-in db [:sheet :frames frame-name])] - (when start {:fx [[:dispatch [::edit-cell start]]]})))) - (rf/reg-event-fx ::make-frame (undoable) @@ -285,7 +287,6 @@ (rf/reg-event-db ::highlight-matrix - (undoable) (fn highlight-matrix [db [_ content]] (assoc-in db [:ui :grid :highlighted-cells] (set (mapcat identity (get-in diff --git a/src/bean/ui/paste.cljs b/src/bean/ui/paste.cljs index aa714c4..b384996 100644 --- a/src/bean/ui/paste.cljs +++ b/src/bean/ui/paste.cljs @@ -70,7 +70,7 @@ [(when (get-in cell [:style :bold]) "font-weight: bold") (when-let [bg (get-in cell [:style :background])] - (str "background: " (util/color-int->hex bg)))])} + (str "background: " (.toString bg 16)))])} (when mc {:colspan (str (inc (- mc c)))}) (when mr {:rowspan (str (inc (- mr r)))})) (:representation cell)])))