Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

simplify SelectionStyle somewhat

  • Loading branch information...
commit 4954b930ca6ebeb82197b5b8832d00bc60198f07 1 parent a6b23e1
JeanPhilippe.bernardy@gmail.com authored
Showing with 18 additions and 17 deletions.
  1. +10 −11 Yi/Buffer/HighLevel.hs
  2. +8 −6 Yi/Keymap/Vim.hs
View
21 Yi/Buffer/HighLevel.hs
@@ -278,17 +278,17 @@ extendRegionToBoundaries unit bs1 bs2 region = do
stop <- pointB
return $ mkRegion start stop
+unitWiseRegion :: TextUnit -> Region -> BufferM Region
+unitWiseRegion unit = extendRegionToBoundaries unit InsideBound OutsideBound
+
+
-- TODO: either decide this is evil and contain it to Vim, or embrace it and move it to the
-- Buffer record.
-lineWiseRegion :: Region -> BufferM Region
-lineWiseRegion = extendRegionToBoundaries Line InsideBound OutsideBound
-
-data SelectionStyle = LineWiseSelection
- | CharWiseSelection
- deriving (Eq,Typeable,Show)
+newtype SelectionStyle = SelectionStyle TextUnit
+ deriving (Typeable)
instance Initializable SelectionStyle where
- initial = CharWiseSelection
+ initial = SelectionStyle Character
-- | Get the current region boundaries
getSelectRegionB :: BufferM Region
@@ -296,7 +296,6 @@ getSelectRegionB = do
m <- getMarkPointB =<< getSelectionMarkB
p <- pointB
let region = mkRegion m p
- selectionStyle <- getDynamicB
- case selectionStyle of
- LineWiseSelection -> lineWiseRegion region
- CharWiseSelection -> return region
+ SelectionStyle unit <- getDynamicB
+ unitWiseRegion unit region
+
View
14 Yi/Keymap/Vim.hs
@@ -99,13 +99,13 @@ vis_mode :: RegionStyle -> VimMode
vis_mode regionStyle = do
write (withBuffer (pointB >>= setSelectionMarkPointB))
core_vis_mode regionStyle
- write (msgClrE >> withBuffer unsetMarkB >> withBuffer (setDynamicB CharWiseSelection))
+ write (msgClrE >> withBuffer unsetMarkB >> withBuffer (setDynamicB $ SelectionStyle Character))
core_vis_mode :: RegionStyle -> VimMode
core_vis_mode regionStyle = do
write $ withEditor $ do setA regionStyleA regionStyle
- withBuffer0 $ setDynamicB $
- case regionStyle of { LineWise -> LineWiseSelection; CharWise -> CharWiseSelection }
+ withBuffer0 $ setDynamicB $ SelectionStyle $
+ case regionStyle of { LineWise -> Line; CharWise -> Character }
printMsg $ msg regionStyle
many (eval cmd_move)
(vis_single regionStyle <|| vis_multi)
@@ -134,6 +134,10 @@ data RegionStyle = LineWise
instance Initializable RegionStyle where
initial = CharWise
+regionStyleToUnit :: RegionStyle -> TextUnit
+regionStyleToUnit LineWise = Line
+regionStyleToUnit CharWise = Character
+
regionStyleA :: Accessor Editor RegionStyle
regionStyleA = dynamicValueA .> dynamicA
@@ -333,9 +337,7 @@ regionFromTo mstart move regionStyle = do
move
stop <- pointB
let region = mkRegion start stop
- case regionStyle of
- LineWise -> lineWiseRegion region
- CharWise -> return region
+ unitWiseRegion (regionStyleToUnit regionStyle) region
yank :: BufferM Point -> BufferM () -> RegionStyle -> EditorM ()
yank mstart move regionStyle = do
Please sign in to comment.
Something went wrong with that request. Please try again.