detect indentation, tabs vs spaces

This commit is contained in:
Chris Wanstrath
2011-09-08 00:37:40 -07:00
parent 10d02d966b
commit c3dc1cc3eb

View File

@@ -105,8 +105,18 @@ class Editor extends Pane
newSession: (code) ->
doc = new EditSession code or ''
doc.setUndoManager new UndoManager
doc.setUseSoftTabs useSoftTabs = @usesSoftTabs code
doc.setTabSize if useSoftTabs then @guessTabSize code else 8
doc
usesSoftTabs: (code) ->
not /^\t/m.test code or @code()
guessTabSize: (code) ->
# * ignores indentation of css/js block comments
match = /^( +)[^*]/im.exec code || @code()
match?[1].length or 2
copy: ->
editor = @ace
text = editor.getSession().doc.getTextRange editor.getSelectionRange()