Merge pull request #450 from ueokande/fix-trim-start

Fix trim start
jh-changes
Shin'ya Ueoka 6 years ago committed by GitHub
commit ab857658c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .circleci/config.yml
  2. 2
      manifest.json
  3. 13
      src/background/controllers/command.js

@ -4,7 +4,7 @@ jobs:
docker: docker:
- image: circleci/node:10-stretch-browsers - image: circleci/node:10-stretch-browsers
environment: environment:
- FIREFOX_VERSION: "60.0.2" - FIREFOX_VERSION: "60.0esr"
working_directory: ~ working_directory: ~
steps: steps:
- restore_cache: - restore_cache:

@ -2,7 +2,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Vim Vixen", "name": "Vim Vixen",
"description": "Vim Vixen", "description": "Vim Vixen",
"version": "0.16", "version": "0.17",
"icons": { "icons": {
"48": "resources/icon_48x48.png", "48": "resources/icon_48x48.png",
"96": "resources/icon_96x96.png" "96": "resources/icon_96x96.png"

@ -2,6 +2,11 @@ import CompletionsInteractor from '../usecases/completions';
import CommandInteractor from '../usecases/command'; import CommandInteractor from '../usecases/command';
import Completions from '../domains/completions'; import Completions from '../domains/completions';
const trimStart = (str) => {
// NOTE String.trimStart is available on Firefox 61
return str.replace(/^\s+/, '');
};
export default class CommandController { export default class CommandController {
constructor() { constructor() {
this.completionsInteractor = new CompletionsInteractor(); this.completionsInteractor = new CompletionsInteractor();
@ -9,13 +14,13 @@ export default class CommandController {
} }
getCompletions(line) { getCompletions(line) {
let trimmed = line.trimStart(); let trimmed = trimStart(line);
let words = trimmed.split(/ +/); let words = trimmed.split(/ +/);
let name = words[0]; let name = words[0];
if (words.length === 1) { if (words.length === 1) {
return this.completionsInteractor.queryConsoleCommand(name); return this.completionsInteractor.queryConsoleCommand(name);
} }
let keywords = trimmed.slice(name.length).trimStart(); let keywords = trimStart(trimmed.slice(name.length));
switch (words[0]) { switch (words[0]) {
case 'o': case 'o':
case 'open': case 'open':
@ -45,14 +50,14 @@ export default class CommandController {
// eslint-disable-next-line complexity // eslint-disable-next-line complexity
exec(line) { exec(line) {
let trimmed = line.trimStart(); let trimmed = trimStart(line);
let words = trimmed.split(/ +/); let words = trimmed.split(/ +/);
let name = words[0]; let name = words[0];
if (words[0].length === 0) { if (words[0].length === 0) {
return Promise.resolve(); return Promise.resolve();
} }
let keywords = trimmed.slice(name.length).trimStart(); let keywords = trimStart(trimmed.slice(name.length));
switch (words[0]) { switch (words[0]) {
case 'o': case 'o':
case 'open': case 'open':