mirror of
https://github.com/atom/atom.git
synced 2026-02-09 22:24:59 -05:00
Merge branch 'master' into multi-cursor
This commit is contained in:
@@ -6,7 +6,11 @@ class CommandInterpreter
|
||||
constructor: ->
|
||||
@parser = PEG.buildParser(fs.read(require.resolve 'commands.pegjs'))
|
||||
|
||||
eval: (editor, command) ->
|
||||
operations = @parser.parse(command)
|
||||
operation.execute(editor) for operation in operations
|
||||
eval: (editor, string) ->
|
||||
command = @parser.parse(string)
|
||||
@lastRelativeAddress = command if command.isRelativeAddress()
|
||||
command.execute(editor)
|
||||
|
||||
repeatRelativeAddress: (editor) ->
|
||||
@lastRelativeAddress?.execute(editor)
|
||||
|
||||
|
||||
@@ -7,3 +7,6 @@ class AddressRange extends Address
|
||||
|
||||
getRange: (editor) ->
|
||||
new Range(@startAddress.getRange(editor).start, @endAddress.getRange(editor).end)
|
||||
|
||||
isRelative: ->
|
||||
@startAddress.isRelative() or @endAddress.isRelative()
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
Command = require 'command-interpreter/command'
|
||||
|
||||
module.exports =
|
||||
class Address
|
||||
class Address extends Command
|
||||
execute: (editor) ->
|
||||
editor.getSelection().setBufferRange(@getRange(editor))
|
||||
|
||||
isAddress: -> true
|
||||
|
||||
5
src/atom/command-interpreter/command.coffee
Normal file
5
src/atom/command-interpreter/command.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class Command
|
||||
isAddress: -> false
|
||||
12
src/atom/command-interpreter/composite-command.coffee
Normal file
12
src/atom/command-interpreter/composite-command.coffee
Normal file
@@ -0,0 +1,12 @@
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class CompositeCommand
|
||||
constructor: (@subcommands) ->
|
||||
|
||||
execute: (editor) ->
|
||||
command.execute(editor) for command in @subcommands
|
||||
|
||||
isRelativeAddress: ->
|
||||
_.all(@subcommands, (command) -> command.isAddress() and command.isRelative())
|
||||
|
||||
@@ -5,3 +5,5 @@ module.exports =
|
||||
class CurrentSelectionAddress extends Address
|
||||
getRange: (editor) ->
|
||||
editor.getSelection().getBufferRange()
|
||||
|
||||
isRelative: -> true
|
||||
|
||||
@@ -6,4 +6,6 @@ class EofAddress extends Address
|
||||
getRange: (editor) ->
|
||||
lastRow = editor.getLastBufferRow()
|
||||
column = editor.getBufferLineLength(lastRow)
|
||||
new Range([lastRow, column], [lastRow, column])
|
||||
new Range([lastRow, column], [lastRow, column])
|
||||
|
||||
isRelative: -> false
|
||||
|
||||
@@ -8,3 +8,5 @@ class LineAddress extends Address
|
||||
|
||||
getRange: ->
|
||||
new Range([@row, 0], [@row + 1, 0])
|
||||
|
||||
isRelative: -> false
|
||||
|
||||
@@ -23,4 +23,6 @@ class RegexAddress extends Address
|
||||
|
||||
return new Range(startPosition, endPosition)
|
||||
else
|
||||
return selectedRange
|
||||
return selectedRange
|
||||
|
||||
isRelative: -> true
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
Command = require 'command-interpreter/command'
|
||||
|
||||
module.exports =
|
||||
class Substitution
|
||||
class Substitution extends Command
|
||||
global: false
|
||||
|
||||
constructor: (@findText, @replaceText, @options) ->
|
||||
@@ -28,3 +30,4 @@ class Substitution
|
||||
text = text[(match.index + match[0].length)..]
|
||||
startIndex = matchStartIndex + @replaceText.length
|
||||
@replace(editor, text, startIndex)
|
||||
|
||||
|
||||
@@ -17,22 +17,32 @@ class CommandPanel extends View
|
||||
escape: 'command-panel:toggle'
|
||||
enter: 'command-panel:execute'
|
||||
|
||||
window.keymap.bindKeys '.editor',
|
||||
'meta-g': 'command-panel:repeat-relative-address'
|
||||
|
||||
@rootView.on 'command-panel:toggle', => @toggle()
|
||||
@rootView.on 'command-panel:execute', => @execute()
|
||||
@rootView.on 'command-panel:repeat-relative-address', => @repeatRelativeAddress()
|
||||
@editor.addClass 'single-line'
|
||||
|
||||
@commandInterpreter = new CommandInterpreter()
|
||||
|
||||
toggle: ->
|
||||
if @parent().length
|
||||
@detach()
|
||||
@rootView.activeEditor().focus()
|
||||
else
|
||||
@rootView.append(this)
|
||||
@prompt.css 'font', @editor.css('font')
|
||||
@editor.focus()
|
||||
@editor.buffer.setText('')
|
||||
if @parent().length then @hide() else @show()
|
||||
|
||||
show: ->
|
||||
@rootView.append(this)
|
||||
@prompt.css 'font', @editor.css('font')
|
||||
@editor.focus()
|
||||
@editor.buffer.setText('')
|
||||
|
||||
hide: ->
|
||||
@detach()
|
||||
@rootView.activeEditor().focus()
|
||||
|
||||
execute: ->
|
||||
@commandInterpreter.eval(@rootView.activeEditor(), @editor.getText())
|
||||
@toggle()
|
||||
@hide()
|
||||
|
||||
repeatRelativeAddress: ->
|
||||
@commandInterpreter.repeatRelativeAddress(@rootView.activeEditor())
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
var CompositeCommand = require('command-interpreter/composite-command')
|
||||
var Substitution = require('command-interpreter/substitution');
|
||||
var LineAddress = require('command-interpreter/line-address');
|
||||
var AddressRange = require('command-interpreter/address-range');
|
||||
@@ -9,10 +10,11 @@
|
||||
|
||||
start
|
||||
= address:address? _ command:substitution? {
|
||||
var operations = [];
|
||||
if (address) operations.push(address);
|
||||
if (command) operations.push(command);
|
||||
return operations;
|
||||
var commands = [];
|
||||
if (address) commands.push(address);
|
||||
if (command) commands.push(command);
|
||||
|
||||
return new CompositeCommand(commands);
|
||||
}
|
||||
|
||||
address = addressRange / primitiveAddress
|
||||
|
||||
@@ -13,7 +13,7 @@ CommandPanel = require 'command-panel'
|
||||
module.exports =
|
||||
class RootView extends View
|
||||
@content: ->
|
||||
@div id: 'root-view', =>
|
||||
@div id: 'root-view', tabindex: -1, =>
|
||||
@div id: 'panes', outlet: 'panes'
|
||||
|
||||
editors: null
|
||||
@@ -28,9 +28,19 @@ class RootView extends View
|
||||
'meta-t': 'toggle-file-finder'
|
||||
'meta-:': 'command-panel:toggle'
|
||||
'alt-meta-i': 'show-console'
|
||||
'meta-f': 'find-in-file'
|
||||
|
||||
@on 'toggle-file-finder', => @toggleFileFinder()
|
||||
@on 'show-console', -> window.showConsole()
|
||||
@on 'find-in-file', =>
|
||||
@commandPanel.show()
|
||||
@commandPanel.editor.setText("/")
|
||||
|
||||
@one 'attach', => @focus()
|
||||
@on 'focus', (e) =>
|
||||
if @editors.length
|
||||
@activeEditor().focus()
|
||||
false
|
||||
|
||||
@commandPanel = new CommandPanel({rootView: this})
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class VimMode
|
||||
@opStack = []
|
||||
|
||||
moveCursorBeforeNewline: =>
|
||||
if not @editor.selection.modifyingSelection and @editor.cursor.isOnEOL() and @editor.getCurrentBufferLine().length > 0
|
||||
if not @editor.getSelection().modifyingSelection and @editor.cursor.isOnEOL() and @editor.getCurrentBufferLine().length > 0
|
||||
@editor.setCursorBufferColumn(@editor.getCurrentBufferLine().length - 1)
|
||||
|
||||
numericPrefix: (e) ->
|
||||
|
||||
Reference in New Issue
Block a user