Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't insert extra close bracket when the cursor is already on top of one #2215

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/swarm-tui/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Brick hiding (Direction, Location)
import Brick.Focus
import Brick.Keybindings qualified as B
import Brick.Widgets.Dialog
import Brick.Widgets.Edit (Editor, applyEdit, handleEditorEvent)
import Brick.Widgets.Edit (Editor, applyEdit, editContentsL, handleEditorEvent)
import Brick.Widgets.List (handleListEvent)
import Brick.Widgets.List qualified as BL
import Brick.Widgets.TabularList.Mixed
Expand Down Expand Up @@ -669,7 +669,9 @@ handleREPLEventTyping = \case
-- finally if none match pass the event to the editor
ev -> do
Brick.zoom (uiState . uiGameplay . uiREPL . replPromptEditor) $ case ev of
CharKey c | c `elem` ("([{" :: String) -> insertMatchingPair c
CharKey c
| c `elem` ("([{" :: String) -> insertMatchingPair c
| c `elem` (")]}" :: String) -> insertOrMovePast c
_ -> handleEditorEvent ev
uiState . uiGameplay . uiREPL . replPromptType %= \case
CmdPrompt _ -> CmdPrompt [] -- reset completions on any event passed to editor
Expand All @@ -685,6 +687,16 @@ insertMatchingPair c = modify . applyEdit $ TZ.insertChar c >>> TZ.insertChar (c
'{' -> '}'
_ -> c

-- | Insert a character in an editor unless it matches the character
-- already at the cursor, in which case we just move past it
-- instead, without inserting an extra copy.
insertOrMovePast :: Char -> EventM Name (Editor Text Name) ()
insertOrMovePast c = do
e <- get
modify . applyEdit $ case TZ.currentChar (e ^. editContentsL) of
Just c' | c' == c -> TZ.moveRight
_ -> TZ.insertChar c

data CompletionType
= FunctionName
| EntityName
Expand Down