MCPcopy Create free account
hub / github.com/astercloud/aster / restoreFocusState

Function restoreFocusState

ui/src/composables/useStreamingState.ts:191–218  ·  view source on GitHub ↗

* Restore focus to previously focused element

()

Source from the content-addressed store, hash-verified

189 * Restore focus to previously focused element
190 */
191 function restoreFocusState(): void {
192 if (!preserveFocus || !containerRef.value) return;
193
194 const state = getPreservedState(surfaceId);
195
196 if (state.focusedElementId) {
197 const el = containerRef.value.querySelector(`#${state.focusedElementId}`)
198 || containerRef.value.querySelector(`[data-component-id="${state.focusedElementId}"]`)
199 || containerRef.value.querySelector(`[name="${state.focusedElementId}"]`);
200
201 if (el && el instanceof HTMLElement) {
202 // Use requestAnimationFrame to ensure DOM is ready
203 requestAnimationFrame(() => {
204 el.focus();
205
206 // Restore cursor position for input elements
207 if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
208 const pendingValue = state.pendingInputValues.get(state.focusedElementId!);
209 if (pendingValue !== undefined) {
210 // Set selection to end of input
211 const len = el.value.length;
212 el.setSelectionRange(len, len);
213 }
214 }
215 });
216 }
217 }
218 }
219
220 /**
221 * Save all state before an update

Callers 1

restoreStateFunction · 0.85

Calls 2

getPreservedStateFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected