Skip to content

Commit

Permalink
Update ScintillaGateway and update to VS2015
Browse files Browse the repository at this point in the history
  • Loading branch information
dail8859 committed Apr 8, 2017
1 parent 3f2aa88 commit b7e041f
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 38 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SurroundSelection
Notepad++ plugin to automatically surround the selection in quotes/brackets/parenthesis/etc.
Notepad++ plugin to automatically surround the selection in quotes/brackets/parenthesis/etc. This can also be used on multiple or rectangluar selections.

**Note:** This is still in early development. It has not been tested with non-US keyboard layouts.

Expand All @@ -12,10 +12,10 @@ Select some text and type one of the following characters:
- `[`

## Installation
No public release is currently available.
Install the plugin by downloading it from the [Release](https://github.com/dail8859/SurroundSelection/releases) page and copy `SurroundSelection.dll` to your `plugins` folder.

## Development
The code has been developed using MSVC 2013. Building the code will generate the DLL which can be used by Notepad++. For convenience, MSVC copies the DLL into the Notepad++ plugin directory.
The code has been developed using MSVC 2015. Building the code will generate the DLL which can be used by Notepad++. For convenience, MSVC copies the DLL into the Notepad++ plugin directory.

## License
This code is released under the [GNU General Public License version 2](http://www.gnu.org/licenses/gpl-2.0.txt).
4 changes: 2 additions & 2 deletions SurroundSelection.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SurroundSelection", "src\SurroundSelection.vcxproj", "{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}"
EndProject
Expand Down
43 changes: 23 additions & 20 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,29 @@ static void SurroundSelectionsWith(char ch1, char ch2) {
// Sort so they are replaced top to bottom
std::sort(selections.begin(), selections.end());

int offset = 0;
int i = 0;

editor.BeginUndoAction();
for (const auto &selection : selections) {
editor.ClearSelections();

int offset = 0;
for (size_t i = 0; i < selections.size(); ++i) {
const auto &selection = selections[i];
editor.SetTargetRange(selection.first + offset, selection.second + offset);

std::string target(editor.GetTargetText(NULL), '\0');
editor.GetTargetText(&target[0]);
auto target = editor.GetTargetText();

// Add in the characters
target.insert(target.begin(), 1, ch1);
target.insert(target.end(), 1, ch2);

editor.ReplaceTarget(-1, target.c_str());
editor.ReplaceTarget(target);

editor.SetSelectionNStart(i, selection.first + offset + 1);
editor.SetSelectionNEnd(i, selection.second + offset + 2 - 1);
if (i == 0)
editor.SetSelection(selection.first + offset + 1, selection.second + offset + 1);
else
editor.AddSelection(selection.first + offset + 1, selection.second + offset + 1);

offset += 2;
++i;
offset += 2; // Add 2 since the replaced string is 2 chars longer
}

editor.EndUndoAction();
Expand Down Expand Up @@ -136,15 +139,15 @@ LRESULT CALLBACK KeyboardProc(int ncode, WPARAM wparam, LPARAM lparam) {

BOOL APIENTRY DllMain(HANDLE hModule, DWORD reasonForCall, LPVOID lpReserved) {
switch (reasonForCall) {
case DLL_PROCESS_ATTACH:
_hModule = hModule;
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_ATTACH:
_hModule = hModule;
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
Expand Down Expand Up @@ -194,4 +197,4 @@ extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam
extern "C" __declspec(dllexport) BOOL isUnicode() {
return TRUE;
}
#endif //UNICODE
#endif
Loading

0 comments on commit b7e041f

Please sign in to comment.