aboutsummaryrefslogtreecommitdiff
path: root/src/console/components
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2020-04-09 10:38:37 +0900
committerGitHub <noreply@github.com>2020-04-09 10:38:37 +0900
commit1656d52d2cefb3846d968c6117484e6aefe7dabe (patch)
treeab58a99b832d2571e2168f2ee0e328bc12d9580e /src/console/components
parentc6c2da8547891b50aef2f08e5f36d258183831ff (diff)
parent5176643e64d8f4a6be5fc73f0eb48dc65322e496 (diff)
Merge pull request #730 from ueokande/refactor-console-and-completion
Refactor console and completions
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 });