Skip to content

Commit

Permalink
fix bugs, add json<->rawtext convert, fix issue#43
Browse files Browse the repository at this point in the history
1. Fix most bugs associated with multiple selections
2. add ability to convert between JSON strings, raw text
3. Fix various bugs all over the place
4. Fix bug in running tests on some versions
5. improve about form
  • Loading branch information
molsonkiko committed Aug 13, 2023
1 parent 882ed4b commit c3243f3
Show file tree
Hide file tree
Showing 36 changed files with 776 additions and 275 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,30 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- When a tree viewer is refreshed using JSON from a file with a different name, the title of the docking form that the user sees doesn't change to reflect the new file. For example, a tree viewer is opened up for `foo.json` and then refreshed with a buffer named `bar.json`, and the title of the docking form still reads `Json Tree View for foo.json`.
- This is also true if a file with a tree viewer is renamed, e.g., the file `foo.json` is renamed to `bar.json`, but the tree viewer still says `Json Tree View for foo.json`.

## [5.5.0] - (UNRELEASED) YYYY-MM-DD
## [5.5.0] - 2023-08-13

### Added

1. __Add support for [operating on selections](/docs/README.md#working-with-selections)__
2. Add [`parse`](/docs/RemesPath.md#vectorized-functions), [`type` and `stringify`](/docs/RemesPath.md#non-vectorized-functions) RemesPath functions.
2. Add method for [selecting every valid JSON element in the file](/docs/README.md#selecting-all-valid-json)
3. Add `D&ump text of current document as JSON string` and `Dump JSON string(s) as ra&w text` convenience methods.
4. Add [`parse`](/docs/RemesPath.md#vectorized-functions), [`type` and `stringify`](/docs/RemesPath.md#non-vectorized-functions) RemesPath functions.
5. Added UI tests.

### Changed

1. Improved RemesPath [boolean indices](/docs/RemesPath.md#boolean-indexing) so that they can be more easily chained together.
2. Removed unneeded RemesPath lexer tests.

### Fixed

1. Bug where `s_slice`, `max_by`, `min_by`, `group_by`, and `sort_by` all did not allow Python-style negative indices.
2. Bug where out-of-bounds negative indices when indexing in an array would throw an error rather than returning an empty array (which is the correct behavior, since RemesPath is not supposed to throw errors for indexing out of bounds).
3. Eliminated huge latency when viewing very long JSON strings in the treeview.
4. Eliminated potential access violation during plugin cleanup.
5. Bug in which the plugin would be mistaken about the position of JSON elements after PPrint-style printing of some JSON containing non-ASCII characters in strings.
6. Bug in which multiple Sort forms could be open.
7. Bug in which running tests in Notepad++ versions older than v8 could cause Notepad++ to crash.

## [5.4.0] - 2023-07-04

Expand Down
7 changes: 2 additions & 5 deletions JsonToolsNppPlugin/Forms/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ namespace JSON_Tools.Forms
{
public partial class AboutForm : Form
{
private static int[] nppVersion = Npp.notepad.GetNppVersion();

public AboutForm()
{
InitializeComponent();
FormStyle.ApplyStyle(this, Main.settings.use_npp_styling);
ThanksWowLinkLabel.LinkColor = ThanksWowLinkLabel.ForeColor; // hidden!
Title.Text = Title.Text.Replace("X.Y.Z.A", Npp.AssemblyVersionString());
string nppVersionString = string.Join(".", nppVersion.Select((x) => x.ToString()));
DebugInfoLabel.Text = DebugInfoLabel.Text.Replace("X.Y.Z", nppVersionString);
DebugInfoLabel.Text = DebugInfoLabel.Text.Replace("X.Y.Z", Npp.nppVersionStr);
}

/// <summary>
Expand Down Expand Up @@ -86,7 +83,7 @@ static void Dogeify()
{
(bool fatal, JNode json, _) = Main.TryParseJson();
if (fatal || json == null) return;
if (nppVersion[0] >= 8)
if (Npp.nppVersionAtLeast8)
{
// add the UDL file to the userDefinedLangs folder so that it can colorize the new file
DirectoryInfo userDefinedLangPath = new DirectoryInfo(Path.Combine(
Expand Down
6 changes: 3 additions & 3 deletions JsonToolsNppPlugin/Forms/SortForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Forms/TreeViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,10 @@ void RuntimeErrorMessage(Exception ex)
return;
}
}
Main.ReformatFileWithJson(query_func, Main.PrettyPrintFromSettings, UsesSelections());
json = query_func;
Main.jsonFileInfos[fname].json = query_func;
query_result = query_func;
Main.ReformatFileWithJson(json, Main.PrettyPrintFromSettings, UsesSelections());
}
// not an assignment expression, so executing the query changes the contents of the tree
// but leaves the text of the document unchanged
Expand Down
11 changes: 6 additions & 5 deletions JsonToolsNppPlugin/JSONTools/JNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,10 @@ public virtual string ToString(bool sort_keys = true, string key_value_sep = ":

internal virtual int ToStringHelper(bool sort_keys, string key_value_sep, string item_sep, StringBuilder sb, bool change_positions, int extra_utf8_bytes, int max_length)
{
if (change_positions) position = sb.Length + extra_utf8_bytes;
var str = ToString();
sb.Append(str);
if (change_positions)
position = sb.Length + extra_utf8_bytes;
var str = ToString();
sb.Append(str);
if (type == Dtype.STR)
return extra_utf8_bytes + JsonParser.ExtraUTF8BytesBetween(str, 1, str.Length - 1);
return extra_utf8_bytes; // only ASCII characters in non-strings
Expand Down Expand Up @@ -975,7 +976,7 @@ internal override int PrettyPrintHelper(int indent, bool sort_keys, PrettyPrintS
JNode v = children[k];
extra_utf8_bytes += JsonParser.ExtraUTF8BytesBetween(k, 0, k.Length);
sb.Append($"{extra_dent}\"{k}\": ");
v.PPrintHelper(indent, depth, sort_keys, sb, change_positions, extra_utf8_bytes, max_line_end, max_length, indent_char);
extra_utf8_bytes = v.PPrintHelper(indent, depth, sort_keys, sb, change_positions, extra_utf8_bytes, max_line_end, max_length, indent_char);
if (sb.Length >= max_length)
return -1;
if (++ctr < children.Count)
Expand Down Expand Up @@ -1211,7 +1212,7 @@ internal override int PrettyPrintHelper(int indent, bool sort_keys, PrettyPrintS
{
int max_line_end = sb.Length + PPRINT_LINE_LENGTH;
sb.Append(extra_dent);
v.PPrintHelper(indent, depth, sort_keys, sb, change_positions, extra_utf8_bytes, max_line_end, max_length, indent_char);
extra_utf8_bytes = v.PPrintHelper(indent, depth, sort_keys, sb, change_positions, extra_utf8_bytes, max_line_end, max_length, indent_char);
if (sb.Length >= max_length)
return -1;
if (++ctr < children.Count)
Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/JSONTools/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class JsonParser
/// <summary>
/// position in JSON string
/// </summary>
private int ii;
public int ii;

/// <summary>
/// the number of extra bytes in the UTF-8 encoding of the text consumed
Expand Down
Loading

0 comments on commit c3243f3

Please sign in to comment.