|
|
|
@ -5,23 +5,23 @@ import Input from './console/Input'; |
|
|
|
|
import Completion from './console/Completion'; |
|
|
|
|
import Message from './console/Message'; |
|
|
|
|
import * as consoleActions from '../../console/actions/console'; |
|
|
|
|
import { State as AppState } from '../reducers'; |
|
|
|
|
|
|
|
|
|
const COMPLETION_MAX_ITEMS = 33; |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
mode?: string; |
|
|
|
|
consoleText?: string; |
|
|
|
|
messageText?: string; |
|
|
|
|
children?: string; |
|
|
|
|
type StateProps = ReturnType<typeof mapStateToProps>; |
|
|
|
|
interface DispatchProps { |
|
|
|
|
dispatch: (action: any) => void, |
|
|
|
|
} |
|
|
|
|
type Props = StateProps & DispatchProps |
|
|
|
|
|
|
|
|
|
class Console extends React.Component<Props> { |
|
|
|
|
private input: HTMLInputElement | null; |
|
|
|
|
private input: React.RefObject<Input>; |
|
|
|
|
|
|
|
|
|
constructor(props: Props) { |
|
|
|
|
super(props); |
|
|
|
|
|
|
|
|
|
this.input = null; |
|
|
|
|
this.input = React.createRef(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onBlur() { |
|
|
|
@ -34,7 +34,7 @@ class Console extends React.Component<Props> { |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
|
|
|
|
|
let value = e.target.value; |
|
|
|
|
let value = (e.target as HTMLInputElement).value; |
|
|
|
|
if (this.props.mode === 'command') { |
|
|
|
|
return this.props.dispatch(consoleActions.enterCommand(value)); |
|
|
|
|
} else if (this.props.mode === 'find') { |
|
|
|
@ -55,15 +55,12 @@ class Console extends React.Component<Props> { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onKeyDown(e: React.KeyboardEvent<HTMLInputElement>) { |
|
|
|
|
if (e.keyCode === KeyboardEvent.DOM_VK_ESCAPE && e.ctrlKey) { |
|
|
|
|
this.props.dispatch(consoleActions.hideCommand()); |
|
|
|
|
} |
|
|
|
|
switch (e.keyCode) { |
|
|
|
|
case KeyboardEvent.DOM_VK_ESCAPE: |
|
|
|
|
switch (e.key) { |
|
|
|
|
case 'Escape': |
|
|
|
|
return this.props.dispatch(consoleActions.hideCommand()); |
|
|
|
|
case KeyboardEvent.DOM_VK_RETURN: |
|
|
|
|
case 'Enter': |
|
|
|
|
return this.doEnter(e); |
|
|
|
|
case KeyboardEvent.DOM_VK_TAB: |
|
|
|
|
case 'Tab': |
|
|
|
|
if (e.shiftKey) { |
|
|
|
|
this.props.dispatch(consoleActions.completionPrev()); |
|
|
|
|
} else { |
|
|
|
@ -72,22 +69,22 @@ class Console extends React.Component<Props> { |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
e.preventDefault(); |
|
|
|
|
break; |
|
|
|
|
case KeyboardEvent.DOM_VK_OPEN_BRACKET: |
|
|
|
|
case '[': |
|
|
|
|
if (e.ctrlKey) { |
|
|
|
|
return this.props.dispatch(consoleActions.hideCommand()); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case KeyboardEvent.DOM_VK_M: |
|
|
|
|
case 'm': |
|
|
|
|
if (e.ctrlKey) { |
|
|
|
|
return this.doEnter(e); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case KeyboardEvent.DOM_VK_N: |
|
|
|
|
case 'n': |
|
|
|
|
if (e.ctrlKey) { |
|
|
|
|
this.selectNext(e); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case KeyboardEvent.DOM_VK_P: |
|
|
|
|
case 'p': |
|
|
|
|
if (e.ctrlKey) { |
|
|
|
|
this.selectPrev(e); |
|
|
|
|
} |
|
|
|
@ -105,9 +102,6 @@ class Console extends React.Component<Props> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: Props) { |
|
|
|
|
if (!this.input) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (prevProps.mode !== 'command' && this.props.mode === 'command') { |
|
|
|
|
this.props.dispatch( |
|
|
|
|
consoleActions.getCompletions(this.props.consoleText)); |
|
|
|
@ -128,7 +122,7 @@ class Console extends React.Component<Props> { |
|
|
|
|
select={this.props.select} |
|
|
|
|
/> |
|
|
|
|
<Input |
|
|
|
|
ref={(c) => { this.input = c; }} |
|
|
|
|
ref={this.input} |
|
|
|
|
mode={this.props.mode} |
|
|
|
|
onBlur={this.onBlur.bind(this)} |
|
|
|
|
onKeyDown={this.onKeyDown.bind(this)} |
|
|
|
@ -148,11 +142,14 @@ class Console extends React.Component<Props> { |
|
|
|
|
|
|
|
|
|
focus() { |
|
|
|
|
window.focus(); |
|
|
|
|
if (this.input) { |
|
|
|
|
this.input.focus(); |
|
|
|
|
if (this.input.current) { |
|
|
|
|
this.input.current.focus(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state: any) => state; |
|
|
|
|
export default connect(mapStateToProps)(Console); |
|
|
|
|
const mapStateToProps = (state: AppState) => ({ ...state }); |
|
|
|
|
|
|
|
|
|
export default connect( |
|
|
|
|
mapStateToProps, |
|
|
|
|
)(Console); |
|
|
|
|