Git commit a9892ac1f34b5639b4b144b49b12b5cee42f71ad by Weng Xuetian. Committed on 14/02/2016 at 23:00. Pushed by xuetianweng into branch 'master'. Support surrogate character sending from input method DocumentPrivate::typeChars currently filters character based on QChar, which is based on UTF-16. For printable character over U+10000, it will be always filtered out. Thus it is not possible to type unicode emoji character (E.g. eggplant U+1F346) in kate, while it is totally possible to copy-paste such string from other places. This commit changes the code to filter characters based on whether it is printable under UTF-32. Also make it possible to type newline character '\n' from input method. REVIEW: 127026 M +12 -0 autotests/src/katedocument_test.cpp M +2 -0 autotests/src/katedocument_test.h M +7 -5 src/document/katedocument.cpp http://commits.kde.org/ktexteditor/a9892ac1f34b5639b4b144b49b12b5cee42f71ad diff --git a/autotests/src/katedocument_test.cpp b/autotests/src/katedocume= nt_test.cpp index 9e9f371..dd41e0f 100644 --- a/autotests/src/katedocument_test.cpp +++ b/autotests/src/katedocument_test.cpp @@ -413,4 +413,16 @@ void KateDocumentTest::testDefStyleNum() QCOMPARE(doc.defStyleNum(0, 0), 0); } = +void KateDocumentTest::testTypeCharsWithSurrogateAndNewLine() +{ + KTextEditor::DocumentPrivate doc; + auto view =3D static_cast(doc.createView(Q_= NULLPTR)); + const uint surrogateUcs4String[] =3D { 0x1f346, '\n', 0x1f346, 0 }; + const auto surrogateString =3D QString::fromUcs4(surrogateUcs4String); + doc.typeChars(view, surrogateString); + + QCOMPARE(doc.text(), surrogateString); +} + + #include "katedocument_test.moc" diff --git a/autotests/src/katedocument_test.h b/autotests/src/katedocument= _test.h index 00781c1..8abbad9 100644 --- a/autotests/src/katedocument_test.h +++ b/autotests/src/katedocument_test.h @@ -51,6 +51,8 @@ private Q_SLOTS: void testDigest(); = void testDefStyleNum(); + + void testTypeCharsWithSurrogateAndNewLine(); }; = #endif // KATE_DOCUMENT_TEST_H diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp index e8ced95..00aaa92 100644 --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -2850,14 +2850,16 @@ int KTextEditor::DocumentPrivate::fromVirtualColumn= (const KTextEditor::Cursor &c bool KTextEditor::DocumentPrivate::typeChars(KTextEditor::ViewPrivate *vie= w, const QString &realChars) { /** - * filter out non-printable + * filter out non-printable chars (convert to utf-32 to support surrog= ate pairs) */ - QString chars; - Q_FOREACH (QChar c, realChars) - if (c.isPrint() || c =3D=3D QChar::fromLatin1('\t')) { - chars.append(c); + const auto realUcs4Chars =3D realChars.toUcs4(); + QVector ucs4Chars; + Q_FOREACH (auto c, realUcs4Chars) + if (QChar::isPrint(c) || c =3D=3D QChar::fromLatin1('\t') || c =3D= =3D QChar::fromLatin1('\n') || c =3D=3D QChar::fromLatin1('\r')) { + ucs4Chars.append(c); } = + QString chars =3D QString::fromUcs4(ucs4Chars.data(), ucs4Chars.size()= ); /** * no printable chars =3D> nothing to insert! */