Merge pull request #1925 from RaiKoHoff/DevNewFeatures

Fix transform backslashes while pasting into search/replace box
This commit is contained in:
Rainer Kottenhoff 2020-01-28 11:10:26 +01:00 committed by GitHub
commit 9bf95eacfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 190 additions and 67 deletions

View File

@ -1 +1 @@
2715
2716

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.20.127.2715"
version="5.20.128.2716"
type="win32"
/>
<description>Notepad3 BETA</description>

View File

@ -476,6 +476,7 @@ class ScintillaWin :
UINT CodePageOfDocument() const noexcept;
bool ValidCodePage(int codePage) const noexcept override;
std::string EncodeWString(std::wstring_view wsv);
sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) noexcept override;
void IdleWork() override;
void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) noexcept override;
@ -507,7 +508,10 @@ class ScintillaWin :
void CopyAllowLine() override;
bool CanPaste() override;
void Paste(bool asBinary) override;
void CreateCallTipWindow(PRectangle rc) override;
void CreateCallTipWindow(PRectangle rc) noexcept override;
#if SCI_EnablePopupMenu
void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) noexcept override;
#endif
void ClaimSelection() noexcept override;
// DBCS
@ -1408,6 +1412,18 @@ UINT ScintillaWin::CodePageOfDocument() const noexcept {
return CodePageFromCharSet(vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage);
}
std::string ScintillaWin::EncodeWString(std::wstring_view wsv) {
if (IsUnicodeMode()) {
const size_t len = UTF8Length(wsv);
std::string putf(len, 0);
UTF8FromUTF16(wsv, putf.data(), len);
return putf;
} else {
// Not in Unicode mode so convert from Unicode to current Scintilla code page
return StringEncode(wsv, CodePageOfDocument());
}
}
sptr_t ScintillaWin::GetTextLength() const noexcept {
return pdoc->CountUTF16(0, pdoc->Length());
}
@ -1811,6 +1827,25 @@ sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam
}
case WM_CONTEXTMENU:
#if SCI_EnablePopupMenu
{
Point pt = PointFromLParam(lParam);
POINT rpt = {static_cast<int>(pt.x), static_cast<int>(pt.y)};
::ScreenToClient(MainHWND(), &rpt);
const Point ptClient = PointFromPOINT(rpt);
if (ShouldDisplayPopup(ptClient)) {
if ((pt.x == -1) && (pt.y == -1)) {
// Caused by keyboard so display menu near caret
pt = PointMainCaret();
POINT spt = POINTFromPoint(pt);
::ClientToScreen(MainHWND(), &spt);
pt = PointFromPOINT(spt);
}
ContextMenu(pt);
return 0;
}
}
#endif
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_INPUTLANGCHANGE:
@ -2505,7 +2540,7 @@ void ScintillaWin::Paste(bool asBinary) {
}
const PasteShape pasteShape = isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream);
if (asBinary /*&& ::IsClipboardFormatAvailable(CF_TEXT)*/) {
if (asBinary) {
if (!asBinary) {
::CloseClipboard();
Redraw();
@ -2513,38 +2548,18 @@ void ScintillaWin::Paste(bool asBinary) {
}
}
// Always use CF_UNICODETEXT if available
// Use CF_UNICODETEXT if available
GlobalMemory memUSelection(::GetClipboardData(CF_UNICODETEXT));
if (memUSelection) {
const wchar_t *uptr = static_cast<const wchar_t *>(memUSelection.ptr);
if (uptr) {
size_t len;
std::vector<char> putf;
// Default Scintilla behaviour in Unicode mode
if (IsUnicodeMode()) {
const size_t bytes = memUSelection.Size();
const std::wstring_view wsv(uptr, bytes / 2);
len = UTF8Length(wsv);
putf.resize(len + 1);
UTF8FromUTF16(wsv, putf.data(), len);
} else {
// CF_UNICODETEXT available, but not in Unicode mode
// Convert from Unicode to current Scintilla code page
const UINT cpDest = CodePageOfDocument();
len = MultiByteLenFromWideChar(cpDest, uptr);
putf.resize(len);
MultiByteFromWideChar(cpDest, uptr, putf.data(), len);
}
InsertPasteShape(putf.data(), len, pasteShape);
}
if (const wchar_t *uptr = static_cast<const wchar_t *>(memUSelection.ptr)) {
const std::string putf = EncodeWString(uptr);
InsertPasteShape(putf.c_str(), putf.length(), pasteShape);
memUSelection.Unlock();
}
::CloseClipboard();
Redraw();
}
void ScintillaWin::CreateCallTipWindow(PRectangle) {
void ScintillaWin::CreateCallTipWindow(PRectangle) noexcept {
if (!ct.wCallTip.Created()) {
HWND wnd = ::CreateWindow(callClassName, L"ACallTip",
WS_POPUP, 100, 100, 150, 20,
@ -2556,6 +2571,18 @@ void ScintillaWin::CreateCallTipWindow(PRectangle) {
}
}
#if SCI_EnablePopupMenu
void ScintillaWin::AddToPopUp(const char *label, int cmd, bool enabled) noexcept {
HMENU hmenuPopup = static_cast<HMENU>(popup.GetID());
if (!label[0])
::AppendMenuA(hmenuPopup, MF_SEPARATOR, 0, "");
else if (enabled)
::AppendMenuA(hmenuPopup, MF_STRING, cmd, label);
else
::AppendMenuA(hmenuPopup, MF_STRING | MF_DISABLED | MF_GRAYED, cmd, label);
}
#endif
void ScintillaWin::ClaimSelection() noexcept {
// Windows does not have a primary selection
}

View File

@ -34,6 +34,7 @@
#include "resource.h"
#include "Version.h"
#include "Encoding.h"
#include "Styles.h"
#include "MuiLanguage.h"
#include "Notepad3.h"
#include "Config/Config.h"
@ -897,7 +898,9 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam
GetWinVersionString(wchBuf, COUNTOF(wchBuf));
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf);
//GetLngString(IDS_MUI_TRANSL_AUTHOR, wchBuf, COUNTOF(wchBuf));
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_SCIVERSION);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_ONIGURUMA);
StringCchCopy(wchBuf, COUNTOF(wchBuf), L"en-US");
for (int lng = 0; lng < MuiLanguages_CountOf(); ++lng) {
if (MUI_LanguageDLLs[lng].bIsActive) {
@ -905,34 +908,35 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam
break;
}
}
StringCchPrintf(wchBuf2, ARRAYSIZE(wchBuf2), L"\nLocale: %s (CP:'%s')",
StringCchPrintf(wchBuf2, ARRAYSIZE(wchBuf2), L"\n- Locale: %s (CP:'%s')",
wchBuf, g_Encodings[CPI_ANSI_DEFAULT].wchLabel);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf2);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_SCIVERSION);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_ONIGURUMA);
//StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_UCHARDET);
//StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_TINYEXPR);
//StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n" VERSION_UTHASH);
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\nScreen-Resolution = %i x %i [pix].", ResX, ResY);
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Current Encoding = '%s'", Encoding_GetLabel(Encoding_Current(CPI_GET)));
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf);
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\nDisplay-DPI = %i x %i (Scale: %i%%).", wndDPI.x, wndDPI.y, ScaleIntToCurrentDPI(100));
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Screen-Resolution = %i x %i [pix]", ResX, ResY);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf);
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\nRendering-Technology = %s.", Settings.RenderingTechnology ? L"DIRECT-WRITE" : L"GDI");
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Display-DPI = %i x %i (Scale: %i%%).", wndDPI.x, wndDPI.y, ScaleIntToCurrentDPI(100));
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf);
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\nZoom = %i%%.", SciCall_GetZoom());
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Rendering-Technology = '%s'", Settings.RenderingTechnology ? L"DIRECT-WRITE" : L"GDI");
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf);
StringCchPrintf(wchBuf, COUNTOF(wchBuf), L"\n- Zoom = %i%%.", SciCall_GetZoom());
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), (IsProcessElevated() ?
L"\nProcess is elevated." :
L"\nProcess is not elevated."));
L"\n- Process is elevated." :
L"\n- Process is not elevated"));
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), (IsUserInAdminGroup() ?
L"\nUser is in Admin-Group." :
L"\nUser is not in Admin-Group."));
L"\n- User is in Admin-Group." :
L"\n- User is not in Admin-Group"));
Style_GetLexerDisplayName(Style_GetCurrentLexerPtr(), wchBuf, COUNTOF(wchBuf));
StringCchPrintf(wchBuf2, ARRAYSIZE(wchBuf2), L"\n- Current Lexer: '%s'", wchBuf);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), wchBuf2);
StringCchCat(wchVerInfo, COUNTOF(wchVerInfo), L"\n");

