summaryrefslogtreecommitdiff
path: root/kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2022-04-16 13:07:24 +0100
committerV3n3RiX <venerix@koprulu.sector>2022-04-16 13:07:24 +0100
commit0c100b7dd2b30e75b799d806df4ef899fd98e1ea (patch)
tree464c922e949c7e4d5d891fb2cdda5daee5612537 /kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch
parente68d405c5d712af4387159df07e226217bdda049 (diff)
gentoo resync : 16.04.2022
Diffstat (limited to 'kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch')
-rw-r--r--kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch112
1 files changed, 112 insertions, 0 deletions
diff --git a/kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch b/kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch
new file mode 100644
index 000000000000..bac8cd017e68
--- /dev/null
+++ b/kde-frameworks/ktexteditor/files/ktexteditor-5.92.0-fix-toggle-comment.patch
@@ -0,0 +1,112 @@
+From 1173d5184e8b073790556dbdba92a8b8abdd62dc Mon Sep 17 00:00:00 2001
+From: Waqar Ahmed <waqar.17a@gmail.com>
+Date: Mon, 14 Mar 2022 09:44:54 +0500
+Subject: [PATCH] Fix toggle comment with space at the start
+
+BUG: 451471
+---
+ autotests/src/katedocument_test.cpp | 48 +++++++++++++++++++++++++++++
+ autotests/src/katedocument_test.h | 1 +
+ src/document/katedocument.cpp | 10 +++++-
+ 3 files changed, 58 insertions(+), 1 deletion(-)
+
+diff --git a/autotests/src/katedocument_test.cpp b/autotests/src/katedocument_test.cpp
+index f0946829..a842f960 100644
+--- a/autotests/src/katedocument_test.cpp
++++ b/autotests/src/katedocument_test.cpp
+@@ -851,4 +851,52 @@ void KateDocumentTest::testKeepUndoOverReload()
+ QCOMPARE(doc.text(), insertedText + initialText);
+ }
+
++void KateDocumentTest::testToggleComment()
++{
++ { // BUG: 451471
++ KTextEditor::DocumentPrivate doc;
++ QVERIFY(doc.highlightingModes().contains(QStringLiteral("Python")));
++ doc.setHighlightingMode(QStringLiteral("Python"));
++ const QString original = QStringLiteral("import hello;\n def method():");
++ doc.setText(original);
++ QVERIFY(doc.lines() == 2);
++
++ doc.commentSelection(doc.documentRange(), {1, 2}, false, 0); // 0 == ToggleComment
++ QCOMPARE(doc.text(), QStringLiteral("#import hello;\n #def method():"));
++
++ doc.commentSelection(doc.documentRange(), {1, 2}, false, 0); // 0 == ToggleComment
++ QCOMPARE(doc.text(), original);
++ }
++
++ { // Comment C++;
++ KTextEditor::DocumentPrivate doc;
++ QVERIFY(doc.highlightingModes().contains(QStringLiteral("C++")));
++ doc.setHighlightingMode(QStringLiteral("C++"));
++ QString original = QStringLiteral("#include<iostream>\nint main()\n{\nreturn 0;\n}\n");
++ doc.setText(original);
++ QVERIFY(doc.lines() == 6);
++
++ doc.commentSelection(doc.documentRange(), {5, 0}, false, 0); // 0 == ToggleComment
++ QCOMPARE(doc.text(), QStringLiteral("// #include<iostream>\n// int main()\n// {\n// return 0;\n// }\n"));
++
++ doc.commentSelection(doc.documentRange(), {5, 0}, false, 0); // 0 == ToggleComment
++ QCOMPARE(doc.text(), original);
++
++ // Comment just a portion
++ doc.commentSelection(Range(1, 0, 1, 3), Cursor(1, 3), false, 0);
++ QCOMPARE(doc.text(), QStringLiteral("#include<iostream>\n/*int*/ main()\n{\nreturn 0;\n}\n"));
++ doc.commentSelection(Range(1, 0, 1, 7), Cursor(1, 3), false, 0);
++ QCOMPARE(doc.text(), original);
++
++ // mixed, one line commented, one not => both get commented
++ original = QStringLiteral(" // int main()\n{}");
++ doc.setText(original);
++ doc.commentSelection(doc.documentRange(), {1, 2}, false, 0);
++ QCOMPARE(doc.text(), QStringLiteral("// // int main()\n// {}"));
++ doc.commentSelection(doc.documentRange(), {1, 2}, false, 0);
++ // after uncommenting, we get original text back with one line commented
++ QCOMPARE(doc.text(), original);
++ }
++}
++
+ #include "katedocument_test.moc"
+diff --git a/autotests/src/katedocument_test.h b/autotests/src/katedocument_test.h
+index c3b24b4c..0076f879 100644
+--- a/autotests/src/katedocument_test.h
++++ b/autotests/src/katedocument_test.h
+@@ -46,6 +46,7 @@ private Q_SLOTS:
+ void testIndentOnPaste();
+ void testAboutToSave();
+ void testKeepUndoOverReload();
++ void testToggleComment();
+ };
+
+ #endif // KATE_DOCUMENT_TEST_H
+diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp
+index 56e8fc7d..b72592b6 100644
+--- a/src/document/katedocument.cpp
++++ b/src/document/katedocument.cpp
+@@ -3995,7 +3995,11 @@ bool KTextEditor::DocumentPrivate::removeStartLineCommentFromSelection(KTextEdit
+ bool allLinesAreCommented = true;
+ for (int line = endLine; line >= startLine; line--) {
+ const auto ln = m_buffer->plainLine(line);
+- if (!ln->startsWith(shortCommentMark) && !ln->startsWith(longCommentMark)) {
++ const QString &text = ln->text();
++ QStringView textView(text.data(), text.size());
++ // Must trim any spaces at the beginning
++ textView = textView.trimmed();
++ if (!textView.startsWith(shortCommentMark) && !textView.startsWith(longCommentMark)) {
+ allLinesAreCommented = false;
+ break;
+ }
+@@ -4031,6 +4035,10 @@ void KTextEditor::DocumentPrivate::commentSelection(KTextEditor::Range selection
+
+ int startAttrib = 0;
+ Kate::TextLine ln = kateTextLine(line);
++ if (!ln) {
++ qWarning() << __FUNCTION__ << __LINE__ << "Unexpected null TextLine for " << line << " lineCount: " << lines();
++ return;
++ }
+
+ if (selectionCol < ln->length()) {
+ startAttrib = ln->attribute(selectionCol);
+--
+GitLab
+