mirror of
https://github.com/logseq/logseq.git
synced 2026-05-29 15:09:41 +00:00
fix: limit mobile comment toolbar (#12713)
* fix: limit mobile comment toolbar * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Tienson Qin <tiensonqin@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -39,23 +39,21 @@
|
||||
|
||||
(defn- insert-page-ref!
|
||||
[]
|
||||
(let [{:keys [block]} (editor-handler/get-state)]
|
||||
(when block
|
||||
(let [input (state/get-input)]
|
||||
(state/clear-editor-action!)
|
||||
(let [selection (editor-handler/get-selection-and-format)
|
||||
{:keys [selection-start selection-end selection]} selection]
|
||||
(if selection
|
||||
(do
|
||||
(editor-handler/delete-and-update input selection-start selection-end)
|
||||
(editor-handler/insert (page-ref/->page-ref selection)))
|
||||
(insert-text page-ref/left-and-right-brackets
|
||||
{:backward-pos 2
|
||||
:check-fn (fn [_ _ _]
|
||||
(let [input (state/get-input)
|
||||
new-pos (cursor/get-caret-pos input)]
|
||||
(state/set-editor-action-data! {:pos new-pos})
|
||||
(commands/handle-step [:editor/search-page])))})))))))
|
||||
(when-let [input (state/get-input)]
|
||||
(state/clear-editor-action!)
|
||||
(let [selection (editor-handler/get-selection-and-format)
|
||||
{:keys [selection-start selection-end selection]} selection]
|
||||
(if selection
|
||||
(do
|
||||
(editor-handler/delete-and-update input selection-start selection-end)
|
||||
(editor-handler/insert (page-ref/->page-ref selection)))
|
||||
(insert-text page-ref/left-and-right-brackets
|
||||
{:backward-pos 2
|
||||
:check-fn (fn [_ _ _]
|
||||
(let [input (state/get-input)
|
||||
new-pos (cursor/get-caret-pos input)]
|
||||
(state/set-editor-action-data! {:pos new-pos})
|
||||
(commands/handle-step [:editor/search-page])))})))))
|
||||
|
||||
(defn- indent-outdent-action
|
||||
[indent?]
|
||||
@@ -151,19 +149,24 @@
|
||||
|
||||
(defn- toolbar-actions
|
||||
[]
|
||||
(let [keyboard (keyboard-action)
|
||||
main-actions [(undo-action)
|
||||
(todo-action)
|
||||
(indent-outdent-action false)
|
||||
(indent-outdent-action true)
|
||||
(tag-action)
|
||||
(camera-action)
|
||||
(page-ref-action)
|
||||
(audio-action)
|
||||
(slash-action)
|
||||
(redo-action)]]
|
||||
{:main main-actions
|
||||
:trailing keyboard}))
|
||||
(if (:comment-editor? (last (state/get-editor-args)))
|
||||
{:main [(page-ref-action)
|
||||
(camera-action)
|
||||
(audio-action)]
|
||||
:trailing nil}
|
||||
(let [keyboard (keyboard-action)
|
||||
main-actions [(undo-action)
|
||||
(todo-action)
|
||||
(indent-outdent-action false)
|
||||
(indent-outdent-action true)
|
||||
(tag-action)
|
||||
(camera-action)
|
||||
(page-ref-action)
|
||||
(audio-action)
|
||||
(slash-action)
|
||||
(redo-action)]]
|
||||
{:main main-actions
|
||||
:trailing keyboard})))
|
||||
|
||||
(defn- action->native
|
||||
[{:keys [id title system-icon]}]
|
||||
|
||||
37
src/test/mobile/editor_toolbar_test.cljs
Normal file
37
src/test/mobile/editor_toolbar_test.cljs
Normal file
@@ -0,0 +1,37 @@
|
||||
(ns mobile.editor-toolbar-test
|
||||
(:require [cljs.test :refer [deftest is testing]]
|
||||
[frontend.commands :as commands]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.state :as state]
|
||||
[frontend.util.cursor :as cursor]
|
||||
[goog.dom :as gdom]
|
||||
[logseq.common.util.page-ref :as page-ref]
|
||||
[mobile.components.editor-toolbar :as editor-toolbar]))
|
||||
|
||||
(deftest comment-toolbar-actions-are-limited
|
||||
(testing "comment editing only exposes reference, photo, and audio"
|
||||
(with-redefs [state/get-editor-args (constantly [{} "edit-block-comment" {:comment-editor? true}])]
|
||||
(let [{:keys [main trailing]} (#'editor-toolbar/toolbar-actions)]
|
||||
(is (= ["page-ref" "camera" "audio"]
|
||||
(mapv :id main)))
|
||||
(is (nil? trailing))))))
|
||||
|
||||
(deftest comment-reference-action-inserts-page-ref
|
||||
(testing "comment reference action works without regular block editor state"
|
||||
(let [input-id "edit-block-comment"
|
||||
input #js {:value ""}
|
||||
insertions (atom [])]
|
||||
(with-redefs [editor-handler/get-state (constantly nil)
|
||||
editor-handler/get-selection-and-format (constantly nil)
|
||||
state/get-edit-input-id (constantly input-id)
|
||||
state/get-input (constantly input)
|
||||
gdom/getElement (fn [id]
|
||||
(when (= id input-id)
|
||||
input))
|
||||
cursor/pos (constantly 0)
|
||||
commands/simple-insert! (fn [id value opts]
|
||||
(swap! insertions conj
|
||||
[id value (:backward-pos opts) (fn? (:check-fn opts))]))]
|
||||
((:handler (#'editor-toolbar/page-ref-action)))
|
||||
(is (= [[input-id page-ref/left-and-right-brackets 2 true]]
|
||||
@insertions))))))
|
||||
Reference in New Issue
Block a user