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

add unsafe_set!(::Textbox, ::String) #4417

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- Add `unsafe_set!(::Textbox, ::String)` [#4417](https://github.com/MakieOrg/Makie.jl/pull/4417)
- Disabled unit prefix conversions for compound units (e.g. `u"m/s"`) to avoid generating incorrect units. [#4583](https://github.com/MakieOrg/Makie.jl/pull/4583)
- Add kwarg to rotate Toggle [#4445](https://github.com/MakieOrg/Makie.jl/pull/4445)
- Fix orientation of environment light textures in RPRMakie [#4629](https://github.com/MakieOrg/Makie.jl/pull/4629).
Expand Down
13 changes: 10 additions & 3 deletions src/makielayout/blocks/textbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@

if ci > length(bbs)
# correct cursorindex if it's outside of the displayed charbbs range
cursorindex[] = length(bbs)
return
ci = cursorindex[] = length(bbs)

Check warning on line 89 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L89

Added line #L89 was not covered by tests
end

if 0 < ci < length(bbs)
Expand Down Expand Up @@ -344,10 +343,18 @@
Sets the stored_string of the given `Textbox` to `string`, triggering listeners of `tb.stored_string`.
"""
function set!(tb::Textbox, string::String)
if !validate_textbox(string, tb.validator[])
if validate_textbox(string, tb.validator[])
unsafe_set!(tb, string)
else
error("Invalid string \"$(string)\" for textbox.")
end
end

"""
unsafe_set!(tb::Textbox, string::String)
Sets the stored_string of the given `Textbox` to `string`, ignoring the possibility that it might not pass the validator function.
"""
function unsafe_set!(tb::Textbox, string::String)

Check warning on line 357 in src/makielayout/blocks/textbox.jl

View check run for this annotation

Codecov / codecov/patch

src/makielayout/blocks/textbox.jl#L357

Added line #L357 was not covered by tests
tb.displayed_string = string
tb.stored_string = string
nothing
Expand Down
7 changes: 7 additions & 0 deletions test/makielayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,10 @@ end
Toggle(f[2,1], orientation=:vertical)
Toggle(f[3,1], orientation=pi/4)
end

@testset "Textbox set! & unsafe_set!" begin
f = Figure()
tb = Textbox(f[1,1], validator = isequal("hi"))
@test isnothing(Makie.set!(tb, "hi"))
@test_throws ErrorException Makie.set!(tb, "there")
@test isnothing(Makie.unsafe_set!(tb, "there"))
Loading