1- module UnisonShare.Page.CodePage exposing (..)
1+ port module UnisonShare.Page.CodePage exposing (..)
22
3+ import Code.BranchRef as BranchRef
34import Code.CodebaseTree as CodebaseTree
45import Code.Config exposing (Config )
56import Code.Definition.Reference exposing (Reference )
@@ -22,7 +23,7 @@ import UI.PageContent as PageContent exposing (PageContent)
2223import UI.PageLayout as PageLayout exposing (PageLayout )
2324import UI.Sidebar as Sidebar exposing (Sidebar )
2425import UnisonShare.AppContext as AppContext exposing (AppContext )
25- import UnisonShare.CodeBrowsingContext exposing (CodeBrowsingContext (..) )
26+ import UnisonShare.CodeBrowsingContext exposing (CodeBrowsingContext )
2627import UnisonShare.Page.CodePageContent as CodePageContent
2728import UnisonShare.PageFooter as PageFooter
2829import UnisonShare.Route as Route exposing (CodeRoute (..) )
@@ -307,7 +308,7 @@ update appContext context codeRoute msg model =
307308 ( model, Cmd . none )
308309
309310 ( _, Keydown event ) ->
310- keydown appContext model event
311+ keydown appContext context model event
311312
312313 ( _, KeyboardShortcutMsg kMsg ) ->
313314 let
@@ -387,20 +388,43 @@ update appContext context codeRoute msg model =
387388
388389 WorkspacePanes . RequestPermalink ref ->
389390 let
390- perspective =
391- case model. config. perspective of
392- Perspective . Root { details } ->
393- case details of
394- RemoteData . Success ( Namespace . Namespace _ hash _) ->
395- Perspective . absoluteRootPerspective hash
396-
397- _ ->
398- model. config. perspective
399-
400- _ ->
401- model. config. perspective
391+ nextRoute p =
392+ Route . projectBranch
393+ context. projectRef
394+ context. branchRef
395+ ( Route . replacePerspective ( Just ref) p)
402396 in
403- ( model, navigateToCode appContext context ( Route . replacePerspective ( Just ref) perspective) )
397+ if not ( BranchRef . isReleaseBranchRef context. branchRef) && Perspective . isRootPerspective model. config. perspective then
398+ -- releases are already permalinks, so no need for
399+ -- permalinks when we are viewing a release
400+ let
401+ perspective =
402+ case model. config. perspective of
403+ Perspective . Root { details } ->
404+ case details of
405+ RemoteData . Success ( Namespace . Namespace _ hash _) ->
406+ Perspective . absoluteRootPerspective hash
407+
408+ _ ->
409+ model. config. perspective
410+
411+ _ ->
412+ model. config. perspective
413+ in
414+ ( model
415+ , Cmd . batch
416+ [ Route . navigate appContext. navKey ( nextRoute perspective)
417+ , copyToClipboard ( Route . toUrlString ( nextRoute perspective))
418+ ]
419+ )
420+
421+ else if BranchRef . isReleaseBranchRef context. branchRef then
422+ -- We do want to copy the release url though
423+ ( model, copyToClipboard ( Route . toUrlString ( nextRoute model. config. perspective)) )
424+
425+ else
426+ -- Skip completely if within a perspective
427+ ( model, Cmd . none )
404428
405429 _ ->
406430 ( model, Cmd . none )
@@ -572,8 +596,8 @@ routeReference route =
572596 Nothing
573597
574598
575- keydown : AppContext -> Model -> KeyboardEvent -> ( Model , Cmd Msg )
576- keydown appContext model keyboardEvent =
599+ keydown : AppContext -> CodeBrowsingContext -> Model -> KeyboardEvent -> ( Model , Cmd Msg )
600+ keydown appContext context model keyboardEvent =
577601 let
578602 shortcut =
579603 KeyboardShortcut . fromKeyboardEvent model. keyboardShortcut keyboardEvent
@@ -594,6 +618,43 @@ keydown appContext model keyboardEvent =
594618 KeyboardShortcut . Sequence _ Escape ->
595619 ( { model | modal = NoModal }, Cmd . none )
596620
621+ KeyboardShortcut . Sequence _ ( Y _) ->
622+ -- Releases are already permalinks, so no need for
623+ -- permalinks when we are viewing a release
624+ -- We also don't have the root hash from within a perspective
625+ if not ( BranchRef . isReleaseBranchRef context. branchRef) && Perspective . isRootPerspective model. config. perspective then
626+ case model. content of
627+ WorkspacePage panes ->
628+ let
629+ perspective =
630+ case model. config. perspective of
631+ Perspective . Root { details } ->
632+ case details of
633+ RemoteData . Success ( Namespace . Namespace _ hash _) ->
634+ Perspective . absoluteRootPerspective hash
635+
636+ _ ->
637+ model. config. perspective
638+
639+ _ ->
640+ model. config. perspective
641+
642+ ref =
643+ case WorkspacePanes . currentlyFocusedReference panes of
644+ Just ( WorkspaceItemRef . DefinitionItemRef r) ->
645+ Just r
646+
647+ _ ->
648+ Nothing
649+ in
650+ ( model, navigateToCode appContext context ( Route . replacePerspective ref perspective) )
651+
652+ _ ->
653+ ( model, Cmd . none )
654+
655+ else
656+ ( model, Cmd . none )
657+
597658 _ ->
598659 if Finder . isShowFinderKeyboardShortcut appContext. operatingSystem shortcut then
599660 let
@@ -611,15 +672,14 @@ keydown appContext model keyboardEvent =
611672-- EFFECTS
612673
613674
675+ port copyToClipboard : String -> Cmd msg
676+
677+
614678navigateToCode : AppContext -> CodeBrowsingContext -> CodeRoute -> Cmd Msg
615- navigateToCode appContext context codeRoute =
616- let
617- route_ =
618- case context of
619- ProjectBranch ps bs ->
620- Route . projectBranch ps bs codeRoute
621- in
622- Route . navigate appContext. navKey route_
679+ navigateToCode appContext { projectRef, branchRef } codeRoute =
680+ Route . navigate
681+ appContext. navKey
682+ ( Route . projectBranch projectRef branchRef codeRoute)
623683
624684
625685
0 commit comments