diff options
author | johnsonj <devnull@localhost> | 2016-01-25 13:18:26 +1100 |
---|---|---|
committer | johnsonj <devnull@localhost> | 2016-01-25 13:18:26 +1100 |
commit | 71c673f7511f4f7f890ffe7ded65a0cf0cec3836 (patch) | |
tree | 4a0d2e117677f567dae844c557183d738fc4f496 | |
parent | 89c4aeb98383ac8aa6e3c8d9983ef53307cba090 (diff) | |
download | scintilla-mirror-71c673f7511f4f7f890ffe7ded65a0cf0cec3836.tar.gz |
Make IME indicators work similarly on all 3 platforms.
-rw-r--r-- | doc/ScintillaHistory.html | 3 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaEditBase.cpp | 42 |
2 files changed, 20 insertions, 25 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index a0f40bac1..764ddd7ca 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -505,6 +505,9 @@ <li> For Qt, release builds have assertions turned off. </li> + <li> + IME target range displayed on Qt for OS X. + </li> </ul> <h3> <a href="http://www.scintilla.org/scite363.zip">Release 3.6.3</a> diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp index fd91e395d..ca4819726 100644 --- a/qt/ScintillaEditBase/ScintillaEditBase.cpp +++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp @@ -447,17 +447,9 @@ static int GetImeCaretPos(QInputMethodEvent *event) return 0; } -static std::vector<int> MapImeIndicators(QInputMethodEvent *event, bool preeditNotChanged) +static std::vector<int> MapImeIndicators(QInputMethodEvent *event) { -#ifndef Q_OS_LINUX - Q_UNUSED(preeditNotChanged) -#endif - const QString preeditStr = event->preeditString(); - std::vector<int> imeIndicator(preeditStr.length(), SC_INDICATOR_UNKNOWN); -#ifdef Q_OS_LINUX - const int imeCaretPos = GetImeCaretPos(event); -#endif - + std::vector<int> imeIndicator(event->preeditString().size(), SC_INDICATOR_UNKNOWN); foreach (QInputMethodEvent::Attribute attr, event->attributes()) { if (attr.type == QInputMethodEvent::TextFormat) { QTextFormat format = attr.value.value<QTextFormat>(); @@ -465,12 +457,12 @@ static std::vector<int> MapImeIndicators(QInputMethodEvent *event, bool preeditN int indicator = SC_INDICATOR_UNKNOWN; switch (charFormat.underlineStyle()) { - case QTextCharFormat::NoUnderline: - indicator = SC_INDICATOR_TARGET; //target input + case QTextCharFormat::NoUnderline: // win32, linux + indicator = SC_INDICATOR_TARGET; break; - case QTextCharFormat::SingleUnderline: - case QTextCharFormat::DashUnderline: - indicator = SC_INDICATOR_INPUT; //normal input + case QTextCharFormat::SingleUnderline: // osx + case QTextCharFormat::DashUnderline: // win32, linux + indicator = SC_INDICATOR_INPUT; break; case QTextCharFormat::DotLine: case QTextCharFormat::DashDotLine: @@ -482,16 +474,19 @@ static std::vector<int> MapImeIndicators(QInputMethodEvent *event, bool preeditN default: indicator = SC_INDICATOR_UNKNOWN; } -#ifdef Q_OS_LINUX - // ibus-qt has a bug to return only one underline style. - // Q_OS_LINUX blocks are temporary work around to cope with it. - if ((attr.length > 0) && (attr.start == imeCaretPos)) { + + if (format.hasProperty(QTextFormat::BackgroundBrush)) // win32, linux indicator = SC_INDICATOR_TARGET; - if ((imeCaretPos == 0) && (preeditNotChanged)) { // moved by an arrow key. - indicator = SC_INDICATOR_INPUT; + +#ifdef Q_OS_OSX + if (charFormat.underlineStyle() == QTextCharFormat::SingleUnderline) { + QColor uc = charFormat.underlineColor(); + if (uc.lightness() < 2) { // osx + indicator = SC_INDICATOR_TARGET; } } #endif + for (int i = attr.start; i < attr.start+attr.length; i++) { imeIndicator[i] = indicator; } @@ -544,10 +539,7 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event) sqt->pdoc->TentativeStart(); // TentativeActive() from now on. - std::vector<int> imeIndicator = MapImeIndicators(event, preeditString == preeditStr); -#ifdef Q_OS_LINUX - preeditString = preeditStr; -#endif + std::vector<int> imeIndicator = MapImeIndicators(event); // Display preedit characters one by one. int imeCharPos[MAXLENINPUTIME] = {0}; |