Skip to content

Commit

Permalink
Hack for evaluating table queries: just eval the sheet a couple of times
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhanshuguptagit committed Mar 19, 2024
1 parent 2b5c850 commit 72e79c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/bean/grid.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,24 @@
(map deps/->cell-dep other-spillers))]
(reduce #(eval-dep %2 %1) sheet* deps-to-reval))))

;; Temporary hack until we figure out how to reval
;; table queries
(defn eval-sheet-a-few-times [sheet]
(let [addresses (->> (:grid sheet)
(util/map-on-matrix-addressed
(fn [address item]
(when (and (not= (:content item) "")
(not (nil? (:content item))))
address)))
(mapcat identity)
(remove nil?))]
(reduce
(fn [sheet* _] (reduce #(eval-cell %2 %1) sheet* addresses)) sheet (range 3))))

(defn update-cell [address sheet content]
(if (= (:content (util/get-cell (:grid sheet) address)) content "")
sheet
(eval-cell address (tables/expand-tables sheet address) content)))
(eval-sheet-a-few-times (eval-cell address (tables/expand-tables sheet address) content))))

(defn- merge-cell [sheet address merge-with]
(let [sheet* (if (not= merge-with address)
Expand Down
3 changes: 2 additions & 1 deletion src/bean/tables.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@
(if-let [at-end-of-table (some (fn [[table-name {:keys [start end]}]]
(when (and (= updated-r (inc (first end)))
(< updated-c (inc (second end)))
(> updated-c (second start)))
(>= updated-c (second start)))
table-name)) (:tables sheet))]

(let [[end-r end-c] (:end (get-table sheet at-end-of-table))]
(resize-table sheet at-end-of-table {:end [(inc end-r) end-c]}))
sheet))

0 comments on commit 72e79c4

Please sign in to comment.