MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / setFocusInternal

Method setFocusInternal

packages/pi-tui/src/tui.ts:380–443  ·  view source on GitHub ↗
({
		component,
		overlayFocusRestore,
	}: {
		component: Component | null;
		overlayFocusRestore: OverlayFocusRestorePolicy;
	})

Source from the content-addressed store, hash-verified

378 }
379
380 private setFocusInternal({
381 component,
382 overlayFocusRestore,
383 }: {
384 component: Component | null;
385 overlayFocusRestore: OverlayFocusRestorePolicy;
386 }): void {
387 const previousFocus = this.focusedComponent;
388 let nextFocus = component;
389 const previousFocusedOverlay = previousFocus
390 ? this.overlayStack.find((entry) => entry.component === previousFocus && this.isOverlayVisible(entry))
391 : undefined;
392 const nextFocusIsOverlay = nextFocus ? this.overlayStack.some((entry) => entry.component === nextFocus) : false;
393 const restoreState = this.getVisibleOverlayFocusRestore();
394 if (nextFocus && !nextFocusIsOverlay) {
395 if (restoreState.status === "blocked" && restoreState.blockedBy === previousFocus) {
396 if (restoreState.resume.status === "focus-target" || !this.isComponentMounted(restoreState.blockedBy)) {
397 nextFocus = this.resolveBlockedOverlayFocusResume(restoreState);
398 } else {
399 this.overlayFocusRestore = {
400 status: "blocked",
401 overlay: restoreState.overlay,
402 blockedBy: nextFocus,
403 resume: restoreState.resume,
404 };
405 }
406 } else if (
407 previousFocusedOverlay &&
408 restoreState.status !== "inactive" &&
409 restoreState.overlay === previousFocusedOverlay &&
410 !this.isOverlayFocusAncestor(previousFocusedOverlay, nextFocus)
411 ) {
412 this.overlayFocusRestore = {
413 status: "blocked",
414 overlay: previousFocusedOverlay,
415 blockedBy: nextFocus,
416 resume: { status: "restore-overlay" },
417 };
418 }
419 } else if (nextFocus === null) {
420 if (restoreState.status === "blocked" && restoreState.blockedBy === previousFocus) {
421 nextFocus = this.resolveBlockedOverlayFocusResume(restoreState);
422 } else if (overlayFocusRestore === "clear") {
423 this.clearOverlayFocusRestore();
424 }
425 }
426
427 if (isFocusable(this.focusedComponent)) {
428 this.focusedComponent.focused = false;
429 }
430
431 this.focusedComponent = nextFocus;
432
433 if (isFocusable(nextFocus)) {
434 nextFocus.focused = true;
435 }
436
437 const focusedOverlay = nextFocus

Callers 2

setFocusMethod · 0.95
handleInputMethod · 0.95

Calls 7

isOverlayVisibleMethod · 0.95
isComponentMountedMethod · 0.95
isFocusableFunction · 0.85

Tested by

no test coverage detected