From 8a06b3d78fd82e84296dc09ad136b23b3f00025b Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Sat, 28 Jan 2023 02:50:34 +0900 Subject: [PATCH] Fix wrong post character counting in hyperscript (#476) A newline `\n` will be normalized as `\r\n` in Django. --- activities/views/compose.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/activities/views/compose.py b/activities/views/compose.py index 2f63691..c2e3618 100644 --- a/activities/views/compose.py +++ b/activities/views/compose.py @@ -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 + -- will be normalized as 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