Allow submitting comment with ctrl+enter

Fixes #427
This commit is contained in:
rubenwardy 2023-08-26 13:38:34 +01:00
parent 798679ca44
commit 8f52c67f0f
6 changed files with 21 additions and 11 deletions

@ -178,7 +178,7 @@ def delete_reply(id):
class CommentForm(FlaskForm):
comment = TextAreaField(lazy_gettext("Comment"), [InputRequired(), Length(2, 2000)])
submit = SubmitField(lazy_gettext("Comment"))
btn_submit = SubmitField(lazy_gettext("Comment"))
@bp.route("/threads/<int:id>/edit/", methods=["GET", "POST"])
@ -280,7 +280,7 @@ class ThreadForm(FlaskForm):
title = StringField(lazy_gettext("Title"), [InputRequired(), Length(3,100)])
comment = TextAreaField(lazy_gettext("Comment"), [InputRequired(), Length(10, 2000)])
private = BooleanField(lazy_gettext("Private"))
submit = SubmitField(lazy_gettext("Open Thread"))
btn_submit = SubmitField(lazy_gettext("Open Thread"))
@bp.route("/threads/new/", methods=["GET", "POST"])

@ -55,4 +55,14 @@ document.querySelectorAll("textarea.markdown").forEach((element) => {
return preview.innerHTML;
}
});
// Ctrl+enter to submit
if (element.getAttribute("data-enter-submit")) {
element.easy_mde.codemirror.on("keyup", (mirror, e) => {
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
element.form?.submit();
e.preventDefault();
}
});
}
})

@ -280,7 +280,7 @@
<script src="/static/libs/easymde.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/libs/easymde.min.css">
<link href="/static/fa/css/all.css" rel="stylesheet">
<script src="/static/js/markdowntextarea.js"></script>
<script src="/static/js/markdowntextarea.js?v=2"></script>
{% block scriptextra %}{% endblock %}
</body>

@ -166,14 +166,14 @@
{% from "macros/forms.html" import render_field, render_submit_field %}
<form method="post" action="{{ url_for('threads.view', id=thread.id) }}" class="card-body">
{{ form.hidden_tag() }}
{{ render_field(form.comment, fieldclass="form-control markdown", label="") }}
{{ render_submit_field(form.submit) }}
{{ render_field(form.comment, fieldclass="form-control markdown", label="", data_enter_submit="1") }}
{{ render_submit_field(form.btn_submit) }}
</form>
{% else %}
<form method="post" action="{{ url_for('threads.view', id=thread.id)}}" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<textarea class="form-control markdown" required maxlength=2000 name="comment"></textarea><br />
<input class="btn btn-primary" type="submit" value="Comment" />
<textarea class="form-control markdown" required maxlength=2000 name="comment" data-enter-submit="1"></textarea><br />
<input class="btn btn-primary" name="btn_submit" type="submit" value="Comment" />
</form>
{% endif %}
{% if thread.private %}

@ -11,7 +11,7 @@
<form method="POST" action="" enctype="multipart/form-data">
{{ form.hidden_tag() }}
{{ render_field(form.comment, label="", class_="m-0", fieldclass="form-control markdown") }} <br />
{{ render_submit_field(form.submit) }}
{{ render_field(form.comment, label="", class_="m-0", fieldclass="form-control markdown", data_enter_submit="1") }} <br />
{{ render_submit_field(form.btn_submit) }}
</form>
{% endblock %}

@ -29,7 +29,7 @@
<a name="reply"></a>
</div>
<div class="card-body">
{{ render_field(form.comment, label="", class_="m-0", fieldclass="form-control markdown") }}
{{ render_field(form.comment, label="", class_="m-0", fieldclass="form-control markdown", data_enter_submit="1") }}
</div>
</div>
</div>
@ -48,7 +48,7 @@
</p>
{% endif %}
{{ render_submit_field(form.submit) }}
{{ render_submit_field(form.btn_submit) }}
</form>