Merge remote-tracking branch 'origin/dev' into better-anchors

This commit is contained in:
Nathan Sobo
2013-01-30 20:45:31 -07:00
26 changed files with 243 additions and 64 deletions

20
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,20 @@
# :rotating_light: Contributing to Atom :rotating_light:
## Issues
* Include screenshots and animated GIFs whenever possible, they are immensely
helpful
* Include the behavior you expected to happen and other places you've seen
that behavior such as Emacs, vi, Xcode, etc.
* Check the Console app for stack traces to include if reporting a crash
* Check the Dev tools (`alt-cmd-i`) for errors and stack traces to include
## Code
* Follow the [JavaScript](https://github.com/styleguide/javascript),
[CSS](https://github.com/styleguide/css),
and [Objective-C](https://github.com/github/objective-c-conventions)
styleguides
* Include thoughtfully worded [Jasmine](http://pivotal.github.com/jasmine/)
specs
* New packages go in `src/packages/`
* Add 3rd-party packages by submoduling in `vendor/packages/`
* Commit messages are in the present tense

View File

@@ -55,8 +55,8 @@ Or you can use `observeConfig` to track changes from a view object.
```coffeescript
class MyView extends View
initialize: ->
@observeConfig 'editor.lineHeight', (lineHeight) =>
@adjustLineHeight(lineHeight)
@observeConfig 'editor.fontSize', () =>
@adjustFontSize()
```
The `observeConfig` method will call the given callback immediately with the

View File

@@ -18,9 +18,9 @@ my-package/
index.coffee
```
**NOTE: NPM behavior is partially implemented until we get a working Node.js
**NOTE:** NPM behavior is partially implemented until we get a working Node.js
API built into Atom. The goal is to make Atom packages be a superset of NPM
packages**
packages
#### package.json

View File

@@ -141,6 +141,8 @@ bool AtomCefClient::OnKeyEvent(CefRefPtr<CefBrowser> browser,
ToggleDevTools(browser);
} else if (event.modifiers == EVENTFLAG_COMMAND_DOWN && event.unmodified_character == '`') {
FocusNextWindow();
} else if (event.modifiers == (EVENTFLAG_COMMAND_DOWN | EVENTFLAG_SHIFT_DOWN) && event.unmodified_character == '~') {
FocusPreviousWindow();
}
else {
return false;

View File

@@ -105,6 +105,7 @@ class AtomCefClient : public CefClient,
bool m_HandlePasteboardCommands = false;
void FocusNextWindow();
void FocusPreviousWindow();
void Open(std::string path);
void Open();
void OpenUnstable(std::string path);

View File

@@ -23,6 +23,24 @@ void AtomCefClient::FocusNextWindow() {
}
}
void AtomCefClient::FocusPreviousWindow() {
NSArray *windows = [NSApp windows];
int count = [windows count];
int start = [windows indexOfObject:[NSApp keyWindow]];
int i = start;
while (true) {
i = i - 1;
if (i == 0) i = count -1;
if (i == start) break;
NSWindow *window = [windows objectAtIndex:i];
if ([window isVisible] && ![window isExcludedFromWindowsMenu]) {
[window makeKeyAndOrderFront:nil];
break;
}
}
}
void AtomCefClient::Open(std::string path) {
NSString *pathString = [NSString stringWithCString:path.c_str() encoding:NSUTF8StringEncoding];
[(AtomApplication *)[AtomApplication sharedApplication] open:pathString];

17
script/fix-author Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
usage() {
echo "usage: $0 sha name email"
exit 1
}
if [ ! $3 ]; then
usage
fi
git filter-branch -f --env-filter "
export GIT_AUTHOR_NAME='$2'
export GIT_AUTHOR_EMAIL='$3'
export GIT_COMMITTER_NAME='$2'
export GIT_COMMITTER_EMAIL='$3'
" -- $1..HEAD

View File

@@ -516,14 +516,61 @@ describe "Editor", ->
editor.getBuffer().saveAs(path)
expect(editor.getGrammar().name).toBe 'Plain Text'
describe "font size", ->
it "sets the initial font size based on the value from config", ->
config.set("editor.fontSize", 20)
newEditor = editor.splitRight()
expect(editor.css('font-size')).toBe '20px'
expect(newEditor.css('font-size')).toBe '20px'
describe "font family", ->
beforeEach ->
expect(editor.css('font-family')).not.toBe 'Courier'
it "sets the initial font family based on the value from config", ->
expect($("head style.font-family")).toExist()
expect($("head style.font-family").text()).toMatch "{font-family: #{config.get('editor.fontFamily')}}"
describe "when the font family changes", ->
it "updates the font family on new and existing editors", ->
rootView.attachToDom()
rootView.height(200)
rootView.width(200)
config.set("editor.fontFamily", "Courier")
newEditor = editor.splitRight()
expect($("head style.font-family").text()).toMatch "{font-family: Courier}"
expect(editor.css('font-family')).toBe 'Courier'
expect(newEditor.css('font-family')).toBe 'Courier'
it "updates the font family of editors and recalculates dimensions critical to cursor positioning", ->
rootView.attachToDom()
rootView.height(200)
rootView.width(200)
lineHeightBefore = editor.lineHeight
charWidthBefore = editor.charWidth
config.set("editor.fontFamily", "Courier")
editor.setCursorScreenPosition [5, 6]
expect(editor.charWidth).not.toBe charWidthBefore
expect(editor.getCursorView().position()).toEqual { top: 5 * editor.lineHeight, left: 6 * editor.charWidth }
expect(editor.verticalScrollbarContent.height()).toBe buffer.getLineCount() * editor.lineHeight
describe "font size", ->
beforeEach ->
expect(editor.css('font-size')).not.toBe "20px"
it "sets the initial font size based on the value from config", ->
expect($("head style.font-size")).toExist()
expect($("head style.font-size").text()).toMatch "{font-size: #{config.get('editor.fontSize')}px}"
describe "when the font size changes", ->
it "updates the font family on new and existing editors", ->
rootView.attachToDom()
rootView.height(200)
rootView.width(200)
config.set("editor.fontSize", 20)
newEditor = editor.splitRight()
expect($("head style.font-size").text()).toMatch "{font-size: 20px}"
expect(editor.css('font-size')).toBe '20px'
expect(newEditor.css('font-size')).toBe '20px'
describe "when the font size changes on the view", ->
it "updates the font sizes of editors and recalculates dimensions critical to cursor positioning", ->
rootView.attachToDom()
rootView.height(200)

View File

@@ -25,3 +25,9 @@ describe "Point", ->
expect(new Point(5, 0).compare(new Point(6, 1))).toBe -1
expect(new Point(5, 5).compare(new Point(4, 1))).toBe 1
expect(new Point(5, 5).compare(new Point(5, 3))).toBe 1
describe ".translate(other)", ->
it "returns a translated point", ->
expect(new Point(1,2).translate([2,4])).toEqual [3,6]
expect(new Point(1,2).translate([-1])).toEqual [0,2]
expect(new Point(1,2).translate([0,-2])).toEqual [1,0]

View File

@@ -32,3 +32,8 @@ describe "Range", ->
expect(new Range([2, 1], [3, 10]).union(new Range([1, 1], [2, 10]))).toEqual [[1, 1], [3, 10]]
expect(new Range([2, 1], [3, 10]).union(new Range([2, 5], [3, 1]))).toEqual [[2, 1], [3, 10]]
expect(new Range([2, 5], [3, 1]).union(new Range([2, 1], [3, 10]))).toEqual [[2, 1], [3, 10]]
describe ".translate(startPoint, endPoint)", ->
it "returns a range translates by the specified start and end points", ->
expect(new Range([1, 1], [2, 10]).translate([1])).toEqual [[2, 1], [3, 10]]
expect(new Range([1, 1], [2, 10]).translate([1,2], [3,4])).toEqual [[2, 3], [5, 14]]

View File

@@ -567,9 +567,9 @@ describe "RootView", ->
editor = null
beforeEach ->
editor = rootView.getActiveEditor()
editor.attachToDom()
it "increases/decreases font size when increase/decrease-font-size events are triggered", ->
editor = rootView.getActiveEditor()
fontSizeBefore = editor.getFontSize()
rootView.trigger 'window:increase-font-size'
expect(editor.getFontSize()).toBe fontSizeBefore + 1

View File

@@ -350,7 +350,7 @@ class EditSession
foldedRows = []
rows = [selection.start.row..selection.end.row]
if selection.start.row isnt selection.end.row and selection.end.column is 0
rows.pop() unless @isFoldedAtScreenRow(@screenPositionForBufferPosition(selection.end).row)
rows.pop() unless @isFoldedAtBufferRow(selection.end.row)
for row in rows
screenRow = @screenPositionForBufferPosition([row]).row
if @isFoldedAtScreenRow(screenRow)
@@ -371,9 +371,7 @@ class EditSession
@foldBufferRow(foldedRow) for foldedRow in foldedRows
newStartPosition = [selection.start.row - 1, selection.start.column]
newEndPosition = [selection.end.row - 1, selection.end.column]
@setSelectedBufferRange([newStartPosition, newEndPosition], preserveFolds: true)
@setSelectedBufferRange(selection.translate([-1]), preserveFolds: true)
moveLineDown: ->
selection = @getSelectedBufferRange()
@@ -385,7 +383,7 @@ class EditSession
foldedRows = []
rows = [selection.end.row..selection.start.row]
if selection.start.row isnt selection.end.row and selection.end.column is 0
rows.shift() unless @isFoldedAtScreenRow(@screenPositionForBufferPosition(selection.end).row)
rows.shift() unless @isFoldedAtBufferRow(selection.end.row)
for row in rows
screenRow = @screenPositionForBufferPosition([row]).row
if @isFoldedAtScreenRow(screenRow)
@@ -410,9 +408,7 @@ class EditSession
@foldBufferRow(foldedRow) for foldedRow in foldedRows
newStartPosition = [selection.start.row + 1, selection.start.column]
newEndPosition = [selection.end.row + 1, selection.end.column]
@setSelectedBufferRange([newStartPosition, newEndPosition], preserveFolds: true)
@setSelectedBufferRange(selection.translate([1]), preserveFolds: true)
mutateSelectedText: (fn) ->

View File

@@ -14,12 +14,13 @@ _ = require 'underscore'
module.exports =
class Editor extends View
@configDefaults:
fontFamily: "Inconsolata, Monaco, Courier"
fontSize: 20
showInvisibles: false
autosave: false
autoIndent: true
autoIndentOnPaste: false
nonWordCharacters: "./\\()\"-_:,.;<>~!@#$%^&*|+=[]{}`~?"
nonWordCharacters: "./\\()\"'-_:,.;<>~!@#$%^&*|+=[]{}`~?"
@content: (params) ->
@div class: @classes(params), tabindex: -1, =>
@@ -341,6 +342,7 @@ class Editor extends View
@observeConfig 'editor.showInvisibles', (showInvisibles) => @setShowInvisibles(showInvisibles)
@observeConfig 'editor.invisibles', (invisibles) => @setInvisibles(invisibles)
@observeConfig 'editor.fontSize', (fontSize) => @setFontSize(fontSize)
@observeConfig 'editor.fontFamily', (fontFamily) => @setFontFamily(fontFamily)
handleEvents: ->
@on 'focus', =>
@@ -681,16 +683,37 @@ class Editor extends View
autosave: ->
@save() if @getPath()?
setFontSize: (@fontSize) ->
if fontSize?
@css('font-size', fontSize + 'px')
return unless @attached
@calculateDimensions()
@updatePaddingOfRenderedLines()
@updateLayerDimensions()
@requestDisplayUpdate()
setFontSize: (fontSize) ->
headTag = $("head")
styleTag = headTag.find("style.font-size")
if styleTag.length == 0
styleTag = $$ -> @style class: 'font-size'
headTag.append styleTag
getFontSize: -> @fontSize
styleTag.text(".editor {font-size: #{fontSize}px}")
@redraw()
getFontSize: ->
parseInt(@css("font-size"))
setFontFamily: (fontFamily) ->
headTag = $("head")
styleTag = headTag.find("style.font-family")
if styleTag.length == 0
styleTag = $$ -> @style class: 'font-family'
headTag.append styleTag
styleTag.text(".editor {font-family: #{fontFamily}}")
@redraw()
getFontFamily: -> @css("font-family")
redraw: ->
return unless @attached
@calculateDimensions()
@updatePaddingOfRenderedLines()
@updateLayerDimensions()
@requestDisplayUpdate()
newSplitEditor: (editSession) ->
new Editor { editSession: editSession ? @activeEditSession.copy() }

View File

@@ -34,6 +34,10 @@ class Point
new Point(row, column)
translate: (other) ->
other = Point.fromObject(other)
new Point(@row + other.row, @column + other.column)
splitAt: (column) ->
if @row == 0
rightColumn = @column - column

View File

@@ -48,6 +48,9 @@ class Range
add: (point) ->
new Range(@start.add(point), @end.add(point))
translate: (startPoint, endPoint=startPoint) ->
new Range(@start.translate(startPoint), @end.translate(endPoint))
intersectsWith: (otherRange) ->
if @start.isLessThanOrEqual(otherRange.start)
@end.isGreaterThanOrEqual(otherRange.start)

View File

@@ -1,4 +1,5 @@
DeferredAtomPackage = require 'deferred-atom-package'
$ = require 'jquery'
module.exports =
class CommandLogger extends DeferredAtomPackage
@@ -7,4 +8,25 @@ class CommandLogger extends DeferredAtomPackage
instanceClass: 'command-logger/src/command-logger-view'
onLoadEvent: (event, instance) -> instance.toggle()
activate: (rootView, state={})->
super
@eventLog = state.eventLog ? {}
rootView.command 'command-logger:clear-data', => @eventLog = {}
registerTriggeredEvent = (eventName) =>
eventNameLog = @eventLog[eventName]
unless eventNameLog
eventNameLog =
count: 0
name: eventName
@eventLog[eventName] = eventNameLog
eventNameLog.count++
eventNameLog.lastRun = new Date().getTime()
originalTrigger = $.fn.trigger
$.fn.trigger = (eventName) ->
eventName = eventName.type if eventName.type
registerTriggeredEvent(eventName) if $(this).events()[eventName]
originalTrigger.apply(this, arguments)
onLoadEvent: (event, instance) -> instance.toggle(@eventLog)

View File

@@ -1,12 +1,11 @@
{$$$} = require 'space-pen'
ScrollView = require 'scroll-view'
$ = require 'jquery'
_ = require 'underscore'
module.exports =
class CommandLoggerView extends ScrollView
@activate: (rootView, state) ->
@instance = new CommandLoggerView(rootView, state?.eventLog)
@instance = new CommandLoggerView(rootView)
@content: (rootView) ->
@div class: 'command-logger', tabindex: -1, =>
@@ -31,29 +30,12 @@ class CommandLoggerView extends ScrollView
'tree-view:directory-modified'
]
initialize: (@rootView, @eventLog={}) ->
initialize: (@rootView) ->
super
@rootView.command 'command-logger:clear-data', => @eventLog = {}
@command 'core:cancel', => @detach()
registerEvent = (eventName) =>
eventNameLog = @eventLog[eventName]
unless eventNameLog
eventNameLog =
count: 0
name: eventName
@eventLog[eventName] = eventNameLog
eventNameLog.count++
eventNameLog.lastRun = new Date().getTime()
originalTrigger = $.fn.trigger
$.fn.trigger = (eventName) ->
eventName = eventName.type if eventName.type
registerEvent(eventName) if $(this).events()[eventName]
originalTrigger.apply(this, arguments)
toggle: ->
toggle: (@eventLog={}) ->
if @hasParent()
@detach()
else

View File

@@ -51,7 +51,7 @@ class CommandPanelView extends View
@previewList.hide()
@previewCount.hide()
@errorMessages.hide()
@prompt.iconSize(@miniEditor.fontSize)
@prompt.iconSize(@miniEditor.getFontSize())
serialize: ->
text: @miniEditor.getText()

View File

@@ -1,2 +1,2 @@
window.keymap.bindKeys '.editor'
'.editor':
'tab': 'snippets:expand'

View File

@@ -1,6 +1,6 @@
# it's critical that these bindings be loaded after those snippets-1 so they
# are later in the cascade, hence breaking the keymap into 2 files
window.keymap.bindKeys '.editor'
'.editor':
'tab': 'snippets:next-tab-stop'
'shift-tab': 'snippets:previous-tab-stop'

View File

@@ -5,7 +5,7 @@ Tabs = require 'tabs'
fs = require 'fs'
describe "Tabs", ->
[rootView, editor, statusBar, buffer, tabs] = []
[rootView, editor, buffer, tabs] = []
beforeEach ->
rootView = new RootView(require.resolve('fixtures/sample.js'))
@@ -118,3 +118,21 @@ describe "Tabs", ->
tabs.find('.tab .close-icon:eq(1)').click()
expect(editor.getActiveEditSessionIndex()).toBe 0
expect(editor.activeEditSession).toBe firstSession
describe "when two tabs have the same file name", ->
[tempPath] = []
beforeEach ->
tempPath = '/tmp/sample.js'
fs.write(tempPath, 'sample')
afterEach ->
fs.remove(tempPath) if fs.exists(tempPath)
it "displays the parent folder name after the file name", ->
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.js'
rootView.open(tempPath)
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.js - fixtures'
expect(tabs.find('.tab:last .file-name').text()).toBe 'sample.js - tmp'
editor.destroyActiveEditSession()
expect(tabs.find('.tab:eq(0) .file-name').text()).toBe 'sample.js'

View File

@@ -1,4 +1,5 @@
{View} = require 'space-pen'
fs = require 'fs'
module.exports =
class Tab extends View
@@ -7,12 +8,14 @@ class Tab extends View
@span class: 'file-name', outlet: 'fileName'
@span class: 'close-icon'
initialize: (@editSession) ->
initialize: (@editSession, @editor) ->
@buffer = @editSession.buffer
@subscribe @buffer, 'path-changed', => @updateFileName()
@subscribe @buffer, 'contents-modified', => @updateModifiedStatus()
@subscribe @buffer, 'saved', => @updateModifiedStatus()
@subscribe @buffer, 'git-status-changed', => @updateModifiedStatus()
@subscribe @editor, 'editor:edit-session-added', => @updateFileName()
@subscribe @editor, 'editor:edit-session-removed', => @updateFileName()
@updateFileName()
@updateModifiedStatus()
@@ -25,4 +28,14 @@ class Tab extends View
@isModified = false
updateFileName: ->
@fileName.text(@editSession.buffer.getBaseName() ? 'untitled')
fileNameText = @editSession.buffer.getBaseName()
if fileNameText?
duplicates = @editor.getEditSessions().filter (session) -> fileNameText is session.buffer.getBaseName()
if duplicates.length > 1
directory = fs.base(fs.directory(@editSession.getPath()))
fileNameText = "#{fileNameText} - #{directory}" if directory
else
fileNameText = 'untitled'
@fileName.text(fileNameText)
@fileName.attr('title', @editSession.getPath())

View File

@@ -34,7 +34,7 @@ class Tabs extends View
false
addTabForEditSession: (editSession) ->
@append(new Tab(editSession))
@append(new Tab(editSession, @editor))
setActiveTab: (index) ->
@find(".tab.active").removeClass('active')

View File

@@ -103,4 +103,4 @@
position: absolute;
pointer-events: none;
z-index: -1;
}
}

View File

@@ -53,10 +53,11 @@
}
.editor .fold-marker:before {
content: '\f25e';
content: '\f060';
-webkit-transform: rotate(90deg);
font-family: 'Octicons Regular';
display: inline-block;
margin-left: .5em;
margin-left: .3em;
margin-top: .1em;
line-height: .8em;
-webkit-font-smoothing: antialiased;

View File

@@ -56,10 +56,11 @@
}
.editor .fold-marker:before {
content: '\f25e';
content: '\f060';
-webkit-transform: rotate(90deg);
font-family: 'Octicons Regular';
display: inline-block;
margin-left: .5em;
margin-left: .3em;
margin-top: .1em;
line-height: .8em;
-webkit-font-smoothing: antialiased;