Forráskód Böngészése

fixed the bug where enter was moving back to the first cell prematurely

Brandon Wong 1 éve%!(EXTRA string=óta)
szülő
commit
187a8e46f4

+ 6 - 0
frontend/src/cljs/microtables_frontend/db.cljs

@@ -1,5 +1,11 @@
 (ns microtables-frontend.db)
 
+(def min-max-row
+  20)
+
+(def min-max-col
+  "G")
+
 (def default-db
   {:controls nil
    ;TODO: add "start" and "end" corners as selection

+ 8 - 2
frontend/src/cljs/microtables_frontend/events.cljs

@@ -45,11 +45,17 @@
 
 ; handle pressing enter (move to the next cell down)
 ; tab is taken care of natively, and is good enough
+;TODO: keyboard movement should determine the size of the table, not the other way around
+;      - highest-row/col should include the position of the in-focus cell
+;      - this function should merely increment the position
+;      - add a new function for tab handling (native isn't good enough anymore)
+;TODO: handle movement within a range selection
+;TODO: handle movement with arrow keys
 (re-frame/reg-event-fx
  ::press-enter-in-cell
  (fn [{:keys [db]} [_ c r]]
-   (let [max-row? (= (coords/highest-row (:table-data db)) r)
-         max-col? (= (coords/highest-col (:table-data db)) c)
+   (let [max-row? (= (coords/highest-row db) r)
+         max-col? (= (coords/highest-col db) c)
          new-col (if max-row?
                    (if max-col?
                      "A"

+ 11 - 5
frontend/src/cljs/microtables_frontend/utils/coordinates.cljs

@@ -1,24 +1,30 @@
-(ns microtables-frontend.utils.coordinates)
+(ns microtables-frontend.utils.coordinates
+  (:require
+   [microtables-frontend.db :as db]))
 
 (defn highest-col
   "Return the highest column (letter) for which there is a non-empty cell"
-  [data]
+  [db]
   ; choose the "max" (alphabetical order) value among the longest keys
-  (->> data
+  (->> db
+       :table-data
        keys
        (group-by #(.-length %))
        (apply max-key key)
        val
+       (concat [db/min-max-col])
        (apply max)))
 
 (defn highest-row
   "Return the highest row (number) for which there is a non-empty cell"
-  [data]
+  [db]
   ; get all the row keys from all the column objects (and flatten), then pick the max
-  (->> data
+  (->> db
+       :table-data
        vals
        (map keys)
        flatten
+       (concat [db/min-max-row])
        (apply max)))
 
 (defn- increment-letter-code [s]

+ 2 - 2
frontend/src/cljs/microtables_frontend/views/sheet.cljs

@@ -36,8 +36,8 @@
    [:tbody
     ;TODO: figure out appropriate starting values for maxrow and maxcol (maybe keep them intentionally small)
     ;TODO: figure out movement (maybe allow scroll overflow)
-    (let [maxrow 50;(coords/highest-row data)
-          maxcol "Z";(coords/highest-col data)
+    (let [maxrow 20;(coords/highest-row data)
+          maxcol "G";(coords/highest-col data)
           cols (take-while (partial not= (coords/next-letter maxcol)) coords/col-letters)]
       (cons
        (header-row cols)