remove debug prints, delete prev behavior

This commit is contained in:
Michael Freno
2025-11-08 22:40:54 -05:00
parent d73fdbebe8
commit cf65ceabf0

View File

@@ -2551,10 +2551,10 @@ function Element:draw(backdropCanvas)
end end
end end
else else
print("[FlexLove] Component not found: " .. self.themeComponent .. " in theme: " .. themeToUse.name) -- Component not found in theme
end end
else else
print("[FlexLove] No theme available for themeComponent: " .. self.themeComponent) -- No theme available for themeComponent
end end
end end
@@ -2603,8 +2603,7 @@ function Element:draw(backdropCanvas)
end end
if displayText and displayText ~= "" then if displayText and displayText ~= "" then
local textColor = isPlaceholder local textColor = isPlaceholder and Color.new(self.textColor.r * 0.5, self.textColor.g * 0.5, self.textColor.b * 0.5, self.textColor.a * 0.5)
and Color.new(self.textColor.r * 0.5, self.textColor.g * 0.5, self.textColor.b * 0.5, self.textColor.a * 0.5)
or self.textColor or self.textColor
local textColorWithOpacity = Color.new(textColor.r, textColor.g, textColor.b, textColor.a * self.opacity) local textColorWithOpacity = Color.new(textColor.r, textColor.g, textColor.b, textColor.a * self.opacity)
love.graphics.setColor(textColorWithOpacity:toRGBA()) love.graphics.setColor(textColorWithOpacity:toRGBA())
@@ -3318,13 +3317,11 @@ function Element:update(dt)
-- Focus editable elements on left click -- Focus editable elements on left click
if button == 1 and self.editable then if button == 1 and self.editable then
print("[Element:update] Calling focus on editable element")
self:focus() self:focus()
-- Handle text click for cursor positioning and word selection -- Handle text click for cursor positioning and word selection
self:_handleTextClick(mx, my, clickCount) self:_handleTextClick(mx, my, clickCount)
elseif button == 1 then elseif button == 1 then
print("[Element:update] Button 1 clicked but editable:", self.editable)
end end
-- Fire release event -- Fire release event
@@ -4239,13 +4236,9 @@ end
--- Focus this element for keyboard input --- Focus this element for keyboard input
function Element:focus() function Element:focus()
if not self.editable then if not self.editable then
print("[Element:focus] Not editable, skipping focus")
return return
end end
print("[Element:focus] Focusing element, editable:", self.editable)
-- Blur previously focused element
if Gui._focusedElement and Gui._focusedElement ~= self then if Gui._focusedElement and Gui._focusedElement ~= self then
Gui._focusedElement:blur() Gui._focusedElement:blur()
end end
@@ -4254,16 +4247,11 @@ function Element:focus()
self._focused = true self._focused = true
Gui._focusedElement = self Gui._focusedElement = self
print("[Element:focus] Focus set, _focused:", self._focused)
-- Reset cursor blink
self:_resetCursorBlink() self:_resetCursorBlink()
-- Select all text if selectOnFocus is enabled
if self.selectOnFocus then if self.selectOnFocus then
self:selectAll() self:selectAll()
else else
-- Move cursor to end of text
self:moveCursorToEnd() self:moveCursorToEnd()
end end
@@ -4362,19 +4350,14 @@ function Element:insertText(text, position)
self._textBuffer = before .. text .. after self._textBuffer = before .. text .. after
self.text = self._textBuffer -- Sync display text self.text = self._textBuffer -- Sync display text
-- Update cursor position
self._cursorPosition = position + utf8.len(text) self._cursorPosition = position + utf8.len(text)
print(string.format("[InsertText] Text: '%s', multiline: %s, autoGrow: %s",
self._textBuffer:gsub("\n", "\\n"), tostring(self.multiline), tostring(self.autoGrow)))
self:_markTextDirty() self:_markTextDirty()
self:_updateTextIfDirty() -- Update immediately to recalculate lines/wrapping self:_updateTextIfDirty() -- Update immediately to recalculate lines/wrapping
self:_updateAutoGrowHeight() -- Then update height based on new content self:_updateAutoGrowHeight() -- Then update height based on new content
self:_validateCursorPosition() self:_validateCursorPosition()
end end
--- Delete text in range
---@param startPos number -- Start position (inclusive) ---@param startPos number -- Start position (inclusive)
---@param endPos number -- End position (inclusive) ---@param endPos number -- End position (inclusive)
function Element:deleteText(startPos, endPos) function Element:deleteText(startPos, endPos)
@@ -4511,7 +4494,9 @@ function Element:_wrapLine(line, maxWidth)
-- Helper function to extract a UTF-8 character by character index -- Helper function to extract a UTF-8 character by character index
local function getUtf8Char(str, charIndex) local function getUtf8Char(str, charIndex)
local byteStart = utf8.offset(str, charIndex) local byteStart = utf8.offset(str, charIndex)
if not byteStart then return "" end if not byteStart then
return ""
end
local byteEnd = utf8.offset(str, charIndex + 1) local byteEnd = utf8.offset(str, charIndex + 1)
if byteEnd then if byteEnd then
return str:sub(byteStart, byteEnd - 1) return str:sub(byteStart, byteEnd - 1)
@@ -4520,11 +4505,7 @@ function Element:_wrapLine(line, maxWidth)
end end
end end
print(string.format("[WrapLine] line length: %d, maxWidth: %.1f, textWrap: %s",
utf8.len(line) or 0, maxWidth, tostring(self.textWrap)))
if self.textWrap == "word" then if self.textWrap == "word" then
-- Word wrapping
local words = {} local words = {}
for word in line:gmatch("%S+") do for word in line:gmatch("%S+") do
table.insert(words, word) table.insert(words, word)
@@ -4535,7 +4516,6 @@ function Element:_wrapLine(line, maxWidth)
local width = font:getWidth(testLine) local width = font:getWidth(testLine)
if width > maxWidth and currentLine ~= "" then if width > maxWidth and currentLine ~= "" then
-- Current line is full, start new line
local currentLineLen = utf8.len(currentLine) local currentLineLen = utf8.len(currentLine)
table.insert(wrappedParts, { table.insert(wrappedParts, {
text = currentLine, text = currentLine,
@@ -4642,15 +4622,9 @@ function Element:_wrapLine(line, maxWidth)
}) })
end end
if #wrappedParts > 1 then
print(string.format("[WrapLine] Returning %d segments for line length %d",
#wrappedParts, utf8.len(line) or 0))
end
return wrappedParts return wrappedParts
end end
--- Get font for text rendering
---@return love.Font ---@return love.Font
function Element:_getFont() function Element:_getFont()
-- Get font path from theme or element -- Get font path from theme or element
@@ -4660,7 +4634,6 @@ function Element:_getFont()
if themeToUse and themeToUse.fonts and themeToUse.fonts[self.fontFamily] then if themeToUse and themeToUse.fonts and themeToUse.fonts[self.fontFamily] then
fontPath = themeToUse.fonts[self.fontFamily] fontPath = themeToUse.fonts[self.fontFamily]
else else
-- Assume fontFamily is a direct path
fontPath = self.fontFamily fontPath = self.fontFamily
end end
end end
@@ -4750,10 +4723,8 @@ function Element:_getCursorScreenPosition()
end end
end end
cursorX = font:getWidth(segmentText) cursorX = font:getWidth(segmentText)
-- Add line offset for wrapped segments
cursorY = (lineNum - 1) * lineHeight + (segmentIdx - 1) * lineHeight cursorY = (lineNum - 1) * lineHeight + (segmentIdx - 1) * lineHeight
print(string.format("[CursorCalc] Line %d, Segment %d, posInLine: %d, startIdx: %d, endIdx: %d, cursorY: %.1f",
lineNum, segmentIdx, posInLine, segment.startIdx, segment.endIdx, cursorY))
return cursorX, cursorY return cursorX, cursorY
end end
end end
@@ -4775,12 +4746,11 @@ function Element:_getCursorScreenPosition()
end end
end end
-- Move to next line (add 1 for the newline character)
charCount = charCount + lineLength + 1 charCount = charCount + lineLength + 1
end end
-- Cursor is at the very end -- Cursor is at the very end
return 0, (#lines) * lineHeight return 0, #lines * lineHeight
end end
--- Update element height based on text content (for autoGrow multiline fields) --- Update element height based on text content (for autoGrow multiline fields)
@@ -4829,22 +4799,14 @@ function Element:_updateAutoGrowHeight()
totalWrappedLines = #lines totalWrappedLines = #lines
end end
-- Ensure at least one line
totalWrappedLines = math.max(1, totalWrappedLines) totalWrappedLines = math.max(1, totalWrappedLines)
-- Calculate new content height
local newContentHeight = totalWrappedLines * lineHeight local newContentHeight = totalWrappedLines * lineHeight
-- Update height if it changed
if self.height ~= newContentHeight then if self.height ~= newContentHeight then
print(string.format("[AutoGrow] Height changing from %s to %s (lines: %d)",
tostring(self.height), tostring(newContentHeight), totalWrappedLines))
self.height = newContentHeight self.height = newContentHeight
self._borderBoxHeight = self.height + self.padding.top + self.padding.bottom self._borderBoxHeight = self.height + self.padding.top + self.padding.bottom
-- Re-layout parent if this element participates in parent layout
if self.parent and not self._explicitlyAbsolute then if self.parent and not self._explicitlyAbsolute then
print("[AutoGrow] Re-layouting parent")
self.parent:layoutChildren() self.parent:layoutChildren()
end end
end end
@@ -4870,6 +4832,11 @@ function Element:_mouseToTextPosition(mouseX, mouseY)
-- Calculate relative X position within text area -- Calculate relative X position within text area
local relativeX = mouseX - contentX local relativeX = mouseX - contentX
-- Account for horizontal scroll offset in single-line inputs
if not self.multiline and self._textScrollX then
relativeX = relativeX + self._textScrollX
end
-- Get font for measuring text -- Get font for measuring text
local font = self:_getFont() local font = self:_getFont()
@@ -4915,11 +4882,9 @@ function Element:_handleTextClick(mouseX, mouseY, clickCount)
-- Store position for potential drag selection -- Store position for potential drag selection
self._mouseDownPosition = pos self._mouseDownPosition = pos
elseif clickCount == 2 then elseif clickCount == 2 then
-- Double click: Select word -- Double click: Select word
self:_selectWordAtPosition(self:_mouseToTextPosition(mouseX, mouseY)) self:_selectWordAtPosition(self:_mouseToTextPosition(mouseX, mouseY))
elseif clickCount >= 3 then elseif clickCount >= 3 then
-- Triple click: Select all (or line in multi-line mode) -- Triple click: Select all (or line in multi-line mode)
self:selectAll() self:selectAll()
@@ -5129,6 +5094,13 @@ function Element:keypressed(key, scancode, isrepeat)
if self:hasSelection() then if self:hasSelection() then
-- Delete selection -- Delete selection
self:deleteSelection() self:deleteSelection()
elseif ctrl then
-- Ctrl/Cmd+Backspace: Delete all text from start to cursor
if self._cursorPosition > 0 then
self:deleteText(0, self._cursorPosition)
self._cursorPosition = 0
self:_validateCursorPosition()
end
elseif self._cursorPosition > 0 then elseif self._cursorPosition > 0 then
-- Delete character before cursor -- Delete character before cursor
-- Update cursor position BEFORE deleteText so updates use correct position -- Update cursor position BEFORE deleteText so updates use correct position