-
Notifications
You must be signed in to change notification settings - Fork 70
Add keyboard shortcuts support for improved navigation #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add comprehensive keyboard shortcuts to improve navigation and usability: Global shortcuts: - `/` to focus search - `g h` to go to recipes/home - `g s` to go to shopping list - `g p` to go to pantry - `g x` to go to preferences - `?` to show keyboard shortcuts help - `Escape` to close modals/dropdowns - `t` to toggle dark/light theme Recipe page shortcuts: - `e` to edit recipe - `a` to add to shopping list - `p` to print recipe - `+/-` to increase/decrease scale - `[/]` to adjust scale by 1 Shopping list shortcuts: - `c` to clear all items Also adds a help button (?) in the navigation bar to show available shortcuts. Closes #248 https://claude.ai/code/session_016paFwPNACFdAEmYmg9txDF
Pull Request Review: Keyboard Shortcuts SupportThank you for this comprehensive PR adding keyboard shortcuts to CookCLI! This is a well-thought-out feature that will significantly improve user experience. Below is my detailed review: ✅ Strengths1. Code Quality & Best Practices
2. User Experience
3. Integration
🐛 Potential Issues & Bugs1. Theme Toggle Function Availability (templates/base.html:580)if (typeof toggleTheme === 'function') {
toggleTheme();
}Issue: The code checks if Recommendation: Review base.html to ensure 2. Global Function Dependencies (keyboard-shortcuts.js:369)if (typeof clearList === 'function') {
if (confirm('Clear all items from shopping list?')) {
clearList();
}
}Issue: Similar issue - depends on Recommendation: Verify that all page-specific functions are properly exposed or add error handling/logging. 3. Modal Backdrop Click Handler (keyboard-shortcuts.js:166-170)modal.addEventListener('click', function(e) {
if (e.target === modal) {
closeShortcutsHelp();
}
});Potential Issue: Event listener is added every time the modal is shown (if it doesn't exist). If the modal is shown/hidden multiple times, you could accumulate event listeners. Recommendation: Either:
4. Scale Adjustment Precision (keyboard-shortcuts.js:345-347)// Round to avoid floating point issues
newValue = Math.round(newValue * 10) / 10;Issue: This limits precision to 1 decimal place. If the scale input supports more precision, this could truncate values. Recommendation: Check the actual precision requirements of the scale input or make this configurable. 5. Missing Error Handling for DOM ElementsSeveral functions assume DOM elements exist without checking:
Recommendation: Add defensive checks or error logging throughout. 🔒 Security Considerations1. XSS Risk in Modal HTML (keyboard-shortcuts.js:71-161)modal.innerHTML = `...`;Assessment: ✅ Low Risk - The HTML is hardcoded and doesn't include any user input, so there's no XSS vulnerability here. However, be cautious if this pattern is copied elsewhere with dynamic content. 2. Global Function Exposurewindow.showShortcutsHelp = function() { ... }
window.closeShortcutsHelp = function() { ... }Assessment: ✅ Acceptable - These functions need to be global for the onclick handlers. No security concerns. ⚡ Performance Considerations1. Event Listener on Every Keydown (keyboard-shortcuts.js:388)document.addEventListener('keydown', handleKeydown);Assessment: ✅ Good - Single global listener is efficient. The 2. DOM Queries in Event HandlersMultiple shortcuts use const searchInput = document.getElementById('search-input');
const editLink = document.querySelector('a[href^="/edit/"]');Issue: Recommendation: // Cache on DOMContentLoaded
let cachedElements = {};
document.addEventListener('DOMContentLoaded', function() {
cachedElements.searchInput = document.getElementById('search-input');
});3. Modal RecreationThe modal checks if it exists before creating a new one: const existingModal = document.getElementById('keyboard-shortcuts-modal');
if (existingModal) {
existingModal.classList.remove('hidden');
return;
}Assessment: ✅ Good - Reuses existing modal, efficient approach. 🧪 Test Coverage
|
| Category | Rating | Notes |
|---|---|---|
| Code Quality | ⭐⭐⭐⭐½ | Well-structured, minor improvements possible |
| Best Practices | ⭐⭐⭐⭐⭐ | Excellent use of IIFE, event delegation |
| Security | ⭐⭐⭐⭐⭐ | No security concerns identified |
| Performance | ⭐⭐⭐⭐ | Good, minor optimization opportunities |
| Test Coverage | ⭐ | CRITICAL: No tests included |
| Documentation | ⭐⭐⭐ | Good inline docs, needs user-facing docs |
| Accessibility | ⭐⭐⭐⭐ | Good keyboard support, minor improvements possible |
✅ Action Items Before Merge
Must Have:
- ✅ Add comprehensive Playwright tests (see test examples above)
- ✅ Verify
toggleThemeandclearListfunctions are available - ✅ Test on Firefox, Safari, and mobile browsers
Should Have:
4.
5.
6.
Nice to Have:
7. 💡 Consider caching frequently accessed DOM elements
8. 💡 Add visual feedback for multi-key sequences
9. 💡 Extract magic numbers to configuration constants
🎯 Conclusion
This is a high-quality PR that adds significant value to CookCLI. The implementation is clean, user-friendly, and follows JavaScript best practices. The main blocker is the lack of test coverage, which is critical given the project's comprehensive testing infrastructure.
Recommendation: Request changes to add Playwright tests before merging. Once tests are added and the minor issues are addressed, this PR will be ready to merge.
Great work overall! 🎉
Replace `is_some()` + `unwrap()` pattern with `if let Some()` in: - cooklang_to_latex.rs - cooklang_to_md.rs - cooklang_to_typst.rs https://claude.ai/code/session_016paFwPNACFdAEmYmg9txDF
Code Review - PR #252: Add keyboard shortcuts supportSummaryThis PR adds comprehensive keyboard shortcuts to the web UI, which is a great UX enhancement. The implementation is generally well-structured with good input detection and modal UI. However, there are several areas that need attention before merging. Critical Issues1. Security: Inline Event HandlersLocation: templates/base.html:501 and base.html:580-593 The PR uses inline onclick handlers, which violates Content Security Policy (CSP) best practices. Recommendation: Use event listeners instead of inline handlers. 2. Race Condition: Function AvailabilityLocation: templates/base.html:586-592 The fallback check for showShortcutsHelp may not work reliably - the script runs immediately but keyboard-shortcuts.js is loaded via a non-blocking script tag. Recommendation: Remove inline handlers or ensure the script loads synchronously. 3. Missing Dependency FunctionsLocation: static/js/keyboard-shortcuts.js:268, js:377 The code calls functions that may not exist: toggleTheme() and clearList() Recommendation: Add defensive checks before calling these functions. Code Quality Issues4. Inconsistent Scale AdjustmentLocation: static/js/keyboard-shortcuts.js:345-360 The scale adjustment dispatches a change event, but it's unclear if the scale input has a listener for this event. 5. Magic Numbers and Hardcoded ValuesLocation: static/js/keyboard-shortcuts.js:241, js:348-349 Values like 1500ms timeout, 0.5 min scale, 200 max scale should be extracted as named constants. 6. Global Namespace PollutionThe IIFE pattern is good, but showShortcutsHelp and closeShortcutsHelp are added to the global window object unnecessarily. Testing Recommendations7. No E2E Tests for Keyboard ShortcutsThe PR adds significant UI functionality but doesn't include Playwright tests. Based on the excellent test infrastructure in tests/e2e/, this should have tests for help modal, navigation shortcuts, recipe shortcuts, and input field detection. Positive Aspects✅ Excellent input detection - The isTyping() function properly handles inputs, textareas, contenteditable, and CodeMirror VerdictChanges Requested - The feature is valuable but needs the critical security and reliability issues addressed before merging. Required Changes:
Recommended Changes:
Once these issues are addressed, this will be a great addition to CookCLI! |
Summary
This PR adds comprehensive keyboard shortcuts support to the Cook CLI web interface, enabling users to navigate and interact with the application more efficiently without relying on mouse clicks.
Key Changes
New keyboard shortcuts module (
static/js/keyboard-shortcuts.js):/for search,g hfor home,g sfor shopping list,g pfor pantry,g xfor preferences)?for help,tfor theme toggle,Escfor closing modals)eto edit,ato add to shopping list,pto print,+/-and[/]to adjust recipe scale)cto clear all items)Updated base template (
templates/base.html):showShortcutsHelp()is available globallyImplementation Details
Testing Recommendations
?andEsckeys+/-and[/]keyshttps://claude.ai/code/session_016paFwPNACFdAEmYmg9txDF