Skip to content

Commit 4abe622

Browse files
committed
permalink: support y and copy
1 parent 2164ecb commit 4abe622

11 files changed

+128
-66
lines changed

src/Code2/Workspace/WorkspacePane.elm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,11 @@ openDependencies config paneId ({ workspaceItems } as model) dependenciesOfRef =
567567
)
568568

569569

570+
currentlyFocusedReference : Model -> Maybe WorkspaceItemRef
571+
currentlyFocusedReference model =
572+
WorkspaceItems.focusedReference model.workspaceItems
573+
574+
570575
currentlyOpenReferences : Model -> List Reference
571576
currentlyOpenReferences model =
572577
WorkspaceItems.definitionReferences model.workspaceItems

src/Code2/Workspace/WorkspacePanes.elm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ openDependenciesOf config model ref =
263263
( { model | right = rightPane }, Cmd.map RightPaneMsg rightPaneCmd )
264264

265265

266+
currentlyFocusedReference : Model -> Maybe WorkspaceItemRef
267+
currentlyFocusedReference model =
268+
case model.focusedPane of
269+
LeftPaneFocus _ ->
270+
WorkspacePane.currentlyFocusedReference model.left
271+
272+
RightPaneFocus ->
273+
WorkspacePane.currentlyFocusedReference model.right
274+
275+
266276
currentlyOpenReferences : Model -> List Reference
267277
currentlyOpenReferences model =
268278
WorkspacePane.currentlyOpenReferences model.left

src/UnisonShare/Api.elm

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Maybe.Extra as MaybeE
1919
import Regex
2020
import Set exposing (Set)
2121
import UnisonShare.Account exposing (Account)
22-
import UnisonShare.CodeBrowsingContext exposing (CodeBrowsingContext(..))
22+
import UnisonShare.CodeBrowsingContext exposing (CodeBrowsingContext)
2323
import UnisonShare.Contribution exposing (ContributionStateToken(..))
2424
import UnisonShare.Contribution.ContributionRef as ContributionRef exposing (ContributionRef)
2525
import UnisonShare.Contribution.ContributionStatus as ContributionStatus exposing (ContributionStatus)
@@ -1308,19 +1308,17 @@ catalog =
13081308

13091309

13101310
baseCodePathFromContext : CodeBrowsingContext -> List String
1311-
baseCodePathFromContext context =
1312-
case context of
1313-
ProjectBranch pr br ->
1314-
let
1315-
( handle, slug ) =
1316-
ProjectRef.toApiStringParts pr
1317-
in
1318-
case br of
1319-
BranchRef.ReleaseBranchRef v ->
1320-
[ "users", handle, "projects", slug, "releases", Version.toString v ]
1311+
baseCodePathFromContext { projectRef, branchRef } =
1312+
let
1313+
( handle, slug ) =
1314+
ProjectRef.toApiStringParts projectRef
1315+
in
1316+
case branchRef of
1317+
BranchRef.ReleaseBranchRef v ->
1318+
[ "users", handle, "projects", slug, "releases", Version.toString v ]
13211319

1322-
_ ->
1323-
[ "users", handle, "projects", slug, "branches", BranchRef.toApiUrlString br ]
1320+
_ ->
1321+
[ "users", handle, "projects", slug, "branches", BranchRef.toApiUrlString branchRef ]
13241322

13251323

13261324
namespace : CodeBrowsingContext -> Perspective -> FQN -> Endpoint

src/UnisonShare/CodeBrowsingContext.elm

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ import Code.BranchRef as BranchRef exposing (BranchRef)
44
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
55

66

7-
type CodeBrowsingContext
8-
= ProjectBranch ProjectRef BranchRef
9-
10-
11-
project : ProjectRef -> BranchRef -> CodeBrowsingContext
12-
project =
13-
ProjectBranch
7+
type alias CodeBrowsingContext =
8+
{ projectRef : ProjectRef, branchRef : BranchRef }
149

1510

1611
equals : CodeBrowsingContext -> CodeBrowsingContext -> Bool
17-
equals (ProjectBranch projectRefA branchRefA) (ProjectBranch projectRefB branchRefB) =
18-
ProjectRef.equals projectRefA projectRefB && BranchRef.equals branchRefA branchRefB
12+
equals contextA contextB =
13+
ProjectRef.equals contextA.projectRef contextB.projectRef && BranchRef.equals contextA.branchRef contextB.branchRef

