hyper/lib/actions/term-groups.js
Raz Friman 6039acd7a9 Update Electron to v6 (#3785)
* 3.0.0

* 3.0.2

* Save

* Save

* Upgrade yarn lock packages

* update node-gyp and node-pty

* update travis and appveyor to node 12

* appveyor is outdated as always

* update travis to xenial

* update node-pty@0.9.0-beta26

* update yarn.lock

* update electron to 6.0.8

* move node-pty to the correct package.json

* Fix linting failure

* Update yarn lockfile to try to fix appveyor build

* Remove unnecessary changes from package.json

* Try to fix appveyor by using a newer image

* Fix linting after my last change

* update electron to 6.0.9

* install windows-build-tools on appveyor

* fix syntax

* switch back to 2017 image

* remove old resolutions field

* revert accidental version change

* update electron to 6.0.11 and electron-rebuild to 1.8.6

* downgrade yarn to 1.18

until this issue is resolved https://github.com/yarnpkg/yarn/issues/7584

* update node-gyp to 6.0.0 and generate a fresh yarn lockfile

* update react and a few other dependencies

* fix lint

* this should actually be electron-builder, I think!

* update a few dependencies

* change to electron-store

electron-config was renamed to electron-store a while ago

* update xterm to v4.1.0 and ora to 4.0.2

* move pify to app/package.json

* TODO: Revert maybe. Throw a fit on every change to maybe fix the resizing issues

* a

* fix react ref problem

* fix split view focus problem

* remove the unnecessary fit

* remove the init col and row

* fix the problem that cannot show about hyper

* update electron to 6.0.12

* fix lint

* add more todos for componentWillReceiveProps deprecation

* update babel and plugins


Co-authored-by: Juan Campa <juancampa@gmail.com>
Co-authored-by: Benjamin Staneck <staneck@gmail.com>
Co-authored-by: ivan <ivanwonder@outlook.com>
2019-10-10 21:20:26 +02:00

171 lines
4.8 KiB
JavaScript

import rpc from '../rpc';
import {
DIRECTION,
TERM_GROUP_RESIZE,
TERM_GROUP_REQUEST,
TERM_GROUP_EXIT,
TERM_GROUP_EXIT_ACTIVE
} from '../constants/term-groups';
import {SESSION_REQUEST} from '../constants/sessions';
import findBySession from '../utils/term-groups';
import getRootGroups from '../selectors';
import {setActiveSession, ptyExitSession, userExitSession} from './sessions';
function requestSplit(direction) {
return () => (dispatch, getState) => {
dispatch({
type: SESSION_REQUEST,
effect: () => {
const {ui} = getState();
rpc.emit('new', {
splitDirection: direction,
cwd: ui.cwd
});
}
});
};
}
export const requestVerticalSplit = requestSplit(DIRECTION.VERTICAL);
export const requestHorizontalSplit = requestSplit(DIRECTION.HORIZONTAL);
export function resizeTermGroup(uid, sizes) {
return {
uid,
type: TERM_GROUP_RESIZE,
sizes
};
}
export function requestTermGroup() {
return (dispatch, getState) => {
dispatch({
type: TERM_GROUP_REQUEST,
effect: () => {
const {ui} = getState();
const {cwd} = ui;
rpc.emit('new', {
isNewGroup: true,
cwd
});
}
});
};
}
export function setActiveGroup(uid) {
return (dispatch, getState) => {
const {termGroups} = getState();
dispatch(setActiveSession(termGroups.activeSessions[uid]));
};
}
// When we've found the next group which we want to
// set as active (after closing something), we also need
// to find the first child group which has a sessionUid.
const findFirstSession = (state, group) => {
if (group.sessionUid) {
return group.sessionUid;
}
for (const childUid of group.children) {
const child = state.termGroups[childUid];
// We want to find the *leftmost* session,
// even if it's nested deep down:
const sessionUid = findFirstSession(state, child);
if (sessionUid) {
return sessionUid;
}
}
};
const findPrevious = (list, old) => {
const index = list.indexOf(old);
// If `old` was the first item in the list,
// choose the other item available:
return index ? list[index - 1] : list[1];
};
const findNextSessionUid = (state, group) => {
// If we're closing a root group (i.e. a whole tab),
// the next group needs to be a root group as well:
if (state.activeRootGroup === group.uid) {
const rootGroups = getRootGroups({termGroups: state});
const nextGroup = findPrevious(rootGroups, group);
return findFirstSession(state, nextGroup);
}
const {children} = state.termGroups[group.parentUid];
const nextUid = findPrevious(children, group.uid);
return findFirstSession(state, state.termGroups[nextUid]);
};
export function ptyExitTermGroup(sessionUid) {
return (dispatch, getState) => {
const {termGroups} = getState();
const group = findBySession(termGroups, sessionUid);
// This might have already been closed:
if (!group) {
return dispatch(ptyExitSession(sessionUid));
}
dispatch({
type: TERM_GROUP_EXIT,
uid: group.uid,
effect: () => {
const activeSessionUid = termGroups.activeSessions[termGroups.activeRootGroup];
if (Object.keys(termGroups.termGroups).length > 1 && activeSessionUid === sessionUid) {
const nextSessionUid = findNextSessionUid(termGroups, group);
dispatch(setActiveSession(nextSessionUid));
}
dispatch(ptyExitSession(sessionUid));
}
});
};
}
export function userExitTermGroup(uid) {
return (dispatch, getState) => {
const {termGroups} = getState();
dispatch({
type: TERM_GROUP_EXIT,
uid,
effect: () => {
const group = termGroups.termGroups[uid];
if (Object.keys(termGroups.termGroups).length <= 1) {
// No need to attempt finding a new active session
// if this is the last one we've got:
return dispatch(userExitSession(group.sessionUid));
}
const activeSessionUid = termGroups.activeSessions[termGroups.activeRootGroup];
if (termGroups.activeRootGroup === uid || activeSessionUid === group.sessionUid) {
const nextSessionUid = findNextSessionUid(termGroups, group);
dispatch(setActiveSession(nextSessionUid));
}
if (group.sessionUid) {
dispatch(userExitSession(group.sessionUid));
} else {
group.children.forEach(childUid => {
dispatch(userExitTermGroup(childUid));
});
}
}
});
};
}
export function exitActiveTermGroup() {
return (dispatch, getState) => {
dispatch({
type: TERM_GROUP_EXIT_ACTIVE,
effect() {
const {sessions, termGroups} = getState();
const {uid} = findBySession(termGroups, sessions.activeUid);
dispatch(userExitTermGroup(uid));
}
});
};
}