remove debug prints, delete prev behavior
This commit is contained in:
@@ -2551,10 +2551,10 @@ function Element:draw(backdropCanvas)
|
||||
end
|
||||
end
|
||||
else
|
||||
print("[FlexLove] Component not found: " .. self.themeComponent .. " in theme: " .. themeToUse.name)
|
||||
-- Component not found in theme
|
||||
end
|
||||
else
|
||||
print("[FlexLove] No theme available for themeComponent: " .. self.themeComponent)
|
||||
-- No theme available for themeComponent
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2603,8 +2603,7 @@ function Element:draw(backdropCanvas)
|
||||
end
|
||||
|
||||
if displayText and displayText ~= "" then
|
||||
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)
|
||||
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)
|
||||
or self.textColor
|
||||
local textColorWithOpacity = Color.new(textColor.r, textColor.g, textColor.b, textColor.a * self.opacity)
|
||||
love.graphics.setColor(textColorWithOpacity:toRGBA())
|
||||
@@ -3318,13 +3317,11 @@ function Element:update(dt)
|
||||
|
||||
-- Focus editable elements on left click
|
||||
if button == 1 and self.editable then
|
||||
print("[Element:update] Calling focus on editable element")
|
||||
self:focus()
|
||||
|
||||
-- Handle text click for cursor positioning and word selection
|
||||
self:_handleTextClick(mx, my, clickCount)
|
||||
elseif button == 1 then
|
||||
print("[Element:update] Button 1 clicked but editable:", self.editable)
|
||||
end
|
||||
|
||||
-- Fire release event
|
||||
@@ -4239,13 +4236,9 @@ end
|
||||
--- Focus this element for keyboard input
|
||||
function Element:focus()
|
||||
if not self.editable then
|
||||
print("[Element:focus] Not editable, skipping focus")
|
||||
return
|
||||
end
|
||||
|
||||
print("[Element:focus] Focusing element, editable:", self.editable)
|
||||
|
||||
-- Blur previously focused element
|
||||
if Gui._focusedElement and Gui._focusedElement ~= self then
|
||||
Gui._focusedElement:blur()
|
||||
end
|
||||
@@ -4254,16 +4247,11 @@ function Element:focus()
|
||||
self._focused = true
|
||||
Gui._focusedElement = self
|
||||
|
||||
print("[Element:focus] Focus set, _focused:", self._focused)
|
||||
|
||||
-- Reset cursor blink
|
||||
self:_resetCursorBlink()
|
||||
|
||||
-- Select all text if selectOnFocus is enabled
|
||||
if self.selectOnFocus then
|
||||
self:selectAll()
|
||||
else
|
||||
-- Move cursor to end of text
|
||||
self:moveCursorToEnd()
|
||||
end
|
||||
|
||||
@@ -4362,19 +4350,14 @@ function Element:insertText(text, position)
|
||||
self._textBuffer = before .. text .. after
|
||||
self.text = self._textBuffer -- Sync display text
|
||||
|
||||
-- Update cursor position
|
||||
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:_updateTextIfDirty() -- Update immediately to recalculate lines/wrapping
|
||||
self:_updateAutoGrowHeight() -- Then update height based on new content
|
||||
self:_validateCursorPosition()
|
||||
end
|
||||
|
||||
--- Delete text in range
|
||||
---@param startPos number -- Start position (inclusive)
|
||||
---@param endPos number -- End position (inclusive)
|
||||
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
|
||||
local function getUtf8Char(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)
|
||||
if byteEnd then
|
||||
return str:sub(byteStart, byteEnd - 1)
|
||||
@@ -4520,11 +4505,7 @@ function Element:_wrapLine(line, maxWidth)
|
||||
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
|
||||
-- Word wrapping
|
||||
local words = {}
|
||||
for word in line:gmatch("%S+") do
|
||||
table.insert(words, word)
|
||||
@@ -4535,7 +4516,6 @@ function Element:_wrapLine(line, maxWidth)
|
||||
local width = font:getWidth(testLine)
|
||||
|
||||
if width > maxWidth and currentLine ~= "" then
|
||||
-- Current line is full, start new line
|
||||
local currentLineLen = utf8.len(currentLine)
|
||||
table.insert(wrappedParts, {
|
||||
text = currentLine,
|
||||
@@ -4642,15 +4622,9 @@ function Element:_wrapLine(line, maxWidth)
|
||||
})
|
||||
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
|
||||
end
|
||||
|
||||
--- Get font for text rendering
|
||||
---@return love.Font
|
||||
function Element:_getFont()
|
||||
-- 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
|
||||
fontPath = themeToUse.fonts[self.fontFamily]
|
||||
else
|
||||
-- Assume fontFamily is a direct path
|
||||
fontPath = self.fontFamily
|
||||
end
|
||||
end
|
||||
@@ -4750,10 +4723,8 @@ function Element:_getCursorScreenPosition()
|
||||
end
|
||||
end
|
||||
cursorX = font:getWidth(segmentText)
|
||||
-- Add line offset for wrapped segments
|
||||
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
|
||||
end
|
||||
end
|
||||
@@ -4775,12 +4746,11 @@ function Element:_getCursorScreenPosition()
|
||||
end
|
||||
end
|
||||
|
||||
-- Move to next line (add 1 for the newline character)
|
||||
charCount = charCount + lineLength + 1
|
||||
end
|
||||
|
||||
-- Cursor is at the very end
|
||||
return 0, (#lines) * lineHeight
|
||||
return 0, #lines * lineHeight
|
||||
end
|
||||
|
||||
--- Update element height based on text content (for autoGrow multiline fields)
|
||||
@@ -4829,22 +4799,14 @@ function Element:_updateAutoGrowHeight()
|
||||
totalWrappedLines = #lines
|
||||
end
|
||||
|
||||
-- Ensure at least one line
|
||||
totalWrappedLines = math.max(1, totalWrappedLines)
|
||||
|
||||
-- Calculate new content height
|
||||
local newContentHeight = totalWrappedLines * lineHeight
|
||||
|
||||
-- Update height if it changed
|
||||
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._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
|
||||
print("[AutoGrow] Re-layouting parent")
|
||||
self.parent:layoutChildren()
|
||||
end
|
||||
end
|
||||
@@ -4870,6 +4832,11 @@ function Element:_mouseToTextPosition(mouseX, mouseY)
|
||||
-- Calculate relative X position within text area
|
||||
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
|
||||
local font = self:_getFont()
|
||||
|
||||
@@ -4915,11 +4882,9 @@ function Element:_handleTextClick(mouseX, mouseY, clickCount)
|
||||
|
||||
-- Store position for potential drag selection
|
||||
self._mouseDownPosition = pos
|
||||
|
||||
elseif clickCount == 2 then
|
||||
-- Double click: Select word
|
||||
self:_selectWordAtPosition(self:_mouseToTextPosition(mouseX, mouseY))
|
||||
|
||||
elseif clickCount >= 3 then
|
||||
-- Triple click: Select all (or line in multi-line mode)
|
||||
self:selectAll()
|
||||
@@ -5129,6 +5094,13 @@ function Element:keypressed(key, scancode, isrepeat)
|
||||
if self:hasSelection() then
|
||||
-- Delete selection
|
||||
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
|
||||
-- Delete character before cursor
|
||||
-- Update cursor position BEFORE deleteText so updates use correct position
|
||||
|
||||
Reference in New Issue
Block a user