Merge remote-tracking branch 'origin/command_dev'

pull/7/head
ChenX 7 years ago
parent c9ade8e366
commit 3bbfa59e43

18
package-lock.json generated

@ -12125,6 +12125,15 @@
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=",
"dev": true
},
"string_decoder": {
"version": "1.0.3",
"resolved": "http://registry.npm.taobao.org/string_decoder/download/string_decoder-1.0.3.tgz",
"integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"string-length": {
"version": "2.0.0",
"resolved": "http://registry.npm.taobao.org/string-length/download/string-length-2.0.0.tgz",
@ -12191,15 +12200,6 @@
}
}
},
"string_decoder": {
"version": "1.0.3",
"resolved": "http://registry.npm.taobao.org/string_decoder/download/string_decoder-1.0.3.tgz",
"integrity": "sha1-D8Z9fBQYJd6UKC3VNr7GubzoYKs=",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"stringstream": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz",

@ -6,7 +6,8 @@ import { CommandStore } from '../Store/CommandStore';
import { CommandLineContainer } from './CommandLineContainer';
import { InputHint } from './commandLineInput/InputHint';
@inject("commandStore") @observer
@inject("commandStore")
@observer
export class CommandComponent extends React.Component<{ commandStore?: CommandStore }, null>
{
style: CSSProperties = {

@ -5,7 +5,7 @@ import * as React from 'react';
import { KeyWord } from '../../../Common/InputState';
import { KeyBoard } from '../../../Common/KeyEnum';
import { FixIndex } from '../../../Common/Utils';
import { FixIndex, ArrayRemove } from '../../../Common/Utils';
interface InputHintProps
{
@ -23,12 +23,13 @@ interface InputHitState
{
command: string;//输入的命令
isShowHistory: Boolean;//显示历史命令
isShowHistory: boolean;//显示历史命令
historyCmdList: Array<string>;//历史命令列表
intelliSenseIndex: number;//感知的当前选择位置
intelliSenseCommand: Array<string>;//感知命令列表
isCNInput: boolean;//是否打开中文输入
}
/**
@ -54,7 +55,8 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
historyCmdList: [],
intelliSenseIndex: -1,
intelliSenseCommand: []
intelliSenseCommand: [],
isCNInput: false
}
}
@ -73,20 +75,17 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
}
// 处理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;
}
this.setState({ command: inputCmd });
if (inputCmd == '')
if (inputCmd == "")
{
this.setState({ intelliSenseCommand: [] });
return;
@ -95,7 +94,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
// 动态生成正则表达式
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');
let intelliSenseCmdList: string[] = [];
@ -106,19 +105,15 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
intelliSenseCmdList.push(cmdName);
}
}
if (intelliSenseCmdList.length > 0)
{
intelliSenseCmdList.sort((c1, c2) =>
{
return c1.length < c2.length ? -1 : 1;
})
}
});
this.setState({
intelliSenseCommand: intelliSenseCmdList,
intelliSenseIndex: 0
});
}
// 是否显示历史命令
public handleShowHistoryCommand = () =>
{
@ -135,11 +130,7 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
if (!this.props.isCmdIng)
{
let hcmdList = this.state.historyCmdList;
let index = hcmdList.indexOf(cmd);
if (index != -1)
{
hcmdList.splice(index, 1)
}
ArrayRemove(hcmdList, cmd);
hcmdList.push(cmd);
}
this.props.handleInputCallback(cmd);
@ -267,7 +258,13 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
<input
type="text"
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}
ref={el => { this.m_InputEl = el; }}
/>

Loading…
Cancel
Save