Skip to content

Commit

Permalink
Fix eolPoint' manouvers
Browse files Browse the repository at this point in the history
Fixes #667 and probably #662 (needs vimtests) and maybe even more.
  • Loading branch information
Fuuzetsu committed Oct 24, 2014
1 parent 79641be commit ec4e3a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -3,6 +3,7 @@

* Try to guess and preserve the file encoding (#638)
* Restore cursor position better after deleteTrailingSpacesB (#666)
* Fix eolPoint' when on last, empty line (#667)

0.10.0
------
Expand Down
29 changes: 17 additions & 12 deletions yi/src/library/Yi/Buffer/Implementation.hs
Expand Up @@ -39,7 +39,6 @@ module Yi.Buffer.Implementation
, newBI
, solPoint
, solPoint'
, eolPoint
, eolPoint'
, charsFromSolBI
, regexRegionBI
Expand Down Expand Up @@ -347,23 +346,29 @@ solPoint line fb = Point $ R.length $ fst $ R.splitAtLine (line - 1) (mem fb)
-- | Point that's at EOL. Notably, this puts you right before the
-- newline character if one exists, and right at the end of the text
-- if one does not.
eolPoint :: Int -- ^ Line for which to grab EOL for
-> BufferImpl syntax -> Point
eolPoint l = Point . checkEol . fst . R.splitAtLine l . mem
eolPoint :: Point
-- ^ Point from which we take the line to find the EOL of
-> BufferImpl syntax
-> Point
eolPoint' p@(Point ofs) fb = Point . checkEol . fst . R.splitAtLine ln $ mem fb
where
-- In case we're somewhere without trailing newline, we need to stay where we are
checkEol t = let l' = R.length t in case R.last t of
Just '\n' -> l' - 1
_ -> l'
ln = lineAt p fb
-- In case we're somewhere without trailing newline, we need to
-- stay where we are
checkEol t =
let l' = R.length t
in case R.last t of
-- We're looking at EOL and we weren't asking for EOL past
-- this point, so back up one for good visual effect
Just '\n' | l' > ofs -> l' - 1
-- We asked for EOL past the last newline so just go to the
-- very end of content
_ -> l'

-- | Get begining of the line relatively to @point@.
solPoint' :: Point -> BufferImpl syntax -> Point
solPoint' point fb = solPoint (lineAt point fb) fb

-- | Get end of the line relative to the point.
eolPoint' :: Point -> BufferImpl s -> Point
eolPoint' p fb = eolPoint (lineAt p fb) fb

charsFromSolBI :: Point -> BufferImpl syntax -> YiString
charsFromSolBI pnt fb = nelemsBI (fromIntegral $ pnt - sol) sol fb
where sol = solPoint' pnt fb
Expand Down
6 changes: 3 additions & 3 deletions yi/src/library/Yi/Buffer/TextUnit.hs
Expand Up @@ -314,9 +314,9 @@ genMoveB Document _ Forward = moveTo =<< sizeB
genMoveB Document _ Backward = moveTo 0 -- impossible to go outside beginning of doc.
genMoveB Character _ Forward = rightB
genMoveB Character _ Backward = leftB
genMoveB VLine _ Forward =
do ofs <- lineMoveRel 1
when (ofs < 1) (maybeMoveB Line Forward)
genMoveB VLine _ Forward = do
ofs <- lineMoveRel 1
when (ofs < 1) (maybeMoveB Line Forward)
genMoveB VLine _ Backward = lineUp
genMoveB unit (boundDir, boundSide) moveDir =
doUntilB_ (genAtBoundaryB unit boundDir boundSide) (moveB Character moveDir)
Expand Down

0 comments on commit ec4e3a8

Please sign in to comment.