@@ -18,8 +18,7 @@ import Control.Monad (forM_, void, when)
18
18
import Data.Char (ord )
19
19
import Data.List (group )
20
20
import Data.Maybe (fromJust , fromMaybe )
21
- import Data.Monoid ((<>) )
22
- import qualified Data.Text as T (unpack , pack , Text )
21
+ import qualified Data.Text as T (unpack )
23
22
import Yi.Buffer hiding (Insert )
24
23
import Yi.Editor
25
24
import Yi.Keymap.Vim.Common
@@ -31,8 +30,7 @@ import Yi.Keymap.Vim.TextObject
31
30
import Yi.Keymap.Vim.Utils (matchFromBool , mkChooseRegisterBinding , mkMotionBinding , addNewLineIfNecessary , pasteInclusiveB )
32
31
import Yi.MiniBuffer (spawnMinibufferE )
33
32
import Yi.Monad (whenM )
34
- import Yi.Region
35
- import qualified Yi.Rope as R (toText , countNewLines , YiString )
33
+ import qualified Yi.Rope as R (toText , countNewLines )
36
34
import Yi.Tag (Tag (Tag ))
37
35
import Yi.Utils (SemiNum ((-~) ))
38
36
@@ -252,10 +250,10 @@ pasteBinding = VimBindingE (f . T.unpack . _unEv)
252
250
253
251
pasteMatch :: RegionStyle -> VisualPaste -> MatchResult (EditorM RepeatToken )
254
252
pasteMatch style p = WholeMatch $ do
255
- register <- getRegisterE . vsActiveRegister =<< getEditorDyn
256
- maybe (pure () ) (paste style p) register
257
- escAction
258
- return Finish
253
+ register <- getRegisterE . vsActiveRegister =<< getEditorDyn
254
+ maybe (pure () ) (paste style p) register
255
+ void escAction
256
+ return Finish
259
257
260
258
paste :: RegionStyle -> VisualPaste -> Register -> EditorM ()
261
259
paste LineWise = linePaste
@@ -265,20 +263,32 @@ pasteBinding = VimBindingE (f . T.unpack . _unEv)
265
263
266
264
linePaste :: VisualPaste -> Register -> EditorM ()
267
265
linePaste p (Register _style rope) = withCurrentBuffer $ do
268
- region <- regionOfSelectionB
269
- when (p == ReplaceSelection ) . void $ deleteRegionWithStyleB region LineWise
270
- insertRopeWithStyleB (addNewLineIfNecessary rope) LineWise
266
+ region <- regionOfSelectionB
267
+ when (p == ReplaceSelection ) . void $ deleteRegionWithStyleB region LineWise
268
+ insertRopeWithStyleB (addNewLineIfNecessary rope) LineWise
271
269
272
270
blockPaste :: VisualPaste -> Register -> EditorM ()
273
- blockPaste p (Register _style rope) =
274
- withCurrentBuffer $ do
271
+ blockPaste p (Register _style rope) = withCurrentBuffer $ do
275
272
here <- pointB
276
273
there <- getSelectionMarkPointB
277
274
(here', there') <- flipRectangleB here there
278
275
reg <- regionOfSelectionB
279
- when (p == ReplaceSelection ) . void $ deleteRegionWithStyleB reg Block
280
276
moveTo (minimum [here, there, here', there'])
281
- pasteInclusiveB rope _style
277
+ when (p == ReplaceSelection ) . void $ deleteRegionWithStyleB reg Block
278
+ if R. countNewLines rope == 0
279
+ then actionOnLeft reg $ maybe (pure () ) (\ _ -> insertRopeWithStyleB rope _style)
280
+ else pasteInclusiveB rope _style
281
+ where
282
+ -- Taken from deleteRegionWithStyleB
283
+ actionOnLeft :: Region -> (Maybe Point -> BufferM () ) -> BufferM ()
284
+ actionOnLeft reg action = savingPointB $ do
285
+ (start, lengths) <- shapeOfBlockRegionB reg
286
+ moveTo start
287
+ forM_ (zip [0 .. ] lengths) $ \ (i, l) -> do
288
+ p' <- pointB
289
+ moveTo start
290
+ void $ lineMoveRel i
291
+ action (if l == 0 then Nothing else Just p')
282
292
283
293
otherPaste :: VisualPaste -> Register -> EditorM ()
284
294
otherPaste _ (Register _style rope) = withCurrentBuffer $ do
0 commit comments