Advertisement
Guest User

Untitled

a guest
Aug 14th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.24 KB | None | 0 0
  1.  
  2. [<JavaScript>]
  3. let indent (right: bool) (cm: CodeMirror) =
  4.     let startCursor = cm.GetCursor(true)
  5.     let endCursor = cm.GetCursor(false)
  6.     let startLine = cm.GetCursor(true).Line
  7.     let endLine = cm.GetCursor(false).Line
  8.     if startLine = endLine then                    
  9.         let ch = startCursor.Ch        
  10.         if right then
  11.             cm.ReplaceSelection(String.replicate (4 - ch % 4) " ")
  12.         else
  13.             let line = cm.GetLine(startLine)
  14.             let notSpace i = i < 0 || line.[i] <> ' '
  15.             let removeCh =
  16.                 if notSpace (ch - 1) then 0
  17.                 elif notSpace (ch - 2) then 1
  18.                 elif notSpace (ch - 3) then 2
  19.                 elif notSpace (ch - 4) then 3
  20.                 else 4
  21.             if removeCh > 0 then
  22.                 cm.ReplaceRange("", CharCoords(startLine, ch - removeCh), startCursor)
  23.     else
  24.         for i = startLine to endLine do
  25.             cm.IndentLine(i, if right then 4 else -4)
  26.  
  27. [<JavaScript>]
  28. let CodeMirrorOptions () =
  29.     CodeMirror.Options(
  30.         IndentUnit = 4,
  31.         TabSize = 4,
  32.         IndentWithTabs = false,
  33.         ExtraKeys = New [
  34.             "Tab" => indent true
  35.             "Shift-Tab" => indent false
  36.         ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement