From 9c2d648916f1a62fc429527bae610f71967843ea Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 7 Aug 2017 01:34:00 +0200 Subject: Main: add Yank --- src/Buffer/Motion.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/Buffer') diff --git a/src/Buffer/Motion.hs b/src/Buffer/Motion.hs index 8e59789..b07a45c 100644 --- a/src/Buffer/Motion.hs +++ b/src/Buffer/Motion.hs @@ -78,3 +78,31 @@ move ToEndOfLine _ = gotoEndOfLine -- TODO use count move ToColumn c = gotoColumn c move WordsForward c = wordsForward c move WordsBackward c = wordsBackward c + + +select :: Motion -> Int -> Buffer -> String +select x i b = + if nls' < nls then take (nls - nls') rs' else + if nrs' < nrs then take (nrs - nrs') rs else + "" + where + (ls, rs) = b + (ls', rs') = move x i b + nls = length ls + nls' = length ls' + nrs = length rs + nrs' = length rs' + + +delete :: Motion -> Int -> Buffer -> Buffer +delete x i b = + ( if nls' < nls then ls' else ls + , if nrs' < nrs then rs' else rs + ) + where + (ls, rs) = b + (ls', rs')= move x i b + nls = length ls + nls' = length ls' + nrs = length rs + nrs' = length rs' -- cgit v1.2.3