Skip to content

Commit 8c537e7

Browse files
committed
fix(caret): keep caret visible during input activity
1 parent a7c0ed0 commit 8c537e7

5 files changed

Lines changed: 55 additions & 9 deletions

File tree

mod.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "InlineInput",
33
"description": "Provides reusable inline input fields for BLT menu rows.",
44
"author": "Perry",
5-
"version": "1.0.0",
5+
"version": "1.0.1",
66
"blt_version": 2,
77
"updates": [
88
{

modules/adapters/shared/input/key_patch.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ function InlineInput:PatchInputBoxKeys(input_box, config, node_gui)
4141
elseif InlineInput:IsModifierKey(key) then
4242
return true
4343
elseif InlineInput:IsKey(key, "insert") then
44-
return session:paste()
44+
local result = session:paste()
45+
InlineInput:ResetCaretBlink(self)
46+
return result
4547
end
4648

4749
local handled, result = InlineInput:ApplySharedInputCommand(session, self, key, {
@@ -57,21 +59,31 @@ function InlineInput:PatchInputBoxKeys(input_box, config, node_gui)
5759
})
5860

5961
if handled then
62+
InlineInput:ResetCaretBlink(self)
6063
return result
6164
end
6265

6366
if InlineInput:IsLeftKey(key) then
6467
InlineInput:MoveCaret(self, -1, { extend_selection = InlineInput:IsShiftDown() })
6568
InlineInput:StartCaretMoveRepeat(config, node_gui, -1)
69+
InlineInput:ResetCaretBlink(self)
6670
return true
6771
elseif InlineInput:IsRightKey(key) then
6872
InlineInput:MoveCaret(self, 1, { extend_selection = InlineInput:IsShiftDown() })
6973
InlineInput:StartCaretMoveRepeat(config, node_gui, 1)
74+
InlineInput:ResetCaretBlink(self)
7075
return true
7176
end
7277

7378
if original_search_key_press then
74-
return original_search_key_press(self, o, key)
79+
local is_text_key = InlineInput:IsTextInputKey(key)
80+
local result = original_search_key_press(self, o, key)
81+
82+
if is_text_key or result then
83+
InlineInput:ResetCaretBlink(self)
84+
end
85+
86+
return result or is_text_key
7587
end
7688
end
7789

@@ -93,6 +105,7 @@ function InlineInput:PatchInputBoxKeys(input_box, config, node_gui)
93105
return true
94106
elseif InlineInput:IsKey(key, "backspace") or InlineInput:IsDeleteKey(key) then
95107
InlineInput:ApplySharedInputCommand(session, self, key)
108+
InlineInput:ResetCaretBlink(self)
96109
return true
97110
elseif InlineInput:IsLeftKey(key) or InlineInput:IsRightKey(key) then
98111
return true
@@ -102,6 +115,10 @@ function InlineInput:PatchInputBoxKeys(input_box, config, node_gui)
102115
local result = original_update_key_down(self, o, key)
103116
self._inline_input_in_key_repeat = nil
104117

118+
if result then
119+
InlineInput:ResetCaretBlink(self)
120+
end
121+
105122
return result
106123
end
107124
end

modules/adapters/shared/input/target.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function InlineInput.InputBoxTarget:set_selection(start_index, end_index)
4040

4141
if text and text.set_selection and type(start_index) == "number" then
4242
text:set_selection(start_index, type(end_index) == "number" and end_index or start_index)
43+
self.library:ResetCaretBlink(self.input_box)
4344
end
4445
end
4546

modules/input/caret.lua

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,36 @@ function InlineInput:StyleCaret(input_box, layer, force_visible)
308308
end
309309
end
310310

311-
function InlineInput:ShowCaret(input_box, layer)
311+
function InlineInput:ResetCaretBlink(input_box)
312312
if input_unfocused(input_box) then
313-
return
313+
return false
314+
end
315+
316+
local caret = input_box and input_box.caret
317+
318+
if not caret then
319+
return false
314320
end
315321

316322
input_box._inline_input_blink_elapsed = 0
317323
input_box._inline_input_blink_alpha_high = true
324+
325+
if caret.set_visible then
326+
caret:set_visible(true)
327+
end
328+
329+
set_caret_alpha(caret, 1)
330+
331+
return true
332+
end
333+
334+
function InlineInput:ShowCaret(input_box, layer)
335+
if input_unfocused(input_box) then
336+
return
337+
end
338+
318339
self:StyleCaret(input_box, layer, true)
319-
set_caret_alpha(input_box.caret, 1)
340+
self:ResetCaretBlink(input_box)
320341
end
321342

322343
function InlineInput:HideCaret(input_box)
@@ -357,9 +378,7 @@ function InlineInput:UpdateCaretBlink(input_box, dt)
357378
end
358379

359380
if input_box._inline_input_blink_alpha_high == nil then
360-
input_box._inline_input_blink_alpha_high = true
361-
self:StyleCaret(input_box, nil, true)
362-
set_caret_alpha(caret, 1)
381+
self:ResetCaretBlink(input_box)
363382
end
364383

365384
local elapsed = (input_box._inline_input_blink_elapsed or 0) + (type(dt) == "number" and dt or 0)
@@ -511,6 +530,7 @@ function InlineInput:SetSelectionToIndex(input_box, index, extend_selection)
511530
end
512531

513532
if current_start == next_start and current_end == next_end then
533+
self:ResetCaretBlink(input_box)
514534
return true
515535
end
516536

@@ -520,6 +540,8 @@ function InlineInput:SetSelectionToIndex(input_box, index, extend_selection)
520540
input_box:update_caret()
521541
end
522542

543+
self:ResetCaretBlink(input_box)
544+
523545
return true
524546
end
525547

@@ -554,6 +576,8 @@ function InlineInput:ClearInputSelection(input_box)
554576
self:UpdateSelectionHighlight(input_box)
555577
end
556578

579+
self:ResetCaretBlink(input_box)
580+
557581
return true
558582
end
559583

@@ -632,6 +656,8 @@ function InlineInput:SetBoxText(input_box, value)
632656
if input_box.update_caret then
633657
input_box:update_caret()
634658
end
659+
660+
self:ResetCaretBlink(input_box)
635661
end
636662

637663
function InlineInput:SetPlaceholderText(config, input_box)

modules/input/editing.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ function InlineInput:SelectWordAtIndex(input_box, index)
139139
input_box:update_caret()
140140
end
141141

142+
self:ResetCaretBlink(input_box)
143+
142144
return true, start_index, end_index
143145
end
144146

0 commit comments

Comments
 (0)