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

Commit c48b4ca

Browse files
committed
fix(plugins/plugin-core-support): clicks in replayed table are erratic
Fixes #5758
1 parent 7997ef0 commit c48b4ca

File tree

1 file changed

+21
-10
lines changed
  • plugins/plugin-core-support/src/lib/cmds

1 file changed

+21
-10
lines changed

plugins/plugin-core-support/src/lib/cmds/replay.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,20 @@ function withNewTabUUID(tab: Tab, uuid: string) {
139139
}
140140

141141
/** Re-emit prior start event in new tab */
142-
function reEmitStartInTab(tab: Tab, uuid: string, startEvent: SnapshotBlock['startEvent']) {
142+
function reEmitStartInTab(tab: Tab, uuid: string, startEvent: SnapshotBlock['startEvent'], emitAsReplay = true) {
143143
const evt = Object.assign({}, startEvent, withNewTabUUID(tab, uuid))
144-
eventBus.emitCommandStart(evt, true)
144+
eventBus.emitCommandStart(evt, emitAsReplay)
145145
}
146146

147147
/** Re-emit prior complete event in new tab */
148-
function reEmitCompleteInTab(tab: Tab, uuid: string, completeEvent: SnapshotBlock['completeEvent']) {
148+
function reEmitCompleteInTab(
149+
tab: Tab,
150+
uuid: string,
151+
completeEvent: SnapshotBlock['completeEvent'],
152+
emitAsReplay = true
153+
) {
149154
const evt = Object.assign({}, completeEvent, withNewTabUUID(tab, uuid))
150-
eventBus.emitCommandComplete(evt, true)
155+
eventBus.emitCommandComplete(evt, emitAsReplay)
151156
}
152157

153158
/** Re-execute command line in new tab */
@@ -168,7 +173,10 @@ function replayClickFor(execUUID: string, rowIdx: number) {
168173
* Record clicks
169174
*
170175
*/
171-
type Click = { completeEvent: SnapshotBlock['completeEvent']; onClicks: { rowIdx: number; onClick: string }[] }
176+
type Click = {
177+
completeEvent: SnapshotBlock['completeEvent']
178+
onClicks: { rowIdx: number; onClick: string; echo: boolean }[]
179+
}
172180
class FlightRecorder {
173181
// eslint-disable-next-line no-useless-constructor
174182
public constructor(private readonly tab: Tab, private readonly blocks: SnapshotBlock[]) {}
@@ -181,8 +189,10 @@ class FlightRecorder {
181189
? {
182190
completeEvent: _.completeEvent,
183191
onClicks: _.completeEvent.response.body
184-
.map((_, rowIdx) =>
185-
_.onclickIdempotent && typeof _.onclick === 'string' ? { rowIdx, onClick: _.onclick } : undefined
192+
.map((row, rowIdx) =>
193+
row.onclickIdempotent && typeof row.onclick === 'string'
194+
? { rowIdx, onClick: row.onclick, echo: !row.onclickSilence }
195+
: undefined
186196
)
187197
.filter(_ => _)
188198
}
@@ -233,6 +243,7 @@ class FlightRecorder {
233243
if (isTable(click.completeEvent.response)) {
234244
const row = click.completeEvent.response.body[rowIdx]
235245
row.onclick = replayClickFor(click.completeEvent.execUUID, rowIdx)
246+
row.onclickExec = 'qexec'
236247
}
237248

238249
events[rowIdx] = xform(event)
@@ -262,7 +273,7 @@ class FlightRecorder {
262273
eventBus.onCommandComplete(fakeTab.uuid, onCommandComplete)
263274

264275
try {
265-
await fakeTab.REPL.pexec(_.onClick, { tab: fakeTab })
276+
await fakeTab.REPL.pexec(_.onClick, { tab: fakeTab, echo: _.echo })
266277
} finally {
267278
eventBus.offCommandStart(fakeTab.uuid, onCommandStart)
268279
eventBus.offCommandComplete(fakeTab.uuid, onCommandComplete)
@@ -360,8 +371,8 @@ export default function(registrar: Registrar) {
360371
const channel = `/${replayClickFor(execUUID, rowIdx)}`
361372
registrar.listen(channel, async () => {
362373
const uuid = splitAlignment[startEvent.tab]
363-
reEmitStartInTab(tab, uuid, startEvent)
364-
reEmitCompleteInTab(tab, uuid, completeEvent)
374+
reEmitStartInTab(tab, uuid, startEvent, false)
375+
reEmitCompleteInTab(tab, uuid, completeEvent, false)
365376
return true
366377
})
367378
}

0 commit comments

Comments
 (0)