From 81a028b706002f205fb7be8a3362e237ec424dd6 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Tue, 11 Jun 2024 20:18:30 +0200 Subject: [PATCH] undo working, limited to undo-ing adding only --- index.html | 106 +++++++---------------------------------------------- 1 file changed, 14 insertions(+), 92 deletions(-) diff --git a/index.html b/index.html index c04eb8d..55ad581 100644 --- a/index.html +++ b/index.html @@ -96,6 +96,7 @@ recognizer.onresult = (event) => { case speechactions[2] : deleteTarget( latest ) speechCommands.push( speechContent ) + addedContent.pop() break; case speechactions[3] : el = latest.cloneNode(true) // does not work properly, losing some attributes, in particular scale can be problematic @@ -118,8 +119,19 @@ recognizer.onresult = (event) => { speechCommands.push( speechContent ) break; case speechactions[5] : - console.log( "should undo", speechCommands.at(-1) ) - // note that not all commands might be undo-able + if ( speechCommands.at(-1) ){ + let prev_cmd_words = speechCommands.at(-1).split(" ").map( i => i.toLowerCase() ) + switch(prev_cmd_words[0]) { + case speechactions[0]: + console.log( "undoing", speechCommands.at(-1) ) + deleteTarget( latest ) + addedContent.pop() + break; + default: + console.log( "can't undo", speechCommands.at(-1) ) + // note that not all commands might be undo-able + } + } break; default: addedContent.push( addNewNoteAsPostItNote(speechContent, "0 1.2 -.5") ) @@ -499,96 +511,6 @@ setTimeout( _ => { - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -