Merge branch 'master' into chrome35

Conflicts:
	apm/package.json
	package.json
This commit is contained in:
Cheng Zhao 2014-07-22 10:13:40 +08:00
commit 52e049bedc
23 changed files with 621 additions and 401 deletions

2
.gitignore vendored
View File

@ -13,5 +13,3 @@ debug.log
docs/output
docs/includes
spec/fixtures/evil-files/
resources/linux/Atom.desktop
resources/linux/debian/control

View File

@ -6,6 +6,6 @@
"url": "https://github.com/atom/atom.git"
},
"dependencies": {
"atom-package-manager": "1.0.0"
"atom-package-manager": "1.1.0"
}
}

View File

@ -14,8 +14,8 @@
"grunt": "~0.4.1",
"grunt-cli": "~0.1.9",
"grunt-coffeelint": "git+https://github.com/atom/grunt-coffeelint.git",
"grunt-contrib-csslint": "~0.1.2",
"grunt-contrib-coffee": "~0.9.0",
"grunt-contrib-csslint": "~0.1.2",
"grunt-contrib-less": "~0.8.0",
"grunt-cson": "0.8.0",
"grunt-download-atom-shell": "~0.8.0",
@ -27,15 +27,15 @@
"json-front-matter": "~0.1.3",
"legal-eagle": "~0.4.0",
"minidump": "~0.7",
"read-package-json": "1.1.8",
"normalize-package-data": "0.2.12",
"npm": "~1.4.5",
"rcedit": "~0.1.2",
"read-package-json": "1.1.8",
"request": "~2.27.0",
"rimraf": "~2.2.2",
"runas": "0.5.x",
"underscore-plus": "1.x",
"unzip": "~0.1.9",
"vm-compatibility-layer": "~0.1.0",
"npm": "~1.4.5"
"vm-compatibility-layer": "~0.1.0"
}
}

View File

@ -4,17 +4,13 @@ _ = require 'underscore-plus'
fs = require 'fs-plus'
runas = null
fillTemplate = (filePath, data) ->
template = _.template(String(fs.readFileSync(filePath + '.in')))
filled = template(data)
fs.writeFileSync(filePath, filled)
module.exports = (grunt) ->
{cp, mkdir, rm} = require('./task-helpers')(grunt)
grunt.registerTask 'install', 'Install the built application', ->
installDir = grunt.config.get('atom.installDir')
shellAppDir = grunt.config.get('atom.shellAppDir')
if process.platform is 'win32'
runas ?= require 'runas'
copyFolder = path.resolve 'script', 'copy-folder.cmd'
@ -32,7 +28,6 @@ module.exports = (grunt) ->
shareDir = path.join(installDir, 'share', 'atom')
iconName = path.join(shareDir,'resources','app','resources','atom.png')
desktopFile = path.join('resources', 'linux', 'Atom.desktop')
mkdir binDir
cp 'atom.sh', path.join(binDir, 'atom')
@ -42,13 +37,17 @@ module.exports = (grunt) ->
# Create Atom.desktop if installation not in temporary folder
tmpDir = if process.env.TMPDIR? then process.env.TMPDIR else '/tmp'
desktopInstallFile = path.join(installDir,'share','applications','Atom.desktop')
if installDir.indexOf(tmpDir) isnt 0
mkdir path.dirname(desktopInstallFile)
desktopFile = path.join('resources', 'linux', 'Atom.desktop.in')
desktopInstallFile = path.join(installDir, 'share', 'applications', 'Atom.desktop')
{description} = grunt.file.readJSON('package.json')
installDir = path.join(installDir,'.') # To prevent "Exec=/usr/local//share/atom/atom"
fillTemplate(desktopFile, {description, installDir, iconName})
cp desktopFile, desktopInstallFile
iconName = path.join(shareDir, 'resources', 'app', 'resources', 'atom.png')
installDir = path.join(installDir, '.') # To prevent "Exec=/usr/local//share/atom/atom"
template = _.template(String(fs.readFileSync(desktopFile)))
filled = template({description, installDir, iconName})
grunt.file.write(desktopInstallFile, filled)
# Create relative symbol link for apm.
process.chdir(binDir)

View File

