Skip to content

Commit

Permalink
79 Keyboard scrolling support (#91)
Browse files Browse the repository at this point in the history
* ide: add debug configuration

* fix: keyboard arrow scrolling for fontpicker
  • Loading branch information
ae9is authored Feb 10, 2025
1 parent 05a3025 commit e5173bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/packages/fontpicker/src",
"sourceMapPathOverrides": {
"webpack:///./packages/fontpicker/src/*": "${workspaceFolder}/packages/fontpicker/src/*"
}
}
]
}
11 changes: 6 additions & 5 deletions packages/fontpicker/src/components/FontPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,16 @@ export default function FontPicker({
// selectedFont should be undefined IFF fontCategories is changed and the currently
// selectedFont is not in the new category.
if (selectedFont) {
const fontElement = popout.querySelector('.font-preview-' + selectedFont.sane) as HTMLElement
if (fontElement && fontElement instanceof HTMLElement) {
const fontTop = fontElement.offsetTop
const fontBottom = fontTop + fontElement.offsetHeight
const fontPreviewElement = popout.querySelector('.font-preview-' + selectedFont.sane) as HTMLElement
const fontOptionElement = fontPreviewElement?.parentElement
if (fontOptionElement && fontOptionElement instanceof HTMLElement) {
const fontTop = fontOptionElement.offsetTop
const fontBottom = fontTop + fontOptionElement.offsetHeight
const popTop = popout.scrollTop
const popBottom = popTop + popout.clientHeight
if (why === 'opening' || fontTop <= popTop) {
popout.scrollTop = fontTop
fontElement.parentElement?.classList.add('selected')
fontOptionElement.classList.add('selected')
const optionRef = getOptionsRef()?.get(selectedFont.sane)
optionRef?.classList.add('selected')
} else if (fontBottom >= popBottom) {
Expand Down

0 comments on commit e5173bf

Please sign in to comment.