@@ -242,34 +242,46 @@ define(function (require, exports, module) {
242242 /**
243243 * Create a new terminal with the default shell
244244 */
245- async function _createNewTerminal ( ) {
245+ async function _createNewTerminal ( cwdOverride ) {
246246 const shell = ShellProfiles . getDefaultShell ( ) ;
247- return _createNewTerminalWithShell ( shell ) ;
247+ return _createNewTerminalWithShell ( shell , cwdOverride ) ;
248+ }
249+
250+ /**
251+ * Convert a VFS path to a native platform path suitable for use as cwd.
252+ * Strips trailing slashes (posix_spawnp can fail with them).
253+ */
254+ function _toNativePath ( vfsPath ) {
255+ let cwd = vfsPath ;
256+ const tauriPrefix = Phoenix . VFS . getTauriDir ( ) ;
257+ if ( cwd . startsWith ( tauriPrefix ) ) {
258+ cwd = Phoenix . fs . getTauriPlatformPath ( cwd ) ;
259+ }
260+ if ( cwd . length > 1 && ( cwd . endsWith ( "/" ) || cwd . endsWith ( "\\" ) ) ) {
261+ cwd = cwd . slice ( 0 , - 1 ) ;
262+ }
263+ return cwd ;
248264 }
249265
250266 /**
251267 * Create a new terminal with a specific shell profile
268+ * @param {Object } shell - Shell profile to use
269+ * @param {string } [cwdOverride] - Optional VFS path to use as cwd instead of project root
252270 */
253- async function _createNewTerminalWithShell ( shell ) {
271+ async function _createNewTerminalWithShell ( shell , cwdOverride ) {
254272 if ( ! shell ) {
255273 console . error ( "Terminal: No shell available" ) ;
256274 return ;
257275 }
258276
259- // Get project root as cwd, converting VFS path to native platform path
260- const projectRoot = ProjectManager . getProjectRoot ( ) ;
277+ // Get cwd: use override if provided, otherwise fall back to project root
261278 let cwd ;
262- if ( projectRoot ) {
263- const fullPath = projectRoot . fullPath ;
264- const tauriPrefix = Phoenix . VFS . getTauriDir ( ) ;
265- if ( fullPath . startsWith ( tauriPrefix ) ) {
266- cwd = Phoenix . fs . getTauriPlatformPath ( fullPath ) ;
267- } else {
268- cwd = fullPath ;
269- }
270- // Remove trailing slash/backslash (posix_spawnp can fail with trailing slashes)
271- if ( cwd . length > 1 && ( cwd . endsWith ( "/" ) || cwd . endsWith ( "\\" ) ) ) {
272- cwd = cwd . slice ( 0 , - 1 ) ;
279+ if ( cwdOverride ) {
280+ cwd = _toNativePath ( cwdOverride ) ;
281+ } else {
282+ const projectRoot = ProjectManager . getProjectRoot ( ) ;
283+ if ( projectRoot ) {
284+ cwd = _toNativePath ( projectRoot . fullPath ) ;
273285 }
274286 }
275287
@@ -626,6 +638,18 @@ define(function (require, exports, module) {
626638 // Register commands
627639 CommandManager . register ( "New Terminal" , CMD_NEW_TERMINAL , _createNewTerminal ) ;
628640 CommandManager . register ( Strings . CMD_VIEW_TERMINAL , CMD_VIEW_TERMINAL , _showTerminal ) ;
641+ CommandManager . register ( Strings . CMD_OPEN_IN_INTEGRATED_TERMINAL ,
642+ Commands . NAVIGATE_OPEN_IN_INTEGRATED_TERMINAL , function ( ) {
643+ const entry = ProjectManager . getSelectedItem ( ) ;
644+ let cwdPath ;
645+ if ( entry ) {
646+ cwdPath = entry . isDirectory ? entry . fullPath : entry . parentPath ;
647+ } else {
648+ const projectRoot = ProjectManager . getProjectRoot ( ) ;
649+ cwdPath = projectRoot ? projectRoot . fullPath : undefined ;
650+ }
651+ _createNewTerminal ( cwdPath ) ;
652+ } ) ;
629653
630654 // Terminal context menu commands
631655 CommandManager . register ( Strings . CMD_COPY , CMD_TERMINAL_COPY , function ( ) {
0 commit comments