aboutsummaryrefslogtreecommitdiff
path: root/src/console/components/Console.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/console/components/Console.tsx')
-rw-r--r--src/console/components/Console.tsx227
1 files changed, 122 insertions, 105 deletions
diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx
index 3fe5cee..d74040d 100644
--- a/src/console/components/Console.tsx
+++ b/src/console/components/Console.tsx
@@ -1,19 +1,21 @@
-import './console.scss';
-import { connect } from 'react-redux';
-import React from 'react';
-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';
-import CommandLineParser, { InputPhase } from "../commandline/CommandLineParser";
+import "./console.scss";
+import { connect } from "react-redux";
+import React from "react";
+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";
+import CommandLineParser, {
+ InputPhase,
+} from "../commandline/CommandLineParser";
import { Command } from "../../shared/Command";
const COMPLETION_MAX_ITEMS = 33;
type StateProps = ReturnType<typeof mapStateToProps>;
interface DispatchProps {
- dispatch: (action: any) => void,
+ dispatch: (action: any) => void;
}
type Props = StateProps & DispatchProps;
@@ -29,7 +31,7 @@ class Console extends React.Component<Props> {
}
onBlur() {
- if (this.props.mode === 'command' || this.props.mode === 'find') {
+ if (this.props.mode === "command" || this.props.mode === "find") {
return this.props.dispatch(consoleActions.hideCommand());
}
}
@@ -39,11 +41,12 @@ class Console extends React.Component<Props> {
e.preventDefault();
const value = (e.target as HTMLInputElement).value;
- if (this.props.mode === 'command') {
+ if (this.props.mode === "command") {
return this.props.dispatch(consoleActions.enterCommand(value));
- } else if (this.props.mode === 'find') {
- return this.props.dispatch(consoleActions.enterFind(
- value === '' ? undefined : value));
+ } else if (this.props.mode === "find") {
+ return this.props.dispatch(
+ consoleActions.enterFind(value === "" ? undefined : value)
+ );
}
}
@@ -61,94 +64,95 @@ class Console extends React.Component<Props> {
onKeyDown(e: React.KeyboardEvent<HTMLInputElement>) {
switch (e.key) {
- case 'Escape':
- return this.props.dispatch(consoleActions.hideCommand());
- case 'Enter':
- return this.doEnter(e);
- case 'Tab':
- if (e.shiftKey) {
- this.props.dispatch(consoleActions.completionPrev());
- } else {
- this.props.dispatch(consoleActions.completionNext());
- }
- e.stopPropagation();
- e.preventDefault();
- break;
- case '[':
- if (e.ctrlKey) {
- e.preventDefault();
- return this.props.dispatch(consoleActions.hideCommand());
- }
- break;
- case 'c':
- if (e.ctrlKey) {
- e.preventDefault();
+ case "Escape":
return this.props.dispatch(consoleActions.hideCommand());
- }
- break;
- case 'm':
- if (e.ctrlKey) {
+ case "Enter":
return this.doEnter(e);
- }
- break;
- case 'n':
- if (e.ctrlKey) {
- this.selectNext(e);
- }
- break;
- case 'p':
- if (e.ctrlKey) {
- this.selectPrev(e);
- }
- break;
+ case "Tab":
+ if (e.shiftKey) {
+ this.props.dispatch(consoleActions.completionPrev());
+ } else {
+ this.props.dispatch(consoleActions.completionNext());
+ }
+ e.stopPropagation();
+ e.preventDefault();
+ break;
+ case "[":
+ if (e.ctrlKey) {
+ e.preventDefault();
+ return this.props.dispatch(consoleActions.hideCommand());
+ }
+ break;
+ case "c":
+ if (e.ctrlKey) {
+ e.preventDefault();
+ return this.props.dispatch(consoleActions.hideCommand());
+ }
+ break;
+ case "m":
+ if (e.ctrlKey) {
+ return this.doEnter(e);
+ }
+ break;
+ case "n":
+ if (e.ctrlKey) {
+ this.selectNext(e);
+ }
+ break;
+ case "p":
+ if (e.ctrlKey) {
+ this.selectPrev(e);
+ }
+ break;
}
}
onChange(e: React.ChangeEvent<HTMLInputElement>) {
const text = e.target.value;
this.props.dispatch(consoleActions.setConsoleText(text));
- if (this.props.mode !== 'command') {
- return
+ if (this.props.mode !== "command") {
+ return;
}
- this.updateCompletions(text)
+ this.updateCompletions(text);
}
-
componentDidUpdate(prevProps: Props) {
- if (prevProps.mode !== 'command' && this.props.mode === 'command') {
+ if (prevProps.mode !== "command" && this.props.mode === "command") {
this.updateCompletions(this.props.consoleText);
this.focus();
- } else if (prevProps.mode !== 'find' && this.props.mode === 'find') {
+ } else if (prevProps.mode !== "find" && this.props.mode === "find") {
this.focus();
}
}
render() {
switch (this.props.mode) {
- case 'command':
- case 'find':
- return <div className='vimvixen-console-command-wrapper'>
- <Completion
- size={COMPLETION_MAX_ITEMS}
- completions={this.props.completions}
- select={this.props.select}
- />
- <Input
- ref={this.input}
- mode={this.props.mode}
- onBlur={this.onBlur.bind(this)}
- onKeyDown={this.onKeyDown.bind(this)}
- onChange={this.onChange.bind(this)}
- value={this.props.consoleText}
- />
- </div>;
- case 'info':
- case 'error':
- return <Message mode={ this.props.mode } >
- { this.props.messageText }
- </Message>;
- default:
- return null;
+ case "command":
+ case "find":
+ return (
+ <div className="vimvixen-console-command-wrapper">
+ <Completion
+ size={COMPLETION_MAX_ITEMS}
+ completions={this.props.completions}
+ select={this.props.select}
+ />
+ <Input
+ ref={this.input}
+ mode={this.props.mode}
+ onBlur={this.onBlur.bind(this)}
+ onKeyDown={this.onKeyDown.bind(this)}
+ onChange={this.onChange.bind(this)}
+ value={this.props.consoleText}
+ />
+ </div>
+ );
+ case "info":
+ case "error":
+ return (
+ <Message mode={this.props.mode}>{this.props.messageText}</Message>
+ );
+ default:
+ return null;
}
}
@@ -166,25 +170,40 @@ class Console extends React.Component<Props> {
} 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;
+ 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;
}
}
}
@@ -192,6 +211,4 @@ class Console extends React.Component<Props> {
const mapStateToProps = (state: AppState) => ({ ...state });
-export default connect(
- mapStateToProps,
-)(Console);
+export default connect(mapStateToProps)(Console);