All specs pass w/ TextMateGrammar for tokenization (auto-indent disabled)

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-03 12:00:05 -06:00
parent 08a55dfcac
commit 1a243adfcf
14 changed files with 68 additions and 34 deletions

View File

@@ -29,7 +29,7 @@ class EditSession
anchorRanges: null
cursors: null
selections: null
autoIndent: true
autoIndent: false # TODO: re-enabled auto-indent after fixing the rest of tokenization
softTabs: true
softWrap: false
@@ -139,10 +139,7 @@ class EditSession
indent: ->
currentRow = @getCursorBufferPosition().row
if @getSelection().isEmpty()
whitespaceMatch = @lineForBufferRow(currentRow).match /^\s*$/
if @autoIndent and whitespaceMatch
@autoIndentRow(currentRow)
else if @softTabs
if @softTabs
@insertText(@tabText)
else
@insertText('\t')

View File

@@ -800,7 +800,7 @@ class Editor extends View
@raw ' ' if line.text == ''
else
for token in line.tokens
@span { class: token.type.replace('.', ' ') }, token.value
@span { class: token.getCssClassString() }, token.value
insertLineElements: (row, lineElements) ->
@spliceLineElements(row, 0, lineElements)

View File

@@ -10,21 +10,18 @@ ChildProcess = require 'child-process'
module.exports =
class Project
tabText: ' '
autoIndent: false
softTabs: true
softWrap: false
rootDirectory: null
editSessions: null
tabText: null
autoIndent: null
softTabs: null
softWrap: null
ignoredPathRegexes: null
constructor: (path) ->
@setPath(path)
@editSessions = []
@buffers = []
@setTabText(' ')
@setAutoIndent(true)
@setSoftTabs(true)
@ignoredPathRegexes = [
/\.DS_Store$/
/(^|\/)\.git(\/|$)/

View File

@@ -26,7 +26,7 @@ class TextMateBundle
@grammarsByFileType[fileType] = grammar
@grammarForFileName: (fileName) ->
extension = fs.extension(fileName)[1...]
extension = fs.extension(fileName)?[1...]
@grammarsByFileType[extension] or @grammarsByFileType["txt"]
@getPreferenceInScope: (scopeSelector, preferenceName) ->

View File

@@ -98,8 +98,8 @@ class Pattern
regex: null
captures: null
constructor: (@grammar, { name, @include, match, begin, end, captures, beginCaptures, endCaptures, patterns, @popRule}) ->
@scopeName = name
constructor: (@grammar, { name, contentName, @include, match, begin, end, captures, beginCaptures, endCaptures, patterns, @popRule}) ->
@scopeName = name ? contentName # TODO: We need special treatment of contentName
if match
@regex = new OnigRegExp(match)
@captures = captures

View File

@@ -32,3 +32,15 @@ class Token
buildTabToken: (tabText) ->
new Token(value: tabText, scopes: @scopes, bufferDelta: 1, isAtomic: true)
getCssClassString: ->
@cssClassString ?= @getCssClasses().join(' ')
getCssClasses: ->
classes = []
for scope in @scopes
scopeComponents = scope.split('.')
for i in [0...scopeComponents.length]
classes.push scopeComponents[0..i].join('-')
classes

View File

@@ -24,6 +24,7 @@ windowAdditions =
$(document).on 'keydown', @_handleKeyEvent
startup: (path) ->
TextMateBundle.loadAll()
@attachRootView(path)
$(window).on 'close', => @close()
$(window).on 'beforeunload', =>
@@ -31,7 +32,6 @@ windowAdditions =
false
$(window).focus()
atom.windowOpened this
TextMateBundle.loadAll()
shutdown: ->
@rootView.deactivate()