File tree 1 file changed +13
-3
lines changed
1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,26 @@ export function initMarkupTasklist() {
14
14
const checkboxes = el . querySelectorAll ( `.task-list-item input[type=checkbox]` ) ;
15
15
16
16
for ( const checkbox of checkboxes ) {
17
- if ( checkbox . dataset . editable ) return ;
17
+ if ( checkbox . dataset . editable ) {
18
+ return ;
19
+ }
20
+
18
21
checkbox . dataset . editable = 'true' ;
19
22
checkbox . addEventListener ( 'input' , async ( ) => {
20
23
const checkboxCharacter = checkbox . checked ? 'x' : ' ' ;
21
24
const position = parseInt ( checkbox . dataset . sourcePosition ) + 1 ;
22
25
23
26
const rawContent = container . querySelector ( '.raw-content' ) ;
24
27
const oldContent = rawContent . textContent ;
25
- const newContent = oldContent . substring ( 0 , position ) + checkboxCharacter + oldContent . substring ( position + 1 ) ;
26
- if ( newContent === oldContent ) return ;
28
+
29
+ const encoder = new TextEncoder ( ) ;
30
+ const buffer = encoder . encode ( oldContent ) ;
31
+ buffer . set ( encoder . encode ( checkboxCharacter ) , position ) ;
32
+ const newContent = new TextDecoder ( ) . decode ( buffer ) ;
33
+
34
+ if ( newContent === oldContent ) {
35
+ return ;
36
+ }
27
37
28
38
// Prevent further inputs until the request is done. This does not use the
29
39
// `disabled` attribute because it causes the border to flash on click.
You can’t perform that action at this time.
0 commit comments