mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
fix: cursor stays out of frame when suggestions get filtered
Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState, useCallback } from "react";
|
||||
import React, { useState, useCallback, useEffect } from "react";
|
||||
import { Text, useInput, Box, measureElement, DOMElement } from "ink";
|
||||
import { Suggestion } from "../runtime/model.js";
|
||||
|
||||
@@ -61,15 +61,17 @@ export default function Suggestions({
|
||||
|
||||
// TODO: tweak this logic to be more accurate as it gives bad offsets on wrap
|
||||
const wrappedPadding = leftPadding % windowWidth;
|
||||
|
||||
const maxPadding = activeDescription.length !== 0 ? windowWidth - SuggestionWidth - DescriptionWidth : windowWidth - SuggestionWidth;
|
||||
|
||||
const swapDescription = wrappedPadding > maxPadding;
|
||||
|
||||
const swappedPadding = swapDescription ? Math.max(wrappedPadding - DescriptionWidth, 0) : wrappedPadding;
|
||||
|
||||
const clampedLeftPadding = Math.min(Math.min(wrappedPadding, swappedPadding), maxPadding);
|
||||
|
||||
useEffect(() => {
|
||||
if (suggestions.length <= activeSuggestionIndex) {
|
||||
setActiveSuggestionIndex(Math.max(suggestions.length - 1, 0));
|
||||
}
|
||||
}, [suggestions]);
|
||||
|
||||
useInput((_, key) => {
|
||||
if (key.upArrow) {
|
||||
setActiveSuggestionIndex(Math.max(0, activeSuggestionIndex - 1));
|
||||
|
||||
Reference in New Issue
Block a user