From 4e360a921011b003153c5d7568abf8f4259bdecd Mon Sep 17 00:00:00 2001 From: Nick Mitchell Date: Fri, 4 Jun 2021 13:16:02 -0400 Subject: [PATCH] fix(plugins/plugin-client-common): when rerunning blocks, output always scrolls to bottom part of #7527 --- .../src/components/Views/Terminal/Block/BlockModel.ts | 4 ++++ .../src/components/Views/Terminal/Block/Output.tsx | 4 +++- .../components/Views/Terminal/ScrollableTerminal.tsx | 11 ++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-client-common/src/components/Views/Terminal/Block/BlockModel.ts b/plugins/plugin-client-common/src/components/Views/Terminal/Block/BlockModel.ts index ec80fb64ea8..c106ed0b4f6 100644 --- a/plugins/plugin-client-common/src/components/Views/Terminal/Block/BlockModel.ts +++ b/plugins/plugin-client-common/src/components/Views/Terminal/Block/BlockModel.ts @@ -204,6 +204,10 @@ export function hasOriginalUUID(block: BlockModel | WithOriginalExecUUID): block return typeof (block as WithOriginalExecUUID).originalExecUUID === 'string' } +export function hasBeenRerun(block: BlockModel): boolean { + return hasOriginalUUID(block) +} + /** Transform to Processing */ export function Processing( block: BlockModel, diff --git a/plugins/plugin-client-common/src/components/Views/Terminal/Block/Output.tsx b/plugins/plugin-client-common/src/components/Views/Terminal/Block/Output.tsx index 4ed92c8860b..fef02060949 100644 --- a/plugins/plugin-client-common/src/components/Views/Terminal/Block/Output.tsx +++ b/plugins/plugin-client-common/src/components/Views/Terminal/Block/Output.tsx @@ -45,6 +45,7 @@ import { FinishedBlock, hasUUID, hasCommand, + hasBeenRerun, isBeingRerun, isFinished, isProcessing, @@ -171,7 +172,8 @@ export default class Output extends React.PureComponent { } private onRender(assertHasContent: boolean): void { - if (this.props.onRender) { + if (this.props.onRender && !this.props.isBeingRerun && !hasBeenRerun(this.props.model)) { + // we don't want reruns to trigger any scrolling behavior this.props.onRender() } this.setState({ assertHasContent }) diff --git a/plugins/plugin-client-common/src/components/Views/Terminal/ScrollableTerminal.tsx b/plugins/plugin-client-common/src/components/Views/Terminal/ScrollableTerminal.tsx index 33667091ca8..7c39772ac42 100644 --- a/plugins/plugin-client-common/src/components/Views/Terminal/ScrollableTerminal.tsx +++ b/plugins/plugin-client-common/src/components/Views/Terminal/ScrollableTerminal.tsx @@ -143,6 +143,7 @@ type ScrollbackState = ScrollbackOptions & { onFocus: (evt: React.FocusEvent) => void onOutputRender: () => void navigateTo: (dir: 'first' | 'last' | 'previous' | 'next') => void + setActiveBlock: (c: Block) => void willFocusBlock: (evt: React.SyntheticEvent) => void willRemoveBlock: (evt: React.SyntheticEvent, idx?: number) => void willUpdateCommand: (idx: number, command: string) => void @@ -403,6 +404,7 @@ export default class ScrollableTerminal extends React.PureComponent { + if (c && c.props && c.props.model && isActive(c.props.model)) { + state._activeBlock = c + } + } + /** * User clicked to focus a block. * @@ -1327,7 +1336,7 @@ export default class ScrollableTerminal extends React.PureComponent (scrollback._activeBlock = c)} + ref={scrollback.setActiveBlock} /> ) })