diff options
author | mitchell <unknown> | 2019-07-11 14:12:28 -0400 |
---|---|---|
committer | mitchell <unknown> | 2019-07-11 14:12:28 -0400 |
commit | 2a15b94200abe8ee0df2dddc296f3dafd55655f8 (patch) | |
tree | 7236773c70225185fe1532d109a66f98c39e8d18 | |
parent | 55446b8967ed0a7f66502424d309f0b8fa74919f (diff) | |
download | scintilla-mirror-2a15b94200abe8ee0df2dddc296f3dafd55655f8.tar.gz |
Backport: Bug [#2038]. Source of input reported in SCN_CHARADDED.
This may be SC_CHARACTERSOURCE_DIRECT_INPUT, SC_CHARACTERSOURCE_TENTATIVE_INPUT,
or SC_CHARACTERSOURCE_IME_RESULT.
Backport of changeset 7613:4cfac35c71bd.
-rw-r--r-- | cocoa/ScintillaCocoa.h | 2 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 6 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 8 | ||||
-rw-r--r-- | curses/ScintillaCurses.cxx | 9 | ||||
-rw-r--r-- | doc/ScintillaDoc.html | 42 | ||||
-rw-r--r-- | doc/ScintillaHistory.html | 5 | ||||
-rw-r--r-- | gtk/ScintillaGTK.cxx | 7 | ||||
-rw-r--r-- | include/Scintilla.h | 4 | ||||
-rw-r--r-- | include/Scintilla.iface | 11 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaEditBase.cpp | 9 | ||||
-rw-r--r-- | src/EditModel.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 13 | ||||
-rw-r--r-- | src/Editor.h | 4 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 8 | ||||
-rw-r--r-- | src/ScintillaBase.h | 2 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 27 |
16 files changed, 106 insertions, 52 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h index 9a74cb6f3..7e91f4c1a 100644 --- a/cocoa/ScintillaCocoa.h +++ b/cocoa/ScintillaCocoa.h @@ -199,7 +199,7 @@ public: void ObserverRemove(); void IdleWork() override; void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override; - ptrdiff_t InsertText(NSString *input); + ptrdiff_t InsertText(NSString *input, CharacterSource charSource); NSRange PositionsFromCharacters(NSRange rangeCharacters) const; NSRange CharactersFromPositions(NSRange rangePositions) const; NSString *RangeTextAsString(NSRange rangePositions) const; diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index b1b44ea00..b40743dad 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -2279,7 +2279,7 @@ bool ScintillaCocoa::KeyboardInput(NSEvent* event) /** * Used to insert already processed text provided by the Cocoa text input system. */ -ptrdiff_t ScintillaCocoa::InsertText(NSString *input) { +ptrdiff_t ScintillaCocoa::InsertText(NSString *input, CharacterSource charSource) { CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), vs.styles[STYLE_DEFAULT].characterSet); std::string encoded = EncodedBytesString((CFStringRef)input, encoding); @@ -2292,11 +2292,11 @@ ptrdiff_t ScintillaCocoa::InsertText(NSString *input) { while (sv.length()) { const unsigned char leadByte = sv[0]; const unsigned int bytesInCharacter = UTF8BytesOfLead[leadByte]; - InsertCharacter(sv.c_str(), bytesInCharacter); + InsertCharacter(sv.c_str(), bytesInCharacter, charSource); sv = sv.substr(bytesInCharacter, sv.length()); } } else { - InsertCharacter(encoded.c_str(), static_cast<unsigned int>(encoded.length())); + InsertCharacter(encoded.c_str(), static_cast<unsigned int>(encoded.length()), charSource); } } return encoded.length(); diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index ad8d7dc01..12e0495d6 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -565,7 +565,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) else if ([aString isKindOfClass:[NSAttributedString class]]) newText = (NSString*) [aString string]; - mOwner.backend->InsertText(newText); + mOwner.backend->InsertText(newText, EditModel::CharacterSource::directInput); } //-------------------------------------------------------------------------------------------------- @@ -674,7 +674,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) NSRange posRangeCurrent = mOwner.backend->PositionsFromCharacters(NSMakeRange(replacementRange.location, 0)); // Note: Scintilla internally works almost always with bytes instead chars, so we need to take // this into account when determining selection ranges and such. - ptrdiff_t lengthInserted = mOwner.backend->InsertText(newText); + ptrdiff_t lengthInserted = mOwner.backend->InsertText(newText, EditModel::CharacterSource::tentativeInput); posRangeCurrent.length = lengthInserted; mMarkedTextRange = mOwner.backend->CharactersFromPositions(posRangeCurrent); // Mark the just inserted text. Keep the marked range for later reset. @@ -2139,9 +2139,9 @@ sourceOperationMaskForDraggingContext: (NSDraggingContext) context - (void)insertText: (id) aString { if ([aString isKindOfClass:[NSString class]]) - mBackend->InsertText(aString); + mBackend->InsertText(aString, EditModel::CharacterSource::directInput); else if ([aString isKindOfClass:[NSAttributedString class]]) - mBackend->InsertText([aString string]); + mBackend->InsertText([aString string], EditModel::CharacterSource::directInput); } //-------------------------------------------------------------------------------------------------- diff --git a/curses/ScintillaCurses.cxx b/curses/ScintillaCurses.cxx index 4941ba344..3325d881b 100644 --- a/curses/ScintillaCurses.cxx +++ b/curses/ScintillaCurses.cxx @@ -1069,8 +1069,13 @@ public: char utf8[6]; int len; toutf8(key, utf8, &len); - return (InsertCharacter(utf8, len), 1); - } else return (AddChar(key), 1); + InsertCharacter(utf8, len, EditModel::CharacterSource::directInput); + return 1; + } else { + char ch = static_cast<char>(key); + InsertCharacter(&ch, 1, EditModel::CharacterSource::directInput); + return 1; + } } else { SCNotification scn = {}; scn.nmhdr.code = SCN_KEY; diff --git a/doc/ScintillaDoc.html b/doc/ScintillaDoc.html index 3252c7823..21b288a21 100644 --- a/doc/ScintillaDoc.html +++ b/doc/ScintillaDoc.html @@ -3815,7 +3815,7 @@ struct Sci_TextToFind { Scintilla may ignore this call in some cases. For example, the inline behaviour might only be supported for some languages.</p> <p>When the inline IME mode is active, characters are added tentatively before being finalised and an <a class="message" href="#SCN_CHARADDED">SCN_CHARADDED</a> - notification is sent for each character.</p> + notification (with <code class="parameter">characterSource</code> set to <code>SC_CHARACTERSOURCE_TENTATIVE_INPUT</code>) is sent for each character.</p> <p><b id="SCI_GRABFOCUS">SCI_GRABFOCUS</b><br /> <b id="SCI_SETFOCUS">SCI_SETFOCUS(bool focus)</b><br /> @@ -7303,7 +7303,7 @@ struct SCNotification { int updated; /* SCN_UPDATEUI */ int listCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION */ - + int characterSource; /* SCN_CHARADDED */ }; </pre> @@ -7405,6 +7405,44 @@ href="#SCI_POSITIONFROMLINE">SCI_POSITIONFROMLINE</a>(lineNumber); for DBCS, it is (first byte * 256 + second byte) for 2 byte characters and the byte value for 1 byte characters. This notification is sent before the character has been styled so processing that depends on styling should instead be performed in the SCN_UPDATEUI notification.</p> + <p>The <code>SCNotification::characterSource</code> field is the source of the character.</p> + + <table class="standard" summary="Character Source"> + <tbody> + <tr> + <th align="left">Symbol</th> + <th>Value</th> + <th align="left">Meaning</th> + </tr> + </tbody> + <tbody> + <tr> + <td><code>SC_CHARACTERSOURCE_DIRECT_INPUT</code></td> + <td>0</td> + <td>Direct input characters, including characters generated by calling keyboard commands like <a class="seealso" href="#SCI_NEWLINE">SCI_NEWLINE</a>.</td> + </tr> + + <tr> + <td><code>SC_CHARACTERSOURCE_TENTATIVE_INPUT</code></td> + <td>1</td> + <td>Tentative input characters. They are used by IME (inline mode, see <a class="seealso" href="#SCI_SETIMEINTERACTION">SCI_SETIMEINTERACTION</a>) + to composite final string, normally different from final composited string (which is the string that has been truly added into current document), + and may be withdrawn when the user cancels typing (e.g. by pressing Esc key). + Some system (at least Cocoa) also use tentative input for non-IME features like using dead key to composite diacritical marks (grave accent, etc.). + These characters are not added to macro recording. Most applications can simply ignore the notification when this value is set. + </td> + </tr> + + <tr> + <td><code>SC_CHARACTERSOURCE_IME_RESULT</code></td> + <td>2</td> + <td>IME (either inline or windowed mode) full composited string. Modern IME is able to composite English word or sentence, + when this value is set, current character may not a Chinese, Japanese or Korean character. + Currently, this is only set on Windows.</td> + </tr> + + </tbody> + </table> <p><b id="SCN_SAVEPOINTREACHED">SCN_SAVEPOINTREACHED</b><br /> <b id="SCN_SAVEPOINTLEFT">SCN_SAVEPOINTLEFT</b><br /> diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 1e7992cdc..2594f70c5 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -559,6 +559,11 @@ <a href="https://sourceforge.net/p/scintilla/feature-requests/1297/">Feature #1297</a>. </li> <li> + Source of input (direct / IME composition / IME result) reported in SCN_CHARADDED so applications + can treat temporary IME composition input differently. + <a href="https://sourceforge.net/p/scintilla/bugs/2038/">Bug #2038</a>. + </li> + <li> Lexer added for DataFlex. <a href="https://sourceforge.net/p/scintilla/feature-requests/1295/">Feature #1295</a>. </li> diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index eab650179..9e3410450 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -2350,7 +2350,7 @@ void ScintillaGTK::CommitThis(char *commitStr) { if (!IsUnicodeMode()) docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true); - InsertCharacter(docChar.c_str(), docChar.size()); + InsertCharacter(docChar.c_str(), docChar.size(), CharacterSource::directInput); } g_free(uniStr); ShowCaretAtCurrentPosition(); @@ -2403,8 +2403,6 @@ void ScintillaGTK::PreeditChangedInlineThis() { std::vector<int> indicator = MapImeIndicators(preeditStr.attrs, preeditStr.str); - const bool tmpRecordingMacro = recordingMacro; - recordingMacro = false; for (glong i = 0; i < preeditStr.uniStrLen; i++) { gchar u8Char[UTF8MaxBytes+2] = {0}; const gint u8CharLen = g_unichar_to_utf8(preeditStr.uniStr[i], u8Char); @@ -2412,11 +2410,10 @@ void ScintillaGTK::PreeditChangedInlineThis() { if (!IsUnicodeMode()) docChar = ConvertText(u8Char, u8CharLen, charSetSource, "UTF-8", true); - InsertCharacter(docChar.c_str(), docChar.size()); + InsertCharacter(docChar.c_str(), docChar.size(), CharacterSource::tentativeInput); DrawImeIndicator(indicator[i], docChar.size()); } - recordingMacro = tmpRecordingMacro; // Move caret to ime cursor position. const int imeEndToImeCaretU32 = preeditStr.cursor_pos - preeditStr.uniStrLen; diff --git a/include/Scintilla.h b/include/Scintilla.h index 5d535ae76..2c9a8ac43 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -1093,6 +1093,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_AC_TAB 3 #define SC_AC_NEWLINE 4 #define SC_AC_COMMAND 5 +#define SC_CHARACTERSOURCE_DIRECT_INPUT 0 +#define SC_CHARACTERSOURCE_TENTATIVE_INPUT 1 +#define SC_CHARACTERSOURCE_IME_RESULT 2 #define SCN_STYLENEEDED 2000 #define SCN_CHARADDED 2001 #define SCN_SAVEPOINTREACHED 2002 @@ -1230,6 +1233,7 @@ struct SCNotification { int updated; /* SCN_UPDATEUI */ int listCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION, */ + int characterSource; /* SCN_CHARADDED */ }; #ifdef INCLUDE_DEPRECATED_FEATURES diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 10ac9091e..7280f71b8 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -3024,6 +3024,15 @@ val SC_AC_COMMAND=5 ali SC_AC_FILLUP=FILL_UP ali SC_AC_DOUBLECLICK=DOUBLE_CLICK +# characterSource for SCN_CHARADDED +enu CharacterSource=SC_CHARACTERSOURCE_ +# Direct input characters. +val SC_CHARACTERSOURCE_DIRECT_INPUT=0 +# IME (inline mode) or dead key tentative input characters. +val SC_CHARACTERSOURCE_TENTATIVE_INPUT=1 +# IME (either inline or windowed mode) full composited string. +val SC_CHARACTERSOURCE_IME_RESULT=2 + ################################################ # For SciLexer.h enu Lexer=SCLEX_ @@ -5173,7 +5182,7 @@ val SCE_DF_ICODE=14 # Events evt void StyleNeeded=2000(int position) -evt void CharAdded=2001(int ch) +evt void CharAdded=2001(int ch, int characterSource) evt void SavePointReached=2002(void) evt void SavePointLeft=2003(void) evt void ModifyAttemptRO=2004(void) diff --git a/qt/ScintillaEditBase/ScintillaEditBase.cpp b/qt/ScintillaEditBase/ScintillaEditBase.cpp index 5a80b1ddd..ccc20b18d 100644 --- a/qt/ScintillaEditBase/ScintillaEditBase.cpp +++ b/qt/ScintillaEditBase/ScintillaEditBase.cpp @@ -259,7 +259,7 @@ void ScintillaEditBase::keyPressEvent(QKeyEvent *event) QString text = event->text(); if (input && !text.isEmpty() && text[0].isPrint()) { QByteArray utext = sqt->BytesForDocument(text); - sqt->InsertCharacter(utext.data(), utext.size()); + sqt->InsertCharacter(utext.data(), utext.size(), EditModel::CharacterSource::directInput); } else { event->ignore(); } @@ -549,7 +549,7 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event) const QString oneCharUTF16 = commitStr.mid(i, ucWidth); const QByteArray oneChar = sqt->BytesForDocument(oneCharUTF16); - sqt->InsertCharacter(oneChar.data(), oneChar.length()); + sqt->InsertCharacter(oneChar.data(), oneChar.length(), EditModel::CharacterSource::directInput); i += ucWidth; } @@ -567,20 +567,17 @@ void ScintillaEditBase::inputMethodEvent(QInputMethodEvent *event) std::vector<int> imeIndicator = MapImeIndicators(event); - const bool recording = sqt->recordingMacro; - sqt->recordingMacro = false; for (unsigned int i = 0; i < preeditStrLen;) { const unsigned int ucWidth = preeditStr.at(i).isHighSurrogate() ? 2 : 1; const QString oneCharUTF16 = preeditStr.mid(i, ucWidth); const QByteArray oneChar = sqt->BytesForDocument(oneCharUTF16); const int oneCharLen = oneChar.length(); - sqt->InsertCharacter(oneChar.data(), oneCharLen); + sqt->InsertCharacter(oneChar.data(), oneCharLen, EditModel::CharacterSource::tentativeInput); DrawImeIndicator(imeIndicator[i], oneCharLen); i += ucWidth; } - sqt->recordingMacro = recording; // Move IME carets. int imeCaretPos = GetImeCaretPos(event); diff --git a/src/EditModel.h b/src/EditModel.h index ab5c23cdb..9aee35a62 100644 --- a/src/EditModel.h +++ b/src/EditModel.h @@ -37,6 +37,7 @@ public: bool primarySelection; enum IMEInteraction { imeWindowed, imeInline } imeInteraction; + enum class CharacterSource { directInput, tentativeInput, imeResult }; int foldFlags; int foldDisplayTextStyle; diff --git a/src/Editor.cxx b/src/Editor.cxx index e963ba339..4cceb1f5d 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1888,7 +1888,7 @@ void Editor::AddChar(char ch) { char s[2]; s[0] = ch; s[1] = '\0'; - InsertCharacter(s, 1); + InsertCharacter(s, 1, CharacterSource::directInput); } void Editor::FilterSelections() { @@ -1899,7 +1899,7 @@ void Editor::FilterSelections() { } // InsertCharacter inserts a character encoded in document code page. -void Editor::InsertCharacter(const char *s, unsigned int len) { +void Editor::InsertCharacter(const char *s, unsigned int len, CharacterSource charSource) { if (len == 0) { return; } @@ -1991,9 +1991,9 @@ void Editor::InsertCharacter(const char *s, unsigned int len) { ch = utf32[0]; } } - NotifyChar(ch); + NotifyChar(ch, charSource); - if (recordingMacro) { + if (recordingMacro && charSource != CharacterSource::tentativeInput) { std::string copy(s, len); // ensure NUL-terminated NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(copy.data())); } @@ -2339,10 +2339,11 @@ void Editor::NotifyErrorOccurred(Document *, void *, int status) { errorStatus = status; } -void Editor::NotifyChar(int ch) { +void Editor::NotifyChar(int ch, CharacterSource charSource) { SCNotification scn = {}; scn.nmhdr.code = SCN_CHARADDED; scn.ch = ch; + scn.characterSource = static_cast<int>(charSource); NotifyParent(scn); } @@ -3088,7 +3089,7 @@ void Editor::NewLine() { for (size_t i = 0; i < countInsertions; i++) { const char *eol = StringFromEOLMode(pdoc->eolMode); while (*eol) { - NotifyChar(*eol); + NotifyChar(*eol, CharacterSource::directInput); if (recordingMacro) { char txt[2]; txt[0] = *eol; diff --git a/src/Editor.h b/src/Editor.h index 9c3f3934c..4077fa1a4 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -393,7 +393,7 @@ protected: // ScintillaBase subclass needs access to much of Editor Sci::Position RealizeVirtualSpace(Sci::Position position, Sci::Position virtualSpace); SelectionPosition RealizeVirtualSpace(const SelectionPosition &position); void AddChar(char ch); - virtual void InsertCharacter(const char *s, unsigned int len); + virtual void InsertCharacter(const char *s, unsigned int len, CharacterSource charSource); void ClearBeforeTentativeStart(); void InsertPaste(const char *text, Sci::Position len); enum PasteShape { pasteStream=0, pasteRectangular = 1, pasteLine = 2 }; @@ -421,7 +421,7 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual int GetCtrlID() { return ctrlID; } virtual void NotifyParent(SCNotification scn) = 0; virtual void NotifyStyleToNeeded(Sci::Position endStyleNeeded); - void NotifyChar(int ch); + void NotifyChar(int ch, CharacterSource charSource); void NotifySavePoint(bool isSavePoint); void NotifyModifyAttempt(); virtual void NotifyDoubleClick(Point pt, int modifiers); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index a72267d32..1e7695d5f 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -79,20 +79,20 @@ void ScintillaBase::Finalise() { } void ScintillaBase::AddCharUTF(const char *s, unsigned int len, bool /*treatAsDBCS*/) { - InsertCharacter(s, len); + InsertCharacter(s, len, CharacterSource::directInput); } -void ScintillaBase::InsertCharacter(const char *s, unsigned int len) { +void ScintillaBase::InsertCharacter(const char *s, unsigned int len, CharacterSource charSource) { const bool isFillUp = ac.Active() && ac.IsFillUpChar(s[0]); if (!isFillUp) { - Editor::InsertCharacter(s, len); + Editor::InsertCharacter(s, len, charSource); } if (ac.Active()) { AutoCompleteCharacterAdded(s[0]); // For fill ups add the character after the autocompletion has // triggered so containers see the key so can display a calltip. if (isFillUp) { - Editor::InsertCharacter(s, len); + Editor::InsertCharacter(s, len, charSource); } } } diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index dc1438155..e922ab057 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -64,7 +64,7 @@ protected: // This method is deprecated, use InsertCharacter instead. The treatAsDBCS parameter is no longer used. virtual void AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS=false); - void InsertCharacter(const char *s, unsigned int len) override; + void InsertCharacter(const char *s, unsigned int len, CharacterSource charSource) override; void Command(int cmdId); void CancelModes() override; int KeyCommand(unsigned int iMessage) override; diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index e2cb3b4a2..ebfe89ad4 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -328,7 +328,7 @@ class ScintillaWin : static int MouseModifiers(uptr_t wParam) noexcept; Sci::Position TargetAsUTF8(char *text) const; - void AddCharUTF16(wchar_t const *wcs, unsigned int wclen); + void AddCharUTF16(wchar_t const *wcs, unsigned int wclen, CharacterSource charSource); Sci::Position EncodedFromUTF8(const char *utf8, char *encoded) const; sptr_t WndPaint(); @@ -341,7 +341,7 @@ class ScintillaWin : void SelectionToHangul(); void EscapeHanja(); void ToggleHanja(); - void AddWString(std::wstring wcs); + void AddWString(std::wstring wcs, CharacterSource charSource); UINT CodePageOfDocument() const; bool ValidCodePage(int codePage) const override; @@ -816,20 +816,20 @@ Sci::Position ScintillaWin::EncodedFromUTF8(const char *utf8, char *encoded) con // Add one character from a UTF-16 string, by converting to either UTF-8 or // the current codepage. Code is similar to HandleCompositionWindowed(). -void ScintillaWin::AddCharUTF16(wchar_t const *wcs, unsigned int wclen) { +void ScintillaWin::AddCharUTF16(wchar_t const *wcs, unsigned int wclen, CharacterSource charSource) { if (IsUnicodeMode()) { size_t len = UTF8Length(wcs, wclen); char utfval[maxLenInputIME * 3]; UTF8FromUTF16(wcs, wclen, utfval, len); utfval[len] = '\0'; - AddCharUTF(utfval, static_cast<unsigned int>(len)); + InsertCharacter(utfval, static_cast<unsigned int>(len), charSource); } else { const UINT cpDest = CodePageOfDocument(); char inBufferCP[maxLenInputIME * 2]; const int size = ::WideCharToMultiByte(cpDest, 0, wcs, wclen, inBufferCP, sizeof(inBufferCP) - 1, 0, 0); for (int i=0; i<size; i++) { - AddChar(inBufferCP[i]); + InsertCharacter(&inBufferCP[i], 1, charSource); } } } @@ -896,7 +896,7 @@ sptr_t ScintillaWin::HandleCompositionWindowed(uptr_t wParam, sptr_t lParam) { if (lParam & GCS_RESULTSTR) { IMContext imc(MainHWND()); if (imc.hIMC) { - AddWString(imc.GetCompositionString(GCS_RESULTSTR)); + AddWString(imc.GetCompositionString(GCS_RESULTSTR), CharacterSource::imeResult); // Set new position after converted const Point pos = PointMainCaret(); @@ -1049,7 +1049,7 @@ std::vector<int> MapImeIndicators(std::vector<BYTE> inputStyle) { } -void ScintillaWin::AddWString(std::wstring wcs) { +void ScintillaWin::AddWString(std::wstring wcs, CharacterSource charSource) { if (wcs.empty()) return; @@ -1059,7 +1059,7 @@ void ScintillaWin::AddWString(std::wstring wcs) { const std::wstring uniChar(wcs, i, ucWidth); std::string docChar = StringEncode(uniChar, codePage); - InsertCharacter(docChar.c_str(), static_cast<unsigned int>(docChar.size())); + InsertCharacter(docChar.c_str(), static_cast<unsigned int>(docChar.size()), charSource); i += ucWidth; } } @@ -1100,20 +1100,17 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { std::vector<int> imeIndicator = MapImeIndicators(imc.GetImeAttributes()); - const bool tmpRecordingMacro = recordingMacro; - recordingMacro = false; const int codePage = CodePageOfDocument(); for (size_t i = 0; i < wcs.size(); ) { const size_t ucWidth = UTF16CharLength(wcs[i]); const std::wstring uniChar(wcs, i, ucWidth); std::string docChar = StringEncode(uniChar, codePage); - InsertCharacter(docChar.c_str(), static_cast<unsigned int>(docChar.size())); + InsertCharacter(docChar.c_str(), static_cast<unsigned int>(docChar.size()), CharacterSource::tentativeInput); DrawImeIndicator(imeIndicator[i], static_cast<unsigned int>(docChar.size())); i += ucWidth; } - recordingMacro = tmpRecordingMacro; // Move IME caret from current last position to imeCaretPos. const int imeEndToImeCaretU16 = imc.GetImeCaretPos() - static_cast<unsigned int>(wcs.size()); @@ -1125,7 +1122,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { view.imeCaretBlockOverride = true; } } else if (lParam & GCS_RESULTSTR) { - AddWString(imc.GetCompositionString(GCS_RESULTSTR)); + AddWString(imc.GetCompositionString(GCS_RESULTSTR), CharacterSource::imeResult); } EnsureCaretVisible(); SetCandidateWindowPos(); @@ -1486,7 +1483,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam lastHighSurrogateChar = 0; wclen = 2; } - AddCharUTF16(wcs, wclen); + AddCharUTF16(wcs, wclen, CharacterSource::directInput); } return 0; @@ -1498,7 +1495,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam } else { wchar_t wcs[3] = {0}; const unsigned int wclen = UTF16FromUTF32Character(static_cast<unsigned int>(wParam), wcs); - AddCharUTF16(wcs, wclen); + AddCharUTF16(wcs, wclen, CharacterSource::directInput); return FALSE; } |