aboutsummaryrefslogtreecommitdiff
path: root/src/console/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/console/components')
-rw-r--r--src/console/components/Console.tsx42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx
index eafe2a7..3fe5cee 100644
--- a/src/console/components/Console.tsx
+++ b/src/console/components/Console.tsx
@@ -6,6 +6,8 @@ import Completion from './console/Completion';
import Message from './console/Message';
import * as consoleActions from '../../console/actions/console';
import { State as AppState } from '../reducers';
+import CommandLineParser, { InputPhase } from "../commandline/CommandLineParser";
+import { Command } from "../../shared/Command";
const COMPLETION_MAX_ITEMS = 33;
@@ -18,6 +20,8 @@ type Props = StateProps & DispatchProps;
class Console extends React.Component<Props> {
private input: React.RefObject<Input>;
+ private commandLineParser: CommandLineParser = new CommandLineParser();
+
constructor(props: Props) {
super(props);
@@ -103,16 +107,16 @@ class Console extends React.Component<Props> {
onChange(e: React.ChangeEvent<HTMLInputElement>) {
const text = e.target.value;
this.props.dispatch(consoleActions.setConsoleText(text));
- if (this.props.mode === 'command') {
- this.props.dispatch(consoleActions.getCompletions(text));
+ if (this.props.mode !== 'command') {
+ return
}
+ this.updateCompletions(text)
}
componentDidUpdate(prevProps: Props) {
if (prevProps.mode !== 'command' && this.props.mode === 'command') {
- this.props.dispatch(
- consoleActions.getCompletions(this.props.consoleText));
+ this.updateCompletions(this.props.consoleText);
this.focus();
} else if (prevProps.mode !== 'find' && this.props.mode === 'find') {
this.focus();
@@ -154,6 +158,36 @@ class Console extends React.Component<Props> {
this.input.current.focus();
}
}
+
+ private updateCompletions(text: string) {
+ const phase = this.commandLineParser.inputPhase(text);
+ if (phase === InputPhase.OnCommand) {
+ return this.props.dispatch(consoleActions.getCommandCompletions(text));
+ } else {
+ const cmd = this.commandLineParser.parse(text);
+ switch (cmd.command) {
+ case Command.Open:
+ case Command.TabOpen:
+ case Command.WindowOpen:
+ this.props.dispatch(consoleActions.getOpenCompletions(this.props.completionTypes, text, cmd.command, cmd.args));
+ break;
+ case Command.Buffer:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
+ break;
+ case Command.BufferDelete:
+ case Command.BuffersDelete:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, true));
+ break;
+ case Command.BufferDeleteForce:
+ case Command.BuffersDeleteForce:
+ this.props.dispatch(consoleActions.getTabCompletions(text, cmd.command, cmd.args, false));
+ break;
+ case Command.Set:
+ this.props.dispatch(consoleActions.getPropertyCompletions(text, cmd.command, cmd.args));
+ break;
+ }
+ }
+ }
}
const mapStateToProps = (state: AppState) => ({ ...state });