zufuliu / notepad4

Notepad4 (Notepad2⨯2, Notepad2++) is a light-weight Scintilla based text editor for Windows with syntax highlighting, code folding, auto-completion and API list for many programming languages and documents, bundled with file browser plugin matepath.
Other
2.6k stars 184 forks source link

Fixed bug and update a string #826

Closed Matteo-Nigro closed 1 month ago

Matteo-Nigro commented 1 month ago

Fixed a bug on the Title Case (Ctrl+Alt+I). When the text is all in capitals, it does not work. It may not be the most elegant method, but it works.

zufuliu commented 1 month ago

That's expected, whole upper-case word (e.g. ACM) is treated as abbreviation.

zufuliu commented 1 month ago

It's might better to use ICU u_strToTitle() than our EditTitleCase():

HMODULE icu = LoadLibraryExW(L"icu.dll", nullptr, kSystemLibraryLoadFlags);
if (icu) {
    using strToTitleSig = int32_t (__cdecl*)(LPWSTR dest, int32_t destCapacity, LPCWSTR src, int32_t srcLength, HANDLE titleIter, const char *locale, int *errorCode);
    u_strToTitleSig pfn_strToTitle = DLLFunction<u_strToTitleSig>(icu, "u_strToTitle");
    if (pfn_strToTitle) {
        char localeName[LOCALE_NAME_MAX_LENGTH] = "";
        GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SNAME, localeName, COUNTOF(localeName));
        int errorCode = 0;
        int charsConverted = pfn_strToTitle(pszTextW, cchTextW, pszTextW, cchTextW, nullptr, localeName, &errorCode);
        if (charsConverted > 0 && errorCode <= 0) {
            bChanged = true;
            flags = 0;
        }
    }
    FreeLibrary(icu);
}
Matteo-Nigro commented 1 month ago

Ok @zufuliu. Thanks for the reply. Since the behavior of the function is as expected...So I don't understand how to proceed... Should I replace the code you suggested in the existing function or do you want me to leave everything unchanged and use the code privately?

zufuliu commented 1 month ago

I reopened issue #241 for title casing discussion, you can revert changes in Edit.cpp.

Matteo-Nigro commented 1 month ago

Ok I undid the changes to the Edit.cpp file keeping only the update to the rc file. Regarding the reopening of the discussion #241, I'll write my thoughts directly there. Thanks