View File

@ -280,7 +280,7 @@ void EditInitWordDelimiter(HWND hwnd)
if (StrIsNotEmpty(Settings2.AutoCompleteFillUpChars))
{
WideCharToMultiByte(Encoding_SciCP, 0, Settings2.AutoCompleteFillUpChars, -1, AutoCompleteFillUpChars, (int)COUNTOF(AutoCompleteFillUpChars), NULL, NULL);
UnSlash(AutoCompleteFillUpChars, Encoding_SciCP);
UnSlashA(AutoCompleteFillUpChars, Encoding_SciCP);
s_ACFillUpCharsHaveNewLn = false;
int i = 0;
@ -5356,6 +5356,7 @@ static LRESULT CALLBACK EditBoxForPasteFixes(HWND hwnd, UINT uMsg, WPARAM wParam
SendMessage(hwnd, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)tchBuf2);
}
else {
UnSlashW(s_tchBuf);
SendMessage(hwnd, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)s_tchBuf);
}
}
@ -5773,6 +5774,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wPara
}
else {
StringCchCopyA(lpszSelection, len + 1, pClip);
UnSlashA(lpszSelection, Encoding_SciCP);
}
}
FreeMem(pClip);
@ -5980,10 +5982,10 @@ static INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wPara
}
}
else {
UnSlash(sg_pefrData->szFind, Encoding_SciCP);
UnSlashA(sg_pefrData->szFind, Encoding_SciCP);
SetDlgItemTextMB2W(hwnd, IDC_FINDTEXT, sg_pefrData->szFind);
if (GetDlgItem(hwnd, IDC_REPLACE)) {
UnSlash(sg_pefrData->szReplace, Encoding_SciCP);
UnSlashA(sg_pefrData->szReplace, Encoding_SciCP);
SetDlgItemTextMB2W(hwnd, IDC_REPLACETEXT, sg_pefrData->szReplace);
}
}
@ -7254,17 +7256,18 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
{
const char* const sep = " ";
SciCall_AutoCCancel();
SciCall_ClearRegisteredImages();
// cppcheck-suppress constArgument
SciCall_AutoCSetSeperator(sep[0]);
SciCall_AutoCSetIgnoreCase(true);
//~SciCall_AutoCSetCaseInsensitiveBehaviour(SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE);
SciCall_AutoCSetChooseSingle(autoInsert);
//~SciCall_AutoCSetOrder(SC_ORDER_PERFORMSORT); // already sorted
SciCall_AutoCSetOrder(SC_ORDER_PERFORMSORT); // already sorted
SciCall_AutoCSetFillups(AutoCompleteFillUpChars);
//~SciCall_AutoCSetMulti(SC_MULTIAUTOC_EACH);
++iWListSize; // zero termination
char* const pList = AllocMem(iWListSize, HEAP_ZERO_MEMORY);
char* const pList = AllocMem(iWListSize + 1, HEAP_ZERO_MEMORY);
if (pList) {
PWLIST pTmp = NULL;
PWLIST pWLItem = NULL;
@ -7276,7 +7279,7 @@ bool EditAutoCompleteWord(HWND hwnd, bool autoInsert)
LL_DELETE(pListHead, pWLItem);
FreeMem(pWLItem);
}
SciCall_AutoCShow(iRootLen, (pList + 1));
SciCall_AutoCShow(iRootLen, pList);
FreeMem(pList);
}
}

