@@ -827,7 +827,7 @@ function createSqueakDisplay(canvas, options) {
827827 deadChars = deadChars . concat ( chars ) ;
828828 }
829829 }
830- if ( ! deadChars . length ) input . value = "" ; // clear input
830+ if ( ! deadChars . length ) resetInput ( ) ;
831831 } ;
832832 input . onkeydown = function ( evt ) {
833833 checkFullscreen ( ) ;
@@ -890,6 +890,32 @@ function createSqueakDisplay(canvas, options) {
890890 if ( ! display . vm ) return true ;
891891 recordModifiers ( evt , display ) ;
892892 } ;
893+ function resetInput ( ) {
894+ input . value = "**" ;
895+ input . selectionStart = 1 ;
896+ input . selectionEnd = 1 ;
897+ }
898+ resetInput ( ) ;
899+ // hack to generate arrow keys when moving the cursor (e.g. via spacebar on iPhone)
900+ // we're not getting any events for that but the cursor (selection) changes
901+ if ( 'ontouchstart' in document ) {
902+ let count = 0 ; // count how often the interval has run after the first move
903+ setInterval ( ( ) => {
904+ const direction = input . selectionStart - 1 ;
905+ if ( direction === 0 ) {
906+ count = 0 ;
907+ return ;
908+ }
909+ // move cursor once, then not for 500ms, then every 250ms
910+ if ( count === 0 || count > 2 ) {
911+ const key = direction < 1 ? 28 : 29 ; // arrow left or right
912+ recordKeyboardEvent ( key , Date . now ( ) , display ) ;
913+ }
914+ input . selectionStart = 1 ;
915+ input . selectionEnd = 1 ;
916+ count ++ ;
917+ } , 250 ) ;
918+ }
893919 // more copy/paste
894920 if ( navigator . clipboard ) {
895921 // new-style copy/paste (all modern browsers)
0 commit comments