bug: addLine skips the first line, even if it's empty #46

Closed
opened 2023-02-16 14:50:12 +08:00 by luiz00martins · 4 comments
luiz00martins commented 2023-02-16 14:50:12 +08:00 (Migrated from github.com)

Minimal Working Example

--Basalt configurated installer
local filePath = "/basalt.lua" --here you can change the file path default: basalt
if not(fs.exists(filePath))then
    shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command
end
local basalt = require(filePath:gsub(".lua", ""))

local main = basalt.createFrame("mainFrame")

local button = main:addTextfield('button')
	:setSize(20, 5)
	:addLine('something')

basalt.autoUpdate()

image

Expected behavior

If the first line is empty, addLine would add the text to the first line.


[X] I am running the latest version.
Tick the box if you are running the latest version!

### Minimal Working Example ```lua --Basalt configurated installer local filePath = "/basalt.lua" --here you can change the file path default: basalt if not(fs.exists(filePath))then shell.run("pastebin run ESs1mg7P packed true "..filePath:gsub(".lua", "")) -- this is an alternative to the wget command end local basalt = require(filePath:gsub(".lua", "")) local main = basalt.createFrame("mainFrame") local button = main:addTextfield('button') :setSize(20, 5) :addLine('something') basalt.autoUpdate() ``` ![image](https://user-images.githubusercontent.com/43142209/219288939-c38024d5-63e1-49d2-a847-868e18d824f2.png) ### Expected behavior If the first line is empty, `addLine` would add the text to the first line. --- [X] I am running the latest version. Tick the box if you are running the latest version!
NoryiE commented 2023-02-17 19:37:47 +08:00 (Migrated from github.com)

Hello! This is not a bug. The textfield always has one line. If you want your text (something) on position 1, you can use this for example:

local main = basalt.createFrame("mainFrame")

local button = main:addTextfield('button')
	:setSize(20, 5)
	:addLine('something')
	:removeLine(1)

basalt.autoUpdate()

Have a nice day!

Hello! This is not a bug. The textfield always has one line. If you want your text (something) on position 1, you can use this for example: ```lua local main = basalt.createFrame("mainFrame") local button = main:addTextfield('button') :setSize(20, 5) :addLine('something') :removeLine(1) basalt.autoUpdate() ``` Have a nice day!
luiz00martins commented 2023-02-18 03:21:31 +08:00 (Migrated from github.com)

This sounds kinda weird decision from a usability standpoint.

As a simple example, say I want to create a program that adds/removes something from a textfield every time a button is pressed. In my head, I'd imagine something like this:

local main = basalt.createFrame("mainFrame")

local textfield = main:addTextfield('txt')
	:setSize(20, 5)

local add_button = main:addButton('add_btn')
	:setSize(10, 3)
	:setPosition(1, 7)
	:setText('Add')
	:onClick(function()
		textfield:addLine('clicked')
	end)

local remove_button = main:addButton('remove_btn')
	:setSize(10, 3)
	:setPosition(12, 7)
	:setText('Remove')
	:onClick(function()
		textfield:removeLine()
	end)

basalt.autoUpdate()

However, that won't work. It'll only add from the second line beyond.

Currently, I'd have to do this:

local main = basalt.createFrame("mainFrame")

local textfield = main:addTextfield('txt')
	:setSize(20, 5)

local add_button = main:addButton('add_btn')
	:setSize(10, 3)
	:setPosition(1, 7)
	:setText('Add')
	:onClick(function()
		-- Notice this weird check.
		if #textfield:getLines() == 1 and textfield:getLine(1) == ' ' then 
			textfield:addLine('clicked'):removeLine(1)
		else
			textfield:addLine('clicked')
		end
	end)

local remove_button = main:addButton('remove_btn')
	:setSize(10, 3)
	:setPosition(12, 7)
	:setText('Remove')
	:onClick(function()
		textfield:removeLine()
	end)

basalt.autoUpdate()

Now you'd have to add a seemingly superfluous if statement to check on a situation that I would imagine would be quite normal. Adding something to the first line instead of the second.

It feels like it would be more ergonomic if an empty textfield would be treated as '0' lines. The current way to 'add one line' feels like a hacky workaround. Note that I didn't say it is. If it's intended and documented behaviour, it's not a workaround. However, it really feels like a hacky workaround.

I think addLine adding to the first line instead of the second would be a more ergonomic and expected behaviour.

This sounds kinda weird decision from a usability standpoint. As a simple example, say I want to create a program that adds/removes something from a textfield every time a button is pressed. In my head, I'd imagine something like this: ```lua local main = basalt.createFrame("mainFrame") local textfield = main:addTextfield('txt') :setSize(20, 5) local add_button = main:addButton('add_btn') :setSize(10, 3) :setPosition(1, 7) :setText('Add') :onClick(function() textfield:addLine('clicked') end) local remove_button = main:addButton('remove_btn') :setSize(10, 3) :setPosition(12, 7) :setText('Remove') :onClick(function() textfield:removeLine() end) basalt.autoUpdate() ``` However, that won't work. It'll only add from the second line beyond. Currently, I'd have to do this: ```lua local main = basalt.createFrame("mainFrame") local textfield = main:addTextfield('txt') :setSize(20, 5) local add_button = main:addButton('add_btn') :setSize(10, 3) :setPosition(1, 7) :setText('Add') :onClick(function() -- Notice this weird check. if #textfield:getLines() == 1 and textfield:getLine(1) == ' ' then textfield:addLine('clicked'):removeLine(1) else textfield:addLine('clicked') end end) local remove_button = main:addButton('remove_btn') :setSize(10, 3) :setPosition(12, 7) :setText('Remove') :onClick(function() textfield:removeLine() end) basalt.autoUpdate() ``` Now you'd have to add a seemingly superfluous `if` statement to check on a situation that I would imagine would be quite normal. Adding something to the first line instead of the second. It feels like it would be more ergonomic if an empty textfield would be treated as '0' lines. The current way to 'add one line' feels like a hacky workaround. Note that I didn't say it _is_. If it's intended and documented behaviour, it's not a workaround. However, it really _feels_ like a hacky workaround. I think `addLine` adding to the first line instead of the second would be a more ergonomic and expected behaviour.
NoryiE commented 2023-02-18 03:34:30 +08:00 (Migrated from github.com)

Hm, thank you. You are probably right. It is one of my goals to make stuff as easy as possible to use/understand. I will change that!

Hm, thank you. You are probably right. It is one of my goals to make stuff as easy as possible to use/understand. I will change that!
NoryiE commented 2023-02-18 06:00:54 +08:00 (Migrated from github.com)

Hey, it should work now. You can see the changes here: a821abe - i figured out, it was already done to behave like you expected it. The problem was, for some reason i accidentally added a space in the first line, so the check if the line is empty, was always false - that's why it was adding a new line instead. However, now should everything work like expected!

Hey, it should work now. You can see the changes here: [a821abe](https://github.com/Pyroxenium/Basalt/commit/a821abed1f29eff993f8e281762f1e3b8fc1f611) - i figured out, it was already done to behave like you expected it. The problem was, for some reason i accidentally added a space in the first line, so the check if the line is empty, was always false - that's why it was adding a new line instead. However, now should everything work like expected!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: GitHub/Basalt#46
No description provided.