Icon representing a recipe

Recipe: dialog_test

created by LociOiling

Profile


Name
dialog_test
ID
102244
Shared with
Public
Parent
None
Children
None
Created on
November 15, 2016 at 20:20 PM UTC
Updated on
November 15, 2016 at 20:20 PM UTC
Description

Demo of an odd bug. Having two newline-delimited textboxes in a dialog can break one of the textboxes, making it read-only.

Best for


Code


-- -- dialog_test -- -- Test of a simple dialog with two textboxes. -- -- When the strings in text boxes are newline-delimited, a problem occurs. -- -- If the string in the second textbox contains more than three newlines, -- the string in the first textbox becomes non-modafiable. That is, you -- won't be able to type in the first textbox, or copy its contents with -- copy and paste. -- -- If the string in the second textbox contains three or fewer newlines, all -- is well. -- -- Displaying newline-delimited strings in a textbox is a trick used for recipes -- which create comma-separated values which can be pasted into a spreadsheet or -- other tool. -- -- In this example, "alpha" is the string for the first textbox. In the simplest -- case, "alpha" consists of a single newline. -- -- The string "bravo" is the second text box. When "bravo" contains just four newlines, -- the textbox for "alpha" stops working. If "bravo" is reduced to three newlines, -- both textboxes work as expected. -- -- -- show report function -- function ShowReport ( msg, alpha, bravo ) local ask = dialog.CreateDialog ( "textbox tester" ) ask.msg = dialog.AddLabel ( "version: " .. msg ) ask.lalpha = dialog.AddLabel ( "---- alpha report length: " .. alpha:len() ) ask.alpha = dialog.AddTextbox ( "alpha:", alpha ) ask.lbravo = dialog.AddLabel ( "---- bravo report length: " .. bravo:len() ) ask.bravo = dialog.AddTextbox ( "bravo:", bravo ) ask.OK = dialog.AddButton ( "OK", 1 ) dialog.Show ( ask ) end -- -- simplest case for alpha -- alpha = "\n" -- -- breaker case for bravo -- four newlines breaks the textbox for alpha -- bravo = "\n\n\n\n" -- -- success case for bravo -- three newlines makes the textbox for alpha work as expected -- bravo2 = "\n\n\n" ShowReport ( "broken version: \"alpha\" read-only", alpha, bravo ) ShowReport ( "fixed version: \"alpha\" is modifiable, copyable", alpha, bravo2 ) -- -- bonus test data -- --[[ alpha = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" .. "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" .. "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n" .. "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\n" .. "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n" .. "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n" .. "ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\n" .. "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n" .. "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n" .. "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\n" .. "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n" .. "lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\n" .. "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n" .. "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\n" .. "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo\n" .. "ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\n" .. "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n" .. "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\n" .. "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n" .. "ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt\n" .. "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n" .. "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n" .. "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n" .. "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" .. "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n" .. "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n" -- 12345678901234567890123456789012345678901234567890123456789012345678901234567890 -- 1 2 3 4 5 6 7 8 ]]-- --[[ bravo = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" .. "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" .. "ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n" .. "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\n" .. "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\n" .. "ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\n" .. "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n" .. "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n" .. "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj\n" .. "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n" .. "lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll\n" .. "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n" -- 12345678901234567890123456789012345678901234567890123456789012345678901234567890 -- 1 2 3 4 5 6 7 8 ]]--

Comments