diff options
author | Neil <nyamatongwe@gmail.com> | 2025-04-22 11:13:52 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-04-22 11:13:52 +1000 |
commit | 99e69de57d94f4bcf8d72a69c9215684ee4152ee (patch) | |
tree | c9d4fb2406babae42a9772309becc59c017f3165 /src | |
parent | ac87d3e3b29fead6e30514535b8cf87dcc66304e (diff) | |
download | scintilla-mirror-99e69de57d94f4bcf8d72a69c9215684ee4152ee.tar.gz |
Move common IME code from platform layers to ScintillaBase.
Diffstat (limited to 'src')
-rw-r--r-- | src/ScintillaBase.cxx | 24 | ||||
-rw-r--r-- | src/ScintillaBase.h | 8 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index a95df76ae..e19f75d36 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -213,6 +213,30 @@ void ScintillaBase::ListNotify(ListBoxEvent *plbe) { } } +void ScintillaBase::MoveImeCarets(Sci::Position offset) noexcept { + // Move carets relatively by bytes. + for (size_t r = 0; r < sel.Count(); r++) { + const Sci::Position positionInsert = sel.Range(r).Start().Position(); + sel.Range(r) = SelectionRange(positionInsert + offset); + } +} + +void ScintillaBase::DrawImeIndicator(int indicator, Sci::Position len) { + // Emulate the visual style of IME characters with indicators. + // Draw an indicator on the character before caret by the character bytes of len + // so it should be called after InsertCharacter(). + // It does not affect caret positions. + const IndicatorNumbers ind = static_cast<IndicatorNumbers>(indicator); + if (ind < IndicatorNumbers::Container || ind > IndicatorNumbers::Max) { + return; + } + pdoc->DecorationSetCurrentIndicator(indicator); + for (size_t r = 0; r < sel.Count(); r++) { + const Sci::Position positionInsert = sel.Range(r).Start().Position(); + pdoc->DecorationFillRange(positionInsert - len, 1, len); + } +} + void ScintillaBase::AutoCompleteInsert(Sci::Position startPos, Sci::Position removeLen, std::string_view text) { UndoGroup ug(pdoc); if (multiAutoCMode == MultiAutoComplete::Once) { diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index bfeb5a3d9..d3a6e1ad6 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -14,6 +14,11 @@ namespace Scintilla::Internal { // blue, with different patterns. constexpr ColourRGBA colourIME(0x0, 0x0, 0xffU); +constexpr int IndicatorInput = static_cast<int>(Scintilla::IndicatorNumbers::Ime); +constexpr int IndicatorTarget = IndicatorInput + 1; +constexpr int IndicatorConverted = IndicatorInput + 2; +constexpr int IndicatorUnknown = IndicatorInput + 3; + class LexState; /** */ @@ -61,6 +66,9 @@ protected: void CancelModes() override; int KeyCommand(Scintilla::Message iMessage) override; + void MoveImeCarets(Sci::Position offset) noexcept; + void DrawImeIndicator(int indicator, Sci::Position len); + void AutoCompleteInsert(Sci::Position startPos, Sci::Position removeLen, std::string_view text); void AutoCompleteStart(Sci::Position lenEntered, const char *list); void AutoCompleteCancel(); |