src/UnisonShare/Page/CodePage.elm

Lines changed: 86 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
module UnisonShare.Page.CodePage exposing (..)
1+
port module UnisonShare.Page.CodePage exposing (..)
22

3+
import Code.BranchRef as BranchRef
34
import Code.CodebaseTree as CodebaseTree
45
import Code.Config exposing (Config)
56
import Code.Definition.Reference exposing (Reference)
@@ -22,7 +23,7 @@ import UI.PageContent as PageContent exposing (PageContent)
2223
import UI.PageLayout as PageLayout exposing (PageLayout)
2324
import UI.Sidebar as Sidebar exposing (Sidebar)
2425
import UnisonShare.AppContext as AppContext exposing (AppContext)
25-
import UnisonShare.CodeBrowsingContext exposing (CodeBrowsingContext(..))
26+
import UnisonShare.CodeBrowsingContext exposing (CodeBrowsingContext)
2627
import UnisonShare.Page.CodePageContent as CodePageContent
2728
import UnisonShare.PageFooter as PageFooter
2829
import 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+
614678
navigateToCode : 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

src/UnisonShare/Page/ProjectContributionChangesPage.elm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import UnisonShare.BranchDiff.DefinitionType as DefinitionType exposing (Definit
3939
import UnisonShare.BranchDiff.LibDep as LibDep exposing (LibDep)
4040
import UnisonShare.BranchDiff.ToggledChangeLines as ToggledChangeLines exposing (ToggledChangeLines)
4141
import UnisonShare.BranchDiffState as BranchDiffState exposing (BranchDiffState)
42-
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
4342
import UnisonShare.Contribution exposing (ContributionDetails)
4443
import UnisonShare.Contribution.ContributionRef exposing (ContributionRef)
4544
import UnisonShare.DefinitionDiff as DefinitionDiff
@@ -235,7 +234,7 @@ update appContext projectRef contribRef msg model =
235234
config =
236235
AppContext.toCodeConfig
237236
appContext
238-
(CodeBrowsingContext.ProjectBranch projectRef bd.oldBranch.ref)
237+
{ projectRef = projectRef, branchRef = bd.oldBranch.ref }
239238
(Perspective.absoluteRootPerspective bd.oldBranch.hash)
240239

241240
( definitionSummaryTooltip, tCmd ) =
@@ -255,7 +254,7 @@ update appContext projectRef contribRef msg model =
255254
config =
256255
AppContext.toCodeConfig
257256
appContext
258-
(CodeBrowsingContext.ProjectBranch projectRef bd.newBranch.ref)
257+
{ projectRef = projectRef, branchRef = bd.newBranch.ref }
259258
(Perspective.absoluteRootPerspective bd.newBranch.hash)
260259

261260
( definitionSummaryTooltip, tCmd ) =

src/UnisonShare/Page/ProjectOverviewPage.elm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import UI.Tag as Tag
4646
import UI.Tooltip as Tooltip
4747
import UnisonShare.Api as ShareApi
4848
import UnisonShare.AppContext as AppContext exposing (AppContext)
49-
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext exposing (CodeBrowsingContext(..))
5049
import UnisonShare.Link as Link
5150
import UnisonShare.PageFooter as PageFooter
5251
import UnisonShare.Project as Project exposing (ProjectDetails)
@@ -171,12 +170,12 @@ update appContext projectRef project msg model =
171170
case project of
172171
Success p ->
173172
AppContext.toCodeConfig appContext
174-
(CodeBrowsingContext.project projectRef (Project.defaultBrowsingBranch p))
173+
{ projectRef = projectRef, branchRef = Project.defaultBrowsingBranch p }
175174
Perspective.relativeRootPerspective
176175

177176
_ ->
178177
AppContext.toCodeConfig appContext
179-
(CodeBrowsingContext.project projectRef BranchRef.main_)
178+
{ projectRef = projectRef, branchRef = BranchRef.main_ }
180179
Perspective.relativeRootPerspective
181180
in
182181
case msg of
@@ -458,7 +457,7 @@ fetchDependencies : AppContext -> ProjectRef -> BranchRef -> Cmd Msg
458457
fetchDependencies appContext projectRef branchRef =
459458
let
460459
browsingContext =
461-
ProjectBranch projectRef branchRef
460+
{ projectRef = projectRef, branchRef = branchRef }
462461

463462
perspective =
464463
Perspective.relativeRootPerspective

src/UnisonShare/Page/ProjectPage.elm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import UnisonShare.Api as ShareApi
3333
import UnisonShare.AppContext exposing (AppContext)
3434
import UnisonShare.AppDocument exposing (AppDocument)
3535
import UnisonShare.AppHeader as AppHeader
36-
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
3736
import UnisonShare.Contribution.ContributionRef as ContributionRef exposing (ContributionRef)
3837
import UnisonShare.Contribution.ContributionStatus as ContributionStatus
3938
import UnisonShare.Page.CodePage as CodePage
@@ -116,7 +115,7 @@ init appContext projectRef route =
116115
ProjectBranch branchRef codeRoute ->
117116
let
118117
codeBrowsingContext =
119-
CodeBrowsingContext.project projectRef branchRef
118+
{ projectRef = projectRef, branchRef = branchRef }
120119

121120
( codePage, codePageCmd ) =
122121
CodePage.init appContext codeBrowsingContext codeRoute
@@ -233,8 +232,8 @@ type Msg
233232
update : AppContext -> ProjectRef -> ProjectRoute -> Msg -> Model -> ( Model, Cmd Msg )
234233
update appContext projectRef route msg model =
235234
let
236-
codeBrowsingContext bs =
237-
CodeBrowsingContext.project projectRef bs
235+
codeBrowsingContext br =
236+
{ projectRef = projectRef, branchRef = br }
238237
in
239238
case ( model.subPage, msg ) of
240239
( _, ChangeRouteTo r ) ->
@@ -746,7 +745,7 @@ updateSubPage : AppContext -> ProjectRef -> Model -> ProjectRoute -> ( Model, Cm
746745
updateSubPage appContext projectRef model route =
747746
let
748747
codeBrowsingContext br =
749-
CodeBrowsingContext.project projectRef br
748+
{ projectRef = projectRef, branchRef = br }
750749

751750
newCodePage branchRef codeRoute =
752751
let

src/UnisonShare/Page/ProjectReleasePage.elm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import UI.Placeholder as Placeholder
2828
import UI.StatusBanner as StatusBanner
2929
import UnisonShare.Api as ShareApi
3030
import UnisonShare.AppContext as AppContext exposing (AppContext)
31-
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
3231
import UnisonShare.InteractiveDoc as InteractiveDoc
3332
import UnisonShare.Link as Link
3433
import UnisonShare.PageFooter as PageFooter
@@ -124,7 +123,7 @@ update appContext projectRef msg model =
124123
config =
125124
AppContext.toCodeConfig
126125
appContext
127-
(CodeBrowsingContext.project projectRef (Release.branchRef release))
126+
{ projectRef = projectRef, branchRef = Release.branchRef release }
128127
Perspective.relativeRootPerspective
129128

130129
( interactiveDoc, cmd, iOutMsg ) =

src/UnisonShare/Page/ProjectReleasesPage.elm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import UI.Tag as Tag
3838
import UnisonShare.Api as ShareApi
3939
import UnisonShare.AppContext as AppContext exposing (AppContext)
4040
import UnisonShare.BranchSummary as BranchSummary exposing (BranchSummary)
41-
import UnisonShare.CodeBrowsingContext as CodeBrowsingContext
4241
import UnisonShare.InteractiveDoc as InteractiveDoc
4342
import UnisonShare.Link as Link
4443
import UnisonShare.PageFooter as PageFooter
@@ -275,7 +274,7 @@ update appContext projectRef msg model =
275274
config =
276275
AppContext.toCodeConfig
277276
appContext
278-
(CodeBrowsingContext.project projectRef (Release.branchRef latest))
277+
{ projectRef = projectRef, branchRef = Release.branchRef latest }
279278
Perspective.relativeRootPerspective
280279

281280
( interactiveDoc, cmd, iOutMsg ) =

0 commit comments

Comments
 (0)