Merge branch 'dev' into web-workers

This commit is contained in:
Nathan Sobo
2013-01-27 18:53:59 -07:00
43 changed files with 635 additions and 92 deletions

View File

@@ -16,7 +16,7 @@ class AtomPackage extends Package
@loadMetadata()
@loadKeymaps()
@loadStylesheets() if @autoloadStylesheets
rootView.activatePackage(@name, this) unless @isDirectory
rootView?.activatePackage(@name, this) unless @isDirectory
catch e
console.warn "Failed to load package named '#{@name}'", e.stack
this

View File

@@ -1,4 +1,5 @@
Range = require 'range'
_ = require 'underscore'
module.exports =
class BufferChangeOperation
@@ -8,7 +9,8 @@ class BufferChangeOperation
newRange: null
newText: null
constructor: ({@buffer, @oldRange, @newText}) ->
constructor: ({@buffer, @oldRange, @newText, @options}) ->
@options ?= {}
do: ->
@oldText = @buffer.getTextInRange(@oldRange)
@@ -26,18 +28,39 @@ class BufferChangeOperation
oldText: @newText
newText: @oldText
splitLines: (text) ->
lines = text.split('\n')
lineEndings = []
for line, index in lines
if _.endsWith(line, '\r')
lines[index] = line[0..-2]
lineEndings[index] = '\r\n'
else
lineEndings[index] = '\n'
{lines, lineEndings}
changeBuffer: ({ oldRange, newRange, newText, oldText }) ->
{ prefix, suffix } = @buffer.prefixAndSuffixForRange(oldRange)
newTextLines = newText.split('\n')
if newTextLines.length == 1
newTextLines = [prefix + newText + suffix]
else
lastLineIndex = newTextLines.length - 1
newTextLines[0] = prefix + newTextLines[0]
newTextLines[lastLineIndex] += suffix
{lines, lineEndings} = @splitLines(newText)
lastLineIndex = lines.length - 1
@buffer.replaceLines(oldRange.start.row, oldRange.end.row, newTextLines)
if lines.length == 1
lines = [prefix + newText + suffix]
else
lines[0] = prefix + lines[0]
lines[lastLineIndex] += suffix
startRow = oldRange.start.row
endRow = oldRange.end.row
normalizeLineEndings = @options.normalizeLineEndings ? true
if normalizeLineEndings and suggestedLineEnding = @buffer.suggestedLineEndingForRow(startRow)
lineEndings[index] = suggestedLineEnding for index in [0..lastLineIndex]
@buffer.lines[startRow..endRow] = lines
@buffer.lineEndings[startRow..endRow] = lineEndings
@buffer.cachedMemoryContents = null
@buffer.conflict = false if @buffer.conflict and !@buffer.isModified()
event = { oldRange, newRange, oldText, newText }
@buffer.trigger 'changed', event
@@ -47,11 +70,11 @@ class BufferChangeOperation
calculateNewRange: (oldRange, newText) ->
newRange = new Range(oldRange.start.copy(), oldRange.start.copy())
newTextLines = newText.split('\n')
if newTextLines.length == 1
{lines} = @splitLines(newText)
if lines.length == 1
newRange.end.column += newText.length
else
lastLineIndex = newTextLines.length - 1
lastLineIndex = lines.length - 1
newRange.end.row += lastLineIndex
newRange.end.column = newTextLines[lastLineIndex].length
newRange.end.column = lines[lastLineIndex].length
newRange

View File

@@ -19,6 +19,7 @@ class Buffer
cachedMemoryContents: null
conflict: false
lines: null
lineEndings: null
file: null
anchors: null
anchorRanges: null
@@ -29,6 +30,7 @@ class Buffer
@anchors = []
@anchorRanges = []
@lines = ['']
@lineEndings = []
if path
throw "Path '#{path}' does not exist" unless fs.exists(path)
@@ -104,10 +106,10 @@ class Buffer
null
getText: ->
@cachedMemoryContents ?= @lines.join('\n')
@cachedMemoryContents ?= @getTextInRange(@getRange())
setText: (text) ->
@change(@getRange(), text)
@change(@getRange(), text, normalizeLineEndings: false)
getRange: ->
new Range([0, 0], [@getLastRow(), @getLastLine().length])
@@ -118,12 +120,14 @@ class Buffer
return @lines[range.start.row][range.start.column...range.end.column]
multipleLines = []
multipleLines.push @lines[range.start.row][range.start.column..] # first line
multipleLines.push @lineForRow(range.start.row)[range.start.column..] # first line
multipleLines.push @lineEndingForRow(range.start.row)
for row in [range.start.row + 1...range.end.row]
multipleLines.push @lines[row] # middle lines
multipleLines.push @lines[range.end.row][0...range.end.column] # last line
multipleLines.push @lineForRow(row) # middle lines
multipleLines.push @lineEndingForRow(row)
multipleLines.push @lineForRow(range.end.row)[0...range.end.column] # last line
return multipleLines.join '\n'
return multipleLines.join ''
getLines: ->
@lines
@@ -131,6 +135,12 @@ class Buffer
lineForRow: (row) ->
@lines[row]
lineEndingForRow: (row) ->
@lineEndings[row] unless row is @getLastRow()
suggestedLineEndingForRow: (row) ->
@lineEndingForRow(row) ? @lineEndingForRow(row - 1)
lineLengthForRow: (row) ->
@lines[row].length
@@ -195,9 +205,9 @@ class Buffer
delete: (range) ->
@change(range, '')
change: (oldRange, newText) ->
change: (oldRange, newText, options) ->
oldRange = Range.fromObject(oldRange)
operation = new BufferChangeOperation({buffer: this, oldRange, newText})
operation = new BufferChangeOperation({buffer: this, oldRange, newText, options})
range = @pushOperation(operation)
range
@@ -214,11 +224,6 @@ class Buffer
prefix: @lines[range.start.row][0...range.start.column]
suffix: @lines[range.end.row][range.end.column..]
replaceLines: (startRow, endRow, newLines) ->
@lines[startRow..endRow] = newLines
@cachedMemoryContents = null
@conflict = false if @conflict and !@isModified()
pushOperation: (operation, editSession) ->
if @undoManager
@undoManager.pushOperation(operation, editSession)

