@@ -167,7 +167,12 @@ impl DeckIdsByNameOrId {
167
167
fn get ( & self , name_or_id : & NameOrId ) -> Option < DeckId > {
168
168
match name_or_id {
169
169
_ if * name_or_id == NameOrId :: default ( ) => self . default ,
170
- NameOrId :: Id ( id) => self . ids . get ( & DeckId ( * id) ) . copied ( ) ,
170
+ NameOrId :: Id ( id) => self
171
+ . ids
172
+ . get ( & DeckId ( * id) )
173
+ // try treating it as a numeric deck name
174
+ . or_else ( || self . names . get ( & UniCase :: new ( id. to_string ( ) ) ) )
175
+ . copied ( ) ,
171
176
NameOrId :: Name ( name) => self . names . get ( & UniCase :: new ( name. to_string ( ) ) ) . copied ( ) ,
172
177
}
173
178
}
@@ -504,7 +509,13 @@ impl Note {
504
509
impl Collection {
505
510
pub ( super ) fn deck_id_by_name_or_id ( & mut self , deck : & NameOrId ) -> Result < Option < DeckId > > {
506
511
match deck {
507
- NameOrId :: Id ( id) => Ok ( self . get_deck ( DeckId ( * id) ) ?. map ( |_| DeckId ( * id) ) ) ,
512
+ NameOrId :: Id ( id) => Ok ( {
513
+ match self . get_deck ( DeckId ( * id) ) ?. map ( |d| d. id ) {
514
+ did @ Some ( _) => did,
515
+ // try treating it as a numeric deck name
516
+ _ => self . get_deck_id ( & id. to_string ( ) ) ?,
517
+ }
518
+ } ) ,
508
519
NameOrId :: Name ( name) => self . get_deck_id ( name) ,
509
520
}
510
521
}
@@ -514,7 +525,13 @@ impl Collection {
514
525
notetype : & NameOrId ,
515
526
) -> Result < Option < Arc < Notetype > > > {
516
527
match notetype {
517
- NameOrId :: Id ( id) => self . get_notetype ( NotetypeId ( * id) ) ,
528
+ NameOrId :: Id ( id) => Ok ( {
529
+ match self . get_notetype ( NotetypeId ( * id) ) ? {
530
+ nt @ Some ( _) => nt,
531
+ // try treating it as a numeric notetype name
532
+ _ => self . get_notetype_by_name ( & id. to_string ( ) ) ?,
533
+ }
534
+ } ) ,
518
535
NameOrId :: Name ( name) => self . get_notetype_by_name ( name) ,
519
536
}
520
537
}
0 commit comments