Add API NPPM_GETCURRENTLINESTR & RunDlg's variable $(CURRENT_LINESTR)

Add new API NPPM_GETCURRENTLINESTR and new variable $(CURRENT_LINESTR) for RunDlg to get the whole current line string.

Fix #11216, close #11265
This commit is contained in:
Daniel Fuchs 2022-02-22 10:17:58 +01:00 committed by Don Ho
parent ca8c302805
commit 052b27e3d7
4 changed files with 13 additions and 2 deletions

View File

@ -466,6 +466,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
#define CURRENT_COLUMN 9
#define NPP_FULL_FILE_PATH 10
#define GETFILENAMEATCURSOR 11
#define CURRENT_LINESTR 12
#define RUNCOMMAND_USER (WM_USER + 3000)
#define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH)
@ -476,6 +477,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
#define NPPM_GETCURRENTWORD (RUNCOMMAND_USER + CURRENT_WORD)
#define NPPM_GETNPPDIRECTORY (RUNCOMMAND_USER + NPP_DIRECTORY)
#define NPPM_GETFILENAMEATCURSOR (RUNCOMMAND_USER + GETFILENAMEATCURSOR)
#define NPPM_GETCURRENTLINESTR (RUNCOMMAND_USER + CURRENT_LINESTR)
// BOOL NPPM_GETXXXXXXXXXXXXXXXX(size_t strLen, TCHAR *str)
// where str is the allocated TCHAR array,
// strLen is the allocated array size

View File

@ -859,11 +859,17 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
}
case NPPM_GETCURRENTWORD:
case NPPM_GETCURRENTLINESTR:
{
const int strSize = CURRENTWORD_MAXLENGTH;
TCHAR str[strSize];
TCHAR str[strSize] = { '\0' };
TCHAR *pTchar = reinterpret_cast<TCHAR *>(lParam);
_pEditView->getGenericSelectedText(str, strSize);
if (message == NPPM_GETCURRENTWORD)
_pEditView->getGenericSelectedText(str, strSize);
else if (message == NPPM_GETCURRENTLINESTR)
_pEditView->getLine(_pEditView->getCurrentLineNumber(), str, strSize);
// For the compability reason, if wParam is 0, then we assume the size of generic_string buffer (lParam) is large enough.
// otherwise we check if the generic_string buffer size is enough for the generic_string to copy.
if (wParam != 0)

View File

@ -95,6 +95,8 @@ int whichVar(TCHAR *str)
return CURRENT_LINE;
else if (!lstrcmp(currentColumn, str))
return CURRENT_COLUMN;
else if (!lstrcmp(currentLineStr, str))
return CURRENT_LINESTR;
return VAR_NOT_RECOGNIZED;
}

View File

@ -32,6 +32,7 @@ const TCHAR nppDir[] = TEXT("NPP_DIRECTORY");
const TCHAR nppFullFilePath[] = TEXT("NPP_FULL_FILE_PATH");
const TCHAR currentLine[] = TEXT("CURRENT_LINE");
const TCHAR currentColumn[] = TEXT("CURRENT_COLUMN");
const TCHAR currentLineStr[] = TEXT("CURRENT_LINESTR");
int whichVar(TCHAR *str);
void expandNppEnvironmentStrs(const TCHAR *strSrc, TCHAR *stringDest, size_t strDestLen, HWND hWnd);