Skip to content

Commit

Permalink
Allow Goto dialog to support line number text to have non numeric suf…
Browse files Browse the repository at this point in the history
…fixes

This patch enables the line number field in the Goto dialog to accept text with
non numeric characters suffixes. For example when you do grep/ripgrep the output
contains something like below.

```
    D:\repos\notepad2\src>rg LINENUM
    Notepad2.rc
    404:        MENUITEM "Line &Numbers\tCtrl+Shift+N",     IDM_VIEW_LINENUMBERS
    745:    "N",            IDM_VIEW_LINENUMBERS,   VIRTKEY, SHIFT, CONTROL, NOINVERT
    1055: IDD_LINENUM DIALOGEX 0, 0, 166, 70
    1061:    EDITTEXT        IDC_LINENUM,7,18,90,14,ES_AUTOHSCROLL
    1535:    IDD_LINENUM, DIALOG
```

It is so much easier to copy the line number by double clicking on the line number
in the CMD and paste it in the Goto dialog. Without this fix we cannot directly
use the copied text as it includes the semi-colon(':')
  • Loading branch information
vineelkovvuri committed Dec 19, 2018
1 parent 2968cd6 commit ed9090f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5436,10 +5436,16 @@ static INT_PTR CALLBACK EditLineNumDlgProc(HWND hwnd, UINT umsg, WPARAM wParam,
case IDOK: {
BOOL fTranslated;
BOOL fTranslated2;

const int iNewLine = (int)GetDlgItemInt(hwnd, IDC_LINENUM, &fTranslated, FALSE);
WCHAR tchLn[32];
int iNewLine = 0;
int iNewCol;

// Extract line number from the text entered
// For example: "5410:" will result in 5410
GetDlgItemText(hwnd, IDC_LINENUM, tchLn, COUNTOF(tchLn));
swscanf_s(tchLn, L"%d", &iNewLine);
fTranslated = (iNewLine != 0);

if (SendDlgItemMessage(hwnd, IDC_COLNUM, WM_GETTEXTLENGTH, 0, 0) > 0) {
iNewCol = GetDlgItemInt(hwnd, IDC_COLNUM, &fTranslated2, FALSE);
} else {
Expand Down

0 comments on commit ed9090f

Please sign in to comment.