diff --git a/CHANGELOG.md b/CHANGELOG.md index a368d788a78..bb0728e0b97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased] +- Add `unsafe_set!(::Textbox, ::String)` [#4417](https://github.com/MakieOrg/Makie.jl/pull/4417) - Moved Axis3 clip planes slightly outside to avoid clipping objects on the border with 0 margin [#4742](https://github.com/MakieOrg/Makie.jl/pull/4742) - Fixed an issue with transformations not propagating to child plots when their spaces only match indirectly. [#4723](https://github.com/MakieOrg/Makie.jl/pull/4723) - Added a tutorial on creating an inset plot [#4697](https://github.com/MakieOrg/Makie.jl/pull/4697) diff --git a/src/makielayout/blocks/textbox.jl b/src/makielayout/blocks/textbox.jl index 58f4252726c..acf06bc01ab 100644 --- a/src/makielayout/blocks/textbox.jl +++ b/src/makielayout/blocks/textbox.jl @@ -86,8 +86,7 @@ function initialize_block!(tbox::Textbox) if ci > length(bbs) # correct cursorindex if it's outside of the displayed charbbs range - cursorindex[] = length(bbs) - return + ci = cursorindex[] = length(bbs) end if 0 < ci < length(bbs) @@ -344,10 +343,18 @@ end 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) tb.displayed_string = string tb.stored_string = string nothing diff --git a/test/SceneLike/makielayout.jl b/test/SceneLike/makielayout.jl index 713dd13e6d7..1d8631650b8 100644 --- a/test/SceneLike/makielayout.jl +++ b/test/SceneLike/makielayout.jl @@ -571,3 +571,11 @@ 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")) +end