Add keyboard shortcuts for POS operations#166
Add keyboard shortcuts for POS operations#166abinandabinand21-sudo wants to merge 8 commits intoBrainWise-DEV:developfrom
Conversation
|
Thank you very much. This feature has been requested multiple times, and we truly appreciate you taking the initiative to implement it. We will review it carefully and get back to you shortly with feedback. Thanks again for the great contribution |
engahmed1190
left a comment
There was a problem hiding this comment.
Review: Keyboard Shortcuts for POS Operations
Thanks for the contribution! Keyboard shortcuts are a great idea for improving cashier efficiency. However, there are several issues that need to be addressed before this can be merged.
1. Fragile button matching via DOM text (Critical)
The entire implementation relies on document.querySelectorAll("button") and matching innerText. This is extremely fragile:
- Breaks if button text changes, is translated (i18n), or has extra whitespace/icons
- Breaks if the UI structure changes (e.g., buttons become
<a>or<div>) - The
setTimeout(() => {}, 300)delay is arbitrary — there's no guarantee the button exists after 300ms
2. Placed in main.js instead of a composable/component (Architecture)
Global event listeners in main.js don't integrate with Vue's lifecycle. This should be a Vue composable (useKeyboardShortcuts) or a component so it can:
- Be properly cleaned up on unmount
- Access Pinia stores directly instead of DOM scraping
- Be tested in isolation
3. Conflicts with browser defaults (UX)
Several shortcuts override common browser behavior:
- Ctrl+D — Bookmark page
- Ctrl+P — Print page
- Ctrl+B — Bold text
- Ctrl+U — View source / underline
- Ctrl+F — Browser find
- Ctrl+I — Italic / DevTools
This will frustrate users who expect standard browser behavior.
4. Input guard is incomplete
The check for active.tagName === "INPUT" won't catch all scenarios — Vue components using contenteditable, custom dropdowns with focus, or shadow DOM inputs will be missed. Also, <select> elements are not guarded.
5. Missing newline at EOF
The diff shows \ No newline at end of file.
6. No configurability or discoverability
- Users can't see available shortcuts anywhere in the UI
- Shortcuts are hardcoded — no way to customize or disable them
Recommendation
The core problems that need fixing:
- DOM text matching should be replaced with direct store actions — call Pinia store methods or emit events instead of finding buttons by text
- Move to a composable —
useKeyboardShortcuts()that registers/unregisters with Vue lifecycle - Reconsider the key bindings — avoid conflicting with browser defaults; consider using a prefix key or
Altmodifier instead ofCtrl
|
Ok i will work on that and i will update |
…and adjust chart data
|
Keyboard shortcuts logic updated as per review comments. Kindly review. |
engahmed1190
left a comment
There was a problem hiding this comment.
Deep Code Review — PR #166: Keyboard Shortcuts for POS
CRITICAL
1. Ctrl+Shift+O/D/H Conflict with Standard Browser Shortcuts
| Shortcut | Browser Default |
|---|---|
Ctrl+Shift+O |
Chrome: Bookmarks Manager |
Ctrl+Shift+D |
Chrome/Firefox: Bookmark All Tabs |
Ctrl+Shift+H |
Firefox: Open History |
While e.preventDefault() suppresses them, overriding well-known browser shortcuts frustrates users who rely on them. 3 out of 5 Ctrl+Shift combos conflict.
Fix: Rethink the key mapping. Options:
- Use
Alt+Shift+combos (less browser conflict) - Use a leader/chord system (e.g., press
Escthen a letter) - At minimum, pick non-conflicting letters
HIGH Issues
2. No Keyboard Shortcut Help/Legend Visible to Users
There's no way for users to discover available shortcuts. Keyboard shortcuts are useless if nobody knows they exist.
Fix: Add a shortcut help panel (e.g., triggered by ? key, or a small icon in the POS header that shows the legend on hover/click).
3. isOnPOSPage Regex Matches False Positives
return /\/pos(\/|$)/.test(window.location.pathname);This matches any path containing /pos — including /reposition, /compost, /deposit, etc.
Fix: Add ^ anchor:
return /^\/pos(\/|$)/.test(window.location.pathname);MEDIUM Issues
4. isEditableTarget Doesn't Cover role="textbox" Elements
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
if (el.isContentEditable) return true;Missing: elements with role="textbox" (used by some rich-text editors and Frappe controls). Shortcuts could fire while a user is typing in one of these.
Fix:
if (el.getAttribute?.("role") === "textbox") return true;5. registerDialog Cleanup Never Called on Unmount
const showPromotionManagement = registerDialog(ref(false), "promotionManagement");registerDialog attaches a .cleanup function, but POSSale.vue never calls it in onUnmounted. If the page ever unmounts (route change), the global dialogCounter will leak, making isAnyDialogOpen permanently true and blocking all shortcuts.
Fix: Call .cleanup() for each registered dialog in an onUnmounted hook.
6. Ctrl+Alt+R — Alt Key Issues on Linux
Alt key on Linux often triggers the window manager menu bar or is intercepted by the desktop environment. Ctrl+Alt+R may never reach the browser on some distros (e.g., GNOME uses Ctrl+Alt combos for workspace switching).
7. Mystery Commit 94c1fc61 "Update main.js"
This commit is titled "Update main.js" but main.js doesn't appear in the changed files. Either a no-op or a reverted change. Clean up via rebase.
LOW Issues
8. Inconsistent Indentation — 4 Spaces Instead of Tabs
useKeyboardShortcuts.js uses 4-space indentation. The project standard is tabs for JS files. Must be consistent.
9. No Unit Tests for the Composable
useKeyboardShortcuts has testable pure logic (isEditableTarget, isOnPOSPage, key dispatch). Adding basic tests would prevent regressions, especially for the route guard regex.
Summary
| Severity | Count | Key Items |
|---|---|---|
| Critical | 1 | 3 browser shortcut conflicts |
| High | 2 | No discoverability for shortcuts, regex false positives |
| Medium | 4 | Missing role="textbox" guard, dialog cleanup leak, Alt+Linux issue, mystery commit |
| Low | 2 | Indentation, no tests |
Recommendation: Do not merge as-is.
- Rethink key bindings — avoid conflicting with browser defaults
- Fix the regex — add
^anchor toisOnPOSPage - Add a shortcut help panel — shortcuts without discoverability won't be used
- Fix indentation to tabs
Feature: Keyboard Shortcuts for POSNext
Summary
This PR introduces keyboard shortcuts to improve usability and efficiency in POSNext.
It enables a faster, keyboard-driven workflow and reduces reliance on mouse interactions during billing operations.
Features Added
Primary POS Actions
Workflow Enhancements
Implementation Details
keydownevent listenerBenefits
Notes
Demo