优化:避免正则表达式构建错误时报错

pull/1323/MERGE
ChenX 4 years ago
parent e78551dc68
commit fa385593f9

@ -5,6 +5,7 @@ import { end } from 'xaop';
import { app } from '../../../ApplicationServices/Application';
import { KeyWord } from '../../../Common/InputState';
import { KeyBoard } from '../../../Common/KeyEnum';
import { Log } from '../../../Common/Log';
import { FixIndex, isLetter, isNum } from '../../../Common/Utils';
import { CommandState } from '../../../Editor/CommandState';
import { CommandStore } from '../../Store/CommandStore';
@ -33,7 +34,7 @@ interface InputHitState
}
/**
*
*
*/
@observer
export class InputHint extends React.Component<InputHintProps, InputHitState>
@ -101,20 +102,33 @@ export class InputHint extends React.Component<InputHintProps, InputHitState>
let searchReg: RegExp;
// 拼接动态正则表达式
let m_comTmp: string = '^' + inputCmd.split('').join('\\w*') + '\\w*$';
searchReg = new RegExp(m_comTmp, 'i');
try
{
searchReg = new RegExp(m_comTmp, 'i');
} catch (error)
{
Log("正则表达式构建错误!");
return;
}
let intelliSenseCmdList: string[] = [];
for (let cmdName of this.props.cmdList)
{
if (inputCmd.length === 1)
try
{
if (cmdName.indexOf(inputCmd) === 0)
if (inputCmd.length === 1)
{
if (cmdName.indexOf(inputCmd) === 0)
intelliSenseCmdList.push(cmdName);
}
else if (cmdName.indexOf(inputCmd) !== -1
|| searchReg.test(cmdName))
{
intelliSenseCmdList.push(cmdName);
}
else if (cmdName.indexOf(inputCmd) !== -1
|| searchReg.test(cmdName))
}
} catch (error)
{
intelliSenseCmdList.push(cmdName);
Log("正则表达式测试错误!");
}
}
intelliSenseCmdList.sort((c1, c2) =>

Loading…
Cancel
Save