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

Commit b3950d4

Browse files
authored
Merge pull request #297 from unisonweb/route-keyboard-shortcuts
Move route specific keyboardshortcuts to pages
2 parents 82b8e96 + 92d7ad6 commit b3950d4

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

src/UnisonLocal/App.elm

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,25 +384,12 @@ keydown model keyboardEvent =
384384
( { model | sidebarToggled = not model.sidebarToggled }, Cmd.none )
385385
in
386386
case shortcut of
387-
KeyboardShortcut.Chord Ctrl (K _) ->
388-
showFinder model Nothing
389-
390-
KeyboardShortcut.Chord Meta (K _) ->
391-
if model.env.operatingSystem == Env.MacOS then
392-
showFinder model Nothing
393-
394-
else
395-
noOp
396-
397387
KeyboardShortcut.Chord Ctrl (B _) ->
398388
toggleSidebar
399389

400390
KeyboardShortcut.Chord Meta (B _) ->
401391
toggleSidebar
402392

403-
KeyboardShortcut.Sequence _ ForwardSlash ->
404-
showFinder model Nothing
405-
406393
KeyboardShortcut.Chord Shift QuestionMark ->
407394
( { model | modal = HelpModal }, Cmd.none )
408395

src/UnisonShare/App.elm

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ type Msg
126126

127127
update : Msg -> Model -> ( Model, Cmd Msg )
128128
update msg ({ env } as model) =
129-
case msg of
130-
LinkClicked urlRequest ->
129+
case ( model.route, msg ) of
130+
( _, LinkClicked urlRequest ) ->
131131
case urlRequest of
132132
Browser.Internal url ->
133133
( model, Nav.pushUrl model.navKey (Url.toString url) )
@@ -137,7 +137,7 @@ update msg ({ env } as model) =
137137
Browser.External _ ->
138138
( model, Cmd.none )
139139

140-
UrlChanged url ->
140+
( _, UrlChanged url ) ->
141141
let
142142
route =
143143
Route.fromUrl env.basePath url
@@ -172,10 +172,10 @@ update msg ({ env } as model) =
172172
Route.Perspective params ->
173173
fetchPerspectiveAndCodebaseTree env.perspective { model2 | env = newEnv params }
174174

175-
ChangePerspective perspective ->
175+
( _, ChangePerspective perspective ) ->
176176
navigateToPerspective model perspective
177177

178-
FetchPerspectiveNamespaceDetailsFinished fqn details ->
178+
( _, FetchPerspectiveNamespaceDetailsFinished fqn details ) ->
179179
let
180180
perspective =
181181
case env.perspective of
@@ -194,24 +194,24 @@ update msg ({ env } as model) =
194194
in
195195
( { model | env = nextEnv }, Cmd.none )
196196

197-
Keydown event ->
197+
( _, Keydown event ) ->
198198
keydown model event
199199

200-
OpenDefinition ref ->
200+
( _, OpenDefinition ref ) ->
201201
navigateToDefinition model ref
202202

203-
ShowModal modal ->
203+
( _, ShowModal modal ) ->
204204
let
205205
( appModal, cmd ) =
206206
AppModal.show modal
207207
in
208208
( { model | appModal = appModal }, Cmd.map AppModalMsg cmd )
209209

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

213213
-- Sub msgs
214-
AppModalMsg amMsg ->
214+
( _, AppModalMsg amMsg ) ->
215215
let
216216
( am, amCmd, out ) =
217217
AppModal.update env amMsg model.appModal
@@ -226,27 +226,34 @@ update msg ({ env } as model) =
226226
in
227227
( newModel, Cmd.batch [ Cmd.map AppModalMsg amCmd, cmd ] )
228228

229-
CatalogMsg cMsg ->
229+
( Route.Catalog, CatalogMsg cMsg ) ->
230230
let
231231
( catalog, cmd ) =
232232
Catalog.update cMsg model.catalog
233233
in
234234
( { model | catalog = catalog }, Cmd.map CatalogMsg cmd )
235235

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

241-
model2 =
242-
{ model | workspace = workspace }
245+
model2 =
246+
{ model | workspace = workspace }
243247

244-
( model3, cmd ) =
245-
handleWorkspaceOutMsg model2 outMsg
246-
in
247-
( model3, Cmd.batch [ cmd, Cmd.map WorkspaceMsg wCmd ] )
248+
( model3, cmd ) =
249+
handleWorkspaceOutMsg model2 outMsg
250+
in
251+
( model3, Cmd.batch [ cmd, Cmd.map WorkspaceMsg wCmd ] )
252+
253+
else
254+
( model, Cmd.none )
248255

