-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Resolve conflicts between custom ⌥⇧→/⌥⇧← and native shortcut keys #14638
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
Comments
需要在捕获阶段监听。 用这个 JS: // 监听键盘按下事件
document.addEventListener('keydown', (event) => {
// 检查是否按下了 Alt、Shift 和 ArrowLeft 键
if (event.altKey && event.shiftKey && event.key === 'ArrowLeft') {
// 阻止默认行为(如果需要)
event.preventDefault();
// 执行自定义逻辑
console.log('Alt + Shift + ArrowLeft 被按下');
}
}, true); 或者这个: // 监听键盘按下事件
document.addEventListener('keydown', (event) => {
// 检查是否按下了 Alt、Shift 和 ArrowLeft 键
const isAltPressed = event.altKey; // Alt 键是否按下
const isShiftPressed = event.shiftKey; // Shift 键是否按下
const isArrowLeftPressed = event.key === 'ArrowLeft'; // 左箭头键是否按下
// 确保没有其他按键被按下
const noOtherKeysPressed = event.ctrlKey === false &&
event.metaKey === false &&
event.key === 'ArrowLeft';
if (isAltPressed && isShiftPressed && isArrowLeftPressed && noOtherKeysPressed) {
// 阻止默认行为(如果需要)
event.preventDefault();
// 执行自定义逻辑
console.log('仅 Alt + Shift + ArrowLeft 被按下');
}
}, true); |
alt+shift+左/右 在开头或结尾会导致 #13980 这个问题(光标丢失),因此进行了屏蔽。 |
实测把快捷键设置为这个之后确实没法在段落开头使用 @Vanessa219 能做到让快捷键优先吗? |
@Vanessa219 好奇问一句, 改成: 如果是 alt+shift+左右, 就跳过 |
不会,要判断 |
用 2 楼的方法 |
改成你的方法,如果用户没有自定义 ⌥⇧→/⌥⇧← 会导致 #13980 这个问题。 后面有限制的,我测试了是可以自定义的,如果有问题麻烦发一下重现步骤。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
解决自定义 ⌥⇧→/⌥⇧← 和原生快捷键冲突
In what scenarios do you need this feature?
这里的代码看起来像是处理 shift+左右键 选择内容 的功能
如果 光标在开头 或者 在结尾, 将调用stopPropagation 取消事件传播, 导致 alt + shift + 左右键 无法触发
导致
通过思源本身提供的快捷键 无法触发对应的功能
自己js代码也无法监听到这个快捷键的事件
The text was updated successfully, but these errors were encountered: