+ fix: (Inline-)IME and Auto-Completion cooperation

This commit is contained in:
Rainer Kottenhoff 2018-09-14 10:45:26 +02:00
parent 197e844ba8
commit b14eaa6da9
8 changed files with 46 additions and 15 deletions

View File

@ -19,6 +19,7 @@ extern "C" {
/* Return false on failure: */
int Scintilla_RegisterClasses(void *hInstance);
int Scintilla_ReleaseResources(void);
int Scintilla_InputCodePage(void);
#endif
int Scintilla_LinkLexers(void);
@ -398,7 +399,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_GETPRINTCOLOURMODE 2149
#define SCFIND_WHOLEWORD 0x2
#define SCFIND_MATCHCASE 0x4
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
#define SCFIND_DOT_MATCH_ALL 0x1000
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
#define SCFIND_WORDSTART 0x00100000
#define SCFIND_REGEXP 0x00200000
#define SCFIND_POSIX 0x00400000
@ -1043,6 +1046,11 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SC_MOD_INSERTCHECK 0x100000
#define SC_MOD_CHANGETABSTOPS 0x200000
#define SC_MODEVENTMASKALL 0x3FFFFF
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
#define SC_CHARADDED_NORMAL 0
#define SC_CHARADDED_TENTATIVE 1
#define SC_CHARADDED_IME 2
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
#define SC_UPDATE_CONTENT 0x1
#define SC_UPDATE_SELECTION 0x2
#define SC_UPDATE_V_SCROLL 0x4

View File

@ -2766,6 +2766,13 @@ val SC_MOD_INSERTCHECK=0x100000
val SC_MOD_CHANGETABSTOPS=0x200000
val SC_MODEVENTMASKALL=0x3FFFFF
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
# modifiers for SCN_CHARADDED: normal input, inline IME tentative, IME full composited
val SC_CHARADDED_NORMAL=0
val SC_CHARADDED_TENTATIVE=1
val SC_CHARADDED_IME=2
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
enu Update=SC_UPDATE_
val SC_UPDATE_CONTENT=0x1
val SC_UPDATE_SELECTION=0x2

View File

@ -1,5 +1,8 @@
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
// >>> NON STD SCI PATCH <<<
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
https://github.com/RaiKoHoff/notepad2
https://github.com/zufuliu/notepad2

View File

@ -62,7 +62,9 @@ EditModel::EditModel() : braces{} {
highlightGuideColumn = 0;
primarySelection = true;
imeInteraction = imeWindowed;
isInlineIMEComposition = false;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
charAddedSource = SC_CHARADDED_NORMAL;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
bidirectional = Bidirectional::bidiDisabled;
foldFlags = 0;
foldDisplayTextStyle = SC_FOLDDISPLAYTEXT_HIDDEN;

View File

@ -37,7 +37,9 @@ public:
bool primarySelection;
enum IMEInteraction { imeWindowed, imeInline } imeInteraction;
bool isInlineIMEComposition;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
int charAddedSource;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
enum class Bidirectional { bidiDisabled, bidiL2R, bidiR2L } bidirectional;

View File

@ -1894,6 +1894,7 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
// Vector elements point into selection in order to change selection.
std::vector<SelectionRange *> selPtrs;
selPtrs.reserve(sel.Count());
for (size_t r = 0; r < sel.Count(); r++) {
selPtrs.push_back(&sel.Range(r));
}
@ -1958,7 +1959,10 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
SetLastXChosen();
}
if (!isInlineIMEComposition) {
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
// We don't handle inline IME tentative characters
if (charAddedSource != SC_CHARADDED_TENTATIVE) {
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
if (treatAsDBCS) {
NotifyChar((static_cast<unsigned char>(s[0]) << 8) |
static_cast<unsigned char>(s[1]));
@ -1976,7 +1980,7 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) {
}
NotifyChar(byte);
}
}
} // >>> NON STD SCI PATCH <<<
if (recordingMacro) {
NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(s));
@ -2327,6 +2331,9 @@ void Editor::NotifyChar(int ch) {
SCNotification scn = {};
scn.nmhdr.code = SCN_CHARADDED;
scn.ch = ch;
// >>>>>>>>>>>>>>> BEG NON STD SCI PATCH >>>>>>>>>>>>>>>
scn.modifiers = charAddedSource;
// <<<<<<<<<<<<<<< END NON STD SCI PATCH <<<<<<<<<<<<<<<
NotifyParent(scn);
}

