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

Commit e180bde

Browse files
committed
fix(plugins/plugin-client-common): markdown code block edits not durable
When editing the code block within Kui (i.e. not in the markdown text source), ... changes are possible, but re-executing the command does not reflect the updated code block text.
1 parent 36a83ef commit e180bde

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,15 @@ export default class SimpleEditor extends React.Component<Props, State> {
212212
})
213213

214214
if (props.onContentChange) {
215-
editor.onDidChangeModelContent(SimpleEditor.onChange(props, editor))
215+
// Notes: using onDidChangeModelContent does not let us
216+
// distinguish between the initial model change and changes
217+
// resulting from user input. Maybe we could look at the
218+
// `versionId` property of the model content change event
219+
// (does 1 mean the first version? it seems to be 2, dunno
220+
// why)... but i'd rather not get into that kind of low-level
221+
// dependence on the internal workings of monaco-editor
222+
// editor.onDidChangeModelContent(SimpleEditor.onChange(props, editor))
223+
editor.onKeyUp(SimpleEditor.onChange(props, editor))
216224
}
217225

218226
if (!options.readOnly && this.props.focus !== false) {

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ type Props<T1 = any, T2 = any, T3 = any> = Value &
6262
/** default: true */
6363
readonly?: boolean
6464

65-
/** Callback when content changes */
66-
onContentChange?: (content: string) => void
67-
6865
/** A Block identifier, to enable cross-referencing with check lists, etc. */
6966
blockId?: string
7067

@@ -107,6 +104,9 @@ type State = Value &
107104

108105
/** Millis timestamp of the last Run completion */
109106
endTime?: number
107+
108+
/** Any updates flowing *up* from the included CodeSnippet component */
109+
codeSnippetValue?: string
110110
}
111111

112112
export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T3>, State> {
@@ -167,12 +167,18 @@ export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T
167167
}
168168

169169
public static getDerivedStateFromProps(props: Props, state?: State) {
170-
if (!state || state.value !== props.value || state.language !== props.language) {
170+
const usePropsValue = !state || !state.codeSnippetValue
171+
172+
if (!usePropsValue && state && state.codeSnippetValue) {
173+
return Object.assign(state, {
174+
value: state.codeSnippetValue
175+
})
176+
} else if (!state || state.value !== props.value || state.language !== props.language) {
171177
const execUUID = uuid()
172178
return Object.assign(
173179
{
174180
execution: props.status || 'not-yet',
175-
value: props.value,
181+
value: usePropsValue ? props.value : state.codeSnippetValue || state.value,
176182
language: props.language,
177183
validated: false
178184
},
@@ -222,6 +228,11 @@ export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T
222228
}
223229
}
224230

231+
/** Updates coming from the CodeSnippet component */
232+
private readonly onContentChange = (codeSnippetValue: string) => {
233+
this.setState({ codeSnippetValue })
234+
}
235+
225236
private input() {
226237
return (
227238
<div className="repl-input-element-wrapper flex-layout flex-fill kui--inverted-color-context kui--relative-positioning">
@@ -230,10 +241,11 @@ export default class Input<T1, T2, T3> extends StreamingConsumer<Props<T1, T2, T
230241
<div className="flex-fill">
231242
<CodeSnippet
232243
wordWrap="on"
233-
tabUUID={this.props.tab ? this.props.tab.uuid : undefined}
234244
value={this.state.value}
235245
language={this.state.language}
236-
onContentChange={this.props.onContentChange}
246+
onContentChange={this.onContentChange}
247+
readonly={this.props.readonly !== false}
248+
tabUUID={this.props.tab ? this.props.tab.uuid : undefined}
237249
/>
238250
</div>
239251
{this.actions()}

0 commit comments

Comments
 (0)