enhance(dwim): re-number its items when dwim in an ordered list (#3358)

* enhance(dwim): re-number list if dwim in ordered list

* fix: regexp for matching a list item

* enhance: don't enable dwim in list if cursor is at beginning of item

Co-authored-by: leizhe <leizhe@leizhedeMacBook-Air.local>
This commit is contained in:
llcc
2021-12-16 20:30:30 +08:00
committed by GitHub
parent f94e01dc27
commit a8c9daad07
3 changed files with 54 additions and 16 deletions

View File

@@ -0,0 +1,20 @@
(ns frontend.util.list
(:require [frontend.util.thingatpt :as thingatpt]
[frontend.util.cursor :as cursor]))
(defn- get-prev-item [& [input]]
(when-let [item (thingatpt/list-item-at-point input)]
(let [{:keys [bullet ordered]} item]
(when-not (or (cursor/textarea-cursor-first-row? input)
(and ordered
(= bullet "1")))
(cursor/move-cursor-up input)
(thingatpt/list-item-at-point input)))))
(defn- get-next-item [& [input]]
(when-let [item (thingatpt/list-item-at-point input)]
(let [{:keys [_bullet _ordered]} item]
(when-not (cursor/textarea-cursor-last-row? input)
(cursor/move-cursor-down input)
(thingatpt/list-item-at-point input)))))