fcitx-qt5-1.0.5-ucs4.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. https://github.com/fcitx/fcitx-qt5/commit/31ecc9f2f9c8eb77082044944bbb6740d35ae7c3
  2. https://github.com/fcitx/fcitx-qt5/commit/8fc110e6125d85d3c50112bc20a6ed36395b2b21
  3. --- /platforminputcontext/qfcitxplatforminputcontext.cpp
  4. +++ /platforminputcontext/qfcitxplatforminputcontext.cpp
  5. @@ -254,6 +254,12 @@
  6. anchor = var2.toInt();
  7. else
  8. anchor = cursor;
  9. +
  10. + // adjust it to real character size
  11. + QVector<uint> tempUCS4 = text.leftRef(cursor).toUcs4();
  12. + cursor = tempUCS4.size();
  13. + tempUCS4 = text.leftRef(anchor).toUcs4();
  14. + anchor = tempUCS4.size();
  15. if (data.surroundingText != text) {
  16. data.surroundingText = text;
  17. proxy->SetSurroundingText(text, cursor, anchor);
  18. @@ -388,6 +394,7 @@
  19. delete data.proxy;
  20. }
  21. data.proxy = new FcitxQtInputContextProxy(m_connection->serviceName(), path, *m_connection->connection(), this);
  22. + data.proxy->setProperty("icData", qVariantFromValue(static_cast<void*>(&data)));
  23. connect(data.proxy, SIGNAL(CommitString(QString)), this, SLOT(commitString(QString)));
  24. connect(data.proxy, SIGNAL(ForwardKey(uint, uint, int)), this, SLOT(forwardKey(uint, uint, int)));
  25. connect(data.proxy, SIGNAL(UpdateFormattedPreedit(FcitxQtFormattedPreeditList,int)), this, SLOT(updateFormattedPreedit(FcitxQtFormattedPreeditList,int)));
  26. @@ -480,15 +487,56 @@
  27. update(Qt::ImCursorRectangle);
  28. }
  29. -void QFcitxPlatformInputContext::deleteSurroundingText(int offset, uint nchar)
  30. +void QFcitxPlatformInputContext::deleteSurroundingText(int offset, uint _nchar)
  31. {
  32. QObject *input = qApp->focusObject();
  33. if (!input)
  34. return;
  35. QInputMethodEvent event;
  36. - event.setCommitString("", offset, nchar);
  37. - QCoreApplication::sendEvent(input, &event);
  38. +
  39. + FcitxQtInputContextProxy *proxy = qobject_cast<FcitxQtInputContextProxy*>(sender());
  40. + if (!proxy) {
  41. + return;
  42. + }
  43. +
  44. + FcitxQtICData *data = static_cast<FcitxQtICData*>(proxy->property("icData").value<void *>());
  45. + QVector<uint> ucsText = data->surroundingText.toUcs4();
  46. +
  47. + int cursor = data->surroundingCursor;
  48. + // make nchar signed so we are safer
  49. + int nchar = _nchar;
  50. + // Qt's reconvert semantics is different from gtk's. It doesn't count the current
  51. + // selection. Discard selection from nchar.
  52. + if (data->surroundingAnchor < data->surroundingCursor) {
  53. + nchar -= data->surroundingCursor - data->surroundingAnchor;
  54. + offset += data->surroundingCursor - data->surroundingAnchor;
  55. + cursor = data->surroundingAnchor;
  56. + } else if (data->surroundingAnchor > data->surroundingCursor) {
  57. + nchar -= data->surroundingAnchor - data->surroundingCursor;
  58. + cursor = data->surroundingCursor;
  59. + }
  60. +
  61. + // validates
  62. + if (nchar >= 0 && cursor + offset >= 0 && cursor + offset + nchar < ucsText.size()) {
  63. + // order matters
  64. + QVector<uint> replacedChars = ucsText.mid(cursor + offset, nchar);
  65. + nchar = QString::fromUcs4(replacedChars.data(), replacedChars.size()).size();
  66. +
  67. + int start, len;
  68. + if (offset >= 0) {
  69. + start = cursor;
  70. + len = offset;
  71. + } else {
  72. + start = cursor;
  73. + len = -offset;
  74. + }
  75. +
  76. + QVector<uint> prefixedChars = ucsText.mid(start, len);
  77. + offset = QString::fromUcs4(prefixedChars.data(), prefixedChars.size()).size() * (offset >= 0 ? 1 : -1);
  78. + event.setCommitString("", offset, nchar);
  79. + QCoreApplication::sendEvent(input, &event);
  80. + }
  81. }
  82. void QFcitxPlatformInputContext::forwardKey(uint keyval, uint state, int type)