From df7c0eacd44df1b49afd60c6caa4b1ce911b4273 Mon Sep 17 00:00:00 2001 From: Snow Date: Thu, 1 Dec 2022 19:47:59 +0800 Subject: [PATCH] TextEditor: Fix commenting shortcut `` When you select a text area in "bottom-up" way (e.g. from line 10 to line 5), then type the shortcut, the text editor will not comment those text for you. Normalize the text range can easily fix this minor bug. --- Userland/Libraries/LibGUI/TextEditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 4723dc9ffc..617a73e5b1 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -1022,7 +1022,7 @@ void TextEditor::keydown_event(KeyEvent& event) if (m_highlighter != nullptr) { auto prefix = m_highlighter->comment_prefix().value_or(""sv); auto suffix = m_highlighter->comment_suffix().value_or(""sv); - auto range = has_selection() ? selection() : TextRange { { m_cursor.line(), m_cursor.column() }, { m_cursor.line(), m_cursor.column() } }; + auto range = has_selection() ? selection().normalized() : TextRange { { m_cursor.line(), m_cursor.column() }, { m_cursor.line(), m_cursor.column() } }; auto is_already_commented = true; for (size_t i = range.start().line(); i <= range.end().line(); i++) {