diff --git a/Versions/build.txt b/Versions/build.txt
index 2095356a4..66510084e 100644
--- a/Versions/build.txt
+++ b/Versions/build.txt
@@ -1 +1 @@
-2624
+2625
diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf
index dcc6cab00..5263c95b3 100644
--- a/res/Notepad3.exe.manifest.conf
+++ b/res/Notepad3.exe.manifest.conf
@@ -3,7 +3,7 @@
Notepad3 BETA
diff --git a/src/Edit.c b/src/Edit.c
index 329c96494..413f77e08 100644
--- a/src/Edit.c
+++ b/src/Edit.c
@@ -1550,46 +1550,47 @@ void EditInvertCase(HWND hwnd)
if (Sci_IsMultiOrRectangleSelection())
{
InfoBoxLng(MB_ICONWARNING, NULL, IDS_MUI_SELRECT);
- return;
}
- const DocPos iSelStart = SciCall_GetSelectionStart();
- const DocPos iSelEnd = SciCall_GetSelectionEnd();
- const DocPos iSelSize = SciCall_GetSelText(NULL);
+ else {
+ const DocPos iSelStart = SciCall_GetSelectionStart();
+ const DocPos iSelEnd = SciCall_GetSelectionEnd();
+ const DocPos iSelSize = SciCall_GetSelText(NULL);
- LPSTR pszText = AllocMem(iSelSize, HEAP_ZERO_MEMORY);
- LPWSTR pszTextW = AllocMem(iSelSize * sizeof(WCHAR), HEAP_ZERO_MEMORY);
- if (!pszText || !pszTextW) {
- FreeMem(pszText);
- FreeMem(pszTextW);
- return;
- }
-
- SciCall_GetSelText(pszText);
-
- int const cchTextW = MultiByteToWideChar(Encoding_SciCP, 0, pszText, (MBWC_DocPos_Cast)(iSelSize - 1),
- pszTextW, (MBWC_DocPos_Cast)iSelSize);
-
- bool bChanged = false;
- for (int i = 0; i < cchTextW; i++) {
- if (IsCharUpperW(pszTextW[i])) {
- pszTextW[i] = LOWORD(CharLowerW((LPWSTR)(LONG_PTR)MAKELONG(pszTextW[i], 0)));
- bChanged = true;
+ LPSTR pszText = AllocMem(iSelSize, HEAP_ZERO_MEMORY);
+ LPWSTR pszTextW = AllocMem(iSelSize * sizeof(WCHAR), HEAP_ZERO_MEMORY);
+ if (!pszText || !pszTextW) {
+ FreeMem(pszText);
+ FreeMem(pszTextW);
}
- else if (IsCharLowerW(pszTextW[i])) {
- pszTextW[i] = LOWORD(CharUpperW((LPWSTR)(LONG_PTR)MAKELONG(pszTextW[i], 0)));
- bChanged = true;
+ else {
+ SciCall_GetSelText(pszText);
+
+ int const cchTextW = MultiByteToWideChar(Encoding_SciCP, 0, pszText, (MBWC_DocPos_Cast)(iSelSize - 1),
+ pszTextW, (MBWC_DocPos_Cast)iSelSize);
+
+ bool bChanged = false;
+ for (int i = 0; i < cchTextW; i++) {
+ if (IsCharUpperW(pszTextW[i])) {
+ pszTextW[i] = LOWORD(CharLowerW((LPWSTR)(LONG_PTR)MAKELONG(pszTextW[i], 0)));
+ bChanged = true;
+ }
+ else if (IsCharLowerW(pszTextW[i])) {
+ pszTextW[i] = LOWORD(CharUpperW((LPWSTR)(LONG_PTR)MAKELONG(pszTextW[i], 0)));
+ bChanged = true;
+ }
+ }
+
+ if (bChanged) {
+ WideCharToMultiByte(Encoding_SciCP, 0, pszTextW, cchTextW,
+ pszText, (MBWC_DocPos_Cast)SizeOfMem(pszText), NULL, NULL);
+ SciCall_Clear();
+ SciCall_AddText((iSelEnd - iSelStart), pszText);
+ SciCall_SetSel(iAnchorPos, iCurPos);
+ }
+ FreeMem(pszText);
+ FreeMem(pszTextW);
}
}
-
- if (bChanged) {
- WideCharToMultiByte(Encoding_SciCP, 0, pszTextW, cchTextW,
- pszText, (MBWC_DocPos_Cast)SizeOfMem(pszText), NULL, NULL);
- SciCall_Clear();
- SciCall_AddText((iSelEnd - iSelStart), pszText);
- SciCall_SetSel(iAnchorPos, iCurPos);
- }
- FreeMem(pszText);
- FreeMem(pszTextW);
_END_UNDO_ACTION_
}
}
@@ -2041,53 +2042,51 @@ void EditHex2Char(HWND hwnd)
char ch[32] = { L'\0' };
if (SciCall_GetSelText(NULL) <= COUNTOF(ch))
{
- _BEGIN_UNDO_ACTION_
-
bool bTrySelExpand = false;
SciCall_GetSelText(ch);
- if (StrChrIA(ch, ' ') || StrChrIA(ch, '\t') || StrChrIA(ch, '\r') || StrChrIA(ch, '\n') || StrChrIA(ch, '-')) {
- return;
- }
-
- if (StrCmpNIA(ch, "0x", 2) == 0 || StrCmpNIA(ch, "\\x", 2) == 0 || StrCmpNIA(ch, "\\u", 2) == 0) {
- ch[0] = '0';
- ch[1] = 'x';
- }
- else if (StrChrIA("xu", ch[0])) {
- ch[0] = '0';
- bTrySelExpand = true;
- }
- else
- return;
-
- unsigned int i = 0;
- if (sscanf_s(ch, "%x", &i) == 1) {
- int cch = 0;
- if (i == 0) {
- ch[0] = 0;
- cch = 1;
+ if (!((StrChrIA(ch, ' ') || StrChrIA(ch, '\t') || StrChrIA(ch, '\r') || StrChrIA(ch, '\n') || StrChrIA(ch, '-'))))
+ {
+ if (StrCmpNIA(ch, "0x", 2) == 0 || StrCmpNIA(ch, "\\x", 2) == 0 || StrCmpNIA(ch, "\\u", 2) == 0) {
+ ch[0] = '0';
+ ch[1] = 'x';
+ }
+ else if (StrChrIA("xu", ch[0])) {
+ ch[0] = '0';
+ bTrySelExpand = true;
}
else {
- WCHAR wch[8] = { L'\0' };
- StringCchPrintfW(wch, COUNTOF(wch), L"%lc", (WCHAR)i);
- cch = WideCharToMultiByte(Encoding_SciCP, 0, wch, -1, ch, COUNTOF(ch), NULL, NULL) - 1;
-
- if (bTrySelExpand && (SciCall_GetCharAt(iSelStart - 1) == '\\')) {
- --iSelStart;
- if (iCurPos < iAnchorPos) { --iCurPos; } else { --iAnchorPos; }
- }
+ return;
}
- EditSetSelectionEx(hwnd, iSelStart, iSelEnd, -1, -1);
- SciCall_ReplaceSel(ch);
- if (iCurPos < iAnchorPos)
- EditSetSelectionEx(hwnd, iCurPos + cch, iCurPos, -1, -1);
- else
- EditSetSelectionEx(hwnd, iAnchorPos, iAnchorPos + cch, -1, -1);
+ _BEGIN_UNDO_ACTION_
+ unsigned int i = 0;
+ if (sscanf_s(ch, "%x", &i) == 1) {
+ int cch = 0;
+ if (i == 0) {
+ ch[0] = 0;
+ cch = 1;
+ }
+ else {
+ WCHAR wch[8] = { L'\0' };
+ StringCchPrintfW(wch, COUNTOF(wch), L"%lc", (WCHAR)i);
+ cch = WideCharToMultiByte(Encoding_SciCP, 0, wch, -1, ch, COUNTOF(ch), NULL, NULL) - 1;
+ if (bTrySelExpand && (SciCall_GetCharAt(iSelStart - 1) == '\\')) {
+ --iSelStart;
+ if (iCurPos < iAnchorPos) { --iCurPos; }
+ else { --iAnchorPos; }
+ }
+ }
+ EditSetSelectionEx(hwnd, iSelStart, iSelEnd, -1, -1);
+ SciCall_ReplaceSel(ch);
+ if (iCurPos < iAnchorPos)
+ EditSetSelectionEx(hwnd, iCurPos + cch, iCurPos, -1, -1);
+ else
+ EditSetSelectionEx(hwnd, iAnchorPos, iAnchorPos + cch, -1, -1);
+ }
+ _END_UNDO_ACTION_
}
- _END_UNDO_ACTION_
}
}
@@ -3666,8 +3665,6 @@ void EditCompressBlanks(HWND hwnd)
const DocLn iLineStart = SciCall_LineFromPosition(iSelStartPos);
const DocLn iLineEnd = SciCall_LineFromPosition(iSelEndPos);
- _BEGIN_UNDO_ACTION_
-
if (SciCall_IsSelectionRectangle())
{
if (bIsSelEmpty) { return; }
@@ -3677,6 +3674,7 @@ void EditCompressBlanks(HWND hwnd)
const DocPos vSpcAnchorMainPos = SciCall_GetRectangularSelectionAnchorVirtualSpace();
const DocPos vSpcCaretMainPos = SciCall_GetRectangularSelectionCaretVirtualSpace();
+ _BEGIN_UNDO_ACTION_
_IGNORE_NOTIFY_CHANGE_;
DocPos iMaxLineLen = Sci_GetRangeMaxLineLength(iLineStart, iLineEnd);
@@ -3727,6 +3725,7 @@ void EditCompressBlanks(HWND hwnd)
SciCall_SetRectangularSelectionCaretVirtualSpace(vSpcCaretMainPos);
}
_OBSERVE_NOTIFY_CHANGE_;
+ _END_UNDO_ACTION_
}
else if (Sci_IsMultiOrRectangleSelection()) {
// @@@ not implemented
@@ -3734,6 +3733,7 @@ void EditCompressBlanks(HWND hwnd)
}
else // SC_SEL_LINES | SC_SEL_STREAM
{
+ _BEGIN_UNDO_ACTION_
_IGNORE_NOTIFY_CHANGE_;
const DocPos iCurPos = SciCall_GetCurrentPos();
@@ -3825,8 +3825,8 @@ void EditCompressBlanks(HWND hwnd)
if (pszOut) { FreeMem(pszOut); }
_OBSERVE_NOTIFY_CHANGE_;
+ _END_UNDO_ACTION_
}
- _END_UNDO_ACTION_
}
diff --git a/src/Notepad3.c b/src/Notepad3.c
index fb82fd4cc..44a278f83 100644
--- a/src/Notepad3.c
+++ b/src/Notepad3.c
@@ -826,7 +826,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
if (s_flagPasteBoard) {
StringCchCat(s_wchWndClass, COUNTOF(s_wchWndClass), L"B");
}
- // Relaunch with elevated privileges
+ // Try to Relaunch with elevated privileges
if (RelaunchElevated(NULL)) {
return 0;
}
@@ -1237,7 +1237,9 @@ HWND InitInstance(HINSTANCE hInstance,LPCWSTR pszCmdLine,int nCmdShow)
}
SciCall_SetSavePoint();
_SetSaveNeededFlag(true);
- FileSave(true, false, false, false, Flags.bPreserveFileModTime); // issued from elevation instances
+ if (StrIsNotEmpty(Globals.CurrentFile)) {
+ FileSave(true, false, false, false, Flags.bPreserveFileModTime); // issued from elevation instances
+ }
}
if (s_flagJumpTo) { // Jump to position
EditJumpTo(Globals.hwndEdit,s_iInitialLine,s_iInitialColumn);
@@ -9653,50 +9655,56 @@ bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus)
WCHAR wchFlags[32] = { L'\0' };
if (s_flagAppIsClosing) { StringCchCopy(wchFlags, COUNTOF(wchFlags), L"/UC"); }
- WININFO wi = GetMyWindowPlacement(Globals.hwndMain, NULL);
+ DocPos const iCurPos = SciCall_GetCurrentPos();
+ int const iCurLn = (int)SciCall_LineFromPosition(iCurPos) + 1;
+ int const iCurCol = (int)SciCall_GetColumn(iCurPos) + 1;
+ WININFO const wi = GetMyWindowPlacement(Globals.hwndMain, NULL);
if (s_lpOrigFileArg) {
lpArgs = StrCutI(lpArgs, s_lpOrigFileArg); // remove file from argument list
}
StringCchPrintf(szArguments, COUNTOF(szArguments),
- L"%s /pos %i,%i,%i,%i,%i %s", wchFlags, wi.x, wi.y, wi.cx, wi.cy, wi.max, lpArgs);
+ L"%s /pos %i,%i,%i,%i,%i /g %i,%i %s", wchFlags, wi.x, wi.y, wi.cx, wi.cy, wi.max, iCurLn, iCurCol, lpArgs);
WCHAR lpTempPathBuffer[MAX_PATH] = { L'\0' };
WCHAR szTempFileName[MAX_PATH] = { L'\0' };
- if (StrIsNotEmpty(Globals.CurrentFile))
+ const WCHAR* szCurFile = StrIsNotEmpty(Globals.CurrentFile) ? Globals.CurrentFile : L".\\Untitled.txt";
+
+ WCHAR tchBase[MAX_PATH] = { L'\0' };
+ StringCchCopy(tchBase, COUNTOF(tchBase), szCurFile);
+ PathStripPath(tchBase);
+
+ if (GetTempPath(MAX_PATH, lpTempPathBuffer) && GetTempFileName(lpTempPathBuffer, TEXT("NP3"), 0, szTempFileName))
{
- WCHAR tchBase[MAX_PATH] = { L'\0' };
- StringCchCopy(tchBase, COUNTOF(tchBase), Globals.CurrentFile);
- PathStripPath(tchBase);
+ size_t const len = StringCchLen(szTempFileName, MAX_PATH); // replace possible unknown extension
+ LPWSTR p = PathFindExtension(szTempFileName);
+ LPCWSTR q = PathFindExtension(szCurFile);
+ if ((p && *p) && (q && *q)) {
+ StringCchCopy(p, (MAX_PATH - len), q);
+ }
- if (GetTempPath(MAX_PATH, lpTempPathBuffer) && GetTempFileName(lpTempPathBuffer, TEXT("NP3"), 0, szTempFileName))
+ if (pFioStatus && FileIO(false, szTempFileName, true, true, false, true, pFioStatus, true, false))
{
- size_t const len = StringCchLen(szTempFileName, MAX_PATH); // replace possible unknown extension
- LPWSTR p = PathFindExtension(szTempFileName);
- LPCWSTR q = PathFindExtension(Globals.CurrentFile);
- if ((p && *p) && (q && *q)) {
- StringCchCopy(p, (MAX_PATH - len), q);
- }
+ // preserve encoding
+ WCHAR wchEncoding[80];
+ Encoding_GetNameW(Encoding_Current(CPI_GET), wchEncoding, COUNTOF(wchEncoding));
- if (pFioStatus && FileIO(false, szTempFileName, true, true, false, true, pFioStatus, true, false))
- {
- // preserve encoding
- WCHAR wchEncoding[80];
- Encoding_GetNameW(Encoding_Current(CPI_GET), wchEncoding, COUNTOF(wchEncoding));
+ StringCchPrintf(szArguments, COUNTOF(szArguments),
+ L"/%s %s /pos %i,%i,%i,%i,%i /g %i,%i /tmpfbuf=\"%s\" %s", wchEncoding, wchFlags, wi.x, wi.y, wi.cx, wi.cy, wi.max, iCurLn, iCurCol, szTempFileName, lpArgs);
- StringCchPrintf(szArguments, COUNTOF(szArguments),
- L"/%s %s /pos %i,%i,%i,%i,%i /tmpfbuf=\"%s\" %s", wchEncoding, wchFlags, wi.x, wi.y, wi.cx, wi.cy, wi.max, szTempFileName, lpArgs);
-
- if (!StrStrI(szArguments, tchBase)) {
+ if (!StrStrI(szArguments, tchBase)) {
+ if (StrIsNotEmpty(Globals.CurrentFile)) {
StringCchPrintf(szArguments, COUNTOF(szArguments), L"%s \"%s\"", szArguments, Globals.CurrentFile);
}
}
- FreeMem(lpExe);
- FreeMem(lpArgs);
}
+ FreeMem(lpExe);
+ FreeMem(lpArgs);
}
+ SaveSettings(false);
+
if (RelaunchElevated(szArguments)) {
// set no change and quit
SciCall_SetSavePoint();
@@ -10274,7 +10282,7 @@ bool RelaunchMultiInst() {
// RelaunchElevated()
//
//
-bool RelaunchElevated(LPWSTR lpArgs)
+bool RelaunchElevated(LPWSTR lpNewCmdLnArgs)
{
if (!IsVista() || s_bIsElevated || !s_flagRelaunchElevated || s_flagDisplayHelp) { return false; }
@@ -10282,30 +10290,26 @@ bool RelaunchElevated(LPWSTR lpArgs)
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
+ WCHAR lpExe[MAX_PATH] = { L'\0' };
+ WCHAR szOrigArgs[2032] = { L'\0' };
+
LPWSTR lpCmdLine = GetCommandLine();
size_t wlen = StringCchLenW(lpCmdLine, 0) + 2UL;
+ ExtractFirstArgument(lpCmdLine, lpExe, szOrigArgs, (int)wlen);
+ // override
+ GetModuleFileName(NULL, lpExe, COUNTOF(lpExe)); // full path
+ if (lpNewCmdLnArgs) {
+ StringCchCopy(szOrigArgs, COUNTOF(szOrigArgs), lpNewCmdLnArgs);
+ }
- WCHAR lpExe[MAX_PATH] = { L'\0' };
- WCHAR szArgs[2032] = { L'\0' };
WCHAR szArguments[2032] = { L'\0' };
- ExtractFirstArgument(lpCmdLine, lpExe, szArgs, (int)wlen);
-
- if (lpArgs) {
- StringCchCopy(szArgs, COUNTOF(szArgs), lpArgs); // override
- }
-
- if (StrStrI(szArgs, L"/f ") || StrStrI(szArgs, L"-f "))
+ if (StrStrI(szOrigArgs, L"/f ") || StrStrI(szOrigArgs, L"-f ") || StrIsEmpty(Globals.IniFile))
{
- StringCchCopy(szArguments, COUNTOF(szArguments), szArgs);
+ StringCchCopy(szArguments, COUNTOF(szArguments), szOrigArgs);
}
else {
- if (StrIsNotEmpty(Globals.IniFile)) {
- StringCchPrintf(szArguments, COUNTOF(szArguments), L"/f \"%s\" %s", Globals.IniFile, szArgs);
- }
- else {
- StringCchCopy(szArguments, COUNTOF(szArguments), szArgs);
- }
+ StringCchPrintf(szArguments, COUNTOF(szArguments), L"/f \"%s\" %s", Globals.IniFile, szOrigArgs);
}
if (StrIsNotEmpty(szArguments)) {
diff --git a/src/Notepad3.h b/src/Notepad3.h
index 30479975c..8f56db1c2 100644
--- a/src/Notepad3.h
+++ b/src/Notepad3.h
@@ -123,7 +123,7 @@ void BeginWaitCursor(LPCWSTR text);
void EndWaitCursor();
bool ActivatePrevInst();
bool RelaunchMultiInst();
-bool RelaunchElevated(LPWSTR lpArgs);
+bool RelaunchElevated(LPWSTR lpNewCmdLnArgs);
bool DoElevatedRelaunch(EditFileIOStatus* pFioStatus);
void SnapToWinInfoPos(HWND hwnd, const WININFO* pWinInfo, bool bFullWorkArea);
void ShowNotifyIcon(HWND hwnd, bool bAdd);
diff --git a/src/VersionEx.h b/src/VersionEx.h
index 0deb12523..0f0ed4712 100644
--- a/src/VersionEx.h
+++ b/src/VersionEx.h
@@ -8,7 +8,7 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 19
#define VERSION_REV 911
-#define VERSION_BUILD 2624
+#define VERSION_BUILD 2625
#define SCINTILLA_VER 420
#define ONIGURUMA_REGEX_VER 6.9.3
#define UCHARDET_VER 2018.09.27