@ -2,14 +2,17 @@ fs = require 'fs'
path = require 'path'
_ = require 'underscore-plus'
fillTemplate = (filePath, data) ->
template = _.template(String(fs.readFileSync(filePath + '.in')))
filled = template(data)
fs.writeFileSync(filePath, filled)
module.exports = (grunt) ->
{spawn} = require('./task-helpers')(grunt)
fillTemplate = (filePath, data) ->
template = _.template(String(fs.readFileSync("#{filePath}.in")))
filled = template(data)
outputPath = path.join(grunt.config.get('atom.buildDir'), path.basename(filePath))
grunt.file.write(outputPath, filled)
outputPath
grunt.registerTask 'mkdeb', 'Create debian package', ->
done = @async()
@ -27,13 +30,11 @@ module.exports = (grunt) ->
iconName = 'atom'
data = {name, version, description, section, arch, maintainer, installDir, iconName}
control = path.join('resources', 'linux', 'debian', 'control')
fillTemplate(control, data)
desktop = path.join('resources', 'linux', 'Atom.desktop')
fillTemplate(desktop, data)
controlFilePath = fillTemplate(path.join('resources', 'linux', 'debian', 'control'), data)
desktopFilePath = fillTemplate(path.join('resources', 'linux', 'Atom.desktop'), data)
icon = path.join('resources', 'atom.png')
buildDir = grunt.config.get('atom.buildDir')
cmd = path.join('script', 'mkdeb')
args = [version, arch, control, desktop, icon, buildDir]
args = [version, arch, controlFilePath, desktopFilePath, icon, buildDir]
spawn({cmd, args}, done)

View File

