@@ -31,6 +31,9 @@ import {Library} from './library.js';
31
31
import { BlockCommandBundle } from './block-command-bundle.js' ;
32
32
import { noAwait } from './async.js' ;
33
33
import { EditContext , Editor } from './editor.js' ;
34
+ import { findAncestor } from './markdown/view-model-util.js' ;
35
+ import { findIndentTarget , indent } from './indent-util.js' ;
36
+ import { assert } from './asserts.js' ;
34
37
35
38
@customElement ( 'pkm-autocomplete' )
36
39
export class Autocomplete extends LitElement {
@@ -194,6 +197,62 @@ export class Autocomplete extends LitElement {
194
197
inline ,
195
198
this . getLinkInsertionCommand ( inline ) ,
196
199
) ,
200
+ {
201
+ description : 'Task' ,
202
+ execute : async ( ) => {
203
+ this . editor . runEditAction ( inline , ( context : EditContext ) => {
204
+ let target = findIndentTarget ( node , context . root ) ;
205
+ if ( target [ viewModel ] . parent ?. type !== 'list-item' ) {
206
+ indent ( node , context . root ) ;
207
+ target = findIndentTarget ( node , context . root ) ;
208
+ }
209
+ const listItem = target [ viewModel ] . parent ;
210
+ assert ( listItem ) ;
211
+ assert ( listItem . type === 'list-item' ) ;
212
+ context . startEditing ( ) ;
213
+ if ( listItem . checked === undefined ) {
214
+ listItem [ viewModel ] . updateChecked ( false ) ;
215
+ } else {
216
+ listItem [ viewModel ] . updateChecked ( undefined ) ;
217
+ }
218
+
219
+ node [ viewModel ] . edit ( {
220
+ // TODO: numbers are too contextual
221
+ startIndex : this . startIndex - 1 ,
222
+ newEndIndex : this . startIndex + 2 ,
223
+ oldEndIndex : this . endIndex ,
224
+ newText : '' ,
225
+ } ) ;
226
+ this . endIndex = this . startIndex ;
227
+ context . focus ( node , this . startIndex - 1 ) ;
228
+ } ) ;
229
+ } ,
230
+ } ,
231
+ {
232
+ description : 'Done' ,
233
+ execute : async ( ) => {
234
+ this . editor . runEditAction ( inline , ( context : EditContext ) => {
235
+ const { ancestor : target } = findAncestor (
236
+ node ,
237
+ context . root ,
238
+ 'list-item' ,
239
+ ) ;
240
+ if ( target ) {
241
+ assert ( target . type === 'list-item' ) ;
242
+ target [ viewModel ] . updateChecked ( true ) ;
243
+ }
244
+ node [ viewModel ] . edit ( {
245
+ // TODO: numbers are too contextual
246
+ startIndex : this . startIndex - 1 ,
247
+ newEndIndex : this . startIndex + 2 ,
248
+ oldEndIndex : this . endIndex ,
249
+ newText : '' ,
250
+ } ) ;
251
+ this . endIndex = this . startIndex ;
252
+ context . focus ( node , this . startIndex - 1 ) ;
253
+ } ) ;
254
+ } ,
255
+ } ,
197
256
] ) ,
198
257
) ;
199
258
this . activate ( inline , cursorIndex ) ;
0 commit comments