Skip to content

Commit 41282a9

Browse files
[#17309] fix: wrong cursor position in a pre-filled composer (#17329)
1 parent 5bb954f commit 41282a9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/status_im2/contexts/chat/composer/effects.cljs

+10-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
(rn/use-effect
9090
(fn []
9191
(maximized-effect state animations dimensions chat-input)
92-
(reenter-screen-effect state dimensions chat-input)
9392
(layout-effect state)
9493
(kb-default-height-effect state)
9594
(background-effect state animations dimensions chat-input)
@@ -98,20 +97,27 @@
9897
(empty-effect state animations subscriptions)
9998
(kb/add-kb-listeners props state animations dimensions)
10099
#(component-will-unmount props))
101-
[max-height]))
100+
[max-height])
101+
(rn/use-effect
102+
(fn []
103+
(reenter-screen-effect state dimensions subscriptions))
104+
[max-height subscriptions]))
102105

103106
(defn use-edit
104107
[{:keys [input-ref]}
105108
{:keys [text-value saved-cursor-position]}
106109
{:keys [edit]}]
107110
(rn/use-effect
108111
(fn []
109-
(let [edit-text (get-in edit [:content :text])]
112+
(let [edit-text (get-in edit [:content :text])
113+
text-value-count (count @text-value)]
110114
(when (and edit @input-ref)
111115
(.focus ^js @input-ref)
112116
(.setNativeProps ^js @input-ref (clj->js {:text edit-text}))
113117
(reset! text-value edit-text)
114-
(reset! saved-cursor-position (count edit-text)))))
118+
(reset! saved-cursor-position (if (zero? text-value-count)
119+
(count edit-text)
120+
text-value-count)))))
115121
[(:message-id edit)]))
116122

117123
(defn use-reply

0 commit comments

Comments
 (0)