-- Copyright (c) 2008 Jean-Philippe BernardymoduleYi.Keymap.Cua(keymap,portableKeymap,cut,paste,copy,del)whereimportPrelude(length,take,drop)importYi.CoreimportYi.FileimportYi.Keymap.Emacs.UtilsimportYi.Misc(adjBlock)importYi.RectangleimportYi.Stringkeymap::KeymapSetkeymap=portableKeymapctrl-- | Introduce a keymap that is compatible with both windows and osx,-- by parameterising the event modifier required for commandsportableKeymap::(Event->Event)->KeymapSetportableKeymapcmd=modelessKeymapSet$selfInsertKeymap<|>move<|>select<|>rect<|>othercmdselfInsertKeymap::KeymapselfInsertKeymap=doc<-printableCharwrite(withBuffer0$replaceSel[c])setMark::Bool->BufferM()setMarkb=doisSet<-getAhighlightSelectionAputArectangleSelectionAbwhen(notisSet)$doputAhighlightSelectionATruepointB>>=setSelectionMarkPointBunsetMark::BufferM()unsetMark=putAhighlightSelectionAFalsereplaceSel::String->BufferM()replaceSels=dohasSel<-getAhighlightSelectionAifhasSelthengetSelectRegionB>>=flipreplaceRegionBselsedowhen(lengths==1)(adjBlock1)insertNsdeleteSel::BufferM()->YiM()deleteSelact=dohaveSelection<-withBuffer$getAhighlightSelectionAifhaveSelectionthenwithEditordelelsewithBuffer(adjBlock(-1)>>act)cut,del,copy,paste::EditorM()cut=copy>>deldel=doasRect<-withBuffer0$getArectangleSelectionAifasRectthenkillRectangleelsewithBuffer0$deleteRegionB=<<getSelectRegionBcopy=do(setRegE=<<)$withBuffer0$doasRect<-getArectangleSelectionAifnotasRectthenreadRegionB=<<getSelectRegionBelsedo(reg,l,r)<-getRectangleunlines'<$>fmap(take(r-l).dropl)<$>lines'<$>readRegionBregpaste=doasRect<-withBuffer0(getArectangleSelectionA)ifasRectthenyankRectangleelsewithBuffer0.replaceSel=<<getRegEmoveKeys::[(Event,BufferM())]moveKeys=[(specKHome,maybeMoveBLineBackward),(specKEnd,maybeMoveBLineForward),(super(specKRight),maybeMoveBLineForward),(super(specKLeft),maybeMoveBLineBackward),(ctrl(specKHome),maybeMoveBDocumentBackward),(ctrl(specKEnd),maybeMoveBDocumentForward),(super(specKUp),maybeMoveBDocumentBackward),(super(specKDown),maybeMoveBDocumentForward),(ctrl(specKRight),moveBunitWordForward),(ctrl(specKLeft),moveBunitWordBackward),(specKUp,moveBVLineBackward),(specKDown,moveBVLineForward),(specKRight,moveBCharacterForward),(specKLeft,moveBCharacterBackward)]move,select,rect::Keymapother::(Event->Event)->Keymapmove=choice[k?>>!unsetMark>>a|(k,a)<-moveKeys]select=choice[shiftk?>>!setMarkFalse>>a|(k,a)<-moveKeys]rect=choice[meta(shiftk)?>>!setMarkTrue>>a|(k,a)<-moveKeys]othercmd=choice[specKBS?>>!deleteSelbdeleteB,specKDel?>>!deleteSel(deleteN1),specKEnter?>>!replaceSel"\n",cmd(char'q')?>>!askQuitEditor,cmd(char'f')?>>isearchKeymapForward,cmd(char'x')?>>!cut,cmd(char'c')?>>!copy,cmd(char'v')?>>!paste,cmd(specKIns)?>>!copy,shift(specKIns)?>>!paste,cmd(char'z')?>>!undoB,cmd(char'y')?>>!redoB,cmd(char's')?>>!fwriteE,cmd(char'o')?>>!findFile,cmd(char'/')?>>!withModeBmodeToggleCommentSelection,cmd(char']')?>>!autoIndentBIncreaseOnly,cmd(char'[')?>>!autoIndentBDecreaseOnly]