Skip to content

Commit d747812

Browse files
authored
Merge pull request #2000 from LarryThiessen/fix-1997-tab-insert-at-caret
#1997 Tab spell list: insert at the remembered caret, not the end of the row
2 parents 805bb95 + b33ab19 commit d747812

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

GSE_QoL/QoL.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,28 @@ GSE.OnEditorMacroBlockTab = function(widget, menuOwner)
326326
local editBox = widget and (widget.editBox or widget.editbox)
327327
if not editBox then return end
328328
editBox:SetScript("OnTabPressed", function()
329+
-- Remember where the caret was when Tab was pressed. Between now and the
330+
-- pick, the editor's debounced live repaint (or a focus-loss commit
331+
-- repaint) can SetText the box, which parks the caret at the END --
332+
-- so a plain Insert landed at the end of the last row. Cancel any
333+
-- pending live repaint via the token the recolour already honours,
334+
-- then restore focus + caret right before inserting.
335+
local cursor = editBox.GetCursorPosition and editBox:GetCursorPosition()
336+
widget.gseRecolourToken = (widget.gseRecolourToken or 0) + 1
337+
local function insertAtCaret(text)
338+
if editBox.SetFocus then editBox:SetFocus() end
339+
if cursor and editBox.SetCursorPosition then editBox:SetCursorPosition(cursor) end
340+
editBox:Insert(text)
341+
end
329342
MenuUtil.CreateContextMenu(editBox, function(ownerRegion, rootDescription)
330343
rootDescription:CreateTitle(L["Insert Spell"])
331344
for _, v in ipairs(getPlayerSpells()) do
332-
rootDescription:CreateButton(v, function() editBox:Insert(v) end)
345+
rootDescription:CreateButton(v, function() insertAtCaret(v) end)
333346
end
334347
rootDescription:CreateTitle(L["Insert GSE Variable"])
335348
for k, _ in pairs(GSEVariables) do
336349
rootDescription:CreateButton(k, function()
337-
editBox:Insert("\n" .. [[=GSE.V["]] .. k .. [["]()]])
350+
insertAtCaret("\n" .. [[=GSE.V["]] .. k .. [["]()]])
338351
end)
339352
end
340353
end)

0 commit comments

Comments
 (0)