Skip to content

Commit 490084b

Browse files
authored
Merge pull request #48 from SinghRajenM/src_FixedFileDeletionIssue
Fixed issue
2 parents d81c0b3 + 947fc7e commit 490084b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

NppJSONViewer/PluginDefinition.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ void openJSONDialog()
219219
delete[] curJSON;
220220
}
221221

222-
void formatSelectedJSON() {
222+
void formatSelectedJSON()
223+
{
223224
// Get the current scintilla
224225
int which = -1;
225226
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
@@ -248,9 +249,25 @@ void formatSelectedJSON() {
248249
rapidjson::StringStream ss(curJSON);
249250
rapidjson::Reader reader;
250251

251-
reader.Parse<rapidjson::kParseFullPrecisionFlag >(ss, pw);
252-
const char* fJson = sb.GetString();
253-
::SendMessage(curScintilla, SCI_REPLACESEL, 0, (LPARAM)fJson);
252+
if (reader.Parse<rapidjson::kParseFullPrecisionFlag >(ss, pw))
253+
{
254+
const char* fJson = sb.GetString();
255+
::SendMessage(curScintilla, SCI_REPLACESEL, 0, (LPARAM)fJson);
256+
}
257+
else
258+
{
259+
// Mark the error position
260+
// Get the current scintilla
261+
start = ::SendMessage(curScintilla, SCI_GETSELECTIONSTART, 0, 0);
262+
263+
size_t errPosition = start + reader.GetErrorOffset();
264+
::SendMessage(curScintilla, SCI_SETSEL, errPosition, errPosition + end);
265+
266+
// Intimate user
267+
::MessageBox(nppData._nppHandle,
268+
TEXT("There was an error while parsing JSON, refer the current selection for possible problematic area."),
269+
TEXT("JSON Viewer"), MB_OK | MB_ICONERROR);
270+
}
254271

255272
delete[] curJSON;
256273
}

0 commit comments

Comments
 (0)