Don't crash Notepad++ when running plugin commands with multiple selections #198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FIX
This would fix #197 .
Previously, running any plugin command other than
Settings
orAbout
would cause Notepad++ to crash if the user had multiple selections. This commit would fix this issue by, whenever they use a single-selection-only command, informing the user and bailing out early if they have multiple selections.You may not agree with this specific approach to fixing this bug, but I would argue that an easily reproduced issue that is guaranteed to cause a Notepad++ crash should be treated with the highest urgency. I won't be offended if you reject this PR, so long as you promptly fix the issue it is intended to address.
HOW THE FIX WORKS
Quite simple; before running any action that involves parsing JSON (these all seem to call the
ConstructJsonDlg
method), we check if the user has multiple selections in the current document. If they do, we show them a message box saying that JSON Viewer doesn't support multiple selections, and return early.If the user has only one selection, we run the plugin command normally.
NEW AFTER-BUILD ACTION
Add a new after-build action to
NPPJSONViewer.vcxproj
that creates anNPPJSONViewer
plugin directory (if one doesn't already exist) in the appropriate Notepad++ installation (%ProgramFiles%\Notepad++
for an x64 build or%ProgramFiles(x86)%\Notepad++
for a Win32 build) and then copies theNPPJSONViewer.dll
that you just built into that plugin folder.I also tried to add another action that would run that Notepad++ installation afterwards, but I couldn't figure out how to do that.