@@ -161,6 +161,19 @@ void showJSONDialog(char *json)
161161 jsonDialog.display ();
162162}
163163
164+ void selectAllIfUnselectedAndSetCurJSON (size_t selectedTextLength, HWND curScintilla) {
165+ if (selectedTextLength == 0 ) {
166+ size_t allTextlength = ::SendMessage (curScintilla, SCI_GETLENGTH, 0 , (LPARAM)curJSON);
167+ ::SendMessage (curScintilla, SCI_SETSELECTIONSTART, 0 , (LPARAM)curJSON);
168+ ::SendMessage (curScintilla, SCI_SETSELECTIONEND, allTextlength, (LPARAM)curJSON);
169+ curJSON = new CHAR[allTextlength];
170+ } else {
171+ curJSON = new CHAR[selectedTextLength+1 ];
172+ }
173+
174+ ::SendMessage (curScintilla, SCI_GETSELTEXT, 0 , (LPARAM)curJSON);
175+ }
176+
164177void openJSONDialog ()
165178{
166179 // Get the current scintilla
@@ -180,18 +193,8 @@ void openJSONDialog()
180193 }
181194
182195 size_t asciiTextLen = end - start;
183- /*
184- if (asciiTextLen == 0)
185- {
186- //MessageBox(nppData._nppHandle,TEXT("Please select a JSON string."),TEXT("JSON Viewer"),MB_OK|MB_ICONINFORMATION);
187- return;
188- }
189- */
196+ selectAllIfUnselectedAndSetCurJSON (asciiTextLen, curScintilla);
190197
191-
192- curJSON = new CHAR[asciiTextLen+1 ];
193-
194- ::SendMessage (curScintilla, SCI_GETSELTEXT, 0 , (LPARAM)curJSON);
195198 showJSONDialog (curJSON);
196199 delete curJSON;
197200}
@@ -214,16 +217,8 @@ void formatSelectedJSON(){
214217 }
215218
216219 size_t asciiTextLen = end - start;
217-
218- if (asciiTextLen == 0 )
219- {
220- // MessageBox(nppData._nppHandle,TEXT("Please select a JSON string."),TEXT("JSON Viewer"),MB_OK|MB_ICONINFORMATION);
221- return ;
222- }
223-
224- curJSON = new CHAR[asciiTextLen+1 ];
220+ selectAllIfUnselectedAndSetCurJSON (asciiTextLen, curScintilla);
225221
226- ::SendMessage (curScintilla, SCI_GETSELTEXT, 0 , (LPARAM)curJSON);
227222 CHAR* fJson =json_format_string (curJSON);
228223 ::SendMessage (curScintilla,SCI_REPLACESEL,0 ,(LPARAM)fJson);
229224
0 commit comments