@@ -219,7 +219,8 @@ void openJSONDialog()
219
219
delete[] curJSON;
220
220
}
221
221
222
- void formatSelectedJSON () {
222
+ void formatSelectedJSON ()
223
+ {
223
224
// Get the current scintilla
224
225
int which = -1 ;
225
226
::SendMessage (nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0 , (LPARAM)&which);
@@ -248,9 +249,25 @@ void formatSelectedJSON() {
248
249
rapidjson::StringStream ss (curJSON);
249
250
rapidjson::Reader reader;
250
251
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
+ }
254
271
255
272
delete[] curJSON;
256
273
}
0 commit comments