Skip to content

Commit

Permalink
fix(plugins/plugin-client-common): redirectToPlainSplitIfNeeded may f…
Browse files Browse the repository at this point in the history
…avor smaller terminals

Fixes #6930
  • Loading branch information
myan9 authored and starpit committed Feb 2, 2021
1 parent 4fca72b commit afa4c58
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,24 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
return this.initEvents(state)
}

/** @return a reasonable default split */
private findMainSplit(excludedIndex?: number) {
return this.state.splits
.slice()
.reverse()
.find((split, idx) => {
const originalIdx = this.state.splits.length - idx - 1
return (
split &&
!this.isMiniSplit(split, originalIdx) &&
(excludedIndex === undefined || originalIdx !== excludedIndex)
)
})
}

/** @return a reasonable default split */
private get current() {
return this.state.splits.find((split, idx) => split && !this.isMiniSplit(split, idx))
return this.findMainSplit()
}

/** @return the uuid of a reasonable default split */
Expand Down Expand Up @@ -611,7 +626,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
// e.g. executing a command in another split
if (idx >= 0 && this.isMiniSplit(this.state.splits[idx], idx)) {
// <-- this is a minisplit
const plainSplit = this.state.splits.find((split, idx) => !this.isMiniSplit(split, idx))
const plainSplit = this.findMainSplit()
if (plainSplit) {
// <-- we found a plain split!
return plainSplit.uuid
Expand Down Expand Up @@ -703,7 +718,9 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
insertIdx?: number
) {
if (!uuid) return
else uuid = this.redirectToPlainSplitIfNeeded(uuid, event)
else {
uuid = this.redirectToPlainSplitIfNeeded(uuid, event)
}

if (isTabLayoutModificationResponse(event.response)) {
const updatedResponse = await this.onTabLayoutModificationRequest(event.response, uuid)
Expand Down Expand Up @@ -897,8 +914,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
: !(await thisSplit.facade.REPL.qexec<boolean>(request.spec.options.ifnot).catch(() => true))
if (!respIf || !respIfNot) {
const { cmdline } = request.spec.options
const mainSplit =
this.state.splits.find((split, idx) => !this.isMiniSplit(split, idx) && idx !== thisSplitIdx) || thisSplit
const mainSplit = this.findMainSplit(thisSplitIdx)
request.spec.options.cmdline = undefined // null this out, since we got it!
mainSplit.facade.REPL.pexec(cmdline)
return
Expand Down

0 comments on commit afa4c58

Please sign in to comment.