When suggestions are not yet set CurrentSuggestion() will panic. This change fixes that with a guard and returns an empty string when there is no current suggestion.
When setting the width of the textarea there were some issues
preventing this from working correctly. These problems included:
- If the maximum width needed to be used, the width of the textarea did
not take into account the prompt and line number width.
- The viewport width did not take into account the style width.
The entire function was confusing to understand and a refactor was
warranted.
As part of this refactor, the bugs mentioned above were fixed and the
code was simplified.
To verify that the logic works as expected, unit tests were expanded to
validate that setting the width works as expected.
Signed-off-by: Michael Lorant <michael.lorant@nine.com.au>
* feat(textinput): do not block input on validation
This PR builds upon the excellent work in #167 and #114 and makes a
breaking change to the validation API.
Currently, validation will completely block text input if the Validate
function returns an error. This is now changed so the function no longer
blocks input if this is the case, thus handing this responsibility to
the clients.
This is helpful for cases where the user is requested to type an
existing system path, and the Validate function keeps asserting the
existence of the path. With the current implementation such a validation
is not possible.
For example:
> /
Err: nil
> /t
Err: /t: No such file or directory
> /tm
Err: /tm: No such file or directory
> /tmp
Err: nil
* fix: change name
---------
Co-authored-by: Maas Lalani <maas@lalani.dev>
* fix(table): substract headers Y size from the total table size
* fix: change GetFrameSize to GetVerticalFrameSize and calc header height
* fix: remove GetVerticalFrameSize at all
* fix: account for headers in height WithHeight, SetHeight
---------
Co-authored-by: Maas Lalani <maas@lalani.dev>
Add improved unit tests for textarea view function.
The end of buffer unit test was flawed and failed to properly check
whether the end of buffer character was in the correct location. This
test has been removed as this feature is now verified as part of these
test cases.
Signed-off-by: Michael Lorant <michael.lorant@nine.com.au>
* fix(textinput): out of range panic if no matched suggestions
* fix(textinput): out of bounds check
Co-authored-by: Maas Lalani <maas@lalani.dev>
---------
Co-authored-by: Maas Lalani <maas@lalani.dev>
As the number of items in `suggestions` and `m.suggestions` is known,
we can use `make` with the expected size instead of appending, which
requires more allocations as the slice grows.
* Fix pasting calculations
Available length calculation now correctly trims pasted text.
* fix(textInput): Width padding added when placeholder is used
When `placeholder` is set, padding from `Width` was not added within the `placeholderView()` function.
* Adding missing 'm.'
* Maintain Width no matter placeholder size delta
* Fixed Math
* Added Comments
* fix: lint
---------
Co-authored-by: Donovan Hubbard <37090676+donovanhubbard@users.noreply.github.com>
Co-authored-by: Maas Lalani <maas@lalani.dev>