@ -6,35 +6,40 @@ Ubuntu LTS 12.04 64-bit is the recommended platform.
* OS with 64-bit or 32-bit architecture
* C++ toolchain
* on Ubuntu/Debian: `sudo apt-get install build-essential`
* on Fedora: `sudo yum --assumeyes install make gcc gcc-c++ glibc-devel`
* git
* [node.js](http://nodejs.org/download/) v0.10.x
* [Ubuntu/Debian/Mint instructions](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os)
* [Fedora instructions](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#fedora)
* [npm](http://www.npmjs.org/) v1.4.x
* `npm` comes with node.js so no explicit installation is needed here.
* You can check `npm` 1.4 or above is installed by running `npm -v`.
* [npm](http://www.npmjs.org/) v1.4.x (bundled with node.js)
* `npm -v` to check the version.
* `npm config set python /usr/bin/python2 -g` to ensure that gyp uses python2.
* You might need to run this command as `sudo`, depending on how you have set up [npm](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os).
* libgnome-keyring-dev
* on Ubuntu/Debian: `sudo apt-get install libgnome-keyring-dev`
* on Fedora: `sudo yum --assumeyes install libgnome-keyring-devel`
* on other distributions refer to the manual on how to install packages
* `npm config set python /usr/bin/python2 -g` to ensure that gyp uses Python 2
* This command may require `sudo` depending on how you have
[configured npm](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os).
* Git
* on Ubuntu/Debian: `sudo apt-get install git`
* on Fedora: `sudo yum install git-core`
### Ubuntu / Debian
* `sudo apt-get install build-essential git libgnome-keyring-dev`
* Instructions for [node.js](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os).
### Fedora
* `sudo yum --assumeyes install make gcc gcc-c++ glibc-devel git-core libgnome-keyring-devel`
* Instructions for [node.js](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#fedora).
### Arch
* `sudo pacman -S base-devel git nodejs libgnome-keyring`
* `export PYTHON=/usr/bin/python2` before building Atom.
## Instructions
If you have problems with permissions don't forget to prefix with `sudo`
```sh
git clone https://github.com/atom/atom
cd atom
script/build # Creates application at $TMPDIR/atom-build/Atom
sudo script/grunt install # Installs command to /usr/local/bin/atom
script/grunt mkdeb # Generates a .deb package at $TMPDIR/atom-build
script/grunt mkdeb # Generates a .deb package at $TMPDIR/atom-build, e.g. /tmp/atom-build
```
To run `atom` and `apm` from a terminal open atom's command palette `ctrl+shift+p` and run `Window: Install Shell Commands`
## Troubleshooting

View File

@ -35,10 +35,14 @@
## Why do I have to use GitHub for Windows?
You don't, You can use your existing Git! GitHub for Windows's Git Shell is just
easier to set up. You need to have Posix tools in your `%PATH%` (i.e. `grep`,
`sed`, et al.), which isn't the default configuration when you install Git. To
fix this, you probably need to fiddle with your system PATH.
You don't. You can use your existing Git! GitHub for Windows's Git Shell is just
easier to set up.
If you _prefer_ using your existing Git installation, make sure git's cmd directory is in your PATH env variable (e.g. `C:\Program Files (x86)\Git\cmd`) before you open your powershell or command window.
Note that you may have to open your command window as administrator. For powershell that doesn't seem to always be the case, though.
If none of this works, do install Github for Windows and use its Git shell. Makes life easier.
## Troubleshooting
@ -62,5 +66,11 @@ fix this, you probably need to fiddle with your system PATH.
* https://github.com/TooTallNate/node-gyp/issues/297
* https://code.google.com/p/gyp/issues/detail?id=393
* Other `node-gyp` errors on first build attempt, even though the right node and python versions are installed.
* Do try the build command one more time, as experience shows it often works on second try in many of these cases.
### Windows build error reports in atom/atom
* Use [this search](https://github.com/atom/atom/search?q=label%3Abuild-error+label%3Awindows&type=Issues) to get a list of reports about build errors on Windows.
* If all fails, use [this search](https://github.com/atom/atom/search?q=label%3Abuild-error+label%3Awindows&type=Issues) to get a list of reports about build errors on Windows, and see if yours has already been reported.
* If it hasn't, please open a new issue with your Windows version 32/64bit and a print/screenshot of your build output, incl. the node and python versions.

View File

@ -15,6 +15,9 @@ unless process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE
module.exports.$ = $
module.exports.$$ = $$
module.exports.$$$ = $$$
if atom.config.get('core.useReactMiniEditors')
module.exports.EditorView = require '../src/react-editor-view'
else
module.exports.EditorView = require '../src/editor-view'
module.exports.ScrollView = require '../src/scroll-view'
module.exports.SelectListView = require '../src/select-list-view'

View File

@ -29,6 +29,7 @@
'ctrl-w': 'core:close'
'ctrl-f4': 'core:close'
'ctrl-z': 'core:undo'
'ctrl-shift-z': 'core:redo'
'ctrl-y': 'core:redo'
'ctrl-x': 'core:cut'
'ctrl-c': 'core:copy'
@ -84,6 +85,8 @@
'ctrl-delete': 'editor:delete-to-end-of-word'
'ctrl-home': 'core:move-to-top'
'ctrl-end': 'core:move-to-bottom'
'ctrl-shift-home': 'core:select-to-top'
'ctrl-shift-end': 'core:select-to-bottom'
# Sublime Parity
'ctrl-a': 'core:select-all'

View File

@ -28,10 +28,10 @@
"delegato": "^1",
"emissary": "^1.2.1",
"first-mate": "^2.0.0",
"fs-plus": "^2.2.3",
"fs-plus": "^2.2.4",
"fstream": "0.1.24",
"fuzzaldrin": "^1.1",
"git-utils": "^2.0",
"git-utils": "^2.1",
"grim": "0.11.0",
"guid": "0.0.10",
"jasmine-tagged": "^1.1.2",
@ -41,7 +41,7 @@
"nslog": "^1.0.0",
"oniguruma": "^3.0.0",
"optimist": "0.4.0",
"pathwatcher": "^2.0.2",
"pathwatcher": "^2.0.3",
"property-accessors": "^1",
"q": "^1.0.1",
"random-words": "0.0.1",
@ -67,7 +67,7 @@
"atom-light-syntax": "0.20.0",
"atom-light-ui": "0.28.0",
"base16-tomorrow-dark-theme": "0.19.0",
"solarized-dark-syntax": "0.20.0",
"solarized-dark-syntax": "0.21.0",
"solarized-light-syntax": "0.11.0",
"archive-view": "1.0.0",
"autocomplete": "0.28.0",
@ -81,7 +81,7 @@
"dev-live-reload": "1.0.0",
"exception-reporting": "0.18.0",
"feedback": "0.33.0",
"find-and-replace": "0.126.0",
"find-and-replace": "0.127.0",
"fuzzy-finder": "0.57.0",
"git-diff": "0.37.0",
"go-to-line": "0.23.0",
@ -102,7 +102,7 @@
"symbols-view": "1.0.0",
"tabs": "0.45.0",
"timecop": "0.21.0",
"tree-view": "1.0.0",
"tree-view": "1.1.0",
"update-package-dependencies": "0.6.0",
"welcome": "0.17.0",
"whitespace": "0.25.0",
@ -111,7 +111,7 @@
"language-c": "0.22.0",
"language-coffee-script": "0.27.0",
"language-css": "0.17.0",
"language-gfm": "0.42.0",
"language-gfm": "0.43.0",
"language-git": "0.9.0",
"language-go": "0.13.0",
"language-html": "0.22.0",
@ -119,7 +119,7 @@
"language-java": "0.11.0",
"language-javascript": "0.36.0",
"language-json": "0.8.0",
"language-less": "0.12.0",
"language-less": "0.13.0",
"language-make": "0.10.0",
"language-objective-c": "0.11.0",
"language-perl": "0.9.0",
@ -128,7 +128,7 @@
"language-python": "0.18.0",
"language-ruby": "0.33.0",
"language-ruby-on-rails": "0.15.0",
"language-sass": "0.13.0",
"language-sass": "0.14.0",
"language-shellscript": "0.8.0",
"language-source": "0.7.0",
"language-sql": "0.9.0",
@ -136,7 +136,7 @@
"language-todo": "0.10.0",
"language-toml": "0.12.0",
"language-xml": "0.15.0",
"language-yaml": "0.11.0"
"language-yaml": "0.13.0"
},
"private": true,
"scripts": {

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
fs = require 'fs'
module.exports.runSpecSuite = (specSuite, logFile, logErrors=true) ->
{$, $$} = require 'atom'
{$, $$} = require '../src/space-pen-extensions'
window[key] = value for key, value of require '../vendor/jasmine'
{TerminalReporter} = require 'jasmine-tagged'

View File

@ -318,8 +318,12 @@ window.setEditorWidthInChars = (editorView, widthInChars, charWidth=editorView.c
editorView.width(charWidth * widthInChars + editorView.gutter.outerWidth())
$(window).trigger 'resize' # update width of editor view's on-screen lines
window.setEditorHeightInLines = (editorView, heightInChars, charHeight=editorView.lineHeight) ->
editorView.height(charHeight * heightInChars + editorView.renderedLines.position().top)
window.setEditorHeightInLines = (editorView, heightInLines, lineHeight=editorView.lineHeight) ->
if editorView.hasClass('react')
editorView.height(editorView.getEditor().getLineHeightInPixels() * heightInLines)
editorView.component?.measureHeightAndWidth()
else
editorView.height(lineHeight * heightInLines + editorView.renderedLines.position().top)
$(window).trigger 'resize' # update editor view's on-screen lines
$.fn.resultOfTrigger = (type) ->

View File

@ -1,6 +1,5 @@
_ = require 'underscore-plus'
fs = require 'fs-plus'
{Git} = require 'atom'
path = require 'path'
require './spec-helper'

View File

@ -12,14 +12,14 @@ CursorsComponent = React.createClass
cursorBlinkIntervalHandle: null
render: ->
{cursorPixelRects, scrollTop, scrollLeft, defaultCharWidth, useHardwareAcceleration} = @props
{performedInitialMeasurement, cursorPixelRects, scrollTop, scrollLeft, defaultCharWidth, useHardwareAcceleration} = @props
{blinkOff} = @state
className = 'cursors'
className += ' blink-off' if blinkOff
div {className},
if @isMounted()
if performedInitialMeasurement
for key, pixelRect of cursorPixelRects
CursorComponent({key, pixelRect, scrollTop, scrollLeft, defaultCharWidth, useHardwareAcceleration})

View File

@ -61,7 +61,7 @@ class Decoration
return if @isDestroyed
@isDestroyed = true
@displayBuffer.removeDecoration(this)
@emit 'destoryed'
@emit 'destroyed'
# Public: Update the marker with new params. Allows you to change the decoration's class.
#

View File

@ -22,6 +22,8 @@ EditorComponent = React.createClass
statics:
performSyncUpdates: false
visible: false
autoHeight: false
pendingScrollTop: null
pendingScrollLeft: null
selectOnMouseMove: false
@ -35,27 +37,28 @@ EditorComponent = React.createClass
gutterWidth: 0
refreshingScrollbars: false
measuringScrollbars: true
pendingVerticalScrollDelta: 0
pendingHorizontalScrollDelta: 0
mouseWheelScreenRow: null
mouseWheelScreenRowClearDelay: 150
scrollSensitivity: 0.4
scrollViewMeasurementRequested: false
heightAndWidthMeasurementRequested: false
measureLineHeightAndDefaultCharWidthWhenShown: false
remeasureCharacterWidthsIfVisibleAfterNextUpdate: false
inputEnabled: true
scrollViewMeasurementInterval: 100
scopedCharacterWidthsChangeCount: null
scrollViewMeasurementPaused: false
domPollingInterval: 100
domPollingIntervalId: null
domPollingPaused: false
render: ->
{focused, fontSize, lineHeight, fontFamily, showIndentGuide, showInvisibles, showLineNumbers, visible} = @state
{editor, cursorBlinkPeriod, cursorBlinkResumeDelay} = @props
{editor, mini, cursorBlinkPeriod, cursorBlinkResumeDelay} = @props
maxLineNumberDigits = editor.getLineCount().toString().length
invisibles = if showInvisibles then @state.invisibles else {}
invisibles = if showInvisibles and not mini then @state.invisibles else {}
hasSelection = editor.getSelection()? and !editor.getSelection().isEmpty()
style = {fontSize, fontFamily}
style.lineHeight = lineHeight unless mini
if @isMounted()
if @performedInitialMeasurement
renderedRowRange = @getRenderedRowRange()
[renderedStartRow, renderedEndRow] = renderedRowRange
cursorPixelRects = @getCursorPixelRects(renderedRowRange)
@ -63,6 +66,7 @@ EditorComponent = React.createClass
decorations = editor.decorationsForScreenRowRange(renderedStartRow, renderedEndRow)
highlightDecorations = @getHighlightDecorations(decorations)
lineDecorations = @getLineDecorations(decorations)
placeholderText = @props.placeholderText if @props.placeholderText? and editor.isEmpty()
scrollHeight = editor.getScrollHeight()
scrollWidth = editor.getScrollWidth()
@ -81,12 +85,14 @@ EditorComponent = React.createClass
if @mouseWheelScreenRow? and not (renderedStartRow <= @mouseWheelScreenRow < renderedEndRow)
mouseWheelScreenRow = @mouseWheelScreenRow
className = 'editor-contents editor-colors'
style.height = scrollViewHeight if @autoHeight
className = 'editor-contents'
className += ' is-focused' if focused
className += ' has-selection' if hasSelection
div className: className, style: {fontSize, lineHeight, fontFamily}, tabIndex: -1,
if showLineNumbers
div {className, style, tabIndex: -1},
if not mini and showLineNumbers
GutterComponent {
ref: 'gutter', onMouseDown: @onGutterMouseDown, onWidthChanged: @onGutterWidthChanged,
lineDecorations, defaultCharWidth, editor, renderedRowRange, maxLineNumberDigits, scrollViewHeight,
@ -103,14 +109,16 @@ EditorComponent = React.createClass
CursorsComponent {
scrollTop, scrollLeft, cursorPixelRects, cursorBlinkPeriod, cursorBlinkResumeDelay,
lineHeightInPixels, defaultCharWidth, @scopedCharacterWidthsChangeCount, @useHardwareAcceleration
lineHeightInPixels, defaultCharWidth, @scopedCharacterWidthsChangeCount, @useHardwareAcceleration,
@performedInitialMeasurement
}
LinesComponent {
ref: 'lines',
editor, lineHeightInPixels, defaultCharWidth, lineDecorations, highlightDecorations,
showIndentGuide, renderedRowRange, @pendingChanges, scrollTop, scrollLeft,
@scrollingVertically, scrollHeight, scrollWidth, mouseWheelScreenRow, invisibles,
visible, scrollViewHeight, @scopedCharacterWidthsChangeCount, lineWidth, @useHardwareAcceleration
visible, scrollViewHeight, @scopedCharacterWidthsChangeCount, lineWidth, @useHardwareAcceleration,
placeholderText, @performedInitialMeasurement
}
ScrollbarComponent
@ -149,8 +157,7 @@ EditorComponent = React.createClass
{editor} = @props
Math.max(1, Math.ceil(editor.getHeight() / editor.getLineHeightInPixels()))
getInitialState: ->
visible: true
getInitialState: -> {}
getDefaultProps: ->
cursorBlinkPeriod: 800
@ -166,7 +173,7 @@ EditorComponent = React.createClass
componentDidMount: ->
{editor} = @props
@scrollViewMeasurementIntervalId = setInterval(@measureScrollView, @scrollViewMeasurementInterval)
@domPollingIntervalId = setInterval(@pollDOM, @domPollingInterval)
@observeEditor()
@listenForDOMEvents()
@ -175,17 +182,14 @@ EditorComponent = React.createClass
@subscribe atom.themes, 'stylesheet-added stylsheet-removed', @onStylesheetsChanged
@subscribe scrollbarStyle.changes, @refreshScrollbars
editor.setVisible(true)
@measureLineHeightAndDefaultCharWidth()
@measureScrollView()
@measureScrollbars()
if @visible = @isVisible()
@performInitialMeasurement()
componentWillUnmount: ->
@props.parentView.trigger 'editor:will-be-removed', [@props.parentView]
@unsubscribe()
clearInterval(@scrollViewMeasurementIntervalId)
@scrollViewMeasurementIntervalId = null
clearInterval(@domPollingIntervalId)
@domPollingIntervalId = null
componentDidUpdate: (prevProps, prevState) ->
cursorsMoved = @cursorsMoved
@ -197,14 +201,27 @@ EditorComponent = React.createClass
if @props.editor.isAlive()
@updateParentViewFocusedClassIfNeeded(prevState)
@updateParentViewMiniClassIfNeeded(prevState)
@props.parentView.trigger 'cursor:moved' if cursorsMoved
@props.parentView.trigger 'selection:changed' if selectionChanged
@props.parentView.trigger 'editor:display-updated'
@visible = @isVisible()
if @performedInitialMeasurement
@measureScrollbars() if @measuringScrollbars
@measureLineHeightAndCharWidthsIfNeeded(prevState)
@measureLineHeightAndDefaultCharWidthIfNeeded(prevState)
@remeasureCharacterWidthsIfNeeded(prevState)
performInitialMeasurement: ->
@updatesPaused = true
@measureLineHeightAndDefaultCharWidth()
@measureHeightAndWidth()
@measureScrollbars()
@props.editor.setVisible(true)
@updatesPaused = false
@performedInitialMeasurement = true
@requestUpdate()
requestUpdate: ->
if @updatesPaused
@updateRequestedWhilePaused = true
@ -220,7 +237,7 @@ EditorComponent = React.createClass
requestAnimationFrame: (fn) ->
@updatesPaused = true
@pauseScrollViewMeasurement()
@pauseDOMPolling()
requestAnimationFrame =>
fn()
@updatesPaused = false
@ -273,7 +290,9 @@ EditorComponent = React.createClass
cursorPixelRects
getLineDecorations: (decorationsByMarkerId) ->
{editor} = @props
{editor, mini} = @props
return {} if mini
decorationsByScreenRow = {}
for markerId, decorations of decorationsByMarkerId
marker = editor.getMarker(markerId)
@ -350,7 +369,7 @@ EditorComponent = React.createClass
scrollViewNode = @refs.scrollView.getDOMNode()
scrollViewNode.addEventListener 'scroll', @onScrollViewScroll
window.addEventListener 'resize', @requestScrollViewMeasurement
window.addEventListener 'resize', @requestHeightAndWidthMeasurement
@listenForIMEEvents()
@ -557,28 +576,23 @@ EditorComponent = React.createClass
@pendingScrollLeft = null
onMouseWheel: (event) ->
event.preventDefault()
animationFramePending = @pendingHorizontalScrollDelta isnt 0 or @pendingVerticalScrollDelta isnt 0
{editor} = @props
# Only scroll in one direction at a time
{wheelDeltaX, wheelDeltaY} = event
if Math.abs(wheelDeltaX) > Math.abs(wheelDeltaY)
# Scrolling horizontally
@pendingHorizontalScrollDelta -= Math.round(wheelDeltaX * @scrollSensitivity)
previousScrollLeft = editor.getScrollLeft()
editor.setScrollLeft(previousScrollLeft - Math.round(wheelDeltaX * @scrollSensitivity))
event.preventDefault() unless previousScrollLeft is editor.getScrollLeft()
else
# Scrolling vertically
@pendingVerticalScrollDelta -= Math.round(wheelDeltaY * @scrollSensitivity)
@mouseWheelScreenRow = @screenRowForNode(event.target)
@clearMouseWheelScreenRowAfterDelay ?= debounce(@clearMouseWheelScreenRow, @mouseWheelScreenRowClearDelay)
@clearMouseWheelScreenRowAfterDelay()
unless animationFramePending
@requestAnimationFrame =>
{editor} = @props
editor.setScrollTop(editor.getScrollTop() + @pendingVerticalScrollDelta)
editor.setScrollLeft(editor.getScrollLeft() + @pendingHorizontalScrollDelta)
@pendingVerticalScrollDelta = 0
@pendingHorizontalScrollDelta = 0
previousScrollTop = editor.getScrollTop()
editor.setScrollTop(previousScrollTop - Math.round(wheelDeltaY * @scrollSensitivity))
event.preventDefault() unless previousScrollTop is editor.getScrollTop()
onScrollViewScroll: ->
if @isMounted()
@ -656,7 +670,7 @@ EditorComponent = React.createClass
onStylesheetsChanged: (stylesheet) ->
@refreshScrollbars() if @containsScrollbarSelector(stylesheet)
@remeasureCharacterWidthsIfVisibleAfterNextUpdate = true
@requestUpdate() if @state.visible
@requestUpdate() if @visible
onScreenLinesChanged: (change) ->
{editor} = @props
@ -733,68 +747,87 @@ EditorComponent = React.createClass
window.addEventListener('mousemove', onMouseMove)
window.addEventListener('mouseup', onMouseUp)
pauseScrollViewMeasurement: ->
@scrollViewMeasurementPaused = true
@resumeScrollViewMeasurementAfterDelay ?= debounce(@resumeScrollViewMeasurement, 100)
@resumeScrollViewMeasurementAfterDelay()
isVisible: ->
node = @getDOMNode()
node.offsetHeight > 0 or node.offsetWidth > 0
resumeScrollViewMeasurement: ->
@scrollViewMeasurementPaused = false
pauseDOMPolling: ->
@domPollingPaused = true
@resumeDOMPollingAfterDelay ?= debounce(@resumeDOMPolling, 100)
@resumeDOMPollingAfterDelay()
resumeScrollViewMeasurementAfterDelay: null # created lazily
resumeDOMPolling: ->
@domPollingPaused = false
requestScrollViewMeasurement: ->
return if @scrollViewMeasurementRequested
resumeDOMPollingAfterDelay: null # created lazily
@scrollViewMeasurementRequested = true
pollDOM: ->
return if @domPollingPaused or not @isMounted()
wasVisible = @visible
if @visible = @isVisible()
if wasVisible
@measureHeightAndWidth()
else
@performInitialMeasurement()
requestHeightAndWidthMeasurement: ->
return if @heightAndWidthMeasurementRequested
@heightAndWidthMeasurementRequested = true
requestAnimationFrame =>
@scrollViewMeasurementRequested = false
@measureScrollView()
@heightAndWidthMeasurementRequested = false
@measureHeightAndWidth()
# Measure explicitly-styled height and width and relay them to the model. If
# these values aren't explicitly styled, we assume the editor is unconstrained
# and use the scrollHeight / scrollWidth as its height and width in
# calculations.
measureScrollView: ->
return if @scrollViewMeasurementPaused
measureHeightAndWidth: ->
return unless @isMounted()
{editor} = @props
editorNode = @getDOMNode()
{editor, parentView} = @props
parentNode = parentView.element
scrollViewNode = @refs.scrollView.getDOMNode()
{position} = getComputedStyle(editorNode)
{width, height} = editorNode.style
{position} = getComputedStyle(parentNode)
{height} = parentNode.style
if position is 'absolute' or height
if @autoHeight
@autoHeight = false
@forceUpdate()
clientHeight = scrollViewNode.clientHeight
editor.setHeight(clientHeight) if clientHeight > 0
else
editor.setHeight(null)
@autoHeight = true
if position is 'absolute' or width
clientWidth = scrollViewNode.clientWidth
paddingLeft = parseInt(getComputedStyle(scrollViewNode).paddingLeft)
clientWidth -= paddingLeft
editor.setWidth(clientWidth) if clientWidth > 0
measureLineHeightAndCharWidthsIfNeeded: (prevState) ->
measureLineHeightAndDefaultCharWidthIfNeeded: (prevState) ->
if not isEqualForProperties(prevState, @state, 'lineHeight', 'fontSize', 'fontFamily')
if @state.visible
if @visible
@measureLineHeightAndDefaultCharWidth()
else
@measureLineHeightAndDefaultCharWidthWhenShown = true
else if @measureLineHeightAndDefaultCharWidthWhenShown and @state.visible and not prevState.visible
else if @measureLineHeightAndDefaultCharWidthWhenShown and @visible
@measureLineHeightAndDefaultCharWidthWhenShown = false
@measureLineHeightAndDefaultCharWidth()
measureLineHeightAndDefaultCharWidth: ->
@measureLineHeightAndDefaultCharWidthWhenShown = false
@refs.lines.measureLineHeightAndDefaultCharWidth()
remeasureCharacterWidthsIfNeeded: (prevState) ->
if not isEqualForProperties(prevState, @state, 'fontSize', 'fontFamily')
if @state.visible
if @visible
@remeasureCharacterWidths()
else
@remeasureCharacterWidthsIfVisibleAfterNextUpdate = true
else if @remeasureCharacterWidthsIfVisibleAfterNextUpdate and @state.visible
else if @remeasureCharacterWidthsIfVisibleAfterNextUpdate and @visible
@remeasureCharacterWidthsIfVisibleAfterNextUpdate = false
@remeasureCharacterWidths()
@ -805,6 +838,7 @@ EditorComponent = React.createClass
@requestUpdate()
measureScrollbars: ->
return unless @visible
@measuringScrollbars = false
{editor} = @props
@ -861,12 +895,6 @@ EditorComponent = React.createClass
node = node.parentNode
null
hide: ->
@setState(visible: false)
show: ->
@setState(visible: true)
getFontSize: ->
@state.fontSize
@ -940,6 +968,10 @@ EditorComponent = React.createClass
if prevState.focused isnt @state.focused
@props.parentView.toggleClass('is-focused', @props.focused)
updateParentViewMiniClassIfNeeded: (prevProps) ->
if prevProps.mini isnt @props.mini
@props.parentView.toggleClass('mini', @props.mini)
runScrollBenchmark: ->
unless process.env.NODE_ENV is 'production'
ReactPerf = require 'react-atom-fork/lib/ReactDefaultPerf'

View File

@ -518,6 +518,8 @@ class Editor extends Model
# {Delegates to: TextBuffer.isModified}
isModified: -> @buffer.isModified()
isEmpty: -> @buffer.isEmpty()
# Public: Determine whether the user should be prompted to save before closing
# this editor.
shouldPromptToSave: -> @isModified() and not @buffer.hasMultipleEditors()

View File

@ -19,9 +19,7 @@ GutterComponent = React.createClass
{scrollHeight, scrollViewHeight, onMouseDown} = @props
div className: 'gutter', onClick: @onClick, onMouseDown: onMouseDown,
# The line-numbers div must have the 'editor-colors' class so it has an
# opaque background to avoid sub-pixel anti-aliasing problems on the GPU
div className: 'gutter line-numbers editor-colors', ref: 'lineNumbers', style:
div className: 'line-numbers', ref: 'lineNumbers', style:
height: Math.max(scrollHeight, scrollViewHeight)
WebkitTransform: @getTransform()
@ -53,6 +51,8 @@ GutterComponent = React.createClass
)
{renderedRowRange, pendingChanges, lineDecorations} = newProps
return false unless renderedRowRange?
for change in pendingChanges when Math.abs(change.screenDelta) > 0 or Math.abs(change.bufferDelta) > 0
return true unless change.end <= renderedRowRange.start or renderedRowRange.end <= change.start

View File

@ -9,7 +9,7 @@ HighlightsComponent = React.createClass
render: ->
div className: 'highlights',
@renderHighlights() if @isMounted()
@renderHighlights() if @props.performedInitialMeasurement
renderHighlights: ->
{editor, highlightDecorations, lineHeightInPixels} = @props

View File

@ -16,18 +16,19 @@ LinesComponent = React.createClass
displayName: 'LinesComponent'
render: ->
if @isMounted()
{editor, highlightDecorations, scrollHeight, scrollWidth} = @props
{performedInitialMeasurement} = @props
if performedInitialMeasurement
{editor, highlightDecorations, scrollHeight, scrollWidth, placeholderText} = @props
{lineHeightInPixels, defaultCharWidth, scrollViewHeight, scopedCharacterWidthsChangeCount} = @props
style =
height: Math.max(scrollHeight, scrollViewHeight)
width: scrollWidth
WebkitTransform: @getTransform()
# The lines div must have the 'editor-colors' class so it has an opaque
# background to avoid sub-pixel anti-aliasing problems on the GPU
div {className: 'lines editor-colors', style},
HighlightsComponent({editor, highlightDecorations, lineHeightInPixels, defaultCharWidth, scopedCharacterWidthsChangeCount})
div {className: 'lines', style},
div className: 'placeholder-text', placeholderText if placeholderText?
HighlightsComponent({editor, highlightDecorations, lineHeightInPixels, defaultCharWidth, scopedCharacterWidthsChangeCount, performedInitialMeasurement})
getTransform: ->
{scrollTop, scrollLeft, useHardwareAcceleration} = @props
@ -48,10 +49,13 @@ LinesComponent = React.createClass
return true unless isEqualForProperties(newProps, @props,
'renderedRowRange', 'lineDecorations', 'highlightDecorations', 'lineHeightInPixels', 'defaultCharWidth',
'scrollTop', 'scrollLeft', 'showIndentGuide', 'scrollingVertically', 'invisibles', 'visible',
'scrollViewHeight', 'mouseWheelScreenRow', 'scopedCharacterWidthsChangeCount', 'lineWidth', 'useHardwareAcceleration'
'scrollViewHeight', 'mouseWheelScreenRow', 'scopedCharacterWidthsChangeCount', 'lineWidth', 'useHardwareAcceleration',
'placeholderText', 'performedInitialMeasurement'
)
{renderedRowRange, pendingChanges} = newProps
return false unless renderedRowRange?
[renderedStartRow, renderedEndRow] = renderedRowRange
for change in pendingChanges
if change.screenDelta is 0
@ -212,7 +216,7 @@ LinesComponent = React.createClass
# Find a common prefix
for scope, i in desiredScopes
break unless scopeStack[i]?.scope is desiredScopes[i]
break unless scopeStack[i] is desiredScopes[i]
# Pop scopes until we're at the common prefx
until scopeStack.length is i

View File

@ -1,15 +1,33 @@
{View, $} = require 'space-pen'
React = require 'react-atom-fork'
EditorComponent = require './editor-component'
{defaults} = require 'underscore-plus'
TextBuffer = require 'text-buffer'
Editor = require './editor'
EditorComponent = require './editor-component'
module.exports =
class ReactEditorView extends View
@content: -> @div class: 'editor react'
@content: (params) ->
attributes = params.attributes ? {}
attributes.class = 'editor react editor-colors'
@div attributes
focusOnAttach: false
constructor: (@editor, @props) ->
constructor: (editorOrParams, @props) ->
if editorOrParams instanceof Editor
@editor = editorOrParams
else
{@editor, mini, placeholderText} = editorOrParams
@props ?= {}
@props.mini = mini
@props.placeholderText = placeholderText
@editor ?= new Editor
buffer: new TextBuffer
softWrap: false
tabLength: 2
softTabs: true
super
getEditor: -> @editor
@ -122,7 +140,7 @@ class ReactEditorView extends View
pane?.splitDown(pane?.copyActiveItem()).activeView
getPane: ->
@closest('.pane').view()
@parent('.item-views').parents('.pane').view()
focus: ->
if @component?
@ -132,11 +150,18 @@ class ReactEditorView extends View
hide: ->
super
@component?.hide()
@pollComponentDOM()
show: ->
super
@component?.show()
@pollComponentDOM()
pollComponentDOM: ->
return unless @component?
valueToRestore = @component.performSyncUpdates
@component.performSyncUpdates = true
@component.pollDOM()
@component.performSyncUpdates = valueToRestore
pageDown: ->
@editor.pageDown()
@ -208,3 +233,9 @@ class ReactEditorView extends View
resetDisplay: -> # No-op shim for package specs
redraw: -> # No-op shim
setPlaceholderText: (placeholderText) ->
if @component?
@component.setProps({placeholderText})
else
@props.placeholderText = placeholderText

View File

@ -3,6 +3,10 @@
@import "octicon-mixins";
.editor.react {
.editor-contents {
width: 100%;
}
.underlayer {
position: absolute;
top: 0;
@ -81,15 +85,18 @@
}
}
.editor {
z-index: 0;
font-family: Inconsolata, Monaco, Consolas, 'Courier New', Courier;
line-height: 1.3;
}
.editor, .editor-contents {
overflow: hidden;
cursor: text;
display: -webkit-flex;
-webkit-user-select: none;
position: relative;
z-index: 0;
font-family: Inconsolata, Monaco, Consolas, 'Courier New', Courier;
line-height: 1.3;
}
.editor .gutter .line-number.cursor-line {