1
0
Fork 0

Handle posting draft with ctrl + enter.

This commit is contained in:
Nicolas Perriault 2017-07-17 15:34:42 +02:00
parent 885e0194c5
commit 575f6086cf
No known key found for this signature in database
GPG Key ID: DA5E4C83904F7A2A
5 changed files with 28 additions and 8 deletions

View File

@ -37,6 +37,7 @@ init { registration, clients } location =
, notificationFilter = NotificationAll
, confirm = Nothing
, search = Search "" Nothing
, ctrlPressed = False
}
in
model

View File

@ -47,7 +47,10 @@ subscriptions { clients, currentView } =
Ports.uploadError (DraftEvent << UploadError)
keyDownsSub =
Keyboard.downs KeyMsg
Keyboard.downs (KeyMsg KeyDown)
keyUpsSub =
Keyboard.ups (KeyMsg KeyUp)
in
Sub.batch
[ timeSub

View File

@ -90,6 +90,11 @@ type WebSocketMsg
| NewWebsocketUserMessage String
type KeyEvent
= KeyUp
| KeyDown
type Msg
= AddFavorite Status
| AskConfirm String Msg Msg
@ -102,7 +107,7 @@ type Msg
| DraftEvent DraftMsg
| FilterNotifications NotificationFilter
| FollowAccount Account
| KeyMsg Keyboard.KeyCode
| KeyMsg KeyEvent Keyboard.KeyCode
| LogoutClient Client
| TimelineLoadNext String String
| MastodonEvent MastodonMsg
@ -255,6 +260,7 @@ type alias Model =
, notificationFilter : NotificationFilter
, confirm : Maybe Confirm
, search : Search
, ctrlPressed : Bool
}

View File

@ -55,20 +55,28 @@ update msg model =
}
! []
KeyMsg code ->
case ( code, model.viewer ) of
( 27, Just _ ) ->
KeyMsg event code ->
case ( event, code, model.viewer ) of
( KeyDown, 27, Just _ ) ->
-- Esc
update (ViewerEvent CloseViewer) model
( 37, Just _ ) ->
( KeyDown, 37, Just _ ) ->
-- Left arrow
update (ViewerEvent PrevAttachment) model
( 39, Just _ ) ->
( KeyDown, 39, Just _ ) ->
-- Right arrow
update (ViewerEvent NextAttachment) model
( KeyDown, 17, _ ) ->
-- Ctrl key down
{ model | ctrlPressed = True } ! []
( KeyUp, 17, _ ) ->
-- Ctrl key up
{ model | ctrlPressed = False } ! []
_ ->
model ! []

View File

@ -139,7 +139,7 @@ visibilitySelector { visibility } =
draftView : Model -> Html Msg
draftView ({ draft, currentUser } as model) =
draftView ({ draft, currentUser, ctrlPressed } as model) =
let
autoMenu =
if draft.showAutoMenu then
@ -197,6 +197,8 @@ draftView ({ draft, currentUser } as model) =
Ok NoOp
else if code == 27 then
Ok <| DraftEvent CloseAutocomplete
else if code == 13 && ctrlPressed then
Ok SubmitDraft
else
Err "not handling that key"
)