diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index db9d8062e9..a4a0f34827 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -2869,6 +2869,16 @@ (on-tab direction))) nil)) +(defn- double-chars-typed? + [value pos key sym] + (and (= key sym) + (>= (count value) 1) + (> pos 0) + (= (nth value (dec pos)) sym) + (if (> (count value) pos) + (not= (nth value pos) sym) + true))) + (defn ^:large-vars/cleanup-todo keydown-not-matched-handler "NOTE: Keydown cannot be used on Android platform" [format] @@ -2941,8 +2951,8 @@ (do (util/stop e) (autopair input-id "(" format nil)) - ;; If you type `xyz`, the last backtick should close the first and not add another autopair - ;; If you type several backticks in a row, each one should autopair to accommodate multiline code (```) + ;; If you type `xyz`, the last backtick should close the first and not add another autopair + ;; If you type several backticks in a row, each one should autopair to accommodate multiline code (```) (-> (keys autopair-map) set (disj "(") @@ -2955,24 +2965,17 @@ (cursor/move-cursor-forward input) (autopair input-id key format nil))) + ; `;;` to add or change property for db graphs + (let [sym ";"] + (and (config/db-based-graph? (state/get-current-repo)) (double-chars-typed? value pos key sym))) + (state/pub-event! [:editor/new-property]) + (let [sym "$"] - (and (= key sym) - (>= (count value) 1) - (> pos 0) - (= (nth value (dec pos)) sym) - (if (> (count value) pos) - (not= (nth value pos) sym) - true))) + (double-chars-typed? value pos key sym)) (commands/simple-insert! input-id "$$" {:backward-pos 2}) (let [sym "^"] - (and (= key sym) - (>= (count value) 1) - (> pos 0) - (= (nth value (dec pos)) sym) - (if (> (count value) pos) - (not= (nth value pos) sym) - true))) + (double-chars-typed? value pos key sym)) (commands/simple-insert! input-id "^^" {:backward-pos 2}) :else diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 9e38a3c686..f20cc152e3 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -76,6 +76,7 @@ [frontend.util.persist-var :as persist-var] [goog.dom :as gdom] [logseq.common.config :as common-config] + [logseq.common.util :as common-util] [promesa.core :as p] [lambdaisland.glogi :as log] [rum.core :as rum] @@ -981,20 +982,35 @@ (fn [{:keys [editing-default-property?]}] (when (and (not (state/editing?)) editing-block (not editing-default-property?)) - (editor-handler/edit-block! editing-block (or pos :max))))))] + (let [content (:block/content (db/entity (:db/id editing-block))) + [content' pos] (if (and (>= (count content) pos) + (>= pos 2) + (= (util/nth-safe content (dec pos)) + (util/nth-safe content (- pos 2)) + ";")) + [(str (common-util/safe-subs content 0 (- pos 2)) + (common-util/safe-subs content pos)) + (- pos 2)] + [nil pos])] + ;; FIXME: Still allow input `;;` + ;; `ESC` shouldn't clear `;;` + (editor-handler/edit-block! editing-block (or pos :max) + (cond-> {} + content' + (assoc :custom-content content'))))))))] (when (seq blocks) (let [input (some-> (state/get-edit-input-id) (gdom/getElement))] (if input (shui/popup-show! input - #(property-dialog/dialog blocks opts') - {:align "start" - :as-dropdown? true - :auto-focus? true}) + #(property-dialog/dialog blocks opts') + {:align "start" + :as-dropdown? true + :auto-focus? true}) (shui/dialog-open! #(property-dialog/dialog blocks opts') - {:id :property-dialog - :align "start" - :content-props {:onOpenAutoFocus #(.preventDefault %)}}))))))) + {:id :property-dialog + :align "start" + :content-props {:onOpenAutoFocus #(.preventDefault %)}}))))))) (rum/defc multi-tabs-dialog []