From 3d9bda237ec9d5c5e9dad87195de160486935aa7 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 22 Dec 2023 14:49:23 -0300 Subject: [PATCH] Fix redo functionality --- .../Board/Output/Output.container.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/components/Board/Output/Output.container.js b/src/components/Board/Output/Output.container.js index ea3b4827c..39f900229 100644 --- a/src/components/Board/Output/Output.container.js +++ b/src/components/Board/Output/Output.container.js @@ -232,13 +232,22 @@ export class OutputContainer extends Component { handleRepeatLastSpokenSentence = event => { const Z_KEY_CODE = 90; const Y_KEY_CODE = 89; + const { output } = this.props; if ( - (event.ctrlKey && event.shiftKey && event.keyCode === Z_KEY_CODE) || - (event.ctrlKey && event.keyCode === Y_KEY_CODE) + ((event.ctrlKey && event.shiftKey && event.keyCode === Z_KEY_CODE) || + (event.ctrlKey && event.keyCode === Y_KEY_CODE)) && + !!output.length ) { - const { output } = this.props; - const lastSpokenSymbol = output.findLast( - (element, index) => element.label && index !== output.length - 1 + const isLastSpokenSymbol = (element, index) => { + if (output.length === 1) return true; + if (element.label) { + return element.type === 'live' ? index < output.length - 1 : true; + } + return false; + }; + + const lastSpokenSymbol = output.findLast((element, index) => + isLastSpokenSymbol(element, index) ); const text = lastSpokenSymbol ? lastSpokenSymbol.label : ''; this.speakOutput(text);