Browse Source

TextEditor: Fix commenting shortcut `<Ctrl-/>`

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.
Snow 2 years ago
parent
commit
df7c0eacd4
1 changed files with 1 additions and 1 deletions
  1. 1 1
      Userland/Libraries/LibGUI/TextEditor.cpp

+ 1 - 1
Userland/Libraries/LibGUI/TextEditor.cpp

@@ -1022,7 +1022,7 @@ void TextEditor::keydown_event(KeyEvent& event)
         if (m_highlighter != nullptr) {
         if (m_highlighter != nullptr) {
             auto prefix = m_highlighter->comment_prefix().value_or(""sv);
             auto prefix = m_highlighter->comment_prefix().value_or(""sv);
             auto suffix = m_highlighter->comment_suffix().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;
             auto is_already_commented = true;
             for (size_t i = range.start().line(); i <= range.end().line(); i++) {
             for (size_t i = range.start().line(); i <= range.end().line(); i++) {