Skip to content

Commit

Permalink
Clear ErrorForm when no errors; fix JSONL SortForm
Browse files Browse the repository at this point in the history
  • Loading branch information
molsonkiko committed Sep 27, 2024
1 parent 4c0b8f9 commit d5da2a8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 53 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7. Fix bug where plugin actions (mainly RemesPath queries in [regex mode](/docs/README.md#regex-search-form)) that set the text of the entire document to an empty string would not do anything. Those actions will now correctly remove all the text in the document.
8. Fix [issue 79](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/79) where, on higher display resolutions than the default 125% normally used by molsonkiko in development, some of the advanced controls in the [find/replace form](/docs/README.md#find-and-replace-form) would not be visible.
9. Fix annoying but harmless bug where, if the user had two views open and [ran a plugin command on one or more selections](/docs/README.md#working-with-selections) in the second view, the indicator that JsonTools uses to remember selections (which is supposed to be hidden at all times) would cause the selections to be underlined.
10. Address [issue 80](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/80); now [error form](/docs/README.md#error-form-and-status-bar) will be cleared of errors when the JSON parser does not log any syntax errors.
11. Make it so that JSON Lines documents are correctly formatted as JSON Lines after sorting by the [sort form](/docs/README.md#sort-form).

## [8.1.0] - 2024-08-23

Expand Down
7 changes: 5 additions & 2 deletions JsonToolsNppPlugin/Forms/SortForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SortForm()

private void SortButton_Clicked(object sender, EventArgs e)
{
(ParserState parserState, JNode json, bool usesSelections, _) = Main.TryParseJson(preferPreviousDocumentType:true);
(ParserState parserState, JNode json, bool usesSelections, DocumentType docType) = Main.TryParseJson(preferPreviousDocumentType:true);
if (parserState == ParserState.FATAL || json == null)
return;
string pathQuery = "@" + PathTextBox.Text;
Expand Down Expand Up @@ -93,7 +93,10 @@ private void SortButton_Clicked(object sender, EventArgs e)
if (!SortSingleJson(jsonAtPath, query))
return;
}
Main.ReformatFileWithJson(json, Main.PrettyPrintFromSettings, usesSelections);
Func<JNode, string> formatter = Main.PrettyPrintFromSettings;
if (docType == DocumentType.JSONL)
formatter = Main.ToJsonLinesFromSettings;
Main.ReformatFileWithJson(json, formatter, usesSelections);
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,12 +703,14 @@ public static (ParserState parserState, JNode node, bool usesSelections, Documen
string msg = "There were {0} syntax errors in the document. Would you like to see them?\r\n(You can turn off these prompts in the settings (offer_to_show_lint setting))";
if (Translator.ShowTranslatedMessageBox(msg, "View syntax errors in document?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, 1, lintCount) == DialogResult.Yes)
{
if (errorForm != null)
if (errorForm != null && !errorForm.IsDisposed)
Npp.notepad.HideDockingForm(errorForm);
OpenErrorForm(activeFname, true);
//mainThreadForm.Invoke(new Action(() => OpenErrorForm(activeFname, true)));
}
}
if (lintCount == 0 && errorForm != null && !errorForm.IsDisposed) // clear errorForm when no errors found
errorForm.Invoke(new Action(() => errorForm.Reload(activeFname, new List<JsonLint>())));
if (fatal)
{
// jump to the position of the fatal error (if in whole document mode and not auto-triggered)
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("8.1.0.10")]
[assembly: AssemblyFileVersion("8.1.0.10")]
[assembly: AssemblyVersion("8.1.0.11")]
[assembly: AssemblyFileVersion("8.1.0.11")]
7 changes: 7 additions & 0 deletions JsonToolsNppPlugin/Tests/UserInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ public static bool Test()
("treenode_click", new object[]{new string[] { "3 : \"{\\\"5\\\": [6]}\"" } }),
("tree_query", new object[]{"@ = ``"}), // test that using RemesPath to clear text of document works
("compare_text", new object[]{""}),
// TEST SORT FORM ON JSON LINES
("overwrite", new object[]{"[1,'foo',true]\n[2,'bar',false]"}),
("set_document_type", new object[]{"JSONL"}),
("sort_form_run", new object[]{"", false, false, 2, "1"}),
("compare_text", new object[]{"[2,\"bar\",false]\n[1,\"foo\",true]"}),
("sort_form_run", new object[]{"[0]", false, true, 3, "s_len(str(@))"}),
("compare_text", new object[]{"[false,\"bar\",2]\n[1,\"foo\",true]"}),
};

var messages = new List<string>();
Expand Down
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ Of course, there's also the default sort, which can only compare numbers to numb

See the [general notes on string sorting](/README.md#note-on-how-jsontools-sorts-strings) for more notes on how strings are sorted.

For versions of JsonTools [v8.2](/CHANGELOG.md#820---unreleased-yyyy-mm-dd) and newer, [JSON Lines](#json-lines-documents) documents remain formatted as JSON Lines after sorting by the sort form. Earlier versions of JsonTools pretty-printed all JSON after sorting, including JSON Lines.

## Regex search form ##

*Added in [v6.0](/CHANGELOG.md#600---2023-12-13)*
Expand Down
Loading

0 comments on commit d5da2a8

Please sign in to comment.