|
|
@ -5,7 +5,7 @@ import * as React from 'react';
|
|
|
|
|
|
|
|
|
|
|
|
import { KeyWord } from '../../../Common/InputState';
|
|
|
|
import { KeyWord } from '../../../Common/InputState';
|
|
|
|
import { KeyBoard } from '../../../Common/KeyEnum';
|
|
|
|
import { KeyBoard } from '../../../Common/KeyEnum';
|
|
|
|
import { FixIndex } from '../../../Common/Utils';
|
|
|
|
import { FixIndex, ArrayRemove } from '../../../Common/Utils';
|
|
|
|
|
|
|
|
|
|
|
|
interface InputHintProps
|
|
|
|
interface InputHintProps
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -23,12 +23,13 @@ interface InputHitState
|
|
|
|
{
|
|
|
|
{
|
|
|
|
command: string;//输入的命令
|
|
|
|
command: string;//输入的命令
|
|
|
|
|
|
|
|
|
|
|
|
isShowHistory: Boolean;//显示历史命令
|
|
|
|
isShowHistory: boolean;//显示历史命令
|
|
|
|
|
|
|
|
|
|
|
|
historyCmdList: Array<string>;//历史命令列表
|
|
|
|
historyCmdList: Array<string>;//历史命令列表
|
|
|
|
|
|
|
|
|
|
|
|
intelliSenseIndex: number;//感知的当前选择位置
|
|
|
|
intelliSenseIndex: number;//感知的当前选择位置
|
|
|
|
intelliSenseCommand: Array<string>;//感知命令列表
|
|
|
|
intelliSenseCommand: Array<string>;//感知命令列表
|
|
|
|
|
|
|
|
isCNInput: boolean;//是否打开中文输入
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -54,7 +55,8 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
|
|
|
|
historyCmdList: [],
|
|
|
|
historyCmdList: [],
|
|
|
|
|
|
|
|
|
|
|
|
intelliSenseIndex: -1,
|
|
|
|
intelliSenseIndex: -1,
|
|
|
|
intelliSenseCommand: []
|
|
|
|
intelliSenseCommand: [],
|
|
|
|
|
|
|
|
isCNInput: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -73,20 +75,17 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理input输入的命令,尝试感知
|
|
|
|
// 处理input输入的命令,尝试感知
|
|
|
|
public handleOnChangeIntelliSense = (e: React.FormEvent<HTMLInputElement>) =>
|
|
|
|
public handleOnChangeIntelliSense(cmd: string)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//输入的命令
|
|
|
|
//输入的命令
|
|
|
|
let inputCmd = e.currentTarget.value.trim();
|
|
|
|
let inputCmd = cmd.trim();
|
|
|
|
|
|
|
|
this.setState({ command: inputCmd });
|
|
|
|
//没有执行命令才会进行感知
|
|
|
|
//没有执行命令才会进行感知
|
|
|
|
if (this.props.isCmdIng)
|
|
|
|
if (this.props.isCmdIng || this.state.isCNInput)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.setState({ command: inputCmd });
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputCmd == "")
|
|
|
|
this.setState({ command: inputCmd });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inputCmd == '')
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.setState({ intelliSenseCommand: [] });
|
|
|
|
this.setState({ intelliSenseCommand: [] });
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -95,7 +94,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
|
|
|
|
// 动态生成正则表达式
|
|
|
|
// 动态生成正则表达式
|
|
|
|
let searchReg: RegExp = new RegExp('');
|
|
|
|
let searchReg: RegExp = new RegExp('');
|
|
|
|
// 拼接动态正则表达式
|
|
|
|
// 拼接动态正则表达式
|
|
|
|
let m_comTmp: string = '^' + inputCmd.trim().toUpperCase().split('').join('\\w*') + '\\w*$';
|
|
|
|
let m_comTmp: string = '^' + inputCmd.toUpperCase().split('').join('\\w*') + '\\w*$';
|
|
|
|
searchReg = new RegExp(m_comTmp, 'i');
|
|
|
|
searchReg = new RegExp(m_comTmp, 'i');
|
|
|
|
|
|
|
|
|
|
|
|
let intelliSenseCmdList: string[] = [];
|
|
|
|
let intelliSenseCmdList: string[] = [];
|
|
|
@ -106,19 +105,15 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
|
|
|
|
intelliSenseCmdList.push(cmdName);
|
|
|
|
intelliSenseCmdList.push(cmdName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (intelliSenseCmdList.length > 0)
|
|
|
|
intelliSenseCmdList.sort((c1, c2) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
intelliSenseCmdList.sort((c1, c2) =>
|
|
|
|
return c1.length < c2.length ? -1 : 1;
|
|
|
|
{
|
|
|
|
});
|
|
|
|
return c1.length < c2.length ? -1 : 1;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
this.setState({
|
|
|
|
intelliSenseCommand: intelliSenseCmdList,
|
|
|
|
intelliSenseCommand: intelliSenseCmdList,
|
|
|
|
intelliSenseIndex: 0
|
|
|
|
intelliSenseIndex: 0
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 是否显示历史命令
|
|
|
|
// 是否显示历史命令
|
|
|
|
public handleShowHistoryCommand = () =>
|
|
|
|
public handleShowHistoryCommand = () =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -135,11 +130,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
|
|
|
|
if (!this.props.isCmdIng)
|
|
|
|
if (!this.props.isCmdIng)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let hcmdList = this.state.historyCmdList;
|
|
|
|
let hcmdList = this.state.historyCmdList;
|
|
|
|
let index = hcmdList.indexOf(cmd);
|
|
|
|
ArrayRemove(hcmdList, cmd);
|
|
|
|
if (index != -1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
hcmdList.splice(index, 1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hcmdList.push(cmd);
|
|
|
|
hcmdList.push(cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.props.handleInputCallback(cmd);
|
|
|
|
this.props.handleInputCallback(cmd);
|
|
|
@ -267,7 +258,13 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
|
|
|
|
<input
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
type="text"
|
|
|
|
placeholder={this.props.cmdPrompt == "" ? "请输入命令:" : ""}
|
|
|
|
placeholder={this.props.cmdPrompt == "" ? "请输入命令:" : ""}
|
|
|
|
onChange={this.handleOnChangeIntelliSense}
|
|
|
|
onCompositionStart={() => this.state.isCNInput = true}
|
|
|
|
|
|
|
|
onCompositionEnd={(e) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.state.isCNInput = false;
|
|
|
|
|
|
|
|
this.handleOnChangeIntelliSense(e.currentTarget.value);
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
onChange={(e) => { this.handleOnChangeIntelliSense(e.target.value) }}
|
|
|
|
value={this.state.command}
|
|
|
|
value={this.state.command}
|
|
|
|
ref={el => { this.m_InputEl = el; }}
|
|
|
|
ref={el => { this.m_InputEl = el; }}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|