From 26b5189bd2f86c320694fa5008481788f95cbf57 Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Fri, 27 Sep 2024 16:49:14 -0400 Subject: [PATCH 1/3] correct errant return value in textbox logic --- src/makielayout/blocks/textbox.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/makielayout/blocks/textbox.jl b/src/makielayout/blocks/textbox.jl index 58f4252726c..444acbb6da7 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) From 24fd6c48685dc2f081806a60a3d936789abef0c3 Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Thu, 3 Oct 2024 10:17:41 -0400 Subject: [PATCH 2/3] add unsafe_set!(::Textbox...) --- CHANGELOG.md | 1 + src/makielayout/blocks/textbox.jl | 10 +++++++++- test/makielayout.jl | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db95ea697ab..591d19bfa33 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) - Prevent more default actions when canvas has focus [#4602](https://github.com/MakieOrg/Makie.jl/pull/4602). - Fix an error in `convert_arguments` for PointBased plots and 3D polygons [#4585](https://github.com/MakieOrg/Makie.jl/pull/4585). - Fix polygon rendering issue of `crossbar(..., show_notch = true)` in CairoMakie [#4587](https://github.com/MakieOrg/Makie.jl/pull/4587). diff --git a/src/makielayout/blocks/textbox.jl b/src/makielayout/blocks/textbox.jl index 444acbb6da7..acf06bc01ab 100644 --- a/src/makielayout/blocks/textbox.jl +++ b/src/makielayout/blocks/textbox.jl @@ -343,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/makielayout.jl b/test/makielayout.jl index d0da12133e5..b8be6f1b951 100644 --- a/test/makielayout.jl +++ b/test/makielayout.jl @@ -547,3 +547,11 @@ end end @test isempty(limits.listeners) 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 From 0ad42c0d4f011f26e889ccfb67ec4ed5505cb6ac Mon Sep 17 00:00:00 2001 From: Ben Arthur Date: Tue, 18 Feb 2025 12:59:42 -0500 Subject: [PATCH 3/3] fix tests --- test/SceneLike/makielayout.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/SceneLike/makielayout.jl b/test/SceneLike/makielayout.jl index b0ef635ddba..1d8631650b8 100644 --- a/test/SceneLike/makielayout.jl +++ b/test/SceneLike/makielayout.jl @@ -578,3 +578,4 @@ end @test isnothing(Makie.set!(tb, "hi")) @test_throws ErrorException Makie.set!(tb, "there") @test isnothing(Makie.unsafe_set!(tb, "there")) +end