|
|
|
@ -22,6 +22,7 @@ enum TipType
|
|
|
|
|
export interface CommandItemProps
|
|
|
|
|
{
|
|
|
|
|
commandData: ICommand;
|
|
|
|
|
parentInput: React.RefObject<HTMLInputElement>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -33,7 +34,6 @@ export interface CommandItemProps
|
|
|
|
|
export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
@observable private flag: TipType = TipType.OK;
|
|
|
|
|
private m_InputEl: HTMLInputElement;
|
|
|
|
|
private m_commandItemEl: HTMLLIElement;
|
|
|
|
|
@observable private isCNInput: boolean = false;
|
|
|
|
|
private isReset = false;
|
|
|
|
|
constructor(props)
|
|
|
|
@ -47,20 +47,16 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
if (e.keyCode === KeyBoard.Escape)
|
|
|
|
|
{
|
|
|
|
|
this.flag = TipType.InputNull;
|
|
|
|
|
this.m_InputEl.blur();
|
|
|
|
|
this.props.parentInput.current?.focus();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (e.keyCode === KeyBoard.Enter || e.keyCode === KeyBoard.Space)
|
|
|
|
|
{
|
|
|
|
|
this.m_InputEl.blur();
|
|
|
|
|
this.props.parentInput.current?.focus();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
};
|
|
|
|
|
this.m_InputEl.addEventListener('blur', () =>
|
|
|
|
|
{
|
|
|
|
|
if (this.m_commandItemEl)
|
|
|
|
|
this.m_commandItemEl.parentElement.focus();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
handleLiClick = () =>
|
|
|
|
|
{
|
|
|
|
@ -109,7 +105,6 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
handleOnBlur = () =>
|
|
|
|
|
{
|
|
|
|
|
let target = this.m_InputEl;
|
|
|
|
|
|
|
|
|
|
let cserver = CommandServer.GetInstance() as CommandServer;
|
|
|
|
|
|
|
|
|
|
const commandData = this.props.commandData;
|
|
|
|
@ -141,8 +136,8 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
target.value = commandData.customizeed || commandData.defaultCustom;
|
|
|
|
|
this.flag = TipType.OK;
|
|
|
|
|
}
|
|
|
|
|
this.flag = TipType.OK;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render()
|
|
|
|
@ -164,7 +159,6 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
return (
|
|
|
|
|
<li
|
|
|
|
|
onClick={this.handleLiClick}
|
|
|
|
|
ref={el => this.m_commandItemEl = el}
|
|
|
|
|
>
|
|
|
|
|
<li>{store.commandData.icon ? <img src={`${ICON_CDN}/${store.commandData.icon}`} /> : <></>}</li>
|
|
|
|
|
<li>{store.commandData.chName}</li>
|
|
|
|
@ -195,10 +189,7 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
this.isCNInput = false;
|
|
|
|
|
this.handleOnChange();
|
|
|
|
|
}}
|
|
|
|
|
onFocus={e =>
|
|
|
|
|
{
|
|
|
|
|
e.target.setSelectionRange(0, e.target.value.length);
|
|
|
|
|
}}
|
|
|
|
|
onFocus={e => e.target.select()}
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
onChange={this.handleOnChange}
|
|
|
|
|
onBlur={this.handleOnBlur}
|
|
|
|
@ -223,7 +214,7 @@ export class CommandItem extends React.Component<CommandItemProps, {}>{
|
|
|
|
|
if (e.keyCode === KeyBoard.Escape)
|
|
|
|
|
{
|
|
|
|
|
(e.currentTarget.lastElementChild.firstElementChild as HTMLButtonElement).click();
|
|
|
|
|
this.m_commandItemEl.parentElement.focus();
|
|
|
|
|
this.props.parentInput.current?.focus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (e.keyCode === KeyBoard.Enter)
|
|
|
|
|