@@ -28,10 +28,12 @@ import { and, not, bool, eq } from '@cardstack/boxel-ui/helpers';
28
28
import { File } from ' @cardstack/boxel-ui/icons' ;
29
29
30
30
import {
31
+ identifyCard ,
31
32
isCardDef ,
32
33
isCardDocumentString ,
33
34
hasExecutableExtension ,
34
35
RealmPaths ,
36
+ isResolvedCodeRef ,
35
37
type ResolvedCodeRef ,
36
38
PermissionsContextName ,
37
39
} from ' @cardstack/runtime-common' ;
@@ -464,15 +466,20 @@ export default class CodeSubmode extends Component<Signature> {
464
466
return undefined ;
465
467
}
466
468
467
- private get shouldDisplayPlayground() {
468
- return isCardDef (this .selectedCardOrField ?.cardOrField );
469
+ private get selectedCardRef(): ResolvedCodeRef | undefined {
470
+ let baseDefType = this .selectedCardOrField ?.cardOrField ;
471
+ if (! isCardDef (baseDefType )) {
472
+ return undefined ;
473
+ }
474
+ let codeRef = identifyCard (baseDefType );
475
+ if (! isResolvedCodeRef (codeRef )) {
476
+ return undefined ;
477
+ }
478
+ return codeRef ;
469
479
}
470
480
471
481
get showSpecPreview() {
472
- return (
473
- ! this .moduleContentsResource .isLoading &&
474
- this .selectedDeclaration ?.exportName
475
- );
482
+ return this .selectedCardOrField ?.exportName ;
476
483
}
477
484
478
485
private get itemToDeleteAsCard() {
@@ -489,7 +496,22 @@ export default class CodeSubmode extends Component<Signature> {
489
496
}
490
497
491
498
@action
492
- goToDefinition(
499
+ private goToDefinitionAndResetCursorPosition(
500
+ codeRef : ResolvedCodeRef | undefined ,
501
+ localName : string | undefined ,
502
+ ) {
503
+ this .goToDefinition (codeRef , localName );
504
+ if (this .codePath ) {
505
+ let urlString = this .codePath .toString ();
506
+ this .recentFilesService .updateCursorPositionByURL (
507
+ urlString .endsWith (' gts' ) ? urlString : ` ${urlString }.gts ` ,
508
+ undefined ,
509
+ );
510
+ }
511
+ }
512
+
513
+ @action
514
+ private goToDefinition(
493
515
codeRef : ResolvedCodeRef | undefined ,
494
516
localName : string | undefined ,
495
517
) {
@@ -808,7 +830,7 @@ export default class CodeSubmode extends Component<Signature> {
808
830
@ selectedDeclaration ={{this .selectedDeclaration }}
809
831
@ selectDeclaration ={{this .selectDeclaration }}
810
832
@ delete ={{this .setItemToDelete }}
811
- @ goToDefinition ={{this .goToDefinition }}
833
+ @ goToDefinition ={{this .goToDefinitionAndResetCursorPosition }}
812
834
@ createFile ={{perform this . createFile}}
813
835
@ openSearch ={{search.openSearchToResults }}
814
836
/>
@@ -932,7 +954,7 @@ export default class CodeSubmode extends Component<Signature> {
932
954
@ moduleContentsResource ={{this .moduleContentsResource }}
933
955
@ card ={{this .selectedCardOrField.cardOrField }}
934
956
@ cardTypeResource ={{this .selectedCardOrField.cardType }}
935
- @ goToDefinition ={{this .goToDefinition }}
957
+ @ goToDefinition ={{this .goToDefinitionAndResetCursorPosition }}
936
958
@ isReadOnly ={{this .isReadOnly }}
937
959
as | SchemaEditorTitle SchemaEditorPanel |
938
960
>
@@ -957,7 +979,7 @@ export default class CodeSubmode extends Component<Signature> {
957
979
</: content >
958
980
</A.Item >
959
981
</SchemaEditor >
960
- {{#if this . shouldDisplayPlayground }}
982
+ {{#if this . selectedCardRef }}
961
983
<A.Item
962
984
class =' accordion-item'
963
985
@ contentClass =' accordion-item-content'
@@ -968,8 +990,8 @@ export default class CodeSubmode extends Component<Signature> {
968
990
<: title >Playground</: title >
969
991
<: content >
970
992
<PlaygroundPanel
971
- @ moduleContentsResource ={{this .moduleContentsResource }}
972
- @ cardType ={{this .selectedCardOrField.cardType }}
993
+ @ codeRef ={{this .selectedCardRef }}
994
+ @ isLoadingNewModule ={{this .moduleContentsResource.isLoadingNewModule }}
973
995
/>
974
996
</: content >
975
997
</A.Item >
0 commit comments