Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.

Move route specific keyboardshortcuts to pages #297

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/UnisonLocal/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -384,25 +384,12 @@ keydown model keyboardEvent =
( { model | sidebarToggled = not model.sidebarToggled }, Cmd.none )
in
case shortcut of
KeyboardShortcut.Chord Ctrl (K _) ->
showFinder model Nothing

KeyboardShortcut.Chord Meta (K _) ->
if model.env.operatingSystem == Env.MacOS then
showFinder model Nothing

else
noOp

KeyboardShortcut.Chord Ctrl (B _) ->
toggleSidebar

KeyboardShortcut.Chord Meta (B _) ->
toggleSidebar

KeyboardShortcut.Sequence _ ForwardSlash ->
showFinder model Nothing

KeyboardShortcut.Chord Shift QuestionMark ->
( { model | modal = HelpModal }, Cmd.none )

Expand Down
71 changes: 34 additions & 37 deletions src/UnisonShare/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ type Msg

update : Msg -> Model -> ( Model, Cmd Msg )
update msg ({ env } as model) =
case msg of
LinkClicked urlRequest ->
case ( model.route, msg ) of
( _, LinkClicked urlRequest ) ->
case urlRequest of
Browser.Internal url ->
( model, Nav.pushUrl model.navKey (Url.toString url) )
Expand All @@ -137,7 +137,7 @@ update msg ({ env } as model) =
Browser.External _ ->
( model, Cmd.none )

UrlChanged url ->
( _, UrlChanged url ) ->
let
route =
Route.fromUrl env.basePath url
Expand Down Expand Up @@ -172,10 +172,10 @@ update msg ({ env } as model) =
Route.Perspective params ->
fetchPerspectiveAndCodebaseTree env.perspective { model2 | env = newEnv params }

ChangePerspective perspective ->
( _, ChangePerspective perspective ) ->
navigateToPerspective model perspective

FetchPerspectiveNamespaceDetailsFinished fqn details ->
( _, FetchPerspectiveNamespaceDetailsFinished fqn details ) ->
let
perspective =
case env.perspective of
Expand All @@ -194,24 +194,24 @@ update msg ({ env } as model) =
in
( { model | env = nextEnv }, Cmd.none )

Keydown event ->
( _, Keydown event ) ->
keydown model event

OpenDefinition ref ->
( _, OpenDefinition ref ) ->
navigateToDefinition model ref

ShowModal modal ->
( _, ShowModal modal ) ->
let
( appModal, cmd ) =
AppModal.show modal
in
( { model | appModal = appModal }, Cmd.map AppModalMsg cmd )

ToggleSidebar ->
( _, ToggleSidebar ) ->
( { model | sidebarToggled = not model.sidebarToggled }, Cmd.none )

-- Sub msgs
AppModalMsg amMsg ->
( _, AppModalMsg amMsg ) ->
let
( am, amCmd, out ) =
AppModal.update env amMsg model.appModal
Expand All @@ -226,27 +226,34 @@ update msg ({ env } as model) =
in
( newModel, Cmd.batch [ Cmd.map AppModalMsg amCmd, cmd ] )

CatalogMsg cMsg ->
( Route.Catalog, CatalogMsg cMsg ) ->
let
( catalog, cmd ) =
Catalog.update cMsg model.catalog
in
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )

WorkspaceMsg wMsg ->
let
( workspace, wCmd, outMsg ) =
Workspace.update env wMsg model.workspace
( _, WorkspaceMsg wMsg ) ->
-- TODO: Clean this up, there should be a top level Project route
-- instead of 2 separate workspace routes (perspective and
-- definition)
if model.route /= Route.Catalog then
let
( workspace, wCmd, outMsg ) =
Workspace.update env wMsg model.workspace

model2 =
{ model | workspace = workspace }
model2 =
{ model | workspace = workspace }

( model3, cmd ) =
handleWorkspaceOutMsg model2 outMsg
in
( model3, Cmd.batch [ cmd, Cmd.map WorkspaceMsg wCmd ] )
( model3, cmd ) =
handleWorkspaceOutMsg model2 outMsg
in
( model3, Cmd.batch [ cmd, Cmd.map WorkspaceMsg wCmd ] )

