Skip to content

Commit 947fc7e

Browse files
committed
Fixed issue
1 parent fae3b57 commit 947fc7e

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
@@ -205,7 +205,8 @@ void openJSONDialog()
205205
delete[] curJSON;
206206
}
207207

208-
void formatSelectedJSON() {
208+
void formatSelectedJSON()
209+
{
209210
// Get the current scintilla
210211
int which = -1;
211212
::SendMessage(nppData._nppHandle, NPPM_GETCURRENTSCINTILLA, 0, (LPARAM)&which);
@@ -234,9 +235,25 @@ void formatSelectedJSON() {
234235
rapidjson::StringStream ss(curJSON);
235236
rapidjson::Reader reader;
236237

237-
reader.Parse<rapidjson::kParseFullPrecisionFlag >(ss, pw);
238-
const char* fJson = sb.GetString();
239-
::SendMessage(curScintilla, SCI_REPLACESEL, 0, (LPARAM)fJson);
238+
if (reader.Parse<rapidjson::kParseFullPrecisionFlag >(ss, pw))
239+
{
240+
const char* fJson = sb.GetString();
241+
::SendMessage(curScintilla, SCI_REPLACESEL, 0, (LPARAM)fJson);
242+
}
243+
else
244+
{
245+
// Mark the error position
246+
// Get the current scintilla
247+
start = ::SendMessage(curScintilla, SCI_GETSELECTIONSTART, 0, 0);
248+
249+
size_t errPosition = start + reader.GetErrorOffset();
250+
::SendMessage(curScintilla, SCI_SETSEL, errPosition, errPosition + end);
251+
252+
// Intimate user
253+
::MessageBox(nppData._nppHandle,
254+
TEXT("There was an error while parsing JSON, refer the current selection for possible problematic area."),
255+
TEXT("JSON Viewer"), MB_OK | MB_ICONERROR);
256+
}
240257

241258
delete[] curJSON;
242259
}

0 commit comments

Comments
 (0)