MCPcopy Index your code
hub / github.com/tinyplex/tinybase / bindKeyboard

Function bindKeyboard

site/js/common/search.ts:168–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

166
167 // Keyboard navigation
168 const bindKeyboard = () =>
169 addEventListener('keydown', (event: KeyboardEvent) => {
170 if (doc.activeElement == input) {
171 const hovered = queryElement(results, '.hover');
172 switch (event.code) {
173 case 'Escape':
174 return input.blur();
175 case 'ArrowDown':
176 preventDefault(event);
177 return moveHover(
178 hovered,
179 hovered?.nextSibling ?? results.firstChild,
180 );
181 case 'ArrowUp':
182 preventDefault(event);
183 return moveHover(
184 hovered,
185 hovered?.previousSibling ?? results.lastChild,
186 );
187 case 'Enter':
188 return hovered?.dispatchEvent(new MouseEvent('mousedown'));
189 }
190 } else if (event.code == 'KeyK' && event.metaKey) {
191 input.focus();
192 preventDefault(event);
193 }
194 });
195 });
196};
197

Callers 1

bindUIFunction · 0.85

Calls 4

queryElementFunction · 0.90
preventDefaultFunction · 0.90
moveHoverFunction · 0.85
addEventListenerFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…