mirror of
https://github.com/atom/atom.git
synced 2026-02-09 14:15:24 -05:00
Merge branch 'snippets'
Conflicts: src/app/root-view.coffee
This commit is contained in:
24
src/app/anchor-range.coffee
Normal file
24
src/app/anchor-range.coffee
Normal file
@@ -0,0 +1,24 @@
|
||||
Range = require 'range'
|
||||
|
||||
module.exports =
|
||||
class AnchorRange
|
||||
start: null
|
||||
end: null
|
||||
|
||||
constructor: (@editSession, bufferRange) ->
|
||||
bufferRange = Range.fromObject(bufferRange)
|
||||
@startAnchor = @editSession.addAnchorAtBufferPosition(bufferRange.start, ignoreEqual: true)
|
||||
@endAnchor = @editSession.addAnchorAtBufferPosition(bufferRange.end)
|
||||
|
||||
getBufferRange: ->
|
||||
new Range(@startAnchor.getBufferPosition(), @endAnchor.getBufferPosition())
|
||||
|
||||
getScreenRange: ->
|
||||
new Range(@startAnchor.getScreenPosition(), @endAnchor.getScreenPosition())
|
||||
|
||||
containsBufferPosition: (bufferPosition) ->
|
||||
@getBufferRange().containsPoint(bufferPosition)
|
||||
|
||||
destroy: ->
|
||||
@startAnchor.destroy()
|
||||
@endAnchor.destroy()
|
||||
@@ -8,12 +8,17 @@ class Anchor
|
||||
bufferPosition: null
|
||||
screenPosition: null
|
||||
|
||||
constructor: (@editSession) ->
|
||||
constructor: (@editSession, options = {}) ->
|
||||
{ @ignoreEqual } = options
|
||||
|
||||
handleBufferChange: (e) ->
|
||||
{ oldRange, newRange } = e
|
||||
position = @getBufferPosition()
|
||||
return if position.isLessThan(oldRange.end)
|
||||
|
||||
if @ignoreEqual
|
||||
return if position.isLessThanOrEqual(oldRange.end)
|
||||
else
|
||||
return if position.isLessThan(oldRange.end)
|
||||
|
||||
newRow = newRange.end.row
|
||||
newColumn = newRange.end.column
|
||||
@@ -56,4 +61,7 @@ class Anchor
|
||||
screenPosition = @editSession.screenPositionForBufferPosition(@bufferPosition, options)
|
||||
@setScreenPosition(screenPosition, bufferChange: options.bufferChange, clip: false, assignBufferPosition: false)
|
||||
|
||||
destroy: ->
|
||||
@editSession.removeAnchor(this)
|
||||
|
||||
_.extend(Anchor.prototype, EventEmitter)
|
||||
|
||||
@@ -9,13 +9,15 @@ module.exports =
|
||||
class Atom
|
||||
keymap: null
|
||||
windows: null
|
||||
userConfigurationPath: null
|
||||
configFilePath: null
|
||||
configDirPath: null
|
||||
rootViewStates: null
|
||||
|
||||
constructor: (@loadPath, nativeMethods) ->
|
||||
@windows = []
|
||||
@setUpKeymap()
|
||||
@userConfigurationPath = fs.absolute "~/.atom/atom.coffee"
|
||||
@configDirPath = fs.absolute("~/.atom")
|
||||
@configFilePath = fs.join(@configDirPath, "atom.coffee")
|
||||
@rootViewStates = {}
|
||||
|
||||
setUpKeymap: ->
|
||||
|
||||
@@ -12,7 +12,7 @@ class BindingSet
|
||||
commandForEvent: null
|
||||
parser: null
|
||||
|
||||
constructor: (@selector, mapOrFunction) ->
|
||||
constructor: (@selector, mapOrFunction, @index) ->
|
||||
@parser = PEG.buildParser(fs.read(require.resolve 'keystroke-pattern.pegjs'))
|
||||
@specificity = Specificity(@selector)
|
||||
@commandsByKeystrokes = {}
|
||||
|
||||
@@ -26,6 +26,12 @@ class Buffer
|
||||
getPath: ->
|
||||
@path
|
||||
|
||||
getExtension: ->
|
||||
if @getPath()
|
||||
@getPath().split('/').pop().split('.').pop()
|
||||
else
|
||||
null
|
||||
|
||||
setPath: (path) ->
|
||||
@path = path
|
||||
@trigger "path-change", this
|
||||
|
||||
@@ -150,6 +150,9 @@ class Cursor
|
||||
getCurrentLineBufferRange: ->
|
||||
@editSession.bufferRangeForBufferRow(@getBufferRow())
|
||||
|
||||
getCurrentWordPrefix: ->
|
||||
@editSession.getTextInBufferRange([@getBeginningOfCurrentWordBufferPosition(), @getBufferPosition()])
|
||||
|
||||
isAtBeginningOfLine: ->
|
||||
@getBufferPosition().column == 0
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ DisplayBuffer = require 'display-buffer'
|
||||
Cursor = require 'cursor'
|
||||
Selection = require 'selection'
|
||||
EventEmitter = require 'event-emitter'
|
||||
AnchorRange = require 'anchor-range'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
@@ -22,6 +23,7 @@ class EditSession
|
||||
scrollLeft: 0
|
||||
displayBuffer: null
|
||||
anchors: null
|
||||
anchorRanges: null
|
||||
cursors: null
|
||||
selections: null
|
||||
autoIndent: true
|
||||
@@ -34,6 +36,7 @@ class EditSession
|
||||
@displayBuffer = new DisplayBuffer(@buffer, { @tabText })
|
||||
@tokenizedBuffer = @displayBuffer.tokenizedBuffer
|
||||
@anchors = []
|
||||
@anchorRanges = []
|
||||
@cursors = []
|
||||
@selections = []
|
||||
@addCursorAtScreenPosition([0, 0])
|
||||
@@ -234,11 +237,21 @@ class EditSession
|
||||
getAnchors: ->
|
||||
new Array(@anchors...)
|
||||
|
||||
addAnchor: ->
|
||||
anchor = new Anchor(this)
|
||||
addAnchor: (options) ->
|
||||
anchor = new Anchor(this, options)
|
||||
@anchors.push(anchor)
|
||||
anchor
|
||||
|
||||
addAnchorAtBufferPosition: (bufferPosition, options) ->
|
||||
anchor = @addAnchor(options)
|
||||
anchor.setBufferPosition(bufferPosition)
|
||||
anchor
|
||||
|
||||
addAnchorRange: (range) ->
|
||||
anchorRange = new AnchorRange(this, range)
|
||||
@anchorRanges.push(anchorRange)
|
||||
anchorRange
|
||||
|
||||
removeAnchor: (anchor) ->
|
||||
_.remove(@anchors, anchor)
|
||||
|
||||
@@ -342,6 +355,9 @@ class EditSession
|
||||
getSelectedText: ->
|
||||
@getLastSelection().getText()
|
||||
|
||||
getTextInBufferRange: (range) ->
|
||||
@buffer.getTextInRange(range)
|
||||
|
||||
moveCursorUp: ->
|
||||
@moveCursors (cursor) -> cursor.moveUp()
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ class Editor extends View
|
||||
getSelectionsOrderedByBufferPosition: -> @activeEditSession.getSelectionsOrderedByBufferPosition()
|
||||
getLastSelectionInBuffer: -> @activeEditSession.getLastSelectionInBuffer()
|
||||
getSelectedText: -> @activeEditSession.getSelectedText()
|
||||
getSelectedBufferRange: -> @activeEditSession.getSelectedBufferRange()
|
||||
setSelectedBufferRange: (bufferRange, options) -> @activeEditSession.setSelectedBufferRange(bufferRange, options)
|
||||
setSelectedBufferRanges: (bufferRanges, options) -> @activeEditSession.setSelectedBufferRanges(bufferRanges, options)
|
||||
addSelectionForBufferRange: (bufferRange, options) -> @activeEditSession.addSelectionForBufferRange(bufferRange, options)
|
||||
|
||||
@@ -20,21 +20,21 @@ class Keymap
|
||||
'meta-o': 'open'
|
||||
|
||||
$(document).on 'new-window', => $native.newWindow()
|
||||
$(document).on 'open-user-configuration', => atom.open(atom.userConfigurationPath)
|
||||
$(document).on 'open-user-configuration', => atom.open(atom.configFilePath)
|
||||
$(document).on 'open', =>
|
||||
path = $native.openDialog()
|
||||
atom.open(path) if path
|
||||
|
||||
bindKeys: (selector, bindings) ->
|
||||
@bindingSets.unshift(new BindingSet(selector, bindings))
|
||||
index = @bindingSets.length
|
||||
@bindingSets.unshift(new BindingSet(selector, bindings, index))
|
||||
|
||||
bindingsForElement: (element) ->
|
||||
keystrokeMap = {}
|
||||
currentNode = $(element)
|
||||
|
||||
while currentNode.length
|
||||
bindingSets = @bindingSets.filter (set) -> currentNode.is(set.selector)
|
||||
bindingSets.sort (a, b) -> b.specificity - a.specificity
|
||||
bindingSets = @bindingSetsForNode(currentNode)
|
||||
_.defaults(keystrokeMap, set.commandsByKeystrokes) for set in bindingSets
|
||||
currentNode = currentNode.parent()
|
||||
|
||||
@@ -46,12 +46,11 @@ class Keymap
|
||||
@queuedKeystrokes = null
|
||||
currentNode = $(event.target)
|
||||
while currentNode.length
|
||||
candidateBindingSets = @bindingSets.filter (set) -> currentNode.is(set.selector)
|
||||
candidateBindingSets.sort (a, b) -> b.specificity - a.specificity
|
||||
candidateBindingSets = @bindingSetsForNode(currentNode)
|
||||
for bindingSet in candidateBindingSets
|
||||
command = bindingSet.commandForEvent(event)
|
||||
if command
|
||||
@triggerCommandEvent(event, command)
|
||||
continue if @triggerCommandEvent(event, command)
|
||||
return false
|
||||
else if command == false
|
||||
return false
|
||||
@@ -63,10 +62,23 @@ class Keymap
|
||||
|
||||
!isMultiKeystroke
|
||||
|
||||
bindingSetsForNode: (node) ->
|
||||
bindingSets = @bindingSets.filter (set) -> node.is(set.selector)
|
||||
bindingSets.sort (a, b) ->
|
||||
if b.specificity == a.specificity
|
||||
b.index - a.index
|
||||
else
|
||||
b.specificity - a.specificity
|
||||
|
||||
triggerCommandEvent: (keyEvent, commandName) ->
|
||||
commandEvent = $.Event(commandName)
|
||||
commandEvent.keyEvent = keyEvent
|
||||
aborted = false
|
||||
commandEvent.abortKeyBinding = ->
|
||||
@stopImmediatePropagation()
|
||||
aborted = true
|
||||
$(keyEvent.target).trigger(commandEvent)
|
||||
aborted
|
||||
|
||||
multiKeystrokeStringForEvent: (event) ->
|
||||
currentKeystroke = @keystrokeStringForEvent(event)
|
||||
|
||||
6
src/app/keymaps/snippets.coffee
Normal file
6
src/app/keymaps/snippets.coffee
Normal file
@@ -0,0 +1,6 @@
|
||||
window.keymap.bindKeys '.editor'
|
||||
'tab': 'snippets:expand'
|
||||
|
||||
window.keymap.bindKeys '.editor'
|
||||
'tab': 'snippets:next-tab-stop'
|
||||
'shift-tab': 'snippets:previous-tab-stop'
|
||||
@@ -90,6 +90,7 @@ class Project
|
||||
softWrap: @getSoftWrap()
|
||||
|
||||
@editSessions.push editSession
|
||||
@trigger 'new-edit-session', editSession
|
||||
editSession
|
||||
|
||||
buildBuffer: (filePath) ->
|
||||
|
||||
@@ -40,6 +40,9 @@ class Range
|
||||
inspect: ->
|
||||
"[#{@start.inspect()} - #{@end.inspect()}]"
|
||||
|
||||
add: (point) ->
|
||||
new Range(@start.add(point), @end.add(point))
|
||||
|
||||
intersectsWith: (otherRange) ->
|
||||
if @start.isLessThanOrEqual(otherRange.start)
|
||||
@end.isGreaterThanOrEqual(otherRange.start)
|
||||
|
||||
@@ -174,7 +174,7 @@ class RootView extends View
|
||||
|
||||
loadUserConfiguration: ->
|
||||
try
|
||||
require atom.userConfigurationPath if fs.exists(atom.userConfigurationPath)
|
||||
require atom.configFilePath if fs.exists(atom.configFilePath)
|
||||
catch error
|
||||
console.error "Failed to load `#{atom.userConfigurationPath}`", error.message, error
|
||||
console.error "Failed to load `#{atom.configFilePath}`", error.message, error
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ class TokenizedBuffer
|
||||
@aceAdaptor = new AceAdaptor(this)
|
||||
|
||||
requireAceMode: ->
|
||||
extension = if @buffer.getPath() then @buffer.getPath().split('/').pop().split('.').pop() else null
|
||||
modeName = switch extension
|
||||
modeName = switch @buffer.getExtension()
|
||||
when 'js' then 'javascript'
|
||||
when 'coffee' then 'coffee'
|
||||
when 'rb', 'ru' then 'ruby'
|
||||
|
||||
Reference in New Issue
Block a user