Skip to content

Commit

Permalink
don't show the scratch when in the command line window
Browse files Browse the repository at this point in the history
  • Loading branch information
tek committed Jan 12, 2024
1 parent fb84292 commit 7f68045
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/uracil/lib/Uracil/Data/Paste.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ data Paste =
ident :: Ident,
index :: Int,
updated :: Chronos.Time,
scratch :: ScratchId,
scratch :: Maybe ScratchId,
visual :: Bool
}
deriving stock (Eq, Show)
14 changes: 10 additions & 4 deletions packages/uracil/lib/Uracil/Paste.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Ribosome (
pluginLogReports,
resumeReport,
)
import Ribosome.Api (normal, redraw, undo, unnamedRegister, vimGetOption, visualModeActive)
import Ribosome.Api (normal, redraw, undo, unnamedRegister, vimGetOption, visualModeActive, nvimCallFunction)
import Ribosome.Register (Register, registerRepr)
import qualified Ribosome.Register as Register (Register (..))
import qualified Ribosome.Scratch as Scratch
Expand Down Expand Up @@ -195,6 +195,12 @@ logPaste update index visual yank =
visualT =
if visual then "visual" else "normal"

inCommandLineWindow ::
Member Rpc r =>
Sem r Bool
inCommandLineWindow =
(/= "") <$> nvimCallFunction @Text "getcmdwintype" []

insertPaste ::
Members [Scratch, AtomicState Env, Stop YankError, Stop Report, Log, ChronosTime, Async, Input Ident] r =>
Members [Settings !! SettingError, Settings, Rpc] r =>
Expand All @@ -207,11 +213,11 @@ insertPaste isUpdate paster index = do
yank <- yankByIndex index
logPaste isUpdate index visual yank
paster yank
scratch <- ensureYankScratch
scratch <- ifM inCommandLineWindow (pure Nothing) ensureYankScratch
updated <- Time.now
ident <- input
atomicModify' (#paste ?~ Paste ident index updated scratch.id visual)
selectYankInScratch scratch index
atomicModify' (#paste ?~ Paste ident index updated ((.id) <$> scratch) visual)
traverse_ (selectYankInScratch index) scratch
redraw
void (async (waitAndCancelPaste ident))

Expand Down
20 changes: 14 additions & 6 deletions packages/uracil/lib/Uracil/YankScratch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import qualified Ribosome.Scratch as Scratch
import qualified Uracil.Data.Env as Env
import Uracil.Data.Env (Env)
import qualified Uracil.Data.Paste as Paste
import Uracil.Data.Paste (Paste (Paste))
import qualified Uracil.Data.Yank as Yank (content)
import qualified Uracil.Data.YankError as YankError (YankError (EmptyHistory))
import Uracil.Data.YankError (YankError)
Expand Down Expand Up @@ -109,18 +110,25 @@ showYankScratch = do

selectYankInScratch ::
Member Rpc r =>
ScratchState ->
Int ->
ScratchState ->
Sem r ()
selectYankInScratch scr line =
selectYankInScratch line scr =
setLine (scr ^. #window) line *> moveSign line

ensureYankScratch ::
Members [Rpc, Scratch, AtomicState Env, Stop YankError, Stop Report] r =>
Sem r ScratchState
ensureYankScratch = do
existing <- fmap join . traverse (Scratch.find . (.scratch)) =<< atomicGets (.paste)
maybe showYankScratch pure existing
Sem r (Maybe ScratchState)
ensureYankScratch =
atomicGets (.paste) >>= \case
Just Paste {scratch = Just prev} -> do
check =<< Scratch.find prev
Just Paste {scratch = Nothing} ->
pure Nothing
Nothing ->
Just <$> showYankScratch
where
check = fmap Just . fromMaybeA showYankScratch

deleteYankScratch ::
Member Scratch r =>
Expand Down

0 comments on commit 7f68045

Please sign in to comment.