+add: define line number for file:/// URL (separator is ':' )

This commit is contained in:
Rainer Kottenhoff 2021-08-05 01:22:09 +02:00
parent 8e1200cb8c
commit 78078f2f5d
4 changed files with 66 additions and 22 deletions

View File

@ -32,6 +32,11 @@
#include "Config/Config.h"
#include "DarkMode/DarkMode.h"
#pragma warning(push)
#pragma warning(disable : 4201) // union/struct w/o name
#include "tinyexpr/tinyexpr.h"
#pragma warning(pop)
#include "Scintilla.h"
@ -1391,7 +1396,6 @@ void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc)
//
// PathCanonicalizeEx()
//
//
bool PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchPath)
{
WCHAR filePath[MAX_PATH] = { L'\0' };
@ -1414,7 +1418,6 @@ bool PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchPath)
//
// GetLongPathNameEx()
//
//
DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer)
{
DWORD const dwRet = GetLongPathName(lpszPath, lpszPath, cchBuffer);
@ -1534,6 +1537,34 @@ DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSe
}
//=============================================================================
//
// SplitFilePathLineNum()
//
void SplitFilePathLineNum(LPWSTR lpszPath, int * lineNum) {
LPWSTR const lpszSplit = StrRChr(lpszPath, NULL, L':');
if (lpszSplit) {
char chLnNumber[128];
char const defchar = (char)0x24;
WideCharToMultiByte(CP_ACP, (WC_COMPOSITECHECK | WC_DISCARDNS), &lpszSplit[1], -1, chLnNumber, COUNTOF(chLnNumber), &defchar, NULL);
te_xint_t iExprError = 0;
int const ln = (int)te_interp(chLnNumber, &iExprError);
if (iExprError == 0) {
lpszSplit[0] = L'\0'; // split
if (lineNum) {
*lineNum = ln;
}
}
} else {
if (lineNum) {
*lineNum = -1; // not found
}
}
}
//=============================================================================
//
// FormatNumberStr()
@ -2432,10 +2463,10 @@ size_t NormalizeColumnVector(LPSTR chStrg_in, LPWSTR wchStrg_out, size_t iCount)
//=============================================================================
//
// Char2FloatW()
// Char2Float()
// Locale indpendant simple character to float conversion
//
bool Char2FloatW(WCHAR* wnumber, float* fresult)
bool Char2Float(WCHAR* wnumber, float* fresult)
{
if (!wnumber || !fresult) {
return false;
@ -2480,7 +2511,7 @@ bool Char2FloatW(WCHAR* wnumber, float* fresult)
if (wnumber[i] == L'e' || wnumber[i] == L'E') {
++i;
float fexp = 0.0f;
if (Char2FloatW(&(wnumber[i]), &fexp)) {
if (Char2Float(&(wnumber[i]), &fexp)) {
exponent = powf(10, fexp);
}
}

View File

@ -170,6 +170,16 @@ __forceinline bool IsAsyncKeyDown(int key) {
// ----------------------------------------------------------------------------
inline bool Char2Int(LPCWSTR str, int *value) {
LPWSTR end;
*value = (int)wcstol(str, &end, 10);
return (str != end);
}
bool Char2Float(WCHAR *wnumber, float *fresult);
void Float2String(float fValue, LPWSTR lpszStrg, int cchSize);
// ----------------------------------------------------------------------------
#define RGB_SUB(X, Y) (((X) > (Y)) ? ((X) - (Y)) : ((Y) - (X)))
__forceinline COLORREF CalcContrastColor(COLORREF rgb, int alpha) {
@ -415,7 +425,7 @@ bool PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchPath);
DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer);
void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSourcePath);
DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative);
void SplitFilePathLineNum(LPWSTR lpszPath, int *lineNum);
bool StrLTrimI(LPWSTR pszSource,LPCWSTR pszTrimChars);
bool StrRTrimI(LPWSTR pszSource,LPCWSTR pszTrimChars);
@ -781,15 +791,6 @@ int ReadStrgsFromCSV(LPCWSTR wchCSVStrg, prefix_t sMatrix[], int iCount, int iLe
size_t ReadVectorFromString(LPCWSTR wchStrg, int iVector[], size_t iCount, int iMin, int iMax, int iDefault, bool ordered);
size_t NormalizeColumnVector(LPSTR chStrg_in, LPWSTR wchStrg_out, size_t iCount);
inline bool Char2IntW(LPCWSTR str, int* value)
{
LPWSTR end;
*value = (int)wcstol(str, &end, 10);
return (str != end);
}
bool Char2FloatW(WCHAR* wnumber, float* fresult);
void Float2String(float fValue, LPWSTR lpszStrg, int cchSize);
#define MAX_ESCAPE_HEX_DIGIT 4
int Hex2Char(char* ch, int cnt);

View File

@ -6917,6 +6917,8 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
wchUrl[cchUrl] = L'\0';
StrTrim(wchUrl, L" \r\n\t");
SplitFilePathLineNum(wchPath, NULL);
DWORD cchPath = MAX_PATH;
if (FAILED(PathCreateFromUrl(wchUrl, wchPath, &cchPath, 0))) {
const char *p = &pUrlBegin[CONSTSTRGLEN("file://")];
@ -6924,8 +6926,9 @@ void HandleDWellStartEnd(const DocPos position, const UINT uid)
StringCchCopyN(wchPath, COUNTOF(wchPath), wchUrl, cchUrl); // no op
//cchPath = (DWORD)StringCchLen(wchFilePath, MAX_PATH);
}
//NormalizePathEx(wchPath, COUNTOF(wchPath), true, false);
//NormalizePathEx(wchPath, COUNTOF(wchPath), true, false);
bool found = true;
if (PathIsExistingFile(wchPath)) {
GetLngStringW2MB(IDS_MUI_URL_FILE_EXISTS, chCallTip, (int)(COUNTOF(chCallTip) >> 1));
@ -7119,6 +7122,9 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
WCHAR szUnEscW[INTERNET_MAX_URL_LENGTH + 1];
DWORD dCch = COUNTOF(szUnEscW);
int lineNum = -1;
SplitFilePathLineNum(szTextW, &lineNum);
if ((operation & OPEN_WITH_NOTEPAD3) && UrlIsFileUrl(szTextW)) {
PathCreateFromUrl(szTextW, szUnEscW, &dCch, 0);
@ -7129,15 +7135,21 @@ bool HandleHotSpotURLClicked(const DocPos position, const HYPERLINK_OPS operatio
PathCanonicalizeEx(szFileName, (DWORD)(COUNTOF(szUnEscW) - lenPfx));
bool success = false;
if (PathIsExistingFile(szFileName)) {
FileLoad(szFileName, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
success = FileLoad(szFileName, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
}
else if (PathIsDirectory(szFileName)) {
WCHAR tchFile[MAX_PATH] = { L'\0' };
if (OpenFileDlg(Globals.hwndMain, tchFile, COUNTOF(tchFile), szFileName)) {
FileLoad(tchFile, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
success = FileLoad(tchFile, false, false, false, Settings.SkipUnicodeDetection, Settings.SkipANSICodePageDetection, false);
}
}
if (success && (lineNum >= 0)) {
lineNum = clampi(lineNum - 1, 0, INT_MAX);
//~SciCall_GotoLine((DocLn)lineNum);
PostMessage(Globals.hwndEdit, SCI_GOTOLINE, (WPARAM)lineNum, 0);
}
bHandled = true;
} else if (operation & OPEN_WITH_BROWSER) {

View File

@ -2892,7 +2892,7 @@ bool Style_StrGetCharSet(LPCWSTR lpszStyle, int* i)
if (p) {
p += CONSTSTRGLEN(L"charset:");
int iValue = 0;
if (Char2IntW(p, &iValue)) {
if (Char2Int(p, &iValue)) {
*i = max_i(SC_CHARSET_ANSI, iValue);
return true;
}
@ -2910,7 +2910,7 @@ bool Style_StrGetSizeInt(LPCWSTR lpszStyle, int* i)
WCHAR *p = StrStr(lpszStyle, L"size:");
if (p) {
p += CONSTSTRGLEN(L"size:");
return Char2IntW(p, i);
return Char2Int(p, i);
}
return false;
}
@ -2941,7 +2941,7 @@ bool Style_StrGetSizeFloat(LPCWSTR lpszStyle, float* f)
TrimSpcW(tch);
float fValue = 0.0;
if (Char2FloatW(tch, &fValue)) {
if (Char2Float(tch, &fValue)) {
if (fSign != 0) {
// relative size calculation
float const base = *f; // base is input
@ -2973,7 +2973,7 @@ bool Style_StrGetSizeStr(LPCWSTR lpszStyle, LPWSTR lpszSize, int cchSize)
TrimSpcW(tch);
float fValue = 0.0f;
if (Char2FloatW(tch, &fValue)) {
if (Char2Float(tch, &fValue)) {
WCHAR wchFloatVal[64];
fValue = (float)fabs(fValue);
bool const isZero = (fValue == 0.0f);