From 444ec122a20eff3f62b3af3cb1e357e5dd134b21 Mon Sep 17 00:00:00 2001 From: hackape Date: Wed, 3 May 2017 11:47:10 +0800 Subject: [PATCH] :sparkle: open tab to newly created file address Coding/WebIDE#108 --- app/commands/commandBindings/file.js | 18 ++++++++++++++++-- app/components/FileTree/actions.js | 4 +--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/commands/commandBindings/file.js b/app/commands/commandBindings/file.js index 0c25de03..9863dfb2 100644 --- a/app/commands/commandBindings/file.js +++ b/app/commands/commandBindings/file.js @@ -1,4 +1,4 @@ -/* @flow weak */ +import uniqueId from 'lodash/uniqueId' import { bindActionCreators } from 'redux' import store, { getState, dispatch } from '../../store' import mobxStore from '../../mobxStore' @@ -50,6 +50,18 @@ function createFolderAtPath (path) { ) } +function openTabOfNewFile (path) { + TabActions.createTab({ + id: uniqueId('tab_'), + type: 'editor', + title: path.split('/').pop(), + path: path, + content: { + body: '', + } + }) +} + export default { 'file:new_file': (c) => { const node = c.context @@ -62,7 +74,9 @@ export default { message: 'Enter the path for the new file.', defaultValue, selectionRange: [path.length, defaultValue.length] - }).then(createFile) + }) + .then(createFile) + .then(openTabOfNewFile) }, 'file:new_folder': (c) => { const node = c.context diff --git a/app/components/FileTree/actions.js b/app/components/FileTree/actions.js index e2263b25..e5b1830e 100644 --- a/app/components/FileTree/actions.js +++ b/app/components/FileTree/actions.js @@ -25,9 +25,7 @@ export function openNode (node, shouldBeFolded = null, deep = false) { } } else { const tabType = getTabType(node) - if ( - getTabType(node) === 'TEXT' - ) { + if (getTabType(node) === 'TEXT') { api.readFile(node.path) .then(data => { dispatch(TabActions.createTab({