Handle posting draft with ctrl + enter.
This commit is contained in:
parent
885e0194c5
commit
575f6086cf
@ -37,6 +37,7 @@ init { registration, clients } location =
|
||||
, notificationFilter = NotificationAll
|
||||
, confirm = Nothing
|
||||
, search = Search "" Nothing
|
||||
, ctrlPressed = False
|
||||
}
|
||||
in
|
||||
model
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 ! []
|
||||
|
||||
|
@ -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"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user