Text selection in console window now accounts for text filter. Only items shown to the user can be selected and copied.

This commit is contained in:
Jakob Friedl
2025-10-12 16:40:34 +02:00
parent 392aaec972
commit 25f5bac12b

View File

@@ -12,7 +12,8 @@ type
agent*: UIAgent agent*: UIAgent
showConsole*: bool showConsole*: bool
inputBuffer: array[MAX_INPUT_LENGTH, char] inputBuffer: array[MAX_INPUT_LENGTH, char]
console*: ConsoleItems console*: ConsoleItems # Stores all console items
consoleFiltered*: ConsoleItems # Temporarily stores console items that are displayed to the user
history: seq[string] history: seq[string]
historyPosition: int historyPosition: int
currentInput: string currentInput: string
@@ -51,10 +52,13 @@ proc Console*(agent: UIAgent): ConsoleComponent =
zeroMem(addr result.inputBuffer[0], MAX_INPUT_LENGTH) zeroMem(addr result.inputBuffer[0], MAX_INPUT_LENGTH)
result.console = new ConsoleItems result.console = new ConsoleItems
result.console.items = @[] result.console.items = @[]
result.consoleFiltered = new ConsoleItems
result.consoleFiltered.items = @[]
result.history = @[] result.history = @[]
result.historyPosition = -1 result.historyPosition = -1
result.currentInput = "" result.currentInput = ""
result.textSelect = textselect_create(getLineAtIndex, getNumLines, cast[pointer](result.console), 0) # Text selection covers only console items that are shown to the user even after using text filters
result.textSelect = textselect_create(getLineAtIndex, getNumLines, cast[pointer](result.consoleFiltered), 0)
result.filter = ImGuiTextFilter_ImGuiTextFilter("") result.filter = ImGuiTextFilter_ImGuiTextFilter("")
#[ #[
@@ -343,6 +347,9 @@ proc draw*(component: ConsoleComponent, connection: WsConnection) =
let childWindowFlags = ImGuiChildFlags_NavFlattened.int32 or ImGui_ChildFlags_Borders.int32 or ImGui_ChildFlags_AlwaysUseWindowPadding.int32 or ImGuiChildFlags_FrameStyle.int32 let childWindowFlags = ImGuiChildFlags_NavFlattened.int32 or ImGui_ChildFlags_Borders.int32 or ImGui_ChildFlags_AlwaysUseWindowPadding.int32 or ImGuiChildFlags_FrameStyle.int32
if igBeginChild_Str("##Console", vec2(-1.0f, -footerHeight), childWindowFlags, ImGuiWindowFlags_HorizontalScrollbar.int32): if igBeginChild_Str("##Console", vec2(-1.0f, -footerHeight), childWindowFlags, ImGuiWindowFlags_HorizontalScrollbar.int32):
# Reset console items shown in the UI
component.consoleFiltered.items = @[]
# Display console items # Display console items
for item in component.console.items: for item in component.console.items:
@@ -352,12 +359,14 @@ proc draw*(component: ConsoleComponent, connection: WsConnection) =
if not component.filter.ImGuiTextFilter_PassFilter(item.getText(), nil): if not component.filter.ImGuiTextFilter_PassFilter(item.getText(), nil):
continue continue
component.consoleFiltered.items.add(item)
item.print() item.print()
# Auto-scroll to bottom # Auto-scroll to bottom
if igGetScrollY() >= igGetScrollMaxY(): if igGetScrollY() >= igGetScrollMaxY():
igSetScrollHereY(1.0f) igSetScrollHereY(1.0f)
# Update selection
component.textSelect.textselect_update() component.textSelect.textselect_update()
except IndexDefect: except IndexDefect: