优化:避免光标在命令智能提示列表时,快速输入命令+空格调用了错误的命令(加入冷却期

pull/1500/head
ChenX 3 years ago
parent 09e6d6fa21
commit 9982d34e4a

@ -33,6 +33,49 @@ interface InputHitState
intelliSenseCommand: Array<string>;//感知命令列表 intelliSenseCommand: Array<string>;//感知命令列表
} }
class CoolDownTime
{
IsCoolDownTime = false;
ExecFunc: Function;
TimerId: any;
constructor() { }
//进入冷却期
CoolDown(time: number)
{
if (this.TimerId) clearTimeout(this.TimerId);
this.IsCoolDownTime = true;//进入冷却期
this.TimerId = setTimeout(() =>
{
if (this.ExecFunc)
{
this.ExecFunc();//施放
this.ExecFunc = undefined;
}
this.TimerId = undefined;
this.IsCoolDownTime = false;//解除冷却
}, time);
}
//清除所有的状态
Clear()
{
if (this.TimerId) clearTimeout(this.TimerId);
this.TimerId = undefined;
this.ExecFunc = undefined;
this.IsCoolDownTime = false;
}
//设定延时执行的函数
Exec(f: Function)
{
if (this.IsCoolDownTime)
this.ExecFunc = f;
else
f();
}
}
/** /**
* *
*/ */
@ -43,6 +86,8 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
private inputEl: HTMLInputElement; private inputEl: HTMLInputElement;
private selectIndex: number = 0; //选择历史命令索引 private selectIndex: number = 0; //选择历史命令索引
private isCNInput: boolean = false; private isCNInput: boolean = false;
private coolTime = new CoolDownTime;
constructor(p, s) constructor(p, s)
{ {
super(p, s); super(p, s);
@ -77,6 +122,8 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
// 处理input输入的命令,尝试感知 // 处理input输入的命令,尝试感知
public handleOnChangeIntelliSense(cmd: string) public handleOnChangeIntelliSense(cmd: string)
{ {
this.coolTime.CoolDown(500);//冷却,避免光标在位置的时候,快速输入命令+空格调用了错误的命令
if (cmd === " ") if (cmd === " ")
this.isCNInput = false;//手心输入法 this.isCNInput = false;//手心输入法
@ -265,7 +312,10 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
onClick={() => { this.handleCallback(item); }} onClick={() => { this.handleCallback(item); }}
key={index} key={index}
className={index == this.state.intelliSenseIndex ? "hover" : ""} className={index == this.state.intelliSenseIndex ? "hover" : ""}
onMouseMove={() => { this.setState({ intelliSenseIndex: index }); }} onMouseMove={() =>
{
this.coolTime.Exec(() => this.setState({ intelliSenseIndex: index }));
}}
> >
{item} {item}
</li> </li>

Loading…
Cancel
Save