Allow plugins to set the parent/predecessor of a new session (#3723)

This commit is contained in:
Jason Gauci 2019-10-14 17:09:30 -07:00 committed by Benjamin Staneck
parent 6deb733d63
commit 71953e0fdf
6 changed files with 22 additions and 19 deletions

View file

@ -10,16 +10,16 @@ const commands = {
}, },
'tab:new': focusedWindow => { 'tab:new': focusedWindow => {
if (focusedWindow) { if (focusedWindow) {
focusedWindow.rpc.emit('termgroup add req'); focusedWindow.rpc.emit('termgroup add req', {});
} else { } else {
setTimeout(app.createWindow, 0); setTimeout(app.createWindow, 0);
} }
}, },
'pane:splitRight': focusedWindow => { 'pane:splitRight': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('split request vertical'); focusedWindow && focusedWindow.rpc.emit('split request vertical', {});
}, },
'pane:splitDown': focusedWindow => { 'pane:splitDown': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('split request horizontal'); focusedWindow && focusedWindow.rpc.emit('split request horizontal', {});
}, },
'pane:close': focusedWindow => { 'pane:close': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('termgroup close req'); focusedWindow && focusedWindow.rpc.emit('termgroup close req');

View file

@ -89,7 +89,7 @@ module.exports = class Window {
// If no callback is passed to createWindow, // If no callback is passed to createWindow,
// a new session will be created by default. // a new session will be created by default.
if (!fn) { if (!fn) {
fn = win => win.rpc.emit('termgroup add req'); fn = win => win.rpc.emit('termgroup add req', {});
} }
// app.windowCallback is the createWindow callback // app.windowCallback is the createWindow callback
@ -166,7 +166,8 @@ module.exports = class Window {
uid: options.uid, uid: options.uid,
splitDirection: options.splitDirection, splitDirection: options.splitDirection,
shell: session.shell, shell: session.shell,
pid: session.pty.pid pid: session.pty ? session.pty.pid : null,
activeUid: options.activeUid
}); });
// If this is the initial session, flush any events that might have // If this is the initial session, flush any events that might have

View file

@ -17,7 +17,7 @@ import {
SESSION_SEARCH_CLOSE SESSION_SEARCH_CLOSE
} from '../constants/sessions'; } from '../constants/sessions';
export function addSession({uid, shell, pid, cols, rows, splitDirection}) { export function addSession({uid, shell, pid, cols, rows, splitDirection, activeUid}) {
return (dispatch, getState) => { return (dispatch, getState) => {
const {sessions} = getState(); const {sessions} = getState();
const now = Date.now(); const now = Date.now();
@ -29,7 +29,7 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
cols, cols,
rows, rows,
splitDirection, splitDirection,
activeUid: sessions.activeUid, activeUid: activeUid ? activeUid : sessions.activeUid,
now now
}); });
}; };

View file

@ -12,14 +12,15 @@ import getRootGroups from '../selectors';
import {setActiveSession, ptyExitSession, userExitSession} from './sessions'; import {setActiveSession, ptyExitSession, userExitSession} from './sessions';
function requestSplit(direction) { function requestSplit(direction) {
return () => (dispatch, getState) => { return activeUid => (dispatch, getState) => {
dispatch({ dispatch({
type: SESSION_REQUEST, type: SESSION_REQUEST,
effect: () => { effect: () => {
const {ui} = getState(); const {ui, sessions} = getState();
rpc.emit('new', { rpc.emit('new', {
splitDirection: direction, splitDirection: direction,
cwd: ui.cwd cwd: ui.cwd,
activeUid: activeUid ? activeUid : sessions.activeUid
}); });
} }
}); });
@ -37,7 +38,7 @@ export function resizeTermGroup(uid, sizes) {
}; };
} }
export function requestTermGroup() { export function requestTermGroup(activeUid) {
return (dispatch, getState) => { return (dispatch, getState) => {
dispatch({ dispatch({
type: TERM_GROUP_REQUEST, type: TERM_GROUP_REQUEST,
@ -46,7 +47,8 @@ export function requestTermGroup() {
const {cwd} = ui; const {cwd} = ui;
rpc.emit('new', { rpc.emit('new', {
isNewGroup: true, isNewGroup: true,
cwd cwd,
activeUid
}); });
} }
}); });

View file

@ -142,16 +142,16 @@ rpc.on('session search close', () => {
store_.dispatch(sessionActions.closeSearch()); store_.dispatch(sessionActions.closeSearch());
}); });
rpc.on('termgroup add req', () => { rpc.on('termgroup add req', ({activeUid}) => {
store_.dispatch(termGroupActions.requestTermGroup()); store_.dispatch(termGroupActions.requestTermGroup(activeUid));
}); });
rpc.on('split request horizontal', () => { rpc.on('split request horizontal', ({activeUid}) => {
store_.dispatch(termGroupActions.requestHorizontalSplit()); store_.dispatch(termGroupActions.requestHorizontalSplit(activeUid));
}); });
rpc.on('split request vertical', () => { rpc.on('split request vertical', ({activeUid}) => {
store_.dispatch(termGroupActions.requestVerticalSplit()); store_.dispatch(termGroupActions.requestVerticalSplit(activeUid));
}); });
rpc.on('reset fontSize req', () => { rpc.on('reset fontSize req', () => {

View file

@ -42,7 +42,7 @@ const reducer = (state = initialState, action) => {
cols: action.cols, cols: action.cols,
rows: action.rows, rows: action.rows,
uid: action.uid, uid: action.uid,
shell: action.shell.split('/').pop(), shell: action.shell ? action.shell.split('/').pop() : null,
pid: action.pid pid: action.pid
}) })
); );