Skip to content

Commit

Permalink
Various updates, Closes #8
Browse files Browse the repository at this point in the history
- Added & for Alt-key underlines in menu
- Added AdditionalChars for INI file to extend functionality
- Switched cursor to end of insertion instead of beginning of insertion when done
  • Loading branch information
mvincent authored and dail8859 committed Apr 15, 2019
1 parent 373dd4a commit 674398a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Select some text and type one of the following characters:
- `{` or `}`
- `<` or `>`

The configuration file SurroundSelection.ini provides additional characters to surround with. Use as (for example):

AdditionalChars=*-_

to use `*`, `-` and `_` to act as surround characters as the above examples do.

## Installation
Install the plugin by downloading it from the [Release](https://github.com/dail8859/SurroundSelection/releases) page and copy `SurroundSelection.dll` to your `plugins` folder. You can also install it via the Plugin Admin or Plugin Manager (depending on your Notepad++ version).

Expand Down
15 changes: 11 additions & 4 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ static bool hasFocus = true;
static ScintillaGateway editor;
static LPWORD kbBuff = (LPWORD)new byte[buffChars];
static PBYTE kbState = new byte[256];
TCHAR addChars[1024];

static void enableSurroundSelection();
static void showAbout();

LRESULT CALLBACK KeyboardProc(int ncode, WPARAM wparam, LPARAM lparam);

FuncItem funcItem[] = {
{ TEXT("Enable"), enableSurroundSelection, 0, false, nullptr },
{ TEXT("&Enable"), enableSurroundSelection, 0, false, nullptr },
{ TEXT(""), nullptr, 0, false, nullptr },
{ TEXT("About..."), showAbout, 0, false, nullptr }
};
Expand Down Expand Up @@ -114,10 +115,11 @@ static void SurroundSelectionsWith(char ch1, char ch2) {

editor.ReplaceTarget(target);

// leave cursor at end of insertion
if (i == 0)
editor.SetSelection(selection.first + offset + 1, selection.second + offset + 1);
editor.SetSelection(selection.second + offset + 1, selection.first + offset + 1);
else
editor.AddSelection(selection.first + offset + 1, selection.second + offset + 1);
editor.AddSelection(selection.second + offset + 1, selection.first + offset + 1);

offset += 2; // Add 2 since the replaced string is 2 chars longer
}
Expand Down Expand Up @@ -153,6 +155,10 @@ LRESULT CALLBACK KeyboardProc(int ncode, WPARAM wparam, LPARAM lparam) {
ch1 = '{'; ch2 = '}';
} else if (ch == '<' || ch == '>') {
ch1 = '<'; ch2 = '>';
} else {
for (unsigned int i = 0; i < _tcslen(addChars); i++)
if (ch == addChars[i])
ch1 = ch2 = (char)ch;
}

if (ch1 != 0 && editor.GetSelectionEmpty() == 0) {
Expand Down Expand Up @@ -189,7 +195,7 @@ extern "C" __declspec(dllexport) void setInfo(NppData notepadPlusData) {
}

extern "C" __declspec(dllexport) const wchar_t *getName() {
return TEXT("SurroundSelection");
return TEXT("S&urroundSelection");
}

extern "C" __declspec(dllexport) FuncItem *getFuncsArray(int *nbF) {
Expand All @@ -211,6 +217,7 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode) {
hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, (HINSTANCE)_hModule, ::GetCurrentThreadId());
SendMessage(nppData._nppHandle, NPPM_SETMENUITEMCHECK, funcItem[0]._cmdID, 1);
}
GetPrivateProfileString(TEXT("SurroundSelection"), TEXT("AdditionalChars"), TEXT(""), addChars, 1023, GetIniFilePath());
break;
}
case NPPN_SHUTDOWN:
Expand Down

0 comments on commit 674398a

Please sign in to comment.