fix: 自定义工具的快捷键显示

This commit is contained in:
unanmed 2024-04-22 12:14:14 +08:00
parent 3be0fe50ff
commit 5b74a22494

View File

@ -55,9 +55,32 @@ function DefaultTool(props: CustomToolbarProps) {
function KeyTool(props: CustomToolbarProps<'hotkey'>) { function KeyTool(props: CustomToolbarProps<'hotkey'>) {
const { item, toolbar } = props; const { item, toolbar } = props;
const unwarpAssist = (assist: number) => {
let res = '';
if (assist & (1 << 0)) {
res += 'Ctrl + ';
}
if (assist & (1 << 1)) {
res += 'Shift + ';
}
if (assist & (1 << 2)) {
res += 'Alt + ';
}
return res;
};
const getKeyShow = (key: KeyCode, assist: number) => {
return unwarpAssist(assist) + KeyCodeUtils.toString(key);
};
return ( return (
<span class="button-text" onClick={() => toolbar.emitTool(item.id)}> <span
{KeyCodeUtils.toString(item.key)} class="button-text"
style="padding: 0 5px"
onClick={() => toolbar.emitTool(item.id)}
>
{getKeyShow(item.key, item.assist)}
</span> </span>
); );
} }