Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix double tab autocomplete list #61

Merged
merged 1 commit into from
Apr 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/mercury/components/terminal-link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import { connect } from 'react-redux';
import SmoothScroll from './scroll.jsx';
import Terminal from './terminal.jsx';
import { getDirectory } from 'utils';
// This is only here because getDirectory needs the file system is a parameter
// For other state needs, use connect!
import store from 'mercury/store';

import type {
StoreState,
Expand Down Expand Up @@ -78,7 +75,7 @@ class TerminalLink extends React.Component<Props, State> {
getCurrentInputCommand() {
const history = this.props.terminal.history;
return history[this.state.historyIndex];
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some of these functions standard functions without semi colons and some are variables assigned to a function lambda (like onPaste) above? We should standardize that at some point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because class methods aren't bound normally, so the value of this can be undefined in callback methods. The assigned lambda is experimental syntax that automatically binds properly. More about that here: https://reactjs.org/docs/handling-events.html (about halfway down the page).

}

handleKey = (e: SyntheticKeyboardEvent<HTMLDivElement>) => {
const history = this.props.terminal.history;
Expand Down Expand Up @@ -125,10 +122,7 @@ class TerminalLink extends React.Component<Props, State> {
this.setState({
cursor: this.state.cursor + 1
});
} else if (
e.keyCode === Constants.KEY_HOME &&
this.state.cursor !== 0
) {
} else if (e.keyCode === Constants.KEY_HOME && this.state.cursor !== 0) {
this.setState({
cursor: 0
});
Expand Down Expand Up @@ -164,7 +158,7 @@ class TerminalLink extends React.Component<Props, State> {
// Grab Matches
const workingDirectory = getDirectory(
this.props.terminal.workingDirectory,
store.getState().wfs
this.props.wfs
);
// Guaranteed to exist since we're in the directory
if (!workingDirectory) return;
Expand Down Expand Up @@ -193,14 +187,13 @@ class TerminalLink extends React.Component<Props, State> {
tabPressed: false
});
this.props.addCommand(command, true);
for (let i = 0; i < matches.length; i++) {
matches.forEach(match => {
this.props.addCommand(
(workingDirectory.data[i].type === Constants.DIR_TYPE
? 'DIR '
: 'FILE ') + workingDirectory.data[i].name,
(match.type === Constants.DIR_TYPE ? 'DIR ' : 'FILE ') +
match.name,
false
);
}
});
} else {
this.setState({
tabPressed: true
Expand Down