else
( model, Cmd.none )

PerspectiveLandingMsg rMsg ->
( _, PerspectiveLandingMsg rMsg ) ->
let
( perspectiveLanding, outMsg ) =
PerspectiveLanding.update rMsg model.perspectiveLanding
Expand All @@ -264,7 +271,7 @@ update msg ({ env } as model) =
PerspectiveLanding.None ->
( model2, Cmd.none )

CodebaseTreeMsg cMsg ->
( _, CodebaseTreeMsg cMsg ) ->
let
( codebaseTree, cCmd, outMsg ) =
CodebaseTree.update env cMsg model.codebaseTree
Expand Down Expand Up @@ -292,13 +299,16 @@ update msg ({ env } as model) =
in
( model3, Cmd.batch [ cmd, Cmd.map CodebaseTreeMsg cCmd ] )

KeyboardShortcutMsg kMsg ->
( _, KeyboardShortcutMsg kMsg ) ->
let
( keyboardShortcut, cmd ) =
KeyboardShortcut.update kMsg model.keyboardShortcut
in
( { model | keyboardShortcut = keyboardShortcut }, Cmd.map KeyboardShortcutMsg cmd )

_ ->
( model, Cmd.none )



-- UPDATE HELPERS
Expand Down Expand Up @@ -392,25 +402,12 @@ keydown model keyboardEvent =
( { model | sidebarToggled = not model.sidebarToggled }, Cmd.none )
in
case shortcut of
KeyboardShortcut.Chord Ctrl (K _) ->
showFinder model Nothing

KeyboardShortcut.Chord Meta (K _) ->
if model.env.operatingSystem == Env.MacOS then
showFinder model Nothing

else
noOp

KeyboardShortcut.Chord Ctrl (B _) ->
toggleSidebar

KeyboardShortcut.Chord Meta (B _) ->
toggleSidebar

KeyboardShortcut.Sequence _ ForwardSlash ->
showFinder model Nothing

KeyboardShortcut.Chord Shift QuestionMark ->
let
( am, amCmd ) =
Expand Down
19 changes: 16 additions & 3 deletions src/Workspace.elm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ update env msg ({ workspaceItems } as model) =
KeyboardShortcut.fromKeyboardEvent model.keyboardShortcut event

( nextModel, cmd, out ) =
handleKeyboardShortcut { model | keyboardShortcut = keyboardShortcut } shortcut
handleKeyboardShortcut env { model | keyboardShortcut = keyboardShortcut } shortcut
in
( nextModel, Cmd.batch [ cmd, Cmd.map KeyboardShortcutMsg kCmd ], out )

Expand Down Expand Up @@ -313,8 +313,8 @@ openDefinitionsFocusToOutMsg openDefs =
|> Maybe.withDefault Emptied


handleKeyboardShortcut : Model -> KeyboardShortcut -> ( Model, Cmd Msg, OutMsg )
handleKeyboardShortcut ({ workspaceItems } as model) shortcut =
handleKeyboardShortcut : Env -> Model -> KeyboardShortcut -> ( Model, Cmd Msg, OutMsg )
handleKeyboardShortcut env ({ workspaceItems } as model) shortcut =
let
scrollToCmd =
WorkspaceItems.focus
Expand Down Expand Up @@ -351,6 +351,19 @@ handleKeyboardShortcut ({ workspaceItems } as model) shortcut =
( { model | workspaceItems = next }, scrollToCmd next, openDefinitionsFocusToOutMsg next )
in
case shortcut of
KeyboardShortcut.Chord Ctrl (K _) ->
( model, Cmd.none, ShowFinderRequest Nothing )

KeyboardShortcut.Chord Meta (K _) ->
if env.operatingSystem == Env.MacOS then
( model, Cmd.none, ShowFinderRequest Nothing )

else
( model, Cmd.none, None )

Sequence _ ForwardSlash ->
( model, Cmd.none, ShowFinderRequest Nothing )

Chord Alt ArrowDown ->
moveDown

Expand Down