Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the enforce string option. Allow user to insert a number or a boolean value from the Insert context menu #104

Open
bostondevin opened this issue Jun 19, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@bostondevin
Copy link
Contributor

Currently user can't insert a number (only a string) in tree mode - maybe add an option for Number to the context menu? Also boolean too.

@josdejong
Copy link
Owner

The way to insert a text, number, or boolean is to click "Insert value" from the context menu. What you type as value determines what the type of the value will be, if you enter 123 it will be a number, if you enter true it will be a boolean, if you enter hello world it will be a string.

Is it that that icon of the "Insert value" button (a double quote) is misleading in this regard?

@josdejong josdejong added the question Further information is requested label Jun 20, 2022
@bostondevin
Copy link
Contributor Author

bostondevin commented Jun 20, 2022

Aha! Yes - that did make me assume it was inserting a string because of those quotes!

I was trying to somehow convert an existing string value to a number without going into the code view and deleting the quotes. The Convert To menu has Object and Array as options - should it have String, Number, Boolean as well excluding from the options whatever type it currently is?

@josdejong
Copy link
Owner

Ok I'll see if I can come up with a better icon.

Normally there is no need to specify the type explicitly, the editor detects the type itself and turns it into a number or boolean when needed. This conversion only works after you have edited the value though, it's not applied when loading a document. Does that working for you?

(On a side note: in rare cases, you want to enter a string containing a numeric value, you can enforce to keep the value as string via the dropdown of "Edit value", and then select "Enforce string").

@brownieboy
Copy link

brownieboy commented Jun 29, 2022

I discovered (by accident!) that clicking Edit Value->Enforce string on the pop-up menu when the current value is already a string representation of a number, will actually change the value a number (confirmed in the Code view).

So that menu option is actually a toggle. I'm not sure if that's by design or a bug though? If it's by design then we need the menu text to say "Enforce number" when the value is a string representation of a number. Note: it works with floats as well, so "Enforce number" rather than "Enforce integer" if you want to go that way.

@josdejong
Copy link
Owner

Thanks for your input @brownieboy. I'm indeed not totally happy with how it works now, the feature is quite deep hidden away and a bit vague to understand.

This menu item "Enforce string" is indeed a toggle, it has a toggle icon which is checked when the value is a string containing a numeric value, and unchecked when not. If you check it, the contents will be turned into a string. If you uncheck it (like you describe) it will be turned into a number if the contents are a numeric value.

Thinking about a solution: maybe I can add a new entry to the list "Convert to: Structure | Object | Array | value". It can become a list "Structure | Object | Array | string | auto", and it should highlight the type that the value currently has. When selecting "string" it will keep the value always a string also when it contains a numeric value, and when selecting "auto", it will convert the value into whatever contents the value has, that can be: null, boolean, number, string.

@josdejong josdejong added enhancement New feature or request and removed question Further information is requested labels Jun 29, 2022
@brownieboy
Copy link

This menu item "Enforce string" is indeed a toggle, it has a toggle icon which is checked when the value is a string containing a numeric value, and unchecked when not.

Yes, I'd totally missed the checkbox. So that makes sense now.

Thanks for your quick response, @josdejong .

@josdejong josdejong changed the title Allow user to insert a number or a boolean value from the Insert context menu Improve the enforce string option. Allow user to insert a number or a boolean value from the Insert context menu Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants