Skip to content

Commit 5ccc307

Browse files
authored
Merge pull request #48 from robinvd/master
fix startOfLine and EndOfLine movement commands
2 parents 38dfe3d + a50fe95 commit 5ccc307

File tree

1 file changed

+14
-2
lines changed
  • rasa-ext-vim/src/Rasa/Ext

1 file changed

+14
-2
lines changed

rasa-ext-vim/src/Rasa/Ext/Vim.hs

+14-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Rasa.Ext.Cursors
1111
import Control.Monad
1212
import Control.Lens
1313
import Data.Default
14+
import Data.Maybe (fromMaybe)
1415
import Data.Typeable
1516
import qualified Yi.Rope as Y
1617

@@ -178,8 +179,19 @@ normal _ = return ()
178179

179180
-- | Move cursors to end of the line
180181
endOfLine :: BufAction ()
181-
endOfLine = findNext "\n"
182+
endOfLine = do
183+
txt <- getText
184+
overRanges . map $ overBoth $ coordEndOfLine txt
185+
where
186+
coordEndOfLine :: Y.YiString -> Coord -> Coord
187+
coordEndOfLine txt (Coord row col) = Coord row maxColumn
188+
where
189+
maxColumn :: Int
190+
maxColumn = fromMaybe col (txt ^? asLines . ix row . to Y.length)
182191

183192
-- | Move cursors to start of the line
184193
startOfLine :: BufAction ()
185-
startOfLine = findPrev "\n"
194+
startOfLine = overRanges . map $ overBoth coordStartOfLine
195+
where
196+
coordStartOfLine :: Coord -> Coord
197+
coordStartOfLine (Coord x _) = Coord x 0

0 commit comments

Comments
 (0)