@@ -136,6 +136,14 @@ class Constants {
136
136
* @default 'off'
137
137
*/
138
138
brailleMode = 'off' ;
139
+
140
+ /**
141
+ * We lock the selection so we don't pick up programatic selection changes
142
+ * @type {boolean }
143
+ * @default false
144
+ */
145
+ lockSelection = false ;
146
+
139
147
/**
140
148
* The current sonification mode. Can be 'on', 'off', 'sep' (seperated), or 'same' (all played at once).
141
149
* @type {("on"|"off"|"sep"|"same") }
@@ -3782,6 +3790,7 @@ class Display {
3782
3790
}
3783
3791
}
3784
3792
if ( onoff == 'on' ) {
3793
+ constants . lockSelection = true ;
3785
3794
if ( constants . chartType == 'box' ) {
3786
3795
// braille mode is on before any plot is selected
3787
3796
if (
@@ -3819,6 +3828,9 @@ class Display {
3819
3828
if ( position . x == - 1 && position . y == - 1 ) {
3820
3829
constants . brailleInput . setSelectionRange ( 0 , 0 ) ;
3821
3830
}
3831
+ setTimeout ( function ( ) {
3832
+ constants . lockSelection = false ;
3833
+ } , 50 ) ;
3822
3834
} else {
3823
3835
constants . brailleMode = 'off' ;
3824
3836
document
@@ -3925,6 +3937,7 @@ class Display {
3925
3937
* Updates the position of the cursor in the braille display based on the current chart type and position.
3926
3938
*/
3927
3939
UpdateBraillePos ( ) {
3940
+ constants . lockSelection = true ;
3928
3941
if (
3929
3942
constants . chartType == 'bar' ||
3930
3943
constants . chartType == 'hist' ||
@@ -3954,6 +3967,11 @@ class Display {
3954
3967
let targetLabel = this . boxplotGridPlaceholders [ sectionPos ] ;
3955
3968
let haveTargetLabel = false ;
3956
3969
let adjustedPos = 0 ;
3970
+ // bookmark: shiny issue: this is being called twice??
3971
+ // and the issue happens on 2nd call, sometimes it skips like 75% or whatever
3972
+ //
3973
+ // on first call, we might call it multiple as we're setting up, I care but let's check that later
3974
+
3957
3975
if ( constants . brailleData ) {
3958
3976
for ( let i = 0 ; i < constants . brailleData . length ; i ++ ) {
3959
3977
if ( constants . brailleData [ i ] . type != 'blank' ) {
@@ -3982,6 +4000,9 @@ class Display {
3982
4000
) {
3983
4001
constants . brailleInput . setSelectionRange ( positionL1 . x , positionL1 . x ) ;
3984
4002
}
4003
+ setTimeout ( function ( ) {
4004
+ constants . lockSelection = false ;
4005
+ } , 50 ) ;
3985
4006
}
3986
4007
3987
4008
/**
@@ -4286,16 +4307,20 @@ class Display {
4286
4307
constants . verboseText = verboseText ;
4287
4308
// aria live hack. If we're repeating (Space), aria won't detect if text is the same, so we modify vey slightly by adding / removing period at the end
4288
4309
if ( output == constants . infoDiv . innerHTML ) {
4289
- if ( constants . infoDiv . innerHTML . endsWith ( '.' ) ) {
4290
- if ( output . endsWith ( '.' ) ) {
4291
- output = output . slice ( 0 , - 1 ) ;
4310
+ if ( constants . infoDiv . textContent . endsWith ( '.' ) ) {
4311
+ if ( output . endsWith ( '.</p> ' ) ) {
4312
+ output = output . replace ( '.</p>' , '</p>' ) ;
4292
4313
}
4293
4314
} else {
4294
- output = output + '.' ;
4315
+ output = output . replace ( '</p>' , '.</p>' ) ;
4295
4316
}
4296
4317
}
4297
4318
4298
- if ( constants . infoDiv ) constants . infoDiv . innerHTML = output ;
4319
+ // could also try this hack, but we'll need a time gap
4320
+ if ( constants . infoDiv ) {
4321
+ constants . infoDiv . innerHTML = '' ;
4322
+ constants . infoDiv . innerHTML = output ;
4323
+ }
4299
4324
if ( constants . review ) {
4300
4325
if ( output . length > 0 ) {
4301
4326
constants . review . value = output . replace ( / < [ ^ > ] * > ? / gm, '' ) ;
@@ -8307,7 +8332,7 @@ class Control {
8307
8332
*
8308
8333
* @returns {void }
8309
8334
*/
8310
- SetControls ( ) {
8335
+ async SetControls ( ) {
8311
8336
constants . events . push ( [
8312
8337
document ,
8313
8338
'keydown' ,
@@ -8406,6 +8431,12 @@ class Control {
8406
8431
constants . brailleMode == 'on' &&
8407
8432
constants . brailleInput . selectionStart
8408
8433
) {
8434
+ if ( constants . lockSelection ) {
8435
+ return ;
8436
+ }
8437
+ // we lock the selection while we're changing stuff so it doesn't loop
8438
+ constants . lockSelection = true ;
8439
+
8409
8440
let cursorPos = constants . brailleInput . selectionStart ;
8410
8441
// we're using braille cursor, update the selection from what was clicked
8411
8442
cursorPos = constants . brailleInput . selectionStart ;
@@ -8447,18 +8478,29 @@ class Control {
8447
8478
8448
8479
// update display / text / audio
8449
8480
if ( testEnd ) {
8481
+ this . lockPosition = true ;
8450
8482
control . UpdateAll ( ) ;
8483
+ this . lockPosition = false ;
8451
8484
}
8452
8485
if ( testEnd ) {
8453
8486
audio . playEnd ( ) ;
8454
8487
}
8455
8488
}
8489
+ setTimeout ( function ( ) {
8490
+ constants . lockSelection = false ;
8491
+ } , 50 ) ;
8456
8492
}
8457
8493
} ) ;
8458
8494
} else if ( [ ] . concat ( singleMaidr . type ) . includes ( 'heat' ) ) {
8459
8495
document . addEventListener ( 'selectionchange' , function ( e ) {
8460
8496
if ( constants . brailleMode == 'on' ) {
8497
+ if ( constants . lockSelection ) {
8498
+ return ;
8499
+ }
8500
+
8461
8501
let pos = constants . brailleInput . selectionStart ;
8502
+ // we lock the selection while we're changing stuff so it doesn't loop
8503
+ constants . lockSelection = true ;
8462
8504
8463
8505
// exception: don't let users click the seperator char
8464
8506
let seperatorPositions = constants . brailleInput . value
@@ -8490,6 +8532,9 @@ class Control {
8490
8532
if ( testEnd ) {
8491
8533
audio . playEnd ( ) ;
8492
8534
}
8535
+ setTimeout ( function ( ) {
8536
+ constants . lockSelection = false ;
8537
+ } , 50 ) ;
8493
8538
} else {
8494
8539
// we're using normal cursor, let the default handle it
8495
8540
}
@@ -8505,23 +8550,35 @@ class Control {
8505
8550
) {
8506
8551
document . addEventListener ( 'selectionchange' , function ( e ) {
8507
8552
if ( constants . brailleMode == 'on' ) {
8508
- let pos = constants . brailleInput . selectionStart ;
8509
- // we're using braille cursor, update the selection from what was clicked
8510
- pos = constants . brailleInput . selectionStart ;
8511
- if ( pos < 0 ) {
8512
- pos = 0 ;
8553
+ if ( constants . lockSelection ) {
8554
+ return ;
8513
8555
}
8514
- position . x = pos ;
8515
- control . lockPosition ( ) ; // bar etc is default, no need to supply values
8516
- let testEnd = true ;
8517
8556
8518
- // update display / text / audio
8519
- if ( testEnd ) {
8520
- control . UpdateAll ( ) ;
8521
- }
8522
- if ( testEnd ) {
8523
- audio . playEnd ( ) ;
8557
+ // we lock the selection while we're changing stuff so it doesn't loop
8558
+ constants . lockSelection = true ;
8559
+
8560
+ if ( constants . brailleInput ) {
8561
+ let pos = constants . brailleInput . selectionStart ;
8562
+ // we're using braille cursor, update the selection from what was clicked
8563
+ pos = constants . brailleInput . selectionStart ;
8564
+ if ( pos < 0 ) {
8565
+ pos = 0 ;
8566
+ }
8567
+ position . x = pos ;
8568
+ control . lockPosition ( ) ; // bar etc is default, no need to supply values
8569
+ let testEnd = true ;
8570
+
8571
+ // update display / text / audio
8572
+ if ( testEnd ) {
8573
+ control . UpdateAll ( ) ;
8574
+ }
8575
+ if ( testEnd ) {
8576
+ audio . playEnd ( ) ;
8577
+ }
8524
8578
}
8579
+ setTimeout ( function ( ) {
8580
+ constants . lockSelection = false ;
8581
+ } , 50 ) ;
8525
8582
} else {
8526
8583
// we're using normal cursor, let the default handle it
8527
8584
}
@@ -10081,8 +10138,14 @@ class Control {
10081
10138
// braille cursor routing
10082
10139
document . addEventListener ( 'selectionchange' , function ( e ) {
10083
10140
if ( constants . brailleMode == 'on' ) {
10084
- let pos = constants . brailleInput . selectionStart ;
10141
+ if ( constants . lockSelection ) {
10142
+ return ;
10143
+ }
10144
+ // we lock the selection while we're changing stuff so it doesn't loop
10145
+ constants . lockSelection = true ;
10146
+
10085
10147
// we're using braille cursor, update the selection from what was clicked
10148
+ let pos = constants . brailleInput . selectionStart ;
10086
10149
pos = constants . brailleInput . selectionStart ;
10087
10150
if ( pos < 0 ) {
10088
10151
pos = 0 ;
@@ -10098,6 +10161,9 @@ class Control {
10098
10161
if ( testEnd ) {
10099
10162
audio . playEnd ( ) ;
10100
10163
}
10164
+ setTimeout ( function ( ) {
10165
+ constants . lockSelection = false ;
10166
+ } , 50 ) ;
10101
10167
}
10102
10168
} ) ;
10103
10169
0 commit comments