{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RankNTypes #-}
module Matterhorn.State.Editing
( requestSpellCheck
, editingKeybindings
, editingKeyHandlers
, messageEditingKeybindings
, toggleMultilineEditing
, invokeExternalEditor
, handlePaste
, handleInputSubmission
, getEditorContent
, handleEditingInput
, cancelAutocompleteOrReplyOrEdit
, replyToLatestMessage
, Direction(..)
, tabComplete
)
where
import Prelude ()
import Matterhorn.Prelude
import Brick.Main ( invalidateCache, invalidateCacheEntry )
import Brick.Widgets.Edit ( Editor, applyEdit , handleEditorEvent
, getEditContents, editContentsL )
import qualified Brick.Widgets.List as L
import qualified Codec.Binary.UTF8.Generic as UTF8
import Control.Arrow
import qualified Control.Concurrent.STM as STM
import qualified Data.ByteString as BS
import Data.Char ( isSpace )
import qualified Data.Foldable as F
import qualified Data.Map as M
import Data.Maybe ( fromJust )
import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Zipper as Z
import qualified Data.Text.Zipper.Generic.Words as Z
import Data.Time ( getCurrentTime )
import Graphics.Vty ( Event(..), Key(..) )
import Lens.Micro.Platform ( Lens', (%=), (.=), (.~), to, _Just )
import qualified System.Environment as Sys
import qualified System.Exit as Sys
import qualified System.IO as Sys
import qualified System.IO.Temp as Sys
import qualified System.Process as Sys
import Text.Aspell ( AspellResponse(..), mistakeWord, askAspell )
import Network.Mattermost.Types ( Post(..), ChannelId, TeamId )
import Matterhorn.Config
import {-# SOURCE #-} Matterhorn.Command ( dispatchCommand )
import Matterhorn.InputHistory
import Matterhorn.Events.Keybindings
import Matterhorn.State.Common
import Matterhorn.State.Autocomplete
import Matterhorn.State.Attachments
import Matterhorn.State.Messages
import Matterhorn.Types hiding ( newState )
import Matterhorn.Types.Common ( sanitizeUserText' )
startMultilineEditing :: MH ()
startMultilineEditing :: MH ()
startMultilineEditing = do
EventM Name () -> MH ()
forall a. EventM Name a -> MH a
mh EventM Name ()
forall n. Ord n => EventM n ()
invalidateCache
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Bool -> Identity Bool) -> TeamState -> Identity TeamState)
-> (Bool -> Identity Bool)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Bool -> Identity Bool)
-> ChatEditState -> Identity ChatEditState)
-> (Bool -> Identity Bool)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState)
-> ((Bool -> Identity Bool)
-> EphemeralEditState -> Identity EphemeralEditState)
-> (Bool -> Identity Bool)
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Identity Bool)
-> EphemeralEditState -> Identity EphemeralEditState
Lens' EphemeralEditState Bool
eesMultiline ((Bool -> Identity Bool) -> ChatState -> Identity ChatState)
-> Bool -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
toggleMultilineEditing :: MH ()
toggleMultilineEditing :: MH ()
toggleMultilineEditing = do
EventM Name () -> MH ()
forall a. EventM Name a -> MH a
mh EventM Name ()
forall n. Ord n => EventM n ()
invalidateCache
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Bool -> Identity Bool) -> TeamState -> Identity TeamState)
-> (Bool -> Identity Bool)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Bool -> Identity Bool)
-> ChatEditState -> Identity ChatEditState)
-> (Bool -> Identity Bool)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState)
-> ((Bool -> Identity Bool)
-> EphemeralEditState -> Identity EphemeralEditState)
-> (Bool -> Identity Bool)
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Identity Bool)
-> EphemeralEditState -> Identity EphemeralEditState
Lens' EphemeralEditState Bool
eesMultiline ((Bool -> Identity Bool) -> ChatState -> Identity ChatState)
-> (Bool -> Bool) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Bool -> Bool
not
Bool
multiline <- Getting Bool ChatState Bool -> MH Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool) -> TeamState -> Const Bool TeamState)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState)
-> ((Bool -> Const Bool Bool)
-> ChatEditState -> Const Bool ChatEditState)
-> (Bool -> Const Bool Bool)
-> TeamState
-> Const Bool TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Const Bool EphemeralEditState)
-> ChatEditState -> Const Bool ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Const Bool EphemeralEditState)
-> ChatEditState -> Const Bool ChatEditState)
-> ((Bool -> Const Bool Bool)
-> EphemeralEditState -> Const Bool EphemeralEditState)
-> (Bool -> Const Bool Bool)
-> ChatEditState
-> Const Bool ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool)
-> EphemeralEditState -> Const Bool EphemeralEditState
Lens' EphemeralEditState Bool
eesMultiline)
Int
numLines <- Getting Int ChatState Int -> MH Int
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Int TeamState)
-> ChatState -> Const Int ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Int TeamState)
-> ChatState -> Const Int ChatState)
-> ((Int -> Const Int Int) -> TeamState -> Const Int TeamState)
-> Getting Int ChatState Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Int ChatEditState)
-> TeamState -> Const Int TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Int ChatEditState)
-> TeamState -> Const Int TeamState)
-> ((Int -> Const Int Int)
-> ChatEditState -> Const Int ChatEditState)
-> (Int -> Const Int Int)
-> TeamState
-> Const Int TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const Int (Editor Text Name))
-> ChatEditState -> Const Int ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor((Editor Text Name -> Const Int (Editor Text Name))
-> ChatEditState -> Const Int ChatEditState)
-> ((Int -> Const Int Int)
-> Editor Text Name -> Const Int (Editor Text Name))
-> (Int -> Const Int Int)
-> ChatEditState
-> Const Int ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> [Text])
-> SimpleGetter (Editor Text Name) [Text]
forall s a. (s -> a) -> SimpleGetter s a
to Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContentsGetting Int (Editor Text Name) [Text]
-> ((Int -> Const Int Int) -> [Text] -> Const Int [Text])
-> (Int -> Const Int Int)
-> Editor Text Name
-> Const Int (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.([Text] -> Int) -> SimpleGetter [Text] Int
forall s a. (s -> a) -> SimpleGetter s a
to [Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length)
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
multiline Bool -> Bool -> Bool
&& Int
numLines Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1) MH ()
resetAutocomplete
invokeExternalEditor :: MH ()
invokeExternalEditor :: MH ()
invokeExternalEditor = do
Maybe String
mEnv <- IO (Maybe String) -> MH (Maybe String)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe String) -> MH (Maybe String))
-> IO (Maybe String) -> MH (Maybe String)
forall a b. (a -> b) -> a -> b
$ String -> IO (Maybe String)
Sys.lookupEnv String
"EDITOR"
let editorProgram :: String
editorProgram = String -> (String -> String) -> Maybe String -> String
forall b a. b -> (a -> b) -> Maybe a -> b
maybe String
"vi" String -> String
forall a. a -> a
id Maybe String
mEnv
(ChatState -> IO ChatState) -> MH ()
mhSuspendAndResume ((ChatState -> IO ChatState) -> MH ())
-> (ChatState -> IO ChatState) -> MH ()
forall a b. (a -> b) -> a -> b
$ \ ChatState
st -> do
String -> (String -> Handle -> IO ChatState) -> IO ChatState
forall (m :: * -> *) a.
(MonadIO m, MonadMask m) =>
String -> (String -> Handle -> m a) -> m a
Sys.withSystemTempFile String
"matterhorn_editor.md" ((String -> Handle -> IO ChatState) -> IO ChatState)
-> (String -> Handle -> IO ChatState) -> IO ChatState
forall a b. (a -> b) -> a -> b
$ \String
tmpFileName Handle
tmpFileHandle -> do
Handle -> String -> IO ()
Sys.hPutStr Handle
tmpFileHandle (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"\n" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$
Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContents (Editor Text Name -> [Text]) -> Editor Text Name -> [Text]
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor
Handle -> IO ()
Sys.hClose Handle
tmpFileHandle
ExitCode
status <- String -> IO ExitCode
Sys.system (String
editorProgram String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
tmpFileName)
case ExitCode
status of
ExitCode
Sys.ExitSuccess -> do
ByteString
tmpBytes <- String -> IO ByteString
BS.readFile String
tmpFileName
case ByteString -> Either UnicodeException Text
T.decodeUtf8' ByteString
tmpBytes of
Left UnicodeException
_ -> do
Text -> ChatState -> IO ChatState
postErrorMessageIO Text
"Failed to decode file contents as UTF-8" ChatState
st
Right Text
t -> do
let tmpLines :: [Text]
tmpLines = Text -> [Text]
T.lines (Text -> [Text]) -> Text -> [Text]
forall a b. (a -> b) -> a -> b
$ Text -> Text
sanitizeUserText' Text
t
ChatState -> IO ChatState
forall (m :: * -> *) a. Monad m => a -> m a
return (ChatState -> IO ChatState) -> ChatState -> IO ChatState
forall a b. (a -> b) -> a -> b
$ ChatState
st ChatState -> (ChatState -> ChatState) -> ChatState
forall a b. a -> (a -> b) -> b
& (TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((TextZipper Text -> Identity (TextZipper Text))
-> TeamState -> Identity TeamState)
-> (TextZipper Text -> Identity (TextZipper Text))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((TextZipper Text -> Identity (TextZipper Text))
-> ChatEditState -> Identity ChatEditState)
-> (TextZipper Text -> Identity (TextZipper Text))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> ((TextZipper Text -> Identity (TextZipper Text))
-> Editor Text Name -> Identity (Editor Text Name))
-> (TextZipper Text -> Identity (TextZipper Text))
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(TextZipper Text -> Identity (TextZipper Text))
-> Editor Text Name -> Identity (Editor Text Name)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL ((TextZipper Text -> Identity (TextZipper Text))
-> ChatState -> Identity ChatState)
-> TextZipper Text -> ChatState -> ChatState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ([Text] -> Maybe Int -> TextZipper Text
Z.textZipper [Text]
tmpLines Maybe Int
forall a. Maybe a
Nothing)
Sys.ExitFailure Int
_ -> ChatState -> IO ChatState
forall (m :: * -> *) a. Monad m => a -> m a
return ChatState
st
handlePaste :: BS.ByteString -> MH ()
handlePaste :: ByteString -> MH ()
handlePaste ByteString
bytes = do
let pasteStr :: Text
pasteStr = String -> Text
T.pack (ByteString -> String
forall b s. UTF8Bytes b s => b -> String
UTF8.toString ByteString
bytes)
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Text -> TextZipper Text -> TextZipper Text
forall a. Monoid a => a -> TextZipper a -> TextZipper a
Z.insertMany (Text -> Text
sanitizeUserText' Text
pasteStr))
[Text]
contents <- Getting [Text] ChatState [Text] -> MH [Text]
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const [Text] TeamState)
-> ChatState -> Const [Text] ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const [Text] TeamState)
-> ChatState -> Const [Text] ChatState)
-> (([Text] -> Const [Text] [Text])
-> TeamState -> Const [Text] TeamState)
-> Getting [Text] ChatState [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const [Text] ChatEditState)
-> TeamState -> Const [Text] TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const [Text] ChatEditState)
-> TeamState -> Const [Text] TeamState)
-> (([Text] -> Const [Text] [Text])
-> ChatEditState -> Const [Text] ChatEditState)
-> ([Text] -> Const [Text] [Text])
-> TeamState
-> Const [Text] TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const [Text] (Editor Text Name))
-> ChatEditState -> Const [Text] ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor((Editor Text Name -> Const [Text] (Editor Text Name))
-> ChatEditState -> Const [Text] ChatEditState)
-> (([Text] -> Const [Text] [Text])
-> Editor Text Name -> Const [Text] (Editor Text Name))
-> ([Text] -> Const [Text] [Text])
-> ChatEditState
-> Const [Text] ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> [Text])
-> SimpleGetter (Editor Text Name) [Text]
forall s a. (s -> a) -> SimpleGetter s a
to Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContents)
case [Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
contents Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 of
Bool
True -> MH ()
startMultilineEditing
Bool
False -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
editingPermitted :: ChatState -> Bool
editingPermitted :: ChatState -> Bool
editingPermitted ChatState
st =
([Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContents (Editor Text Name -> [Text]) -> Editor Text Name -> [Text]
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1) Bool -> Bool -> Bool
||
ChatState
stChatState -> Getting Bool ChatState Bool -> Bool
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool) -> TeamState -> Const Bool TeamState)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState)
-> ((Bool -> Const Bool Bool)
-> ChatEditState -> Const Bool ChatEditState)
-> (Bool -> Const Bool Bool)
-> TeamState
-> Const Bool TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Const Bool EphemeralEditState)
-> ChatEditState -> Const Bool ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Const Bool EphemeralEditState)
-> ChatEditState -> Const Bool ChatEditState)
-> ((Bool -> Const Bool Bool)
-> EphemeralEditState -> Const Bool EphemeralEditState)
-> (Bool -> Const Bool Bool)
-> ChatEditState
-> Const Bool ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool)
-> EphemeralEditState -> Const Bool EphemeralEditState
Lens' EphemeralEditState Bool
eesMultiline
messageEditingKeybindings :: KeyConfig -> KeyHandlerMap
messageEditingKeybindings :: KeyConfig -> KeyHandlerMap
messageEditingKeybindings KeyConfig
kc =
let KeyHandlerMap Map Event KeyHandler
m = Lens' ChatState (Editor Text Name) -> KeyConfig -> KeyHandlerMap
editingKeybindings ((TeamState -> f TeamState) -> ChatState -> f ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> f TeamState) -> ChatState -> f ChatState)
-> ((Editor Text Name -> f (Editor Text Name))
-> TeamState -> f TeamState)
-> (Editor Text Name -> f (Editor Text Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> f ChatEditState) -> TeamState -> f TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> f ChatEditState) -> TeamState -> f TeamState)
-> ((Editor Text Name -> f (Editor Text Name))
-> ChatEditState -> f ChatEditState)
-> (Editor Text Name -> f (Editor Text Name))
-> TeamState
-> f TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> f (Editor Text Name))
-> ChatEditState -> f ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) KeyConfig
kc
in Map Event KeyHandler -> KeyHandlerMap
KeyHandlerMap (Map Event KeyHandler -> KeyHandlerMap)
-> Map Event KeyHandler -> KeyHandlerMap
forall a b. (a -> b) -> a -> b
$ (KeyHandler -> KeyHandler)
-> Map Event KeyHandler -> Map Event KeyHandler
forall a b k. (a -> b) -> Map k a -> Map k b
M.map KeyHandler -> KeyHandler
withUserTypingAction Map Event KeyHandler
m
withUserTypingAction :: KeyHandler -> KeyHandler
withUserTypingAction :: KeyHandler -> KeyHandler
withUserTypingAction KeyHandler
kh =
KeyHandler
kh { khHandler :: KeyEventHandler
khHandler = KeyEventHandler
newH }
where
oldH :: KeyEventHandler
oldH = KeyHandler -> KeyEventHandler
khHandler KeyHandler
kh
newH :: KeyEventHandler
newH = KeyEventHandler
oldH { kehHandler :: EventHandler
kehHandler = EventHandler
newKEH }
oldKEH :: EventHandler
oldKEH = KeyEventHandler -> EventHandler
kehHandler KeyEventHandler
oldH
newKEH :: EventHandler
newKEH = EventHandler
oldKEH { ehAction :: MH ()
ehAction = EventHandler -> MH ()
ehAction EventHandler
oldKEH MH () -> MH () -> MH ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> MH ()
sendUserTypingAction }
editingKeybindings :: Lens' ChatState (Editor T.Text Name) -> KeyConfig -> KeyHandlerMap
editingKeybindings :: Lens' ChatState (Editor Text Name) -> KeyConfig -> KeyHandlerMap
editingKeybindings Lens' ChatState (Editor Text Name)
editor = [KeyEventHandler] -> KeyConfig -> KeyHandlerMap
mkKeybindings ([KeyEventHandler] -> KeyConfig -> KeyHandlerMap)
-> [KeyEventHandler] -> KeyConfig -> KeyHandlerMap
forall a b. (a -> b) -> a -> b
$ Lens' ChatState (Editor Text Name) -> [KeyEventHandler]
editingKeyHandlers Lens' ChatState (Editor Text Name)
editor
editingKeyHandlers :: Lens' ChatState (Editor T.Text Name) -> [KeyEventHandler]
editingKeyHandlers :: Lens' ChatState (Editor Text Name) -> [KeyEventHandler]
editingKeyHandlers Lens' ChatState (Editor Text Name)
editor =
[ KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorTransposeCharsEvent
Text
"Transpose the final two characters"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.transposeChars)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorBolEvent
Text
"Go to the start of the current line"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.gotoBOL)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorEolEvent
Text
"Go to the end of the current line"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.gotoEOL)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorDeleteCharacter
Text
"Delete the character at the cursor"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.deleteChar)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorKillToBolEvent
Text
"Delete from the cursor to the start of the current line"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.killToBOL)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorKillToEolEvent
Text
"Kill the line to the right of the current position and copy it" (MH () -> KeyEventHandler) -> MH () -> KeyEventHandler
forall a b. (a -> b) -> a -> b
$ do
TextZipper Text
z <- Getting (TextZipper Text) ChatState (TextZipper Text)
-> MH (TextZipper Text)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> ChatState -> Const (TextZipper Text) ChatState
Lens' ChatState (Editor Text Name)
editor((Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> ChatState -> Const (TextZipper Text) ChatState)
-> ((TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> Getting (TextZipper Text) ChatState (TextZipper Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Editor Text Name -> Const (TextZipper Text) (Editor Text Name)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL)
let restOfLine :: Text
restOfLine = TextZipper Text -> Text
forall a. Monoid a => TextZipper a -> a
Z.currentLine (TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.killToBOL TextZipper Text
z)
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Text -> Identity Text) -> TeamState -> Identity TeamState)
-> (Text -> Identity Text)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Text -> Identity Text)
-> ChatEditState -> Identity ChatEditState)
-> (Text -> Identity Text)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Text -> Identity Text) -> ChatEditState -> Identity ChatEditState
Lens' ChatEditState Text
cedYankBuffer ((Text -> Identity Text) -> ChatState -> Identity ChatState)
-> Text -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Text
restOfLine
(Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.killToEOL
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorNextCharEvent
Text
"Move one character to the right"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveRight)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorPrevCharEvent
Text
"Move one character to the left"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveLeft)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorNextWordEvent
Text
"Move one word to the right"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. GenericTextZipper a => TextZipper a -> TextZipper a
Z.moveWordRight)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorPrevWordEvent
Text
"Move one word to the left"
((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. GenericTextZipper a => TextZipper a -> TextZipper a
Z.moveWordLeft)
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorDeletePrevWordEvent
Text
"Delete the word to the left of the cursor" (MH () -> KeyEventHandler) -> MH () -> KeyEventHandler
forall a b. (a -> b) -> a -> b
$ do
(Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a.
(Eq a, GenericTextZipper a) =>
TextZipper a -> TextZipper a
Z.deletePrevWord
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorDeleteNextWordEvent
Text
"Delete the word to the right of the cursor" (MH () -> KeyEventHandler) -> MH () -> KeyEventHandler
forall a b. (a -> b) -> a -> b
$ do
(Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. GenericTextZipper a => TextZipper a -> TextZipper a
Z.deleteWord
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorHomeEvent
Text
"Move the cursor to the beginning of the input" (MH () -> KeyEventHandler) -> MH () -> KeyEventHandler
forall a b. (a -> b) -> a -> b
$ do
(Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
gotoHome
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorEndEvent
Text
"Move the cursor to the end of the input" (MH () -> KeyEventHandler) -> MH () -> KeyEventHandler
forall a b. (a -> b) -> a -> b
$ do
(Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
gotoEnd
, KeyEvent -> Text -> MH () -> KeyEventHandler
mkKb KeyEvent
EditorYankEvent
Text
"Paste the current buffer contents at the cursor" (MH () -> KeyEventHandler) -> MH () -> KeyEventHandler
forall a b. (a -> b) -> a -> b
$ do
Text
buf <- Getting Text ChatState Text -> MH Text
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Text TeamState)
-> ChatState -> Const Text ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Text TeamState)
-> ChatState -> Const Text ChatState)
-> ((Text -> Const Text Text) -> TeamState -> Const Text TeamState)
-> Getting Text ChatState Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Text ChatEditState)
-> TeamState -> Const Text TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Text ChatEditState)
-> TeamState -> Const Text TeamState)
-> ((Text -> Const Text Text)
-> ChatEditState -> Const Text ChatEditState)
-> (Text -> Const Text Text)
-> TeamState
-> Const Text TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Text -> Const Text Text)
-> ChatEditState -> Const Text ChatEditState
Lens' ChatEditState Text
cedYankBuffer)
(Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState
Lens' ChatState (Editor Text Name)
editor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Text -> TextZipper Text -> TextZipper Text
forall a. Monoid a => a -> TextZipper a -> TextZipper a
Z.insertMany Text
buf)
]
getEditorContent :: MH Text
getEditorContent :: MH Text
getEditorContent = do
Editor Text Name
cmdLine <- Getting (Editor Text Name) ChatState (Editor Text Name)
-> MH (Editor Text Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor)
let (Text
line:[Text]
rest) = Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContents Editor Text Name
cmdLine
Text -> MH Text
forall (m :: * -> *) a. Monad m => a -> m a
return (Text -> MH Text) -> Text -> MH Text
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
"\n" ([Text] -> Text) -> [Text] -> Text
forall a b. (a -> b) -> a -> b
$ Text
line Text -> [Text] -> [Text]
forall a. a -> [a] -> [a]
: [Text]
rest
handleInputSubmission :: TeamId -> ChannelId -> Text -> MH ()
handleInputSubmission :: TeamId -> ChannelId -> Text -> MH ()
handleInputSubmission TeamId
tId ChannelId
cId Text
content = do
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.clearZipper
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Maybe Int -> Identity (Maybe Int))
-> TeamState -> Identity TeamState)
-> (Maybe Int -> Identity (Maybe Int))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Maybe Int -> Identity (Maybe Int))
-> ChatEditState -> Identity ChatEditState)
-> (Maybe Int -> Identity (Maybe Int))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState)
-> ((Maybe Int -> Identity (Maybe Int))
-> EphemeralEditState -> Identity EphemeralEditState)
-> (Maybe Int -> Identity (Maybe Int))
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Int -> Identity (Maybe Int))
-> EphemeralEditState -> Identity EphemeralEditState
Lens' EphemeralEditState (Maybe Int)
eesInputHistoryPosition ((Maybe Int -> Identity (Maybe Int))
-> ChatState -> Identity ChatState)
-> Maybe Int -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Maybe Int
forall a. Maybe a
Nothing
(InputHistory -> Identity InputHistory)
-> ChatState -> Identity ChatState
Lens' ChatState InputHistory
csInputHistory ((InputHistory -> Identity InputHistory)
-> ChatState -> Identity ChatState)
-> (InputHistory -> InputHistory) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Text -> ChannelId -> InputHistory -> InputHistory
addHistoryEntry Text
content ChannelId
cId
case Text -> Maybe (Char, Text)
T.uncons Text
content of
Just (Char
'/', Text
cmd) ->
Text -> MH ()
dispatchCommand Text
cmd
Maybe (Char, Text)
_ -> do
Vector AttachmentData
attachments <- Getting (Vector AttachmentData) ChatState (Vector AttachmentData)
-> MH (Vector AttachmentData)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Const (Vector AttachmentData) TeamState)
-> ChatState -> Const (Vector AttachmentData) ChatState)
-> ((Vector AttachmentData
-> Const (Vector AttachmentData) (Vector AttachmentData))
-> TeamState -> Const (Vector AttachmentData) TeamState)
-> Getting
(Vector AttachmentData) ChatState (Vector AttachmentData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Vector AttachmentData) ChatEditState)
-> TeamState -> Const (Vector AttachmentData) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Vector AttachmentData) ChatEditState)
-> TeamState -> Const (Vector AttachmentData) TeamState)
-> ((Vector AttachmentData
-> Const (Vector AttachmentData) (Vector AttachmentData))
-> ChatEditState -> Const (Vector AttachmentData) ChatEditState)
-> (Vector AttachmentData
-> Const (Vector AttachmentData) (Vector AttachmentData))
-> TeamState
-> Const (Vector AttachmentData) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(List Name AttachmentData
-> Const (Vector AttachmentData) (List Name AttachmentData))
-> ChatEditState -> Const (Vector AttachmentData) ChatEditState
Lens' ChatEditState (List Name AttachmentData)
cedAttachmentList((List Name AttachmentData
-> Const (Vector AttachmentData) (List Name AttachmentData))
-> ChatEditState -> Const (Vector AttachmentData) ChatEditState)
-> ((Vector AttachmentData
-> Const (Vector AttachmentData) (Vector AttachmentData))
-> List Name AttachmentData
-> Const (Vector AttachmentData) (List Name AttachmentData))
-> (Vector AttachmentData
-> Const (Vector AttachmentData) (Vector AttachmentData))
-> ChatEditState
-> Const (Vector AttachmentData) ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Vector AttachmentData
-> Const (Vector AttachmentData) (Vector AttachmentData))
-> List Name AttachmentData
-> Const (Vector AttachmentData) (List Name AttachmentData)
forall n (t1 :: * -> *) e1 (t2 :: * -> *) e2.
Lens (GenericList n t1 e1) (GenericList n t2 e2) (t1 e1) (t2 e2)
L.listElementsL)
EditMode
mode <- Getting EditMode ChatState EditMode -> MH EditMode
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Const EditMode TeamState)
-> ChatState -> Const EditMode ChatState)
-> ((EditMode -> Const EditMode EditMode)
-> TeamState -> Const EditMode TeamState)
-> Getting EditMode ChatState EditMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const EditMode ChatEditState)
-> TeamState -> Const EditMode TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const EditMode ChatEditState)
-> TeamState -> Const EditMode TeamState)
-> ((EditMode -> Const EditMode EditMode)
-> ChatEditState -> Const EditMode ChatEditState)
-> (EditMode -> Const EditMode EditMode)
-> TeamState
-> Const EditMode TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditMode -> Const EditMode EditMode)
-> ChatEditState -> Const EditMode ChatEditState
Lens' ChatEditState EditMode
cedEditMode)
ChannelId -> EditMode -> Text -> [AttachmentData] -> MH ()
sendMessage ChannelId
cId EditMode
mode Text
content ([AttachmentData] -> MH ()) -> [AttachmentData] -> MH ()
forall a b. (a -> b) -> a -> b
$ Vector AttachmentData -> [AttachmentData]
forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList Vector AttachmentData
attachments
MH ()
resetAttachmentList
MH ()
resetAutocomplete
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((EditMode -> Identity EditMode)
-> TeamState -> Identity TeamState)
-> (EditMode -> Identity EditMode)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((EditMode -> Identity EditMode)
-> ChatEditState -> Identity ChatEditState)
-> (EditMode -> Identity EditMode)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditMode -> Identity EditMode)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EditMode
cedEditMode ((EditMode -> Identity EditMode)
-> ChatState -> Identity ChatState)
-> EditMode -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= EditMode
NewPost
closingPunctuationMarks :: String
closingPunctuationMarks :: String
closingPunctuationMarks = String
".,'\";:)]!?"
isSmartClosingPunctuation :: Event -> Bool
isSmartClosingPunctuation :: Event -> Bool
isSmartClosingPunctuation (EvKey (KChar Char
c) []) = Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
closingPunctuationMarks
isSmartClosingPunctuation Event
_ = Bool
False
handleEditingInput :: Event -> MH ()
handleEditingInput :: Event -> MH ()
handleEditingInput Event
e = do
Int
beforeLineCount <- Getting Int ChatState Int -> MH Int
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Int TeamState)
-> ChatState -> Const Int ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Int TeamState)
-> ChatState -> Const Int ChatState)
-> ((Int -> Const Int Int) -> TeamState -> Const Int TeamState)
-> Getting Int ChatState Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Int ChatEditState)
-> TeamState -> Const Int TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Int ChatEditState)
-> TeamState -> Const Int TeamState)
-> ((Int -> Const Int Int)
-> ChatEditState -> Const Int ChatEditState)
-> (Int -> Const Int Int)
-> TeamState
-> Const Int TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const Int (Editor Text Name))
-> ChatEditState -> Const Int ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor((Editor Text Name -> Const Int (Editor Text Name))
-> ChatEditState -> Const Int ChatEditState)
-> ((Int -> Const Int Int)
-> Editor Text Name -> Const Int (Editor Text Name))
-> (Int -> Const Int Int)
-> ChatEditState
-> Const Int ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> [Text])
-> SimpleGetter (Editor Text Name) [Text]
forall s a. (s -> a) -> SimpleGetter s a
to Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContentsGetting Int (Editor Text Name) [Text]
-> ((Int -> Const Int Int) -> [Text] -> Const Int [Text])
-> (Int -> Const Int Int)
-> Editor Text Name
-> Const Int (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.([Text] -> Int) -> SimpleGetter [Text] Int
forall s a. (s -> a) -> SimpleGetter s a
to [Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length)
Bool
smartBacktick <- Getting Bool ChatState Bool -> MH Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const Bool ChatResources)
-> ChatState -> Const Bool ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const Bool ChatResources)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool)
-> ChatResources -> Const Bool ChatResources)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const Bool Config)
-> ChatResources -> Const Bool ChatResources
Lens' ChatResources Config
crConfiguration((Config -> Const Bool Config)
-> ChatResources -> Const Bool ChatResources)
-> ((Bool -> Const Bool Bool) -> Config -> Const Bool Config)
-> (Bool -> Const Bool Bool)
-> ChatResources
-> Const Bool ChatResources
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool) -> Config -> Const Bool Config
Lens' Config Bool
configSmartBacktickL)
let smartChars :: String
smartChars = String
"*`_"
ChatState
st <- Getting ChatState ChatState ChatState -> MH ChatState
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting ChatState ChatState ChatState
forall a. a -> a
id
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Maybe Int -> Identity (Maybe Int))
-> TeamState -> Identity TeamState)
-> (Maybe Int -> Identity (Maybe Int))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Maybe Int -> Identity (Maybe Int))
-> ChatEditState -> Identity ChatEditState)
-> (Maybe Int -> Identity (Maybe Int))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState)
-> ((Maybe Int -> Identity (Maybe Int))
-> EphemeralEditState -> Identity EphemeralEditState)
-> (Maybe Int -> Identity (Maybe Int))
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Int -> Identity (Maybe Int))
-> EphemeralEditState -> Identity EphemeralEditState
Lens' EphemeralEditState (Maybe Int)
eesInputHistoryPosition ((Maybe Int -> Identity (Maybe Int))
-> ChatState -> Identity ChatState)
-> Maybe Int -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Maybe Int
forall a. Maybe a
Nothing
Bool
smartEditing <- Getting Bool ChatState Bool -> MH Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const Bool ChatResources)
-> ChatState -> Const Bool ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const Bool ChatResources)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool)
-> ChatResources -> Const Bool ChatResources)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const Bool Config)
-> ChatResources -> Const Bool ChatResources
Lens' ChatResources Config
crConfiguration((Config -> Const Bool Config)
-> ChatResources -> Const Bool ChatResources)
-> ((Bool -> Const Bool Bool) -> Config -> Const Bool Config)
-> (Bool -> Const Bool Bool)
-> ChatResources
-> Const Bool ChatResources
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool) -> Config -> Const Bool Config
Lens' Config Bool
configSmartEditingL)
Bool
justCompleted <- Getting Bool ChatState Bool -> MH Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool) -> TeamState -> Const Bool TeamState)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState)
-> ((Bool -> Const Bool Bool)
-> ChatEditState -> Const Bool ChatEditState)
-> (Bool -> Const Bool Bool)
-> TeamState
-> Const Bool TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool)
-> ChatEditState -> Const Bool ChatEditState
Lens' ChatEditState Bool
cedJustCompleted)
Config
conf <- Getting Config ChatState Config -> MH Config
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const Config ChatResources)
-> ChatState -> Const Config ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const Config ChatResources)
-> ChatState -> Const Config ChatState)
-> ((Config -> Const Config Config)
-> ChatResources -> Const Config ChatResources)
-> Getting Config ChatState Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const Config Config)
-> ChatResources -> Const Config ChatResources
Lens' ChatResources Config
crConfiguration)
let keyMap :: KeyHandlerMap
keyMap = Lens' ChatState (Editor Text Name) -> KeyConfig -> KeyHandlerMap
editingKeybindings ((TeamState -> f TeamState) -> ChatState -> f ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> f TeamState) -> ChatState -> f ChatState)
-> ((Editor Text Name -> f (Editor Text Name))
-> TeamState -> f TeamState)
-> (Editor Text Name -> f (Editor Text Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> f ChatEditState) -> TeamState -> f TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> f ChatEditState) -> TeamState -> f TeamState)
-> ((Editor Text Name -> f (Editor Text Name))
-> ChatEditState -> f ChatEditState)
-> (Editor Text Name -> f (Editor Text Name))
-> TeamState
-> f TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> f (Editor Text Name))
-> ChatEditState -> f ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) (Config -> KeyConfig
configUserKeys Config
conf)
case Event -> KeyHandlerMap -> Maybe KeyHandler
lookupKeybinding Event
e KeyHandlerMap
keyMap of
Just KeyHandler
kb | ChatState -> Bool
editingPermitted ChatState
st -> (EventHandler -> MH ()
ehAction (EventHandler -> MH ()) -> EventHandler -> MH ()
forall a b. (a -> b) -> a -> b
$ KeyEventHandler -> EventHandler
kehHandler (KeyEventHandler -> EventHandler)
-> KeyEventHandler -> EventHandler
forall a b. (a -> b) -> a -> b
$ KeyHandler -> KeyEventHandler
khHandler KeyHandler
kb)
Maybe KeyHandler
_ -> do
case Event
e of
EvKey Key
KBS [] | (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ ChatState -> Bool
editingPermitted ChatState
st) ->
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.clearZipper
EvKey Key
KBS [] | ChatState -> Bool
editingPermitted ChatState
st Bool -> Bool -> Bool
&& Bool
smartBacktick ->
let backspace :: MH ()
backspace = (TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. (Eq a, Monoid a) => TextZipper a -> TextZipper a
Z.deletePrevChar
in case String -> Editor Text Name -> Maybe Char
forall a. String -> Editor Text a -> Maybe Char
cursorAtOneOf String
smartChars (ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) of
Maybe Char
Nothing -> MH ()
backspace
Just Char
ch ->
if | (Char -> Editor Text Name -> Bool
forall a. Char -> Editor Text a -> Bool
cursorAtChar Char
ch (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveLeft (Editor Text Name -> Editor Text Name)
-> Editor Text Name -> Editor Text Name
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) Bool -> Bool -> Bool
&&
(Editor Text Name -> Bool
forall a. Editor Text a -> Bool
cursorIsAtEnd (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveRight (Editor Text Name -> Editor Text Name)
-> Editor Text Name -> Editor Text Name
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) ->
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.deleteChar (TextZipper Text -> TextZipper Text)
-> (TextZipper Text -> TextZipper Text)
-> TextZipper Text
-> TextZipper Text
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> TextZipper Text -> TextZipper Text
forall a. (Eq a, Monoid a) => TextZipper a -> TextZipper a
Z.deletePrevChar)
| Bool
otherwise -> MH ()
backspace
EvKey (KChar Char
ch) []
| ChatState -> Bool
editingPermitted ChatState
st Bool -> Bool -> Bool
&& Bool
smartBacktick Bool -> Bool -> Bool
&& Char
ch Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
smartChars ->
let doInsertChar :: MH ()
doInsertChar = do
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Char -> TextZipper Text -> TextZipper Text
forall a. Monoid a => Char -> TextZipper a -> TextZipper a
Z.insertChar Char
ch)
MH ()
sendUserTypingAction
curLine :: Text
curLine = TextZipper Text -> Text
forall a. Monoid a => TextZipper a -> a
Z.currentLine (TextZipper Text -> Text) -> TextZipper Text -> Text
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (TextZipper Text) ChatState (TextZipper Text)
-> TextZipper Text
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (TextZipper Text) TeamState)
-> ChatState -> Const (TextZipper Text) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (TextZipper Text) TeamState)
-> ChatState -> Const (TextZipper Text) ChatState)
-> ((TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> TeamState -> Const (TextZipper Text) TeamState)
-> Getting (TextZipper Text) ChatState (TextZipper Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (TextZipper Text) ChatEditState)
-> TeamState -> Const (TextZipper Text) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (TextZipper Text) ChatEditState)
-> TeamState -> Const (TextZipper Text) TeamState)
-> ((TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> ChatEditState -> Const (TextZipper Text) ChatEditState)
-> (TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> TeamState
-> Const (TextZipper Text) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> ChatEditState -> Const (TextZipper Text) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor((Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> ChatEditState -> Const (TextZipper Text) ChatEditState)
-> ((TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> (TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> ChatEditState
-> Const (TextZipper Text) ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Editor Text Name -> Const (TextZipper Text) (Editor Text Name)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL
in if | (Editor Text Name -> Bool
forall a. Editor Text a -> Bool
cursorIsAtEnd (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) Bool -> Bool -> Bool
&&
Text
curLine Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"``" Bool -> Bool -> Bool
&&
Char
ch Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'`' -> do
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Text -> TextZipper Text -> TextZipper Text
forall a. Monoid a => a -> TextZipper a -> TextZipper a
Z.insertMany (Char -> Text
T.singleton Char
ch))
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Bool -> Identity Bool) -> TeamState -> Identity TeamState)
-> (Bool -> Identity Bool)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Bool -> Identity Bool)
-> ChatEditState -> Identity ChatEditState)
-> (Bool -> Identity Bool)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Identity EphemeralEditState)
-> ChatEditState -> Identity ChatEditState)
-> ((Bool -> Identity Bool)
-> EphemeralEditState -> Identity EphemeralEditState)
-> (Bool -> Identity Bool)
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Identity Bool)
-> EphemeralEditState -> Identity EphemeralEditState
Lens' EphemeralEditState Bool
eesMultiline ((Bool -> Identity Bool) -> ChatState -> Identity ChatState)
-> Bool -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
| (Editor Text Name -> Bool
forall a. Editor Text a -> Bool
editorEmpty (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) Bool -> Bool -> Bool
||
((Char -> Editor Text Name -> Bool
forall a. Char -> Editor Text a -> Bool
cursorAtChar Char
' ' ((TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveLeft (Editor Text Name -> Editor Text Name)
-> Editor Text Name -> Editor Text Name
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor)) Bool -> Bool -> Bool
&&
(Editor Text Name -> Bool
forall a. Editor Text a -> Bool
cursorIsAtEnd (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor)) ->
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Text -> TextZipper Text -> TextZipper Text
forall a. Monoid a => a -> TextZipper a -> TextZipper a
Z.insertMany (String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Char
chChar -> String -> String
forall a. a -> [a] -> [a]
:Char
chChar -> String -> String
forall a. a -> [a] -> [a]
:[]) (TextZipper Text -> TextZipper Text)
-> (TextZipper Text -> TextZipper Text)
-> TextZipper Text
-> TextZipper Text
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveLeft)
| (Char -> Editor Text Name -> Bool
forall a. Char -> Editor Text a -> Bool
cursorAtChar Char
ch (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) Bool -> Bool -> Bool
&&
(Editor Text Name -> Bool
forall a. Editor Text a -> Bool
cursorIsAtEnd (Editor Text Name -> Bool) -> Editor Text Name -> Bool
forall a b. (a -> b) -> a -> b
$ (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveRight (Editor Text Name -> Editor Text Name)
-> Editor Text Name -> Editor Text Name
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting (Editor Text Name) ChatState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) ->
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.moveRight
| Bool
otherwise -> MH ()
doInsertChar
| ChatState -> Bool
editingPermitted ChatState
st -> do
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
smartEditing Bool -> Bool -> Bool
&& Bool
justCompleted Bool -> Bool -> Bool
&& Event -> Bool
isSmartClosingPunctuation Event
e) (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. (Eq a, Monoid a) => TextZipper a -> TextZipper a
Z.deletePrevChar
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Text -> TextZipper Text -> TextZipper Text
forall a. Monoid a => a -> TextZipper a -> TextZipper a
Z.insertMany (Text -> Text
sanitizeUserText' (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
ch))
MH ()
sendUserTypingAction
Event
_ | ChatState -> Bool
editingPermitted ChatState
st -> do
Lens' ChatState (Editor Text Name)
-> (Event -> Editor Text Name -> EventM Name (Editor Text Name))
-> Event
-> MH ()
forall b e.
Lens' ChatState b -> (e -> b -> EventM Name b) -> e -> MH ()
mhHandleEventLensed ((TeamState -> f TeamState) -> ChatState -> f ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> f TeamState) -> ChatState -> f ChatState)
-> ((Editor Text Name -> f (Editor Text Name))
-> TeamState -> f TeamState)
-> (Editor Text Name -> f (Editor Text Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> f ChatEditState) -> TeamState -> f TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> f ChatEditState) -> TeamState -> f TeamState)
-> ((Editor Text Name -> f (Editor Text Name))
-> ChatEditState -> f ChatEditState)
-> (Editor Text Name -> f (Editor Text Name))
-> TeamState
-> f TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> f (Editor Text Name))
-> ChatEditState -> f ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor) Event -> Editor Text Name -> EventM Name (Editor Text Name)
forall t n.
(DecodeUtf8 t, Eq t, GenericTextZipper t) =>
Event -> Editor t n -> EventM n (Editor t n)
handleEditorEvent Event
e
MH ()
sendUserTypingAction
| Bool
otherwise -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
let ctx :: AutocompleteContext
ctx = AutocompleteContext :: Bool -> Bool -> AutocompleteContext
AutocompleteContext { autocompleteManual :: Bool
autocompleteManual = Bool
False
, autocompleteFirstMatch :: Bool
autocompleteFirstMatch = Bool
False
}
AutocompleteContext -> MH ()
checkForAutocompletion AutocompleteContext
ctx
IO () -> MH ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ ChatEditState -> IO ()
resetSpellCheckTimer (ChatEditState -> IO ()) -> ChatEditState -> IO ()
forall a b. (a -> b) -> a -> b
$ ChatState
stChatState
-> Getting ChatEditState ChatState ChatEditState -> ChatEditState
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const ChatEditState TeamState)
-> ChatState -> Const ChatEditState ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const ChatEditState TeamState)
-> ChatState -> Const ChatEditState ChatState)
-> ((ChatEditState -> Const ChatEditState ChatEditState)
-> TeamState -> Const ChatEditState TeamState)
-> Getting ChatEditState ChatState ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const ChatEditState ChatEditState)
-> TeamState -> Const ChatEditState TeamState
Lens' TeamState ChatEditState
tsEditState
Int
afterLineCount <- Getting Int ChatState Int -> MH Int
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Int TeamState)
-> ChatState -> Const Int ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Int TeamState)
-> ChatState -> Const Int ChatState)
-> ((Int -> Const Int Int) -> TeamState -> Const Int TeamState)
-> Getting Int ChatState Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Int ChatEditState)
-> TeamState -> Const Int TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Int ChatEditState)
-> TeamState -> Const Int TeamState)
-> ((Int -> Const Int Int)
-> ChatEditState -> Const Int ChatEditState)
-> (Int -> Const Int Int)
-> TeamState
-> Const Int TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const Int (Editor Text Name))
-> ChatEditState -> Const Int ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor((Editor Text Name -> Const Int (Editor Text Name))
-> ChatEditState -> Const Int ChatEditState)
-> ((Int -> Const Int Int)
-> Editor Text Name -> Const Int (Editor Text Name))
-> (Int -> Const Int Int)
-> ChatEditState
-> Const Int ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> [Text])
-> SimpleGetter (Editor Text Name) [Text]
forall s a. (s -> a) -> SimpleGetter s a
to Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContentsGetting Int (Editor Text Name) [Text]
-> ((Int -> Const Int Int) -> [Text] -> Const Int [Text])
-> (Int -> Const Int Int)
-> Editor Text Name
-> Const Int (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.([Text] -> Int) -> SimpleGetter [Text] Int
forall s a. (s -> a) -> SimpleGetter s a
to [Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length)
Bool
isMultiline <- Getting Bool ChatState Bool -> MH Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const Bool TeamState)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool) -> TeamState -> Const Bool TeamState)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const Bool ChatEditState)
-> TeamState -> Const Bool TeamState)
-> ((Bool -> Const Bool Bool)
-> ChatEditState -> Const Bool ChatEditState)
-> (Bool -> Const Bool Bool)
-> TeamState
-> Const Bool TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EphemeralEditState -> Const Bool EphemeralEditState)
-> ChatEditState -> Const Bool ChatEditState
Lens' ChatEditState EphemeralEditState
cedEphemeral((EphemeralEditState -> Const Bool EphemeralEditState)
-> ChatEditState -> Const Bool ChatEditState)
-> ((Bool -> Const Bool Bool)
-> EphemeralEditState -> Const Bool EphemeralEditState)
-> (Bool -> Const Bool Bool)
-> ChatEditState
-> Const Bool ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool)
-> EphemeralEditState -> Const Bool EphemeralEditState
Lens' EphemeralEditState Bool
eesMultiline)
Bool
isPreviewing <- Getting Bool ChatState Bool -> MH Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ChatResources -> Const Bool ChatResources)
-> ChatState -> Const Bool ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const Bool ChatResources)
-> ChatState -> Const Bool ChatState)
-> ((Bool -> Const Bool Bool)
-> ChatResources -> Const Bool ChatResources)
-> Getting Bool ChatState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const Bool Config)
-> ChatResources -> Const Bool ChatResources
Lens' ChatResources Config
crConfiguration((Config -> Const Bool Config)
-> ChatResources -> Const Bool ChatResources)
-> ((Bool -> Const Bool Bool) -> Config -> Const Bool Config)
-> (Bool -> Const Bool Bool)
-> ChatResources
-> Const Bool ChatResources
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Const Bool Bool) -> Config -> Const Bool Config
Lens' Config Bool
configShowMessagePreviewL)
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
beforeLineCount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= Int
afterLineCount Bool -> Bool -> Bool
&& Bool
isMultiline Bool -> Bool -> Bool
&& Bool
isPreviewing) (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ do
TeamId
tId <- Getting TeamId ChatState TeamId -> MH TeamId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting TeamId ChatState TeamId
SimpleGetter ChatState TeamId
csCurrentTeamId
ChannelId
cId <- Getting ChannelId ChatState ChannelId -> MH ChannelId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> SimpleGetter ChatState ChannelId
csCurrentChannelId TeamId
tId)
EventM Name () -> MH ()
forall a. EventM Name a -> MH a
mh (EventM Name () -> MH ()) -> EventM Name () -> MH ()
forall a b. (a -> b) -> a -> b
$ Name -> EventM Name ()
forall n. Ord n => n -> EventM n ()
invalidateCacheEntry (Name -> EventM Name ()) -> Name -> EventM Name ()
forall a b. (a -> b) -> a -> b
$ ChannelId -> Name
ChannelMessages ChannelId
cId
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
justCompleted (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Bool -> Identity Bool) -> TeamState -> Identity TeamState)
-> (Bool -> Identity Bool)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Bool -> Identity Bool)
-> ChatEditState -> Identity ChatEditState)
-> (Bool -> Identity Bool)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Identity Bool) -> ChatEditState -> Identity ChatEditState
Lens' ChatEditState Bool
cedJustCompleted ((Bool -> Identity Bool) -> ChatState -> Identity ChatState)
-> Bool -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
False
sendUserTypingAction :: MH ()
sendUserTypingAction :: MH ()
sendUserTypingAction = do
ChatState
st <- Getting ChatState ChatState ChatState -> MH ChatState
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting ChatState ChatState ChatState
forall a. a -> a
id
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Config -> Bool
configShowTypingIndicator (ChatState
stChatState -> Getting Config ChatState Config -> Config
forall s a. s -> Getting a s a -> a
^.(ChatResources -> Const Config ChatResources)
-> ChatState -> Const Config ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const Config ChatResources)
-> ChatState -> Const Config ChatState)
-> ((Config -> Const Config Config)
-> ChatResources -> Const Config ChatResources)
-> Getting Config ChatState Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Config -> Const Config Config)
-> ChatResources -> Const Config ChatResources
Lens' ChatResources Config
crConfiguration)) (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$
case ChatState
stChatState
-> Getting ConnectionStatus ChatState ConnectionStatus
-> ConnectionStatus
forall s a. s -> Getting a s a -> a
^.Getting ConnectionStatus ChatState ConnectionStatus
Lens' ChatState ConnectionStatus
csConnectionStatus of
ConnectionStatus
Connected -> do
let pId :: Maybe PostId
pId = case ChatState
stChatState -> Getting EditMode ChatState EditMode -> EditMode
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const EditMode TeamState)
-> ChatState -> Const EditMode ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const EditMode TeamState)
-> ChatState -> Const EditMode ChatState)
-> ((EditMode -> Const EditMode EditMode)
-> TeamState -> Const EditMode TeamState)
-> Getting EditMode ChatState EditMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const EditMode ChatEditState)
-> TeamState -> Const EditMode TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const EditMode ChatEditState)
-> TeamState -> Const EditMode TeamState)
-> ((EditMode -> Const EditMode EditMode)
-> ChatEditState -> Const EditMode ChatEditState)
-> (EditMode -> Const EditMode EditMode)
-> TeamState
-> Const EditMode TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditMode -> Const EditMode EditMode)
-> ChatEditState -> Const EditMode ChatEditState
Lens' ChatEditState EditMode
cedEditMode of
Replying Message
_ Post
post -> PostId -> Maybe PostId
forall a. a -> Maybe a
Just (PostId -> Maybe PostId) -> PostId -> Maybe PostId
forall a b. (a -> b) -> a -> b
$ Post -> PostId
postId Post
post
EditMode
_ -> Maybe PostId
forall a. Maybe a
Nothing
TeamId
tId <- Getting TeamId ChatState TeamId -> MH TeamId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting TeamId ChatState TeamId
SimpleGetter ChatState TeamId
csCurrentTeamId
IO () -> MH ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> MH ()) -> IO () -> MH ()
forall a b. (a -> b) -> a -> b
$ do
UTCTime
now <- IO UTCTime
getCurrentTime
let action :: WebsocketAction
action = UTCTime -> ChannelId -> Maybe PostId -> WebsocketAction
UserTyping UTCTime
now (ChatState
stChatState -> Getting ChannelId ChatState ChannelId -> ChannelId
forall s a. s -> Getting a s a -> a
^.TeamId -> SimpleGetter ChatState ChannelId
csCurrentChannelId(TeamId
tId)) Maybe PostId
pId
STM () -> IO ()
forall a. STM a -> IO a
STM.atomically (STM () -> IO ()) -> STM () -> IO ()
forall a b. (a -> b) -> a -> b
$ TChan WebsocketAction -> WebsocketAction -> STM ()
forall a. TChan a -> a -> STM ()
STM.writeTChan (ChatState
stChatState
-> Getting
(TChan WebsocketAction) ChatState (TChan WebsocketAction)
-> TChan WebsocketAction
forall s a. s -> Getting a s a -> a
^.(ChatResources -> Const (TChan WebsocketAction) ChatResources)
-> ChatState -> Const (TChan WebsocketAction) ChatState
Lens' ChatState ChatResources
csResources((ChatResources -> Const (TChan WebsocketAction) ChatResources)
-> ChatState -> Const (TChan WebsocketAction) ChatState)
-> ((TChan WebsocketAction
-> Const (TChan WebsocketAction) (TChan WebsocketAction))
-> ChatResources -> Const (TChan WebsocketAction) ChatResources)
-> Getting
(TChan WebsocketAction) ChatState (TChan WebsocketAction)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(TChan WebsocketAction
-> Const (TChan WebsocketAction) (TChan WebsocketAction))
-> ChatResources -> Const (TChan WebsocketAction) ChatResources
Lens' ChatResources (TChan WebsocketAction)
crWebsocketActionChan) WebsocketAction
action
ConnectionStatus
Disconnected -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
requestSpellCheck :: MH ()
requestSpellCheck :: MH ()
requestSpellCheck = do
ChatState
st <- Getting ChatState ChatState ChatState -> MH ChatState
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting ChatState ChatState ChatState
forall a. a -> a
id
case ChatState
stChatState
-> Getting
(Maybe (Aspell, IO ())) ChatState (Maybe (Aspell, IO ()))
-> Maybe (Aspell, IO ())
forall s a. s -> Getting a s a -> a
^.(TeamState -> Const (Maybe (Aspell, IO ())) TeamState)
-> ChatState -> Const (Maybe (Aspell, IO ())) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Maybe (Aspell, IO ())) TeamState)
-> ChatState -> Const (Maybe (Aspell, IO ())) ChatState)
-> ((Maybe (Aspell, IO ())
-> Const (Maybe (Aspell, IO ())) (Maybe (Aspell, IO ())))
-> TeamState -> Const (Maybe (Aspell, IO ())) TeamState)
-> Getting
(Maybe (Aspell, IO ())) ChatState (Maybe (Aspell, IO ()))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Maybe (Aspell, IO ())) ChatEditState)
-> TeamState -> Const (Maybe (Aspell, IO ())) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Maybe (Aspell, IO ())) ChatEditState)
-> TeamState -> Const (Maybe (Aspell, IO ())) TeamState)
-> ((Maybe (Aspell, IO ())
-> Const (Maybe (Aspell, IO ())) (Maybe (Aspell, IO ())))
-> ChatEditState -> Const (Maybe (Aspell, IO ())) ChatEditState)
-> (Maybe (Aspell, IO ())
-> Const (Maybe (Aspell, IO ())) (Maybe (Aspell, IO ())))
-> TeamState
-> Const (Maybe (Aspell, IO ())) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe (Aspell, IO ())
-> Const (Maybe (Aspell, IO ())) (Maybe (Aspell, IO ())))
-> ChatEditState -> Const (Maybe (Aspell, IO ())) ChatEditState
Lens' ChatEditState (Maybe (Aspell, IO ()))
cedSpellChecker of
Maybe (Aspell, IO ())
Nothing -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (Aspell
checker, IO ()
_) -> do
TeamId
tId <- Getting TeamId ChatState TeamId -> MH TeamId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting TeamId ChatState TeamId
SimpleGetter ChatState TeamId
csCurrentTeamId
[Text]
contents <- Editor Text Name -> [Text]
forall t n. Monoid t => Editor t n -> [t]
getEditContents (Editor Text Name -> [Text]) -> MH (Editor Text Name) -> MH [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Getting (Editor Text Name) ChatState (Editor Text Name)
-> MH (Editor Text Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Const (Editor Text Name) TeamState)
-> ChatState -> Const (Editor Text Name) ChatState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState -> Const (Editor Text Name) TeamState)
-> Getting (Editor Text Name) ChatState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Editor Text Name) ChatEditState)
-> TeamState -> Const (Editor Text Name) TeamState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState)
-> (Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> TeamState
-> Const (Editor Text Name) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ChatEditState -> Const (Editor Text Name) ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor)
AsyncPriority -> IO (Maybe (MH ())) -> MH ()
doAsyncWith AsyncPriority
Preempt (IO (Maybe (MH ())) -> MH ()) -> IO (Maybe (MH ())) -> MH ()
forall a b. (a -> b) -> a -> b
$ do
let query :: IO [AspellResponse]
query = [[AspellResponse]] -> [AspellResponse]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[AspellResponse]] -> [AspellResponse])
-> IO [[AspellResponse]] -> IO [AspellResponse]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text -> IO [AspellResponse]) -> [Text] -> IO [[AspellResponse]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Aspell -> Text -> IO [AspellResponse]
askAspell Aspell
checker) [Text]
contents
postMistakes :: [AspellResponse] -> MH ()
postMistakes :: [AspellResponse] -> MH ()
postMistakes [AspellResponse]
responses = do
let getMistakes :: AspellResponse -> [Text]
getMistakes AspellResponse
AllCorrect = []
getMistakes (Mistakes [Mistake]
ms) = Mistake -> Text
mistakeWord (Mistake -> Text) -> [Mistake] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Mistake]
ms
allMistakes :: Set Text
allMistakes = [Text] -> Set Text
forall a. Ord a => [a] -> Set a
S.fromList ([Text] -> Set Text) -> [Text] -> Set Text
forall a b. (a -> b) -> a -> b
$ [[Text]] -> [Text]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Text]] -> [Text]) -> [[Text]] -> [Text]
forall a b. (a -> b) -> a -> b
$ AspellResponse -> [Text]
getMistakes (AspellResponse -> [Text]) -> [AspellResponse] -> [[Text]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [AspellResponse]
responses
TeamId -> Lens' ChatState TeamState
csTeam(TeamId
tId)((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Set Text -> Identity (Set Text))
-> TeamState -> Identity TeamState)
-> (Set Text -> Identity (Set Text))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Set Text -> Identity (Set Text))
-> ChatEditState -> Identity ChatEditState)
-> (Set Text -> Identity (Set Text))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Set Text -> Identity (Set Text))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Set Text)
cedMisspellings ((Set Text -> Identity (Set Text))
-> ChatState -> Identity ChatState)
-> Set Text -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Set Text
allMistakes
IO [AspellResponse]
-> ([AspellResponse] -> IO (Maybe (MH ()))) -> IO (Maybe (MH ()))
forall a. IO a -> (a -> IO (Maybe (MH ()))) -> IO (Maybe (MH ()))
tryMM IO [AspellResponse]
query (Maybe (MH ()) -> IO (Maybe (MH ()))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (MH ()) -> IO (Maybe (MH ())))
-> ([AspellResponse] -> Maybe (MH ()))
-> [AspellResponse]
-> IO (Maybe (MH ()))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MH () -> Maybe (MH ())
forall a. a -> Maybe a
Just (MH () -> Maybe (MH ()))
-> ([AspellResponse] -> MH ()) -> [AspellResponse] -> Maybe (MH ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [AspellResponse] -> MH ()
postMistakes)
editorEmpty :: Editor Text a -> Bool
editorEmpty :: Editor Text a -> Bool
editorEmpty Editor Text a
e = Editor Text a -> Bool
forall a. Editor Text a -> Bool
cursorIsAtEnd Editor Text a
e Bool -> Bool -> Bool
&&
Editor Text a -> Bool
forall a. Editor Text a -> Bool
cursorIsAtBeginning Editor Text a
e
cursorIsAtEnd :: Editor Text a -> Bool
cursorIsAtEnd :: Editor Text a -> Bool
cursorIsAtEnd Editor Text a
e =
let col :: Int
col = (Int, Int) -> Int
forall a b. (a, b) -> b
snd ((Int, Int) -> Int) -> (Int, Int) -> Int
forall a b. (a -> b) -> a -> b
$ TextZipper Text -> (Int, Int)
forall a. TextZipper a -> (Int, Int)
Z.cursorPosition TextZipper Text
z
curLine :: Text
curLine = TextZipper Text -> Text
forall a. Monoid a => TextZipper a -> a
Z.currentLine TextZipper Text
z
z :: TextZipper Text
z = Editor Text a
eEditor Text a
-> Getting (TextZipper Text) (Editor Text a) (TextZipper Text)
-> TextZipper Text
forall s a. s -> Getting a s a -> a
^.Getting (TextZipper Text) (Editor Text a) (TextZipper Text)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL
in Int
col Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Int
T.length Text
curLine
cursorIsAtBeginning :: Editor Text a -> Bool
cursorIsAtBeginning :: Editor Text a -> Bool
cursorIsAtBeginning Editor Text a
e =
let col :: Int
col = (Int, Int) -> Int
forall a b. (a, b) -> b
snd ((Int, Int) -> Int) -> (Int, Int) -> Int
forall a b. (a -> b) -> a -> b
$ TextZipper Text -> (Int, Int)
forall a. TextZipper a -> (Int, Int)
Z.cursorPosition TextZipper Text
z
z :: TextZipper Text
z = Editor Text a
eEditor Text a
-> Getting (TextZipper Text) (Editor Text a) (TextZipper Text)
-> TextZipper Text
forall s a. s -> Getting a s a -> a
^.Getting (TextZipper Text) (Editor Text a) (TextZipper Text)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL
in Int
col Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
cursorAtOneOf :: [Char] -> Editor Text a -> Maybe Char
cursorAtOneOf :: String -> Editor Text a -> Maybe Char
cursorAtOneOf [] Editor Text a
_ = Maybe Char
forall a. Maybe a
Nothing
cursorAtOneOf (Char
c:String
cs) Editor Text a
e =
if Char -> Editor Text a -> Bool
forall a. Char -> Editor Text a -> Bool
cursorAtChar Char
c Editor Text a
e
then Char -> Maybe Char
forall a. a -> Maybe a
Just Char
c
else String -> Editor Text a -> Maybe Char
forall a. String -> Editor Text a -> Maybe Char
cursorAtOneOf String
cs Editor Text a
e
cursorAtChar :: Char -> Editor Text a -> Bool
cursorAtChar :: Char -> Editor Text a -> Bool
cursorAtChar Char
ch Editor Text a
e =
let col :: Int
col = (Int, Int) -> Int
forall a b. (a, b) -> b
snd ((Int, Int) -> Int) -> (Int, Int) -> Int
forall a b. (a -> b) -> a -> b
$ TextZipper Text -> (Int, Int)
forall a. TextZipper a -> (Int, Int)
Z.cursorPosition TextZipper Text
z
curLine :: Text
curLine = TextZipper Text -> Text
forall a. Monoid a => TextZipper a -> a
Z.currentLine TextZipper Text
z
z :: TextZipper Text
z = Editor Text a
eEditor Text a
-> Getting (TextZipper Text) (Editor Text a) (TextZipper Text)
-> TextZipper Text
forall s a. s -> Getting a s a -> a
^.Getting (TextZipper Text) (Editor Text a) (TextZipper Text)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL
in (Char -> Text
T.singleton Char
ch) Text -> Text -> Bool
`T.isPrefixOf` Int -> Text -> Text
T.drop Int
col Text
curLine
gotoHome :: Z.TextZipper Text -> Z.TextZipper Text
gotoHome :: TextZipper Text -> TextZipper Text
gotoHome = (Int, Int) -> TextZipper Text -> TextZipper Text
forall a. Monoid a => (Int, Int) -> TextZipper a -> TextZipper a
Z.moveCursor (Int
0, Int
0)
gotoEnd :: Z.TextZipper Text -> Z.TextZipper Text
gotoEnd :: TextZipper Text -> TextZipper Text
gotoEnd TextZipper Text
z =
let zLines :: [Text]
zLines = TextZipper Text -> [Text]
forall a. Monoid a => TextZipper a -> [a]
Z.getText TextZipper Text
z
numLines :: Int
numLines = [Text] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Text]
zLines
lastLineLength :: Int
lastLineLength = Text -> Int
T.length (Text -> Int) -> Text -> Int
forall a b. (a -> b) -> a -> b
$ [Text] -> Text
forall a. [a] -> a
last [Text]
zLines
in if Int
numLines Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0
then (Int, Int) -> TextZipper Text -> TextZipper Text
forall a. Monoid a => (Int, Int) -> TextZipper a -> TextZipper a
Z.moveCursor (Int
numLines Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1, Int
lastLineLength) TextZipper Text
z
else TextZipper Text
z
cancelAutocompleteOrReplyOrEdit :: MH ()
cancelAutocompleteOrReplyOrEdit :: MH ()
cancelAutocompleteOrReplyOrEdit = do
TeamId
tId <- Getting TeamId ChatState TeamId -> MH TeamId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting TeamId ChatState TeamId
SimpleGetter ChatState TeamId
csCurrentTeamId
ChannelId
cId <- Getting ChannelId ChatState ChannelId -> MH ChannelId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> SimpleGetter ChatState ChannelId
csCurrentChannelId TeamId
tId)
EventM Name () -> MH ()
forall a. EventM Name a -> MH a
mh (EventM Name () -> MH ()) -> EventM Name () -> MH ()
forall a b. (a -> b) -> a -> b
$ Name -> EventM Name ()
forall n. Ord n => n -> EventM n ()
invalidateCacheEntry (Name -> EventM Name ()) -> Name -> EventM Name ()
forall a b. (a -> b) -> a -> b
$ ChannelId -> Name
ChannelMessages ChannelId
cId
Maybe AutocompleteState
ac <- Getting
(Maybe AutocompleteState) ChatState (Maybe AutocompleteState)
-> MH (Maybe AutocompleteState)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const (Maybe AutocompleteState) TeamState)
-> ChatState -> Const (Maybe AutocompleteState) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Maybe AutocompleteState) TeamState)
-> ChatState -> Const (Maybe AutocompleteState) ChatState)
-> ((Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> TeamState -> Const (Maybe AutocompleteState) TeamState)
-> Getting
(Maybe AutocompleteState) ChatState (Maybe AutocompleteState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Maybe AutocompleteState) ChatEditState)
-> TeamState -> Const (Maybe AutocompleteState) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Maybe AutocompleteState) ChatEditState)
-> TeamState -> Const (Maybe AutocompleteState) TeamState)
-> ((Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> ChatEditState -> Const (Maybe AutocompleteState) ChatEditState)
-> (Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> TeamState
-> Const (Maybe AutocompleteState) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> ChatEditState -> Const (Maybe AutocompleteState) ChatEditState
Lens' ChatEditState (Maybe AutocompleteState)
cedAutocomplete)
case Maybe AutocompleteState
ac of
Just AutocompleteState
_ -> do
MH ()
resetAutocomplete
Maybe AutocompleteState
Nothing -> do
EditMode
mode <- Getting EditMode ChatState EditMode -> MH EditMode
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const EditMode TeamState)
-> ChatState -> Const EditMode ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const EditMode TeamState)
-> ChatState -> Const EditMode ChatState)
-> ((EditMode -> Const EditMode EditMode)
-> TeamState -> Const EditMode TeamState)
-> Getting EditMode ChatState EditMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const EditMode ChatEditState)
-> TeamState -> Const EditMode TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const EditMode ChatEditState)
-> TeamState -> Const EditMode TeamState)
-> ((EditMode -> Const EditMode EditMode)
-> ChatEditState -> Const EditMode ChatEditState)
-> (EditMode -> Const EditMode EditMode)
-> TeamState
-> Const EditMode TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditMode -> Const EditMode EditMode)
-> ChatEditState -> Const EditMode ChatEditState
Lens' ChatEditState EditMode
cedEditMode)
case EditMode
mode of
EditMode
NewPost -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
EditMode
_ -> do
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((EditMode -> Identity EditMode)
-> TeamState -> Identity TeamState)
-> (EditMode -> Identity EditMode)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((EditMode -> Identity EditMode)
-> ChatEditState -> Identity ChatEditState)
-> (EditMode -> Identity EditMode)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditMode -> Identity EditMode)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EditMode
cedEditMode ((EditMode -> Identity EditMode)
-> ChatState -> Identity ChatState)
-> EditMode -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= EditMode
NewPost
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit TextZipper Text -> TextZipper Text
forall a. Monoid a => TextZipper a -> TextZipper a
Z.clearZipper
MH ()
resetAttachmentList
replyToLatestMessage :: MH ()
replyToLatestMessage :: MH ()
replyToLatestMessage = do
Messages
msgs <- Getting Messages ChatState Messages -> MH Messages
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((ClientChannel -> Const Messages ClientChannel)
-> ChatState -> Const Messages ChatState
Lens' ChatState ClientChannel
csCurrentChannel ((ClientChannel -> Const Messages ClientChannel)
-> ChatState -> Const Messages ChatState)
-> ((Messages -> Const Messages Messages)
-> ClientChannel -> Const Messages ClientChannel)
-> Getting Messages ChatState Messages
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ChannelContents -> Const Messages ChannelContents)
-> ClientChannel -> Const Messages ClientChannel
Lens' ClientChannel ChannelContents
ccContents ((ChannelContents -> Const Messages ChannelContents)
-> ClientChannel -> Const Messages ClientChannel)
-> ((Messages -> Const Messages Messages)
-> ChannelContents -> Const Messages ChannelContents)
-> (Messages -> Const Messages Messages)
-> ClientChannel
-> Const Messages ClientChannel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Messages -> Const Messages Messages)
-> ChannelContents -> Const Messages ChannelContents
Lens' ChannelContents Messages
cdMessages)
case (Message -> Bool) -> Messages -> Maybe Message
findLatestUserMessage Message -> Bool
isReplyable Messages
msgs of
Just Message
msg | Message -> Bool
isReplyable Message
msg ->
do Message
rootMsg <- Message -> MH Message
getReplyRootMessage Message
msg
Mode -> MH ()
setMode Mode
Main
TeamId
tId <- Getting TeamId ChatState TeamId -> MH TeamId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting TeamId ChatState TeamId
SimpleGetter ChatState TeamId
csCurrentTeamId
ChannelId
cId <- Getting ChannelId ChatState ChannelId -> MH ChannelId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (TeamId -> SimpleGetter ChatState ChannelId
csCurrentChannelId TeamId
tId)
EventM Name () -> MH ()
forall a. EventM Name a -> MH a
mh (EventM Name () -> MH ()) -> EventM Name () -> MH ()
forall a b. (a -> b) -> a -> b
$ Name -> EventM Name ()
forall n. Ord n => n -> EventM n ()
invalidateCacheEntry (Name -> EventM Name ()) -> Name -> EventM Name ()
forall a b. (a -> b) -> a -> b
$ ChannelId -> Name
ChannelMessages ChannelId
cId
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((EditMode -> Identity EditMode)
-> TeamState -> Identity TeamState)
-> (EditMode -> Identity EditMode)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((EditMode -> Identity EditMode)
-> ChatEditState -> Identity ChatEditState)
-> (EditMode -> Identity EditMode)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditMode -> Identity EditMode)
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState EditMode
cedEditMode ((EditMode -> Identity EditMode)
-> ChatState -> Identity ChatState)
-> EditMode -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Message -> Post -> EditMode
Replying Message
rootMsg (Maybe Post -> Post
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Post -> Post) -> Maybe Post -> Post
forall a b. (a -> b) -> a -> b
$ Message
rootMsgMessage -> Getting (Maybe Post) Message (Maybe Post) -> Maybe Post
forall s a. s -> Getting a s a -> a
^.Getting (Maybe Post) Message (Maybe Post)
Lens' Message (Maybe Post)
mOriginalPost)
Maybe Message
_ -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
data Direction = Forwards | Backwards
tabComplete :: Direction -> MH ()
tabComplete :: Direction -> MH ()
tabComplete Direction
dir = do
let transform :: GenericList n t2 e2 -> GenericList n t2 e2
transform GenericList n t2 e2
list =
let len :: Int
len = GenericList n t2 e2
listGenericList n t2 e2 -> Getting Int (GenericList n t2 e2) Int -> Int
forall s a. s -> Getting a s a -> a
^.(t2 e2 -> Const Int (t2 e2))
-> GenericList n t2 e2 -> Const Int (GenericList n t2 e2)
forall n (t1 :: * -> *) e1 (t2 :: * -> *) e2.
Lens (GenericList n t1 e1) (GenericList n t2 e2) (t1 e1) (t2 e2)
L.listElementsL((t2 e2 -> Const Int (t2 e2))
-> GenericList n t2 e2 -> Const Int (GenericList n t2 e2))
-> ((Int -> Const Int Int) -> t2 e2 -> Const Int (t2 e2))
-> Getting Int (GenericList n t2 e2) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(t2 e2 -> Int) -> SimpleGetter (t2 e2) Int
forall s a. (s -> a) -> SimpleGetter s a
to t2 e2 -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
in case Direction
dir of
Direction
Forwards ->
if (GenericList n t2 e2 -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
L.listSelected GenericList n t2 e2
list Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Maybe Int
forall a. a -> Maybe a
Just (Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)) Bool -> Bool -> Bool
||
(GenericList n t2 e2 -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
L.listSelected GenericList n t2 e2
list Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Int
forall a. Maybe a
Nothing Bool -> Bool -> Bool
&& Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0)
then Int -> GenericList n t2 e2 -> GenericList n t2 e2
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
L.listMoveTo Int
0 GenericList n t2 e2
list
else Int -> GenericList n t2 e2 -> GenericList n t2 e2
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
L.listMoveBy Int
1 GenericList n t2 e2
list
Direction
Backwards ->
if (GenericList n t2 e2 -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
L.listSelected GenericList n t2 e2
list Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0) Bool -> Bool -> Bool
||
(GenericList n t2 e2 -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
L.listSelected GenericList n t2 e2
list Maybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe Int
forall a. Maybe a
Nothing Bool -> Bool -> Bool
&& Int
len Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0)
then Int -> GenericList n t2 e2 -> GenericList n t2 e2
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
L.listMoveTo (Int
len Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) GenericList n t2 e2
list
else Int -> GenericList n t2 e2 -> GenericList n t2 e2
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
L.listMoveBy (-Int
1) GenericList n t2 e2
list
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> TeamState -> Identity TeamState)
-> (List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> ChatEditState -> Identity ChatEditState)
-> (List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe AutocompleteState -> Identity (Maybe AutocompleteState))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Maybe AutocompleteState)
cedAutocomplete((Maybe AutocompleteState -> Identity (Maybe AutocompleteState))
-> ChatEditState -> Identity ChatEditState)
-> ((List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> Maybe AutocompleteState -> Identity (Maybe AutocompleteState))
-> (List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> ChatEditState
-> Identity ChatEditState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(AutocompleteState -> Identity AutocompleteState)
-> Maybe AutocompleteState -> Identity (Maybe AutocompleteState)
forall a a'. Traversal (Maybe a) (Maybe a') a a'
_Just((AutocompleteState -> Identity AutocompleteState)
-> Maybe AutocompleteState -> Identity (Maybe AutocompleteState))
-> ((List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> AutocompleteState -> Identity AutocompleteState)
-> (List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> Maybe AutocompleteState
-> Identity (Maybe AutocompleteState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> AutocompleteState -> Identity AutocompleteState
Lens' AutocompleteState (List Name AutocompleteAlternative)
acCompletionList ((List Name AutocompleteAlternative
-> Identity (List Name AutocompleteAlternative))
-> ChatState -> Identity ChatState)
-> (List Name AutocompleteAlternative
-> List Name AutocompleteAlternative)
-> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= List Name AutocompleteAlternative
-> List Name AutocompleteAlternative
forall (t2 :: * -> *) n e2.
(Splittable t2, Foldable t2) =>
GenericList n t2 e2 -> GenericList n t2 e2
transform
Maybe AutocompleteState
mac <- Getting
(Maybe AutocompleteState) ChatState (Maybe AutocompleteState)
-> MH (Maybe AutocompleteState)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((TeamState -> Const (Maybe AutocompleteState) TeamState)
-> ChatState -> Const (Maybe AutocompleteState) ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Const (Maybe AutocompleteState) TeamState)
-> ChatState -> Const (Maybe AutocompleteState) ChatState)
-> ((Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> TeamState -> Const (Maybe AutocompleteState) TeamState)
-> Getting
(Maybe AutocompleteState) ChatState (Maybe AutocompleteState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Const (Maybe AutocompleteState) ChatEditState)
-> TeamState -> Const (Maybe AutocompleteState) TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Const (Maybe AutocompleteState) ChatEditState)
-> TeamState -> Const (Maybe AutocompleteState) TeamState)
-> ((Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> ChatEditState -> Const (Maybe AutocompleteState) ChatEditState)
-> (Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> TeamState
-> Const (Maybe AutocompleteState) TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe AutocompleteState
-> Const (Maybe AutocompleteState) (Maybe AutocompleteState))
-> ChatEditState -> Const (Maybe AutocompleteState) ChatEditState
Lens' ChatEditState (Maybe AutocompleteState)
cedAutocomplete)
case Maybe AutocompleteState
mac of
Maybe AutocompleteState
Nothing -> do
let ctx :: AutocompleteContext
ctx = AutocompleteContext :: Bool -> Bool -> AutocompleteContext
AutocompleteContext { autocompleteManual :: Bool
autocompleteManual = Bool
True
, autocompleteFirstMatch :: Bool
autocompleteFirstMatch = Bool
True
}
AutocompleteContext -> MH ()
checkForAutocompletion AutocompleteContext
ctx
Just AutocompleteState
ac -> do
case AutocompleteState
acAutocompleteState
-> Getting
(Maybe (Int, AutocompleteAlternative))
AutocompleteState
(Maybe (Int, AutocompleteAlternative))
-> Maybe (Int, AutocompleteAlternative)
forall s a. s -> Getting a s a -> a
^.(List Name AutocompleteAlternative
-> Const
(Maybe (Int, AutocompleteAlternative))
(List Name AutocompleteAlternative))
-> AutocompleteState
-> Const (Maybe (Int, AutocompleteAlternative)) AutocompleteState
Lens' AutocompleteState (List Name AutocompleteAlternative)
acCompletionList((List Name AutocompleteAlternative
-> Const
(Maybe (Int, AutocompleteAlternative))
(List Name AutocompleteAlternative))
-> AutocompleteState
-> Const (Maybe (Int, AutocompleteAlternative)) AutocompleteState)
-> ((Maybe (Int, AutocompleteAlternative)
-> Const
(Maybe (Int, AutocompleteAlternative))
(Maybe (Int, AutocompleteAlternative)))
-> List Name AutocompleteAlternative
-> Const
(Maybe (Int, AutocompleteAlternative))
(List Name AutocompleteAlternative))
-> Getting
(Maybe (Int, AutocompleteAlternative))
AutocompleteState
(Maybe (Int, AutocompleteAlternative))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(List Name AutocompleteAlternative
-> Maybe (Int, AutocompleteAlternative))
-> SimpleGetter
(List Name AutocompleteAlternative)
(Maybe (Int, AutocompleteAlternative))
forall s a. (s -> a) -> SimpleGetter s a
to List Name AutocompleteAlternative
-> Maybe (Int, AutocompleteAlternative)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
L.listSelectedElement of
Maybe (Int, AutocompleteAlternative)
Nothing -> () -> MH ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (Int
_, AutocompleteAlternative
alternative) -> do
let replacement :: Text
replacement = AutocompleteAlternative -> Text
autocompleteAlternativeReplacement AutocompleteAlternative
alternative
maybeEndOfWord :: TextZipper a -> TextZipper a
maybeEndOfWord TextZipper a
z =
if Bool -> (Char -> Bool) -> Maybe Char -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True Char -> Bool
isSpace (TextZipper a -> Maybe Char
forall a. TextZipper a -> Maybe Char
Z.currentChar TextZipper a
z)
then TextZipper a
z
else TextZipper a -> TextZipper a
forall a. GenericTextZipper a => TextZipper a -> TextZipper a
Z.moveWordRight TextZipper a
z
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> TeamState -> Identity TeamState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState)
-> (Editor Text Name -> Identity (Editor Text Name))
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Editor Text Name -> Identity (Editor Text Name))
-> ChatEditState -> Identity ChatEditState
Lens' ChatEditState (Editor Text Name)
cedEditor ((Editor Text Name -> Identity (Editor Text Name))
-> ChatState -> Identity ChatState)
-> (Editor Text Name -> Editor Text Name) -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%=
(TextZipper Text -> TextZipper Text)
-> Editor Text Name -> Editor Text Name
forall t n.
(TextZipper t -> TextZipper t) -> Editor t n -> Editor t n
applyEdit (Char -> TextZipper Text -> TextZipper Text
forall a. Monoid a => Char -> TextZipper a -> TextZipper a
Z.insertChar Char
' ' (TextZipper Text -> TextZipper Text)
-> (TextZipper Text -> TextZipper Text)
-> TextZipper Text
-> TextZipper Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> TextZipper Text -> TextZipper Text
forall a. Monoid a => a -> TextZipper a -> TextZipper a
Z.insertMany Text
replacement (TextZipper Text -> TextZipper Text)
-> (TextZipper Text -> TextZipper Text)
-> TextZipper Text
-> TextZipper Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TextZipper Text -> TextZipper Text
forall a.
(Eq a, GenericTextZipper a) =>
TextZipper a -> TextZipper a
Z.deletePrevWord (TextZipper Text -> TextZipper Text)
-> (TextZipper Text -> TextZipper Text)
-> TextZipper Text
-> TextZipper Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
TextZipper Text -> TextZipper Text
forall a. GenericTextZipper a => TextZipper a -> TextZipper a
maybeEndOfWord)
(TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState
Lens' ChatState TeamState
csCurrentTeam((TeamState -> Identity TeamState)
-> ChatState -> Identity ChatState)
-> ((Bool -> Identity Bool) -> TeamState -> Identity TeamState)
-> (Bool -> Identity Bool)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState
Lens' TeamState ChatEditState
tsEditState((ChatEditState -> Identity ChatEditState)
-> TeamState -> Identity TeamState)
-> ((Bool -> Identity Bool)
-> ChatEditState -> Identity ChatEditState)
-> (Bool -> Identity Bool)
-> TeamState
-> Identity TeamState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Bool -> Identity Bool) -> ChatEditState -> Identity ChatEditState
Lens' ChatEditState Bool
cedJustCompleted ((Bool -> Identity Bool) -> ChatState -> Identity ChatState)
-> Bool -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Bool
True
Bool -> MH () -> MH ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (AutocompleteState
acAutocompleteState -> Getting Int AutocompleteState Int -> Int
forall s a. s -> Getting a s a -> a
^.(List Name AutocompleteAlternative
-> Const Int (List Name AutocompleteAlternative))
-> AutocompleteState -> Const Int AutocompleteState
Lens' AutocompleteState (List Name AutocompleteAlternative)
acCompletionList((List Name AutocompleteAlternative
-> Const Int (List Name AutocompleteAlternative))
-> AutocompleteState -> Const Int AutocompleteState)
-> ((Int -> Const Int Int)
-> List Name AutocompleteAlternative
-> Const Int (List Name AutocompleteAlternative))
-> Getting Int AutocompleteState Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(List Name AutocompleteAlternative
-> Vector AutocompleteAlternative)
-> SimpleGetter
(List Name AutocompleteAlternative)
(Vector AutocompleteAlternative)
forall s a. (s -> a) -> SimpleGetter s a
to List Name AutocompleteAlternative -> Vector AutocompleteAlternative
forall n (t :: * -> *) e. GenericList n t e -> t e
L.listElementsGetting
Int
(List Name AutocompleteAlternative)
(Vector AutocompleteAlternative)
-> ((Int -> Const Int Int)
-> Vector AutocompleteAlternative
-> Const Int (Vector AutocompleteAlternative))
-> (Int -> Const Int Int)
-> List Name AutocompleteAlternative
-> Const Int (List Name AutocompleteAlternative)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Vector AutocompleteAlternative -> Int)
-> SimpleGetter (Vector AutocompleteAlternative) Int
forall s a. (s -> a) -> SimpleGetter s a
to Vector AutocompleteAlternative -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1) MH ()
resetAutocomplete