Skip to content

Commit e03b3ff

Browse files
committed
Minor text field changes
1 parent 786b117 commit e03b3ff

4 files changed

Lines changed: 19 additions & 2 deletions

File tree

penguingui.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,9 @@ function TextField:draw(dt)
16701670
end
16711671

16721672
function TextField:setCursorPosition(pos)
1673+
if pos > #self.text then
1674+
pos = #self.text
1675+
end
16731676
self.cursorPosition = pos
16741677

16751678
if pos < self.textOffset then
@@ -1756,7 +1759,9 @@ function TextField:keyEvent(keyCode, pressed)
17561759

17571760
if #key == 1 then -- Type a character
17581761
self.text = text:sub(1, cursorPos) .. key .. text:sub(cursorPos + 1)
1759-
self:setCursorPosition(cursorPos + 1)
1762+
if text ~= self.text then
1763+
self:setCursorPosition(cursorPos + 1)
1764+
end
17601765
else -- Special character
17611766
if key == "backspace" then
17621767
if cursorPos > 0 then
@@ -2377,6 +2382,9 @@ function List:removeItem(target)
23772382
return nil, -1
23782383
end
23792384
else -- Remove by item
2385+
if target == nil then
2386+
return nil
2387+
end
23802388
item = target
23812389
index = PtUtil.removeObject(self.items, item)
23822390
if index == -1 then

penguingui/List.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ function List:removeItem(target)
159159
return nil, -1
160160
end
161161
else -- Remove by item
162+
if target == nil then
163+
return nil
164+
end
162165
item = target
163166
index = PtUtil.removeObject(self.items, item)
164167
if index == -1 then

penguingui/Panel.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function Panel:add(child)
3737
end
3838

3939
--- Sets the layout manager for this Panel.
40+
-- THIS IS WIP. THE API IS LIKELY TO CHANGE.
4041
-- @param layout The new layout manager for this panel, or nil to clear the
4142
-- layout manager.
4243
function Panel:setLayoutManager(layout)

penguingui/TextField.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ end
130130
-- @param pos The new position for the cursor, where 0 is the beginning of the
131131
-- field.
132132
function TextField:setCursorPosition(pos)
133+
if pos > #self.text then
134+
pos = #self.text
135+
end
133136
self.cursorPosition = pos
134137

135138
if pos < self.textOffset then
@@ -219,7 +222,9 @@ function TextField:keyEvent(keyCode, pressed)
219222

220223
if #key == 1 then -- Type a character
221224
self.text = text:sub(1, cursorPos) .. key .. text:sub(cursorPos + 1)
222-
self:setCursorPosition(cursorPos + 1)
225+
if text ~= self.text then
226+
self:setCursorPosition(cursorPos + 1)
227+
end
223228
else -- Special character
224229
if key == "backspace" then
225230
if cursorPos > 0 then

0 commit comments

Comments
 (0)