[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktexteditor] /: Support surrogate character sending from input method
From:       Weng Xuetian <wengxt () gmail ! com>
Date:       2016-02-14 23:00:42
Message-ID: E1aV5ek-0006Aa-Mc () scm ! kde ! org
[Download RAW message or body]

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/katedocument_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 = static_cast<KTextEditor::ViewPrivate*>(doc.createView(Q_NULLPTR));
+    const uint surrogateUcs4String[] = { 0x1f346, '\n', 0x1f346, 0 };
+    const auto surrogateString = 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 *view, const QString \
&realChars)  {
     /**
-     * filter out non-printable
+     * filter out non-printable chars (convert to utf-32 to support surrogate pairs)
      */
-    QString chars;
-    Q_FOREACH (QChar c, realChars)
-        if (c.isPrint() || c == QChar::fromLatin1('\t')) {
-            chars.append(c);
+    const auto realUcs4Chars = realChars.toUcs4();
+    QVector<uint> ucs4Chars;
+    Q_FOREACH (auto c, realUcs4Chars)
+        if (QChar::isPrint(c) || c == QChar::fromLatin1('\t') || c == \
QChar::fromLatin1('\n') || c == QChar::fromLatin1('\r')) { +            \
ucs4Chars.append(c);  }
 
+    QString chars = QString::fromUcs4(ucs4Chars.data(), ucs4Chars.size());
     /**
      * no printable chars => nothing to insert!
      */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic