Permalink
Browse files

Improved Vim Km block insert/append, with tests.

  • Loading branch information...
rgoulter committed Jul 15, 2014
1 parent 63cefe0 commit caa06cadbdbd140dc837e042c89a972323386671
@@ -756,10 +756,32 @@ leftEdgesOfRegionB Block reg = savingPointB $ do
p <- pointB
eol <- atEol
return (if not eol then Just p else Nothing)
+leftEdgesOfRegionB LineWise reg = savingPointB $ do
+ lastSol <- do
+ moveTo $ regionEnd reg
+ moveToSol
+ pointB
+ let go acc p = do moveTo p
+ moveToSol
+ edge <- pointB
+ if edge >= lastSol
+ then return $ reverse (edge:acc)
+ else do
+ void $ lineMoveRel 1
+ go (edge:acc) =<< pointB
+ go [] (regionStart reg)
leftEdgesOfRegionB _ r = return [regionStart r]
rightEdgesOfRegionB :: RegionStyle -> Region -> BufferM [Point]
--- rightEdgesOfRegionB Block reg = return [regionEnd reg]
+rightEdgesOfRegionB Block reg = savingPointB $ do
+ (l0, _) <- getLineAndColOfPoint $ regionStart reg
+ (l1, _) <- getLineAndColOfPoint $ regionEnd reg
+ moveTo $ 1 + regionEnd reg
+ fmap (reverse . catMaybes) $ forM [0 .. abs (l0 - l1)] $ \i -> savingPointB $ do
+ void $ lineMoveRel $ -i
+ p <- pointB
+ eol <- atEol
+ return (if not eol then Just p else Nothing)
rightEdgesOfRegionB LineWise reg = savingPointB $ do
lastEol <- do
moveTo $ regionEnd reg
@@ -768,8 +790,8 @@ rightEdgesOfRegionB LineWise reg = savingPointB $ do
let go acc p = do moveTo p
moveToEol
edge <- pointB
- if edge > lastEol
- then return $ reverse acc
+ if edge >= lastEol
+ then return $ reverse (edge:acc)
else do
void $ lineMoveRel 1
go (edge:acc) =<< pointB
@@ -0,0 +1,12 @@
+-- Input
+(1,1)
+averyverylongline
+shortline
+
+-- Output
+(1,6)
+averybverylongline
+shortbline
+
+-- Events
+<C-v>j4lAb<Esc>
@@ -0,0 +1,10 @@
+-- Input
+(1,1)
+abc
+def
+-- Output
+(1,3)
+123abc
+123def
+-- Events
+VjI123<Esc>
@@ -0,0 +1,10 @@
+-- Input
+(1,1)
+abc
+def
+-- Output
+(1,3)
+123abc
+123def
+-- Events
+<C-v>jI123<Esc>

0 comments on commit caa06ca

Please sign in to comment.