View File

@@ -1,4 +1,5 @@
AtomPackage = require 'atom-package'
_ = require 'underscore'
module.exports =
class DeferredAtomPackage extends AtomPackage
@@ -10,8 +11,13 @@ class DeferredAtomPackage extends AtomPackage
activate: (@rootView, @state) ->
@instance = null
for event in @loadEvents
@rootView.command event, (e) => @onLoadEvent(e, @getInstance())
onLoadEvent = (e) => @onLoadEvent(e, @getInstance())
if _.isArray(@loadEvents)
for event in @loadEvents
@rootView.command(event, onLoadEvent)
else
for event, selector of @loadEvents
@rootView.command(event, selector, onLoadEvent)
this
deactivate: -> @instance?.deactivate?()

View File

@@ -182,6 +182,7 @@ class Editor extends View
'editor:close-other-edit-sessions': @destroyInactiveEditSessions
'editor:close-all-edit-sessions': @destroyAllEditSessions
'editor:select-grammar': @selectGrammar
'editor:copy-path': @copyPathToPasteboard
documentation = {}
for name, method of editorBindings
@@ -310,9 +311,10 @@ class Editor extends View
setInvisibles: (@invisibles={}) ->
_.defaults @invisibles,
eol: '\u00ac',
space: '\u2022',
eol: '\u00ac'
space: '\u2022'
tab: '\u00bb'
cr: '\u00a4'
@resetDisplay()
checkoutHead: -> @getBuffer().checkoutHead()
@@ -1079,8 +1081,11 @@ class Editor extends View
position += token.value.length
popScope() while scopeStack.length > 0
if not @mini and invisibles?.eol
line.push("<span class='invisible'>#{invisibles.eol}</span>")
if invisibles and not @mini
if invisibles.cr and screenLine.lineEnding is '\r\n'
line.push("<span class='invisible'>#{invisibles.cr}</span>")
if invisibles.eol
line.push("<span class='invisible'>#{invisibles.eol}</span>")
line.push('</pre>')
line.join('')
@@ -1159,3 +1164,7 @@ class Editor extends View
@insertText(text, select: true)
true
copyPathToPasteboard: ->
path = @getPath()
pasteboard.write(path) if path?

View File

@@ -27,6 +27,7 @@
'meta-+': 'window:increase-font-size'
'meta--': 'window:decrease-font-size'
'ctrl-w w': 'window:focus-next-pane'
'ctrl-tab': 'window:focus-next-pane'
'alt-meta-i': 'toggle-dev-tools'

View File

@@ -36,4 +36,5 @@
'meta-U': 'editor:lower-case'
'alt-meta-w': 'editor:close-other-edit-sessions'
'meta-P': 'editor:close-all-edit-sessions'
'meta-l': 'editor:select-grammar'
'meta-L': 'editor:select-grammar'
'ctrl-C': 'editor:copy-path'

View File

@@ -18,7 +18,7 @@ class RootView extends View
disabledPackages: []
@content: ->
@div id: 'root-view', tabindex: -1, =>
@div id: 'root-view', tabindex: 0, =>
@div id: 'horizontal', outlet: 'horizontal', =>
@div id: 'vertical', outlet: 'vertical', =>
@div id: 'panes', outlet: 'panes'

View File

@@ -2,7 +2,7 @@ _ = require 'underscore'
module.exports =
class ScreenLine
constructor: ({tokens, @ruleStack, @bufferRows, @startBufferColumn, @fold, tabLength}) ->
constructor: ({tokens, @lineEnding, @ruleStack, @bufferRows, @startBufferColumn, @fold, tabLength}) ->
@tokens = @breakOutAtomicTokens(tokens, tabLength)
@bufferRows ?= 1
@startBufferColumn ?= 0

View File

@@ -26,6 +26,12 @@ class SelectList extends View
@miniEditor.on 'focusout', => @cancel() unless @cancelling
@on 'core:move-up', => @selectPreviousItem()
@on 'core:move-down', => @selectNextItem()
@on 'core:move-to-top', =>
@selectItem(@list.find('li:first'))
@list.scrollToTop()
@on 'core:move-to-bottom', =>
@selectItem(@list.find('li:last'))
@list.scrollToBottom()
@on 'core:confirm', => @confirmSelection()
@on 'core:cancel', => @cancel()
@@ -62,6 +68,8 @@ class SelectList extends View
@loading.text(message).show()
populateList: ->
return unless @array?
filterQuery = @miniEditor.getText()
if filterQuery.length
filteredArray = fuzzyFilter(@array, filterQuery, key: @filterKey)

View File

@@ -137,8 +137,9 @@ class TokenizedBuffer
buildTokenizedScreenLineForRow: (row, ruleStack) ->
line = @buffer.lineForRow(row)
lineEnding = @buffer.lineEndingForRow(row)
{ tokens, ruleStack } = @languageMode.tokenizeLine(line, ruleStack, row is 0)
new ScreenLine({tokens, ruleStack, @tabLength})
new ScreenLine({tokens, ruleStack, @tabLength, lineEnding})
lineForScreenRow: (row) ->
@linesForScreenRows(row, row)[0]