From e95dafcf75d7b64dfad2e372aa31437d806a9ec8 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Fri, 26 May 2017 11:17:35 -0700 Subject: [PATCH] Some autocomplete tweaks and added ctrl+Enter shortcut --- app/common/constants.js | 1 + app/common/render.js | 10 +++++----- .../components/codemirror/extensions/autocomplete.js | 3 +++ app/ui/components/hotkey.js | 8 +++++--- app/ui/components/settings/shortcuts.js | 5 +++-- app/ui/containers/app.js | 2 +- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/common/constants.js b/app/common/constants.js index 1f46df11a..076fe5bdd 100644 --- a/app/common/constants.js +++ b/app/common/constants.js @@ -60,6 +60,7 @@ export const CHECK_FOR_UPDATES_INTERVAL = 1000 * 60 * 60 * 3; // 3 hours export const MOD_SYM = isMac() ? '⌘' : 'ctrl'; export const ALT_SYM = isMac() ? '⌃' : 'alt'; export const SHIFT_SYM = isMac() ? '⇧' : 'shift'; +export const CTRL_SYM = isMac() ? '⌃' : 'ctrl'; export function joinHotKeys (keys) { return keys.join(isMac() ? '' : '+'); } diff --git a/app/common/render.js b/app/common/render.js index 12cda9886..450355b19 100644 --- a/app/common/render.js +++ b/app/common/render.js @@ -4,7 +4,7 @@ import {setDefaultProtocol} from './misc'; import * as db from './database'; import * as templating from '../templating'; -export async function buildRenderContext (ancestors, rootEnvironment, subEnvironment) { +export async function buildRenderContext (ancestors, rootEnvironment, subEnvironment, variablesOnly = true) { if (!Array.isArray(ancestors)) { ancestors = []; } @@ -52,7 +52,7 @@ export async function buildRenderContext (ancestors, rootEnvironment, subEnviron * original base_url of google.com would be lost. */ if (typeof renderContext[key] === 'string') { - renderContext[key] = await render(environment[key], renderContext, null, true); + renderContext[key] = await render(environment[key], renderContext, null, variablesOnly); } else { renderContext[key] = environment[key]; } @@ -64,7 +64,7 @@ export async function buildRenderContext (ancestors, rootEnvironment, subEnviron // Render up to 5 levels of recursive references. for (let i = 0; i < 3; i++) { - finalRenderContext = await render(finalRenderContext, finalRenderContext, null, true); + finalRenderContext = await render(finalRenderContext, finalRenderContext, null, variablesOnly); } return finalRenderContext; @@ -137,7 +137,7 @@ export async function render (obj, context = {}, blacklistPathRegex = null, vari return next(newObj); } -export async function getRenderContext (request, environmentId, ancestors = null) { +export async function getRenderContext (request, environmentId, ancestors = null, variablesOnly = true) { if (!request) { return {}; } @@ -154,7 +154,7 @@ export async function getRenderContext (request, environmentId, ancestors = null const subEnvironment = await models.environment.getById(environmentId); // Generate the context we need to render - return buildRenderContext(ancestors, rootEnvironment, subEnvironment); + return buildRenderContext(ancestors, rootEnvironment, subEnvironment, variablesOnly); } export async function getRenderedRequest (request, environmentId) { diff --git a/app/ui/components/codemirror/extensions/autocomplete.js b/app/ui/components/codemirror/extensions/autocomplete.js index 1196ef121..68f7c7904 100644 --- a/app/ui/components/codemirror/extensions/autocomplete.js +++ b/app/ui/components/codemirror/extensions/autocomplete.js @@ -148,6 +148,9 @@ CodeMirror.defineOption('environmentAutocomplete', null, (cm, options) => { 'Ctrl-Space': completeForce, // Force autocomplete on hotkey "' '": completeIfAfterTagOrVarOpen }); + + // Close dropdown whenever something is clicked + document.addEventListener('click', () => cm.closeHint()); }); /** diff --git a/app/ui/components/hotkey.js b/app/ui/components/hotkey.js index 6962a5c6f..44ca0912a 100644 --- a/app/ui/components/hotkey.js +++ b/app/ui/components/hotkey.js @@ -1,14 +1,15 @@ import React, {PropTypes, PureComponent} from 'react'; -import {ALT_SYM, isMac, joinHotKeys, MOD_SYM, SHIFT_SYM} from '../../common/constants'; +import {ALT_SYM, CTRL_SYM, isMac, joinHotKeys, MOD_SYM, SHIFT_SYM} from '../../common/constants'; class Hotkey extends PureComponent { render () { - const {char, shift, alt, className} = this.props; + const {char, shift, alt, ctrl, className} = this.props; const chars = [ ]; alt && chars.push(ALT_SYM); shift && chars.push(SHIFT_SYM); - chars.push(MOD_SYM); + ctrl && chars.push(CTRL_SYM); + !ctrl && chars.push(MOD_SYM); chars.push(char); return ( @@ -25,6 +26,7 @@ Hotkey.propTypes = { // Optional alt: PropTypes.bool, shift: PropTypes.bool, + ctrl: PropTypes.bool, className: PropTypes.string }; diff --git a/app/ui/components/settings/shortcuts.js b/app/ui/components/settings/shortcuts.js index cc26773f5..8a36a09c6 100644 --- a/app/ui/components/settings/shortcuts.js +++ b/app/ui/components/settings/shortcuts.js @@ -2,12 +2,12 @@ import React, {PureComponent} from 'react'; import Hotkey from '../hotkey'; class Shortcuts extends PureComponent { - renderHotkey (name, char, shift, alt) { + renderHotkey (name, char, shift, alt, ctrl) { return ( {name} - + ); @@ -26,6 +26,7 @@ class Shortcuts extends PureComponent { {this.renderHotkey('Show Environment Editor', 'E')} {this.renderHotkey('Focus URL Bar', 'L')} {this.renderHotkey('Toggle Sidebar', '\\')} + {this.renderHotkey('Show Autocomplete Dropdown', 'Enter', false, false, true)} {this.renderHotkey('Show App Preferences', ',')} {this.renderHotkey('Show Workspace Settings', ',', true)} {this.renderHotkey('Show Request Settings', ',', true, true)} diff --git a/app/ui/containers/app.js b/app/ui/containers/app.js index c07b76d33..2632f17bf 100644 --- a/app/ui/containers/app.js +++ b/app/ui/containers/app.js @@ -228,7 +228,7 @@ class App extends PureComponent { async _fetchRenderContext () { const {activeEnvironment, activeRequest} = this.props; const environmentId = activeEnvironment ? activeEnvironment._id : null; - return render.getRenderContext(activeRequest, environmentId); + return render.getRenderContext(activeRequest, environmentId, null, false); } async _handleGetRenderContext () {