Fix wrong post character counting in hyperscript (#476)

A newline `\n` will be normalized as `\r\n` in Django.
This commit is contained in:
TAKAHASHI Shuuji 2023-01-28 02:50:34 +09:00 committed by GitHub
parent 653ab07fd6
commit 8a06b3d78f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,7 +59,7 @@ class Compose(FormView):
self.request = request
self.fields["text"].widget.attrs[
"_"
] = f"""
] = rf"""
init
-- Move cursor to the end of existing text
set my.selectionStart to my.value.length
@ -67,7 +67,8 @@ class Compose(FormView):
on load or input
-- Unicode-aware counting to match Python
set characters to Array.from(my.value.trim()).length
-- <LF> will be normalized as <CR><LF> in Django
set characters to Array.from(my.value.replaceAll('\n','\r\n').trim()).length
put {Config.system.post_length} - characters into #character-counter
if characters > {Config.system.post_length} then