249-
PerspectiveLandingMsg rMsg ->
256+
( _, PerspectiveLandingMsg rMsg ) ->
250257
let
251258
( perspectiveLanding, outMsg ) =
252259
PerspectiveLanding.update rMsg model.perspectiveLanding
@@ -264,7 +271,7 @@ update msg ({ env } as model) =
264271
PerspectiveLanding.None ->
265272
( model2, Cmd.none )
266273

267-
CodebaseTreeMsg cMsg ->
274+
( _, CodebaseTreeMsg cMsg ) ->
268275
let
269276
( codebaseTree, cCmd, outMsg ) =
270277
CodebaseTree.update env cMsg model.codebaseTree
@@ -292,13 +299,16 @@ update msg ({ env } as model) =
292299
in
293300
( model3, Cmd.batch [ cmd, Cmd.map CodebaseTreeMsg cCmd ] )
294301

295-
KeyboardShortcutMsg kMsg ->
302+
( _, KeyboardShortcutMsg kMsg ) ->
296303
let
297304
( keyboardShortcut, cmd ) =
298305
KeyboardShortcut.update kMsg model.keyboardShortcut
299306
in
300307
( { model | keyboardShortcut = keyboardShortcut }, Cmd.map KeyboardShortcutMsg cmd )
301308

309+
_ ->
310+
( model, Cmd.none )
311+
302312

303313

304314
-- UPDATE HELPERS
@@ -392,25 +402,12 @@ keydown model keyboardEvent =
392402
( { model | sidebarToggled = not model.sidebarToggled }, Cmd.none )
393403
in
394404
case shortcut of
395-
KeyboardShortcut.Chord Ctrl (K _) ->
396-
showFinder model Nothing
397-
398-
KeyboardShortcut.Chord Meta (K _) ->
399-
if model.env.operatingSystem == Env.MacOS then
400-
showFinder model Nothing
401-
402-
else
403-
noOp
404-
405405
KeyboardShortcut.Chord Ctrl (B _) ->
406406
toggleSidebar
407407

408408
KeyboardShortcut.Chord Meta (B _) ->
409409
toggleSidebar
410410

411-
KeyboardShortcut.Sequence _ ForwardSlash ->
412-
showFinder model Nothing
413-
414411
KeyboardShortcut.Chord Shift QuestionMark ->
415412
let
416413
( am, amCmd ) =

src/Workspace.elm

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ update env msg ({ workspaceItems } as model) =
175175
KeyboardShortcut.fromKeyboardEvent model.keyboardShortcut event
176176

177177
( nextModel, cmd, out ) =
178-
handleKeyboardShortcut { model | keyboardShortcut = keyboardShortcut } shortcut
178+
handleKeyboardShortcut env { model | keyboardShortcut = keyboardShortcut } shortcut
179179
in
180180
( nextModel, Cmd.batch [ cmd, Cmd.map KeyboardShortcutMsg kCmd ], out )
181181

@@ -313,8 +313,8 @@ openDefinitionsFocusToOutMsg openDefs =
313313
|> Maybe.withDefault Emptied
314314

315315

316-
handleKeyboardShortcut : Model -> KeyboardShortcut -> ( Model, Cmd Msg, OutMsg )
317-
handleKeyboardShortcut ({ workspaceItems } as model) shortcut =
316+
handleKeyboardShortcut : Env -> Model -> KeyboardShortcut -> ( Model, Cmd Msg, OutMsg )
317+
handleKeyboardShortcut env ({ workspaceItems } as model) shortcut =
318318
let
319319
scrollToCmd =
320320
WorkspaceItems.focus
@@ -351,6 +351,19 @@ handleKeyboardShortcut ({ workspaceItems } as model) shortcut =
351351
( { model | workspaceItems = next }, scrollToCmd next, openDefinitionsFocusToOutMsg next )
352352
in
353353
case shortcut of
354+
KeyboardShortcut.Chord Ctrl (K _) ->
355+
( model, Cmd.none, ShowFinderRequest Nothing )
356+
357+
KeyboardShortcut.Chord Meta (K _) ->
358+
if env.operatingSystem == Env.MacOS then
359+
( model, Cmd.none, ShowFinderRequest Nothing )
360+
361+
else
362+
( model, Cmd.none, None )
363+
364+
Sequence _ ForwardSlash ->
365+
( model, Cmd.none, ShowFinderRequest Nothing )
366+
354367
Chord Alt ArrowDown ->
355368
moveDown
356369

0 commit comments

Comments
 (0)