fix: bug where restoring value when leaving minimalist mode #138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This fixes a bug where leaving minimalist mode crashes the plugin. If you have for example "set numberwidth=1" the current code will interpret 1 as a boolean value. So when we leave minimalist mode the plugin naively tries to do "set numberwidth=true" which leads to a crash. The reason the current code tries to intepret 1 as boolean is that sometimes it does represent a boolean. But always intepreting numbers as boolean is naive and leads to crashes.
Solution
We save numbers as numbers (instead of saving them as booleans if the number = 1).
Then let's say we try to restore the value "ruler" and the original value is "1" (as it is how vim represents a boolean) then we will try "set ruler=1". It will produce a bug which will be detected by pcall. So now we enter the if block and we try to do "set ruler" which works.
Observation 1
(type(opt) == "number" and (opt == 1 and true or false) or opt)
nested ternary are hard to read and confusing. Alsoopt == 1 and true or false
can be replaced byopt == 1
Instead of the ternary statement we can do:
is much much clearer. I have deleted this part of the code as I don't need it anyway but I would advise to prioritize clean, simple code (with a bit more comments) as opposed to unclear code with nested ternary statements.