File tree Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Expand file tree Collapse file tree 1 file changed +16
-12
lines changed Original file line number Diff line number Diff line change @@ -2251,24 +2251,28 @@ <h3>設定</h3>
2251
2251
} ) ;
2252
2252
document . getElementById ( "cursor" ) . children [ 1 ] . addEventListener ( "beforeinput" , ( e ) => {
2253
2253
if ( e . inputType == "deleteContentBackward" ) {
2254
- let i = 0 ;
2255
- let count = ( ( range ) => range . endOffset - range . startOffset ) ( e . getTargetRanges ( ) [ 0 ] ) ;
2256
- while ( count > 0 ) {
2257
- count -= texts [ cursor_pos [ 0 ] ] [ cursor_pos [ 1 ] - i ] . length ;
2258
- i ++ ;
2259
- }
2260
- let ev = new KeyboardEvent ( "keydown" , { key : "Backspace" , isComposing : false } ) ;
2261
- while ( i > 0 ) {
2262
- e . target . dispatchEvent ( ev ) ;
2263
- i -- ;
2264
- }
2265
- e . preventDefault ( ) ;
2254
+ var beforeDeletionLength = e . target . value . length ;
2266
2255
}
2256
+ console . log ( e ) ;
2267
2257
} ) ;
2268
2258
document . getElementById ( "cursor" ) . children [ 1 ] . addEventListener ( "input" , ( e ) => {
2269
2259
console . log ( e . type , e ) ;
2270
2260
//console.log(document.getElementById("cursor").children[1].selectionStart, document.getElementById("cursor").children[1].selectionEnd);
2271
2261
if ( e . data == null || e . data == undefined ) {
2262
+ if ( e . inputType == "deleteContentBackward" ) {
2263
+ let i = 0 ;
2264
+ let count = beforeDeletionLength ? beforeDeletionLength - e . target . value . length : 0 ;
2265
+ while ( count > 0 ) {
2266
+ count -= texts [ cursor_pos [ 0 ] ] [ cursor_pos [ 1 ] - i ] . length ;
2267
+ i ++ ;
2268
+ }
2269
+ let ev = new KeyboardEvent ( "keydown" , { key : "Backspace" , isComposing : false } ) ;
2270
+ while ( i > 0 ) {
2271
+ e . target . dispatchEvent ( ev ) ;
2272
+ i -- ;
2273
+ }
2274
+ e . preventDefault ( ) ;
2275
+ }
2272
2276
return ;
2273
2277
}
2274
2278
if ( composing ) {
You can’t perform that action at this time.
0 commit comments