|
41 | 41 | [frontend.template :as template] |
42 | 42 | [frontend.util :as util] |
43 | 43 | [frontend.util.cursor :as cursor] |
44 | | - [frontend.util.file-based.drawer :as drawer] |
45 | 44 | [frontend.util.keycode :as keycode] |
46 | 45 | [frontend.util.list :as list] |
47 | 46 | [frontend.util.ref :as ref] |
|
66 | 65 | [logseq.graph-parser.block :as gp-block] |
67 | 66 | [logseq.graph-parser.mldoc :as gp-mldoc] |
68 | 67 | [logseq.graph-parser.property :as gp-property] |
69 | | - [logseq.graph-parser.text :as text] |
70 | 68 | [logseq.graph-parser.utf8 :as utf8] |
71 | 69 | [logseq.outliner.core :as outliner-core] |
72 | 70 | [logseq.outliner.property :as outliner-property] |
|
287 | 285 | ([block value |
288 | 286 | {:keys [force?] |
289 | 287 | :as opts}] |
290 | | - (let [{:block/keys [uuid format repo title]} block |
291 | | - format (or format :markdown) |
| 288 | + (let [{:block/keys [uuid format repo]} block |
292 | 289 | repo (or repo (state/get-current-repo)) |
293 | | - format (or format (state/get-preferred-format)) |
294 | 290 | block-id (let [properties (:block/properties block)] |
295 | 291 | (when (and (not (config/db-based-graph? repo)) (map? properties)) |
296 | 292 | (get properties :id))) |
297 | | - content (if (config/db-based-graph? repo) |
298 | | - (:block/title (db/entity (:db/id block))) |
299 | | - (-> (property-file/remove-built-in-properties-when-file-based repo format title) |
300 | | - (drawer/remove-logbook)))] |
| 293 | + content (:block/title (db/entity (:db/id block)))] |
301 | 294 | (cond |
302 | 295 | (another-block-with-same-id-exists? uuid block-id) |
303 | 296 | (notification/show! |
|
710 | 703 | (when-let [edit-block (state/get-edit-block)] |
711 | 704 | (let [edit-input-id (state/get-edit-input-id) |
712 | 705 | current-input (gdom/getElement edit-input-id)] |
713 | | - (if (config/db-based-graph? (state/get-current-repo)) |
714 | | - (when-let [block (db/entity (:db/id edit-block))] |
715 | | - (let [pos (state/get-edit-pos)] |
716 | | - (p/do! |
717 | | - (ui-outliner-tx/transact! |
718 | | - {:outliner-op :cycle-todos} |
719 | | - (db-based-cycle-todo! block)) |
720 | | - |
721 | | - ;; FIXME: don't change current editor's position |
722 | | - ))) |
723 | | - (let [content (state/get-edit-content) |
724 | | - format (or (db/get-page-format (state/get-current-page)) |
725 | | - (state/get-preferred-format)) |
726 | | - [new-content marker] (status/cycle-marker content nil nil format (state/get-preferred-workflow)) |
727 | | - new-pos (commands/compute-pos-delta-when-change-marker |
728 | | - content marker (cursor/pos current-input))] |
729 | | - (state/set-edit-content! edit-input-id new-content) |
730 | | - (cursor/move-cursor-to current-input new-pos)))))))) |
731 | | - |
732 | | -(defn set-priority |
733 | | - [{:block/keys [priority title] :as block} new-priority] |
734 | | - (when-not (config/db-based-graph? (state/get-current-repo)) |
735 | | - (let [new-content (string/replace-first title |
736 | | - (util/format "[#%s]" priority) |
737 | | - (util/format "[#%s]" new-priority))] |
738 | | - (save-block-if-changed! block new-content)))) |
| 706 | + (when-let [block (db/entity (:db/id edit-block))] |
| 707 | + (let [pos (state/get-edit-pos)] |
| 708 | + (ui-outliner-tx/transact! |
| 709 | + {:outliner-op :cycle-todos} |
| 710 | + (db-based-cycle-todo! block))))))))) |
739 | 711 |
|
740 | 712 | (defn delete-block-aux! |
741 | 713 | [{:block/keys [uuid] :as _block}] |
|
755 | 727 | {:prev-block sibling-entity |
756 | 728 | :new-value (:block/title sibling-entity) |
757 | 729 | :edit-block-f #(edit-block! sibling-entity :max)} |
758 | | - (let [db? (config/db-based-graph? repo) |
759 | | - original-content (if (= (:db/id sibling-entity) (:db/id (state/get-edit-block))) |
| 730 | + (let [original-content (if (= (:db/id sibling-entity) (:db/id (state/get-edit-block))) |
760 | 731 | (state/get-edit-content) |
761 | 732 | (:block/title sibling-entity)) |
762 | | - value' (if db? |
763 | | - original-content |
764 | | - (-> (property-file/remove-built-in-properties-when-file-based repo format original-content) |
765 | | - (drawer/remove-logbook))) |
766 | | - value (if db? |
767 | | - value |
768 | | - (->> value |
769 | | - (property-file/remove-properties-when-file-based repo format) |
770 | | - (drawer/remove-logbook))) |
| 733 | + value' original-content |
771 | 734 | new-value (str value' value) |
772 | 735 | tail-len (count value) |
773 | 736 | pos (max |
|
1453 | 1416 | (js/console.error error) |
1454 | 1417 | (log/error :save-block-failed error))))))) |
1455 | 1418 |
|
1456 | | -(defn- clean-content! |
1457 | | - [repo format content] |
1458 | | - (if (config/db-based-graph? repo) |
1459 | | - content |
1460 | | - (some->> (text/remove-level-spaces content format (config/get-block-pattern format)) |
1461 | | - (drawer/remove-logbook) |
1462 | | - (property-file/remove-properties-when-file-based repo format) |
1463 | | - string/trim))) |
1464 | | - |
1465 | 1419 | (defn delete-asset-of-block! |
1466 | 1420 | [{:keys [repo asset-block href full-text block-id local? delete-local?] :as _opts}] |
1467 | 1421 | (let [block (db-model/query-block-by-uuid block-id) |
|
2629 | 2583 | (when (and |
2630 | 2584 | uuid |
2631 | 2585 | (not (state/block-component-editing?)) |
2632 | | - (not= (clean-content! repo format title) |
2633 | | - (string/trim value))) |
| 2586 | + (not= title (string/trim value))) |
2634 | 2587 | (save-block! repo uuid value)) |
2635 | 2588 |
|
2636 | 2589 | (cond |
|
2699 | 2652 | (when sibling-block |
2700 | 2653 | (let [content (:block/title block) |
2701 | 2654 | value (state/get-edit-content)] |
2702 | | - (when (and value (not= (clean-content! repo format content) (string/trim value))) |
| 2655 | + (when (and value (not= content (string/trim value))) |
2703 | 2656 | (save-block! repo uuid value))) |
2704 | 2657 | (let [sibling-block-id (dom/attr sibling-block "blockid")] |
2705 | 2658 | (cond |
|
3869 | 3822 |
|
3870 | 3823 | (defn replace-block-reference-with-content-at-point |
3871 | 3824 | [] |
3872 | | - (let [repo (state/get-current-repo)] |
3873 | | - (when-let [{:keys [start end link]} (thingatpt/block-ref-at-point)] |
3874 | | - (when-let [block (db/entity [:block/uuid link])] |
3875 | | - (let [block-content (:block/title block) |
3876 | | - format (get block :block/format :markdown) |
3877 | | - block-content-without-prop (-> (property-file/remove-properties-when-file-based repo format block-content) |
3878 | | - (drawer/remove-logbook))] |
3879 | | - (when-let [input (state/get-input)] |
3880 | | - (when-let [current-block-content (gobj/get input "value")] |
3881 | | - (let [block-content* (str (subs current-block-content 0 start) |
3882 | | - block-content-without-prop |
3883 | | - (subs current-block-content end))] |
3884 | | - (state/set-block-content-and-last-pos! input block-content* 1))))))))) |
| 3825 | + (when-let [{:keys [start end link]} (thingatpt/block-ref-at-point)] |
| 3826 | + (when-let [block (db/entity [:block/uuid link])] |
| 3827 | + (let [block-content (:block/title block)] |
| 3828 | + (when-let [input (state/get-input)] |
| 3829 | + (when-let [current-block-content (gobj/get input "value")] |
| 3830 | + (let [block-content* (str (subs current-block-content 0 start) |
| 3831 | + block-content |
| 3832 | + (subs current-block-content end))] |
| 3833 | + (state/set-block-content-and-last-pos! input block-content* 1)))))))) |
3885 | 3834 |
|
3886 | 3835 | (defn copy-current-ref |
3887 | 3836 | [block-id] |
|
3903 | 3852 | (defn replace-ref-with-text! |
3904 | 3853 | [block ref-id] |
3905 | 3854 | (when (and block ref-id) |
3906 | | - (let [repo (state/get-current-repo) |
3907 | | - match (ref/->block-ref ref-id) |
| 3855 | + (let [match (ref/->block-ref ref-id) |
3908 | 3856 | ref-block (db/entity [:block/uuid ref-id]) |
3909 | | - block-ref-content (->> (or (:block/title ref-block) "") |
3910 | | - (property-file/remove-built-in-properties-when-file-based repo |
3911 | | - (get ref-block :block/format :markdown)) |
3912 | | - (drawer/remove-logbook)) |
| 3857 | + block-ref-content (or (:block/title ref-block) "") |
3913 | 3858 | content (string/replace-first (:block/title block) match |
3914 | 3859 | block-ref-content)] |
3915 | 3860 | (save-block! (state/get-current-repo) |
|
0 commit comments