Skip to content

Commit d30ae53

Browse files
committed
feat(editbox): ClearHistory
Empties the up/down input history. The engine's SetHistoryLines internal (FUN_0077cd90) frees the whole history ring when called with 0, so clear = free (0) then reallocate at the saved max — dropping every entry and resetting the write position while keeping the line limit, so the box keeps recording afterward (matching modern semantics, not "history disabled"). No-op when the box has no history. New offsets: OFF_EDITBOX_HISTORY_MAX (+0x388, the ring capacity GetHistoryLines reads), FUN_EDITBOX_SET_HISTORY_MAX. Verified in-game: AddHistoryLine + ClearHistory leaves GetHistoryLines unchanged and the up-arrow history empty; new lines still record.
1 parent 8f32955 commit d30ae53

4 files changed

Lines changed: 43 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ reference in **[docs/API.md](docs/API.md)**.
6767
| [Expansion](docs/API.md#expansion) | `ClassicExpansionAtLeast`, `ClassicExpansionAtMost`, `GetClassicExpansionLevel` |
6868
| [Faction](docs/API.md#faction) | `C_Reputation.GetFactionDataByIndex`, `C_Reputation.GetFactionStandings`, `C_Reputation.GetLastStandingChange`, `C_Reputation.GetWatchedFactionData`, `C_Reputation.SetWatchedFactionByID`, `GetFactionIDByIndex`, `GetFactionInfoByID`, `GetFactionParentID` |
6969
| [Focus](docs/API.md#focus) | `ClearFocus`, `FocusUnit` |
70-
| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `frame:SetShown`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsEventRegistered`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `GetClickFrame` |
70+
| [Frame](docs/API.md#frame) | `region:SetPoint("point")` (one-arg form), `region:SetSize`, `region:GetSize`, `region:IsMouseOver`, `region:GetRect`, `region:IsDragging`, `GetMouseFoci`, `frame:SetShown`, `fontstring:GetStringHeight`, `fontstring:GetUnboundedStringWidth`, `fontstring:GetWrappedWidth`, `fontstring:GetNumLines`, `fontstring:GetLineHeight`, `fontstring:IsTruncated`, `fontstring:SetMaxLines`, `fontstring:GetMaxLines`, `fontstring:SetFormattedText`, `texture:SetRotation`, `texture:GetRotation`, `texture:SetVertexOffset`, `texture:GetVertexOffset`, `texture:SetColorTexture`, `texture:SetMask`, `frame:CreateMaskTexture`, `texture:AddMaskTexture`, `texture:RemoveMaskTexture`, `texture:GetNumMaskTextures`, `texture:GetMaskTexture`, `fontstring:SetRotation`, `fontstring:GetRotation`, `editBox:SetCursorPosition`, `editBox:GetCursorPosition`, `editBox:GetUTF8CursorPosition`, `editBox:ClearHighlightText`, `editBox:HasFocus`, `editBox:HasText`, `editBox:SetHighlightColor`, `editBox:GetHighlightColor`, `editBox:ClearHistory`, `frame:SetResizeBounds`, `frame:HookScript`, `frame:IsEventRegistered`, `frame:GetEffectiveAlpha`, `frame:SetAttribute`, `frame:SetAttributeNoHandler`, `frame:ClearAttribute`, `frame:GetAttribute`, `OnAttributeChanged` (script), `SetModernScriptArgs`, `GetModernScriptArgs`, `PreClick` (script), `PostClick` (script), `GetClickFrame` |
7171
| [FriendList](docs/API.md#friendlist) | `C_FriendList.GetFriendInfo`, `C_FriendList.GetFriendInfoByIndex`, `C_FriendList.GetNumFriends`, `C_FriendList.GetNumOnlineFriends`, `C_FriendList.GetNumWhoResults`, `C_FriendList.GetWhoInfo`, `C_FriendList.IsFriend`, `C_FriendList.IsIgnored`, `C_FriendList.IsIgnoredByGuid`, `C_FriendList.IsWhoQueryPending`, `C_FriendList.SendWhoQueryByName`, `C_FriendList.SetFriendNotes`, `C_FriendList.SetFriendNotesByIndex` |
7272
| [GameObject](docs/API.md#gameobject) | `C_GameObjectInfo.GetGameObjectInfoByID`, `C_GameObjectInfo.RequestLoadGameObjectByID`, `ClosestGameObjectPosition` |
7373
| [Glue](docs/API.md#glue) | `C_Glue.IsOnGlueScreen` |

docs/API.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ build instructions.
202202
- [`editBox:HasText()`](#editboxhastext)
203203
- [`editBox:SetHighlightColor(r, g, b [, a])`](#editboxsethighlightcolorr-g-b--a)
204204
- [`editBox:GetHighlightColor()`](#editboxgethighlightcolor)
205+
- [`editBox:ClearHistory()`](#editboxclearhistory)
205206
- [`frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])`](#framesetresizeboundsminwidth-minheight--maxwidth-maxheight)
206207
- [`frame:HookScript(scriptType, handler)`](#framehookscriptscripttype-handler)
207208
- [`frame:IsEventRegistered(event)`](#frameiseventregisteredevent)
@@ -4699,6 +4700,12 @@ ChatFrameEditBox:SetHighlightColor(1, 0, 0) -- red selection
46994700
Returns the selection-highlight color as four numbers: `r, g, b, a`, each `0`
47004701
to `1`.
47014702

4703+
### `editBox:ClearHistory()`
4704+
4705+
Removes every line from the up/down input history. The history line limit
4706+
(`SetHistoryLines`) stays, so the box keeps recording new lines afterward.
4707+
Does nothing when the box has no history.
4708+
47024709
### `frame:SetResizeBounds(minWidth, minHeight [, maxWidth, maxHeight])`
47034710

47044711
The modern rename of vanilla's `SetMinResize` / `SetMaxResize` pair.

src/Offsets.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7621,6 +7621,17 @@ enum Offsets {
76217621
// the generic region color accessors. The blinking caret is a SEPARATE
76227622
// region at +0x3d4, deliberately left alone.
76237623
OFF_EDITBOX_HIGHLIGHT_REGION = 0x350,
7624+
// Input-history ring buffer: max lines (ring capacity) at +0x388 (what
7625+
// GetHistoryLines reads), write position at +0x38c, container
7626+
// {size@+0x390, alloc@+0x394, data@+0x398} of {char* text, int exec}
7627+
// entries. AddHistoryLine writes at +0x38c and advances modulo +0x388.
7628+
OFF_EDITBOX_HISTORY_MAX = 0x388,
7629+
// `void __thiscall(editbox, int maxLines)` — the SetHistoryLines internal
7630+
// (FUN_0077cd90). Reallocates the history ring to maxLines; maxLines == 0
7631+
// frees the whole buffer and zeroes the container. ClearHistory calls it
7632+
// with 0 then the saved max — empties every entry and resets the write
7633+
// position while keeping the limit (so recording still works after).
7634+
FUN_EDITBOX_SET_HISTORY_MAX = 0x0077cd90,
76247635

76257636
// --- FontString measure internals (GetStringWidth icon fix + GetStringHeight) ---
76267637
// CSimpleFontString::GetStringWidthInternal — `float(__fastcall)(fs /*ecx*/)`,

src/editbox/Methods.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// HasFocus — does this box own keyboard focus
2323
// HasText — is the box non-empty
2424
// Set/GetHighlightColor — the text-selection highlight color
25+
// ClearHistory — empty the up/down input history
2526
//
2627
// The engine already stores and manipulates all of this; we just expose it.
2728
// Every method is registered on the EditBox method registry, so — like any
@@ -48,6 +49,7 @@ using CollapseSelection_t = void(__thiscall *)(void *editbox);
4849
using CountChars_t = int(__thiscall *)(void *editbox, int startByte, int byteCount);
4950
using RegionSetColor_t = void(__thiscall *)(void *region, const uint32_t *colorBGRA);
5051
using RegionGetColor_t = void(__thiscall *)(void *region, uint32_t *outBGRA);
52+
using SetHistoryMax_t = void(__thiscall *)(void *editbox, int maxLines);
5153

5254
// A Lua color arg (0..1) clamped and scaled to a 0..255 byte, matching the
5355
// engine's own float->byte color conversion (truncating, like Texture's
@@ -197,6 +199,27 @@ int __fastcall Script_GetHighlightColor(void *L) {
197199
return 4;
198200
}
199201

202+
// Empties the up/down input history, keeping the line limit so the box keeps
203+
// recording afterward. The engine's SetHistoryLines internal frees the whole
204+
// ring at max 0, so clear = free (0) then reallocate at the saved max — which
205+
// drops every entry and resets the write position. No-op when history was
206+
// never enabled (max 0).
207+
int __fastcall Script_ClearHistory(void *L) {
208+
void *eb = Game::Lua::ResolveObject(L, 1);
209+
if (eb == nullptr) {
210+
Game::Lua::Error(L, "Usage: EditBox:ClearHistory()");
211+
return 0;
212+
}
213+
const int max = Game::Read<int>(eb, Offsets::OFF_EDITBOX_HISTORY_MAX);
214+
if (max > 0) {
215+
auto setMax = reinterpret_cast<SetHistoryMax_t>(
216+
Offsets::FUN_EDITBOX_SET_HISTORY_MAX);
217+
setMax(eb, 0);
218+
setMax(eb, max);
219+
}
220+
return 0;
221+
}
222+
200223
const Game::Lua::FrameMethodEntry g_methods[] = {
201224
{"SetCursorPosition", &Script_SetCursorPosition},
202225
{"GetCursorPosition", &Script_GetCursorPosition},
@@ -206,6 +229,7 @@ const Game::Lua::FrameMethodEntry g_methods[] = {
206229
{"HasText", &Script_HasText},
207230
{"SetHighlightColor", &Script_SetHighlightColor},
208231
{"GetHighlightColor", &Script_GetHighlightColor},
232+
{"ClearHistory", &Script_ClearHistory},
209233
};
210234

211235
void RegisterLuaFunctions() {

0 commit comments

Comments
 (0)