View File

@ -1888,11 +1888,11 @@ size_t SlashW(LPWSTR pchOutput, size_t cchOutLen, LPCWSTR pchInput)
*
* Convert C style \a, \b, \f, \n, \r, \t, \v, \xhh, \uhhhh and \\ into their indicated characters.
*/
size_t UnSlash(LPSTR pchInOut, UINT cpEdit)
size_t UnSlashA(LPSTR pchInOut, UINT cpEdit)
{
LPSTR s = pchInOut;
LPSTR o = pchInOut;
LPSTR const sStart = pchInOut;
LPCSTR const sStart = pchInOut;
while (*s) {
if (*s == '\\') {
@ -1922,22 +1922,22 @@ size_t UnSlash(LPSTR pchInOut, UINT cpEdit)
WCHAR val[2] = L"";
int hex;
val[0] = 0;
hex = GetHexDigit(*(s + 1));
hex = GetHexDigitA(*(s + 1));
if (hex >= 0) {
++s;
val[0] = (WCHAR)hex;
hex = GetHexDigit(*(s + 1));
hex = GetHexDigitA(*(s + 1));
if (hex >= 0) {
++s;
val[0] *= 16;
val[0] += (WCHAR)hex;
if (!bShort) {
hex = GetHexDigit(*(s + 1));
hex = GetHexDigitA(*(s + 1));
if (hex >= 0) {
++s;
val[0] *= 16;
val[0] += (WCHAR)hex;
hex = GetHexDigit(*(s + 1));
hex = GetHexDigitA(*(s + 1));
if (hex >= 0) {
++s;
val[0] *= 16;
@ -1978,6 +1978,85 @@ size_t UnSlash(LPSTR pchInOut, UINT cpEdit)
return (size_t)((ptrdiff_t)(o - sStart));
}
size_t UnSlashW(LPWSTR pchInOut)
{
LPWSTR s = pchInOut;
LPWSTR o = pchInOut;
LPCWSTR const sStart = pchInOut;
while (*s) {
if (*s == '\\') {
++s;
if (*s == L'a')
*o = L'\a';
else if (*s == L'b')
*o = L'\b';
else if (*s == L'e')
*o = L'\x1B';
else if (*s == L'f')
*o = L'\f';
else if (*s == L'n')
*o = L'\n';
else if (*s == L'r')
*o = L'\r';
else if (*s == L't')
*o = L'\t';
else if (*s == L'v')
*o = L'\v';
else if (*s == L'\\')
*o = L'\\';
else if (*s == L'x' || *s == L'u') {
bool bShort = (*s == L'x');
WCHAR val = L'\0';
int hex = GetHexDigitW(*(s + 1));
if (hex >= 0) {
val = (WCHAR)hex;
hex = GetHexDigitW(*(++s + 1));
if (hex >= 0) {
++s;
val *= 16;
val += (WCHAR)hex;
if (!bShort) {
hex = GetHexDigitW(*(s + 1));
if (hex >= 0) {
val *= 16;
val += (WCHAR)hex;
hex = GetHexDigitW(*(++s + 1));
if (hex >= 0) {
++s;
val *= 16;
val += (WCHAR)hex;
}
}
}
}
if (val) {
*o = val;
}
else
--o;
}
else
--o;
}
else {
*o = '\\'; // revert
*++o = *s;
}
}
else
*o = *s;
++o;
if (*s) {
++s;
}
}
*o = '\0';
return (size_t)((ptrdiff_t)(o - sStart));
}
/**
* check, if we have regex sub-group referencing
*/
@ -2015,7 +2094,7 @@ void TransformBackslashes(char* pszInput, bool bRegEx, UINT cpEdit, int* iReplac
// regex handles backslashes itself
// except: replacement is not delegated to regex engine
if (!bRegEx || (iReplaceMsg && (SCI_REPLACETARGET == *iReplaceMsg))) {
UnSlash(pszInput, cpEdit);
UnSlashA(pszInput, cpEdit);
}
}

View File

@ -355,7 +355,9 @@ UINT CharSetFromCodePage(const UINT uCodePage);
size_t SlashA(LPSTR pchOutput, size_t cchOutLen, LPCSTR pchInput);
size_t SlashW(LPWSTR pchOutput, size_t cchOutLen, LPCWSTR pchInput);
size_t UnSlash(LPSTR pchInOut, UINT cpEdit);
size_t UnSlashA(LPSTR pchInOut, UINT cpEdit);
size_t UnSlashW(LPWSTR pchInOut);
void TransformBackslashes(char* pszInput, bool, UINT cpEdit, int* iReplaceMsg);
void TransformMetaChars(char* pszInput, bool, int iEOLMode);
@ -541,14 +543,20 @@ __inline bool IsAlphaNumeric(WCHAR ch) {
((ch >= L'A') && (ch <= L'Z'));
}
// If the character is an hexa digit, get its value.
__inline int GetHexDigit(char ch) {
// If the character is an hexadecimal digit, get its value.
__inline int GetHexDigitA(char ch) {
if (ch >= '0' && ch <= '9') { return ch - '0'; }
if (ch >= 'A' && ch <= 'F') { return ch - 'A' + 10; }
if (ch >= 'a' && ch <= 'f') { return ch - 'a' + 10; }
return -1;
}
__inline int GetHexDigitW(WCHAR ch) {
if (ch >= L'0' && ch <= L'9') { return ch - L'0'; }
if (ch >= L'A' && ch <= L'F') { return ch - L'A' + 10; }
if (ch >= L'a' && ch <= L'f') { return ch - L'a' + 10; }
return -1;
}
// ----------------------------------------------------------------------------
void UrlEscapeEx(LPCWSTR lpURL, LPWSTR lpEscaped, DWORD* pcchEscaped, bool bEscReserved);

View File

@ -1844,6 +1844,7 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl)
SendMessage(hwndEditCtrl, SCI_SETMULTIPLESELECTION, true, 0);
SendMessage(hwndEditCtrl, SCI_SETADDITIONALSELECTIONTYPING, true, 0);
SendMessage(hwndEditCtrl, SCI_SETMULTIPASTE, SC_MULTIPASTE_EACH, 0); // paste into rectangular selection
SendMessage(hwndEditCtrl, SCI_AUTOCSETMULTI, SC_MULTIAUTOC_EACH, 0); // paste into rectangular selection
SendMessage(hwndEditCtrl, SCI_SETMOUSESELECTIONRECTANGULARSWITCH, true, 0);
int const vspaceOpt = Settings2.DenyVirtualSpaceAccess ? SCVS_NONE : NP3_VIRTUAL_SPACE_ACCESS_OPTIONS;
@ -1937,6 +1938,7 @@ static void _InitializeSciEditCtrl(HWND hwndEditCtrl)
#define _CARET_SYMETRY CARET_EVEN /// CARET_EVEN or 0
#define _CARET_ENFORCE CARET_STRICT /// CARET_STRICT or 0
if (Settings2.CurrentLineHorizontalSlop > 0)
SendMessage(hwndEditCtrl, SCI_SETXCARETPOLICY, (WPARAM)(CARET_SLOP | _CARET_SYMETRY | _CARET_ENFORCE), Settings2.CurrentLineHorizontalSlop);
else
@ -4149,10 +4151,9 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
SciCall_SetRectangularSelectionAnchor(anchor);
SciCall_SetRectangularSelectionCaret(caret);
}
#else
SciCall_Paste();
#endif
SciCall_Paste();
_END_UNDO_ACTION_
UpdateToolbar();
UpdateStatusbar(false);

View File

@ -320,6 +320,7 @@ DeclareSciCallV1(SetMouseDWellTime, SETMOUSEDWELLTIME, int, millisec)
DeclareSciCallR0(AutoCActive, AUTOCACTIVE, bool)
DeclareSciCallV0(AutoCComplete, AUTOCCOMPLETE)
DeclareSciCallV0(AutoCCancel, AUTOCCANCEL)
DeclareSciCallV0(ClearRegisteredImages, CLEARREGISTEREDIMAGES)
DeclareSciCallV1(AutoCSetIgnoreCase, AUTOCSETIGNORECASE, bool, flag)
DeclareSciCallV1(AutoCSetCaseInsensitiveBehaviour, AUTOCSETCASEINSENSITIVEBEHAVIOUR, int, options)
DeclareSciCallV1(AutoCSetSeperator, AUTOCSETSEPARATOR, char, seperator)

View File

@ -8,8 +8,8 @@
#define SAPPNAME "Notepad3"
#define VERSION_MAJOR 5
#define VERSION_MINOR 20
#define VERSION_REV 127
#define VERSION_BUILD 2715
#define VERSION_REV 128
#define VERSION_BUILD 2716
#define SCINTILLA_VER 430
#define ONIGURUMA_REGEX_VER 6.9.4
#define UCHARDET_VER 2018.09.27