Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 8ee26e8

Browse files
committed
feat(plugins/plugin-client-common): SourceRef should be default-expanded in Notebooks?
This PR updates SimpleEditor so that, for `simple` props, it is sized to fit, in terms of height. This PR also fixes a longer-standing problem where reducing the width of the window would not result in a re-layout of monaco for SourceRef; we need a min-width: 0 on flex-fill Fixes #5866
1 parent e88ebb3 commit 8ee26e8

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

plugins/plugin-client-common/src/components/Content/Editor/SimpleEditor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,18 @@ export default class SimpleEditor extends React.PureComponent<Props, State> {
118118
)
119119
const editor = Monaco.create(state.wrapper, options)
120120

121+
if (props.simple) {
122+
// size to fit
123+
state.wrapper.style.height = Math.min(400, editor.getContentHeight()) + 'px'
124+
}
125+
121126
state.wrapper['getValueForTests'] = () => {
122127
return editor.getValue()
123128
}
124129

125130
editor.onDidChangeModelContent(SimpleEditor.onChange(props, editor))
126131

127-
if (!props.readonly) {
132+
if (!options.readOnly) {
128133
setTimeout(() => editor.focus())
129134
}
130135

plugins/plugin-client-common/src/components/Content/Editor/lib/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ export default (options: Options): editor.IEditorConstructionOptions => ({
4646
folding: !options.simple || !/markdown|text|shell/i.test(options.language),
4747
lineNumbers: options.simple ? 'off' : 'on',
4848
wordWrap: options.simple ? 'on' : undefined,
49+
renderFinalNewline: !options.simple,
4950
lineDecorationsWidth: options.simple ? 0 : undefined
5051
})

plugins/plugin-client-common/src/components/Views/Terminal/Block/Input.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ export abstract class InputProvider<S extends State = State> extends React.PureC
264264
className="flex-fill"
265265
showMore={strings('Show X', name)}
266266
showLess={strings('Hide X', name)}
267+
expanded={this.props.isPartOfNotebook}
267268
onToggle={() => eventBus.emitTabLayoutChange(getPrimaryTabId(this.props.tab))}
268269
>
269270
<SimpleEditor
270271
tabUUID={getPrimaryTabId(this.props.tab)}
271-
content={_.data}
272+
content={
273+
_.data.replace(/\n$/, '') /* monaco's renderFinalNewline option doesn't seem to do what we need */
274+
}
272275
contentType={_.contentType}
273276
className="kui--source-ref-editor kui--inverted-color-context"
274277
fontSize={12}
@@ -599,7 +602,12 @@ export default class Input extends InputProvider {
599602
const replayed = isReplay(this.props.model)
600603
const completed = this.props.model.startTime && isWithCompleteEvent(this.props.model)
601604
const showingDate = !replayed && completed && !this.props.isWidthConstrained
602-
const noParen = !showingDate
605+
const duration =
606+
!replayed &&
607+
isWithCompleteEvent(this.props.model) &&
608+
this.props.model.completeEvent.completeTime &&
609+
prettyPrintDuration(this.props.model.completeEvent.completeTime - this.props.model.startTime)
610+
const noParen = !showingDate || !duration
603611
const openParen = noParen ? '' : '('
604612
const closeParen = noParen ? '' : ')'
605613

@@ -609,9 +617,7 @@ export default class Input extends InputProvider {
609617
{showingDate && new Date(this.props.model.startTime).toLocaleTimeString()}
610618
<span className="small-left-pad sub-text" ref={c => this.setState({ durationDom: c })}>
611619
{openParen}
612-
{isWithCompleteEvent(this.props.model) &&
613-
this.props.model.completeEvent.completeTime &&
614-
prettyPrintDuration(this.props.model.completeEvent.completeTime - this.props.model.startTime)}
620+
{duration}
615621
{closeParen}
616622
</span>
617623
</span>

plugins/plugin-client-common/src/components/Views/Terminal/Block/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export type BlockViewTraits = {
3838
isPartOfMiniSplit?: boolean
3939
isWidthConstrained?: boolean
4040

41+
/** Is this Block being displayed as part of a Notebook? */
42+
isPartOfNotebook?: boolean
43+
4144
/** Handler for: User clicked to focus on this block */
4245
willFocusBlock?: (evt: React.SyntheticEvent) => void
4346

plugins/plugin-client-common/src/components/Views/Terminal/ScrollableTerminal.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ type ScrollbackState = ScrollbackOptions & {
141141
interface State {
142142
focusedIdx: number
143143
splits: ScrollbackState[]
144+
145+
/** Is this Tab showing a Notebook? */
146+
isNotebook?: boolean
144147
}
145148

146149
/** get the selected texts in window */
@@ -180,7 +183,10 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
180183
this.initClipboardEvents()
181184
this.state = {
182185
focusedIdx: 0,
183-
splits: this.props.snapshot ? this.replaySnapshot() : [this.scrollbackWithWelcome()]
186+
splits: this.props.snapshot ? this.replaySnapshot() : [this.scrollbackWithWelcome()],
187+
188+
// are we loading a notebook from a snapshot?
189+
isNotebook: !!this.props.snapshot
184190
}
185191

186192
this.initSnapshotEvents()
@@ -1106,6 +1112,7 @@ export default class ScrollableTerminal extends React.PureComponent<Props, State
11061112
willFocusBlock={willFocusBlock}
11071113
isExperimental={hasCommand(_) && _.isExperimental}
11081114
isFocused={isFocused}
1115+
isPartOfNotebook={this.state.isNotebook}
11091116
prefersTerminalPresentation={isOk(_) && _.prefersTerminalPresentation}
11101117
isPartOfMiniSplit={isMiniSplit}
11111118
isVisibleInMiniSplit={idx === showThisIdxInMiniSplit || idx === nBlocks - 1}

plugins/plugin-client-common/web/css/static/ui.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ body.still-loading .repl {
119119
}
120120
.flex-fill {
121121
flex: 1;
122+
min-width: 0; /* so that reducing the width of the window causes a reflow; sigh */
122123
}
123124
.kui--rotate-180 {
124125
transform: rotate(180deg);

0 commit comments

Comments
 (0)