针对手心输入法无法得到输入结束事件进行优化

pull/319/MERGE
ChenX 5 years ago
parent 0c4ec0fd20
commit f8064b1612

@ -27,14 +27,9 @@ interface InputHintProps
interface InputHitState
{
command: string;//输入的命令
isShowHistory: boolean;//显示历史命令
intelliSenseIndex: number;//感知的当前选择位置
intelliSenseCommand: Array<string>;//感知命令列表
isCNInput: boolean;//是否打开中文输入
}
/**
@ -44,17 +39,16 @@ interface InputHitState
export class InputHint extends React.Component<InputHintProps, InputHitState>
{
public state: InputHitState;
private m_InputEl: HTMLInputElement;
private m_SelectIndex: number = 0; //选择历史命令索引
private inputEl: HTMLInputElement;
private selectIndex: number = 0; //选择历史命令索引
private isCNInput: boolean = false;
constructor(p, s)
{
super(p, s);
this.state = {
command: "",
isShowHistory: false,
intelliSenseIndex: -1,
intelliSenseCommand: [],
isCNInput: false
};
}
@ -66,9 +60,9 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
end(app.m_Editor.m_KeyCtrl, app.m_Editor.m_KeyCtrl.OnKeyDown, (e: KeyboardEvent) =>
{
//@ts-ignore
if (document.activeElement !== this.m_InputEl && e.target.nodeName !== "INPUT")
if (document.activeElement !== this.inputEl && e.target.nodeName !== "INPUT")
{
this.m_InputEl.focus();
this.inputEl.focus();
}
//导致上下键切换命令时bug
// this.handleOnChangeIntelliSense(this.m_InputEl.value);
@ -82,11 +76,14 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
// 处理input输入的命令,尝试感知
public handleOnChangeIntelliSense(cmd: string)
{
if (cmd === " ")
this.isCNInput = false;//手心输入法
//输入的命令
let inputCmd = cmd.trim();
this.setState({ command: inputCmd });
this.inputEl.value = inputCmd;
//没有执行命令才会进行感知
if (CommandState.CommandIng || this.state.isCNInput)
if (CommandState.CommandIng || this.isCNInput)
{
return;
}
@ -179,7 +176,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
case KeyBoard.Enter:
case KeyBoard.Space:
{
let cmd = this.m_InputEl.value;
let cmd = this.inputEl.value;
if (this.state.intelliSenseCommand.length > 0)
cmd = this.state.intelliSenseCommand[this.state.intelliSenseIndex];
else if (cmd === "" && !CommandState.CommandIng)
@ -219,23 +216,24 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
{
if (e.keyCode == KeyBoard.ArrowUp)
{
this.m_SelectIndex++;
this.selectIndex++;
}
else if (e.keyCode == KeyBoard.ArrowDown)
{
this.m_SelectIndex--;
this.selectIndex--;
}
this.m_SelectIndex = FixIndex(this.m_SelectIndex, this.props.historyCmdList);
this.setState({ command: this.props.historyCmdList[this.m_SelectIndex] });
this.selectIndex = FixIndex(this.selectIndex, this.props.historyCmdList);
this.inputEl.value = this.props.historyCmdList[this.selectIndex];
}
}
}
private Cancel()
{
this.isCNInput = false;
this.inputEl.value = "";
this.setState({
isShowHistory: false,
intelliSenseCommand: [],
command: ""
});
}
@ -282,15 +280,14 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
type="text"
style={{ flex: 1, minWidth: 0, height: CommandInputHeight, border: "none" }}
placeholder={this.props.cmdPrompt == "" ? "请输入命令:" : ""}
onCompositionStart={() => this.state.isCNInput = true}
onCompositionStart={() => this.isCNInput = true}
onCompositionEnd={(e) =>
{
this.state.isCNInput = false;
this.isCNInput = false;
this.handleOnChangeIntelliSense(e.currentTarget.value);
}}
onChange={(e) => { this.handleOnChangeIntelliSense(e.target.value) }}
value={this.state.command}
ref={el => { this.m_InputEl = el; }}
ref={el => { this.inputEl = el; }}
onKeyDown={(e) =>
{
if (e.ctrlKey || e.altKey) e.preventDefault();

Loading…
Cancel
Save