View File

@ -152,8 +152,6 @@ Used by VSCode, Atom etc.
typedef UINT_PTR (WINAPI *SetCoalescableTimerSig)(HWND hwnd, UINT_PTR nIDEvent,
UINT uElapse, TIMERPROC lpTimerFunc, ULONG uToleranceDelay);
// GCC has trouble with the standard COM ABI so do it the old C way with explicit vtables.
using namespace Scintilla;
namespace {
@ -1009,7 +1007,9 @@ sptr_t ScintillaWin::HandleCompositionWindowed(uptr_t wParam, sptr_t lParam) {
if (lParam & GCS_RESULTSTR) {
IMContext imc(MainHWND());
if (imc.hIMC) {
charAddedSource = SC_CHARADDED_IME;
AddWString(imc.GetCompositionString(GCS_RESULTSTR));
charAddedSource = SC_CHARADDED_NORMAL;
// Set new position after converted
const Point pos = PointMainCaret();
@ -1215,7 +1215,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
const bool tmpRecordingMacro = recordingMacro;
recordingMacro = false;
isInlineIMEComposition = true;
charAddedSource = SC_CHARADDED_TENTATIVE;
const int codePage = CodePageOfDocument();
for (size_t i = 0; i < wcs.size(); ) {
const size_t ucWidth = UTF16CharLength(wcs[i]);
@ -1227,7 +1227,7 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
DrawImeIndicator(imeIndicator[i], static_cast<unsigned int>(docChar.size()));
i += ucWidth;
}
isInlineIMEComposition = false;
charAddedSource = SC_CHARADDED_NORMAL;
recordingMacro = tmpRecordingMacro;
// Move IME caret from current last position to imeCaretPos.
@ -1240,7 +1240,9 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
view.imeCaretBlockOverride = true;
}
} else if (lParam & GCS_RESULTSTR) {
charAddedSource = SC_CHARADDED_IME;
AddWString(imc.GetCompositionString(GCS_RESULTSTR));
charAddedSource = SC_CHARADDED_NORMAL;
}
EnsureCaretVisible();
SetCandidateWindowPos();
@ -1463,7 +1465,7 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
KeyCommand(SCI_ZOOMIN);
} else {
KeyCommand(SCI_ZOOMOUT);
}
}
// send to main window too !
::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
} else {
@ -3657,6 +3659,6 @@ int Scintilla_ReleaseResources(void) {
return Scintilla::ResourcesRelease(false);
}
int Scintilla_InputCodePage(void) {
int Scintilla_InputCodePage() {
return InputCodePage();
}

View File

@ -6164,9 +6164,9 @@ static void __fastcall _HandleTinyExpr()
//=============================================================================
//
// _IsIMEOpenNativeMode()
// _IsIMEOpenInNativeMode()
//
static bool __fastcall _IsIMEOpenNativeMode()
static bool __fastcall _IsIMEOpenInNativeMode()
{
bool result = false;
HIMC const himc = ImmGetContext(g_hwndEdit);
@ -6174,7 +6174,7 @@ static bool __fastcall _IsIMEOpenNativeMode()
if (ImmGetOpenStatus(himc)) {
DWORD dwConversion = IME_CMODE_ALPHANUMERIC, dwSentence = 0;
if (ImmGetConversionStatus(himc, &dwConversion, &dwSentence)) {
result = ((dwConversion & IME_CMODE_LANGUAGE) != IME_CMODE_ALPHANUMERIC);
result = (dwConversion != IME_CMODE_ALPHANUMERIC);
}
}
ImmReleaseContext(g_hwndEdit, himc);
@ -6378,7 +6378,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam)
}
if ((g_bAutoCompleteWords || g_bAutoCLexerKeyWords)) {
if ((g_bAutoCinASCIIModeOnly && ich > 0x7F) || _IsIMEOpenNativeMode()) {
if ((g_bAutoCinASCIIModeOnly && (ich > 0x7F)) || (scn->modifiers != SC_CHARADDED_NORMAL)) {
SciCall_AutoCCancel();
return 0LL;
}