mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Merge pull request #11614 from atom/remove-project-dependency
Remove TextEditor's dependency on Project
This commit is contained in:
@@ -5727,28 +5727,6 @@ describe "TextEditor", ->
|
||||
expect(handler).toHaveBeenCalledWith 'OK'
|
||||
expect(editor.getPlaceholderText()).toBe 'OK'
|
||||
|
||||
describe ".checkoutHeadRevision()", ->
|
||||
it "reverts to the version of its file checked into the project repository", ->
|
||||
atom.config.set("editor.confirmCheckoutHeadRevision", false)
|
||||
|
||||
editor.setCursorBufferPosition([0, 0])
|
||||
editor.insertText("---\n")
|
||||
expect(editor.lineTextForBufferRow(0)).toBe "---"
|
||||
|
||||
waitsForPromise ->
|
||||
editor.checkoutHeadRevision()
|
||||
|
||||
runs ->
|
||||
expect(editor.lineTextForBufferRow(0)).toBe "var quicksort = function () {"
|
||||
|
||||
describe "when there's no repository for the editor's file", ->
|
||||
it "doesn't do anything", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor.setText("stuff")
|
||||
editor.checkoutHeadRevision()
|
||||
|
||||
waitsForPromise -> editor.checkoutHeadRevision()
|
||||
|
||||
describe 'gutters', ->
|
||||
describe 'the TextEditor constructor', ->
|
||||
it 'creates a line-number gutter', ->
|
||||
|
||||
@@ -1633,5 +1633,31 @@ describe "Workspace", ->
|
||||
runs ->
|
||||
expect(grammarUsed.argsForCall[0][0].name).toBe 'JavaScript'
|
||||
|
||||
describe ".checkoutHeadRevision()", ->
|
||||
editor = null
|
||||
beforeEach ->
|
||||
atom.config.set("editor.confirmCheckoutHeadRevision", false)
|
||||
|
||||
waitsForPromise -> atom.workspace.open('sample-with-comments.js').then (o) -> editor = o
|
||||
|
||||
it "reverts to the version of its file checked into the project repository", ->
|
||||
editor.setCursorBufferPosition([0, 0])
|
||||
editor.insertText("---\n")
|
||||
expect(editor.lineTextForBufferRow(0)).toBe "---"
|
||||
|
||||
waitsForPromise ->
|
||||
atom.workspace.checkoutHeadRevision(editor)
|
||||
|
||||
runs ->
|
||||
expect(editor.lineTextForBufferRow(0)).toBe ""
|
||||
|
||||
describe "when there's no repository for the editor's file", ->
|
||||
it "doesn't do anything", ->
|
||||
editor = atom.workspace.buildTextEditor()
|
||||
editor.setText("stuff")
|
||||
atom.workspace.checkoutHeadRevision(editor)
|
||||
|
||||
waitsForPromise -> atom.workspace.checkoutHeadRevision(editor)
|
||||
|
||||
escapeStringRegex = (str) ->
|
||||
str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
|
||||
|
||||
@@ -391,6 +391,9 @@ class Project extends Model
|
||||
|
||||
subscribeToBuffer: (buffer) ->
|
||||
buffer.onDidDestroy => @removeBuffer(buffer)
|
||||
buffer.onDidChangePath =>
|
||||
unless @getPaths().length > 0
|
||||
@setPaths([path.dirname(buffer.getPath())])
|
||||
buffer.onWillThrowWatchError ({error, handle}) =>
|
||||
handle()
|
||||
@notificationManager.addWarning """
|
||||
|
||||
@@ -204,7 +204,7 @@ module.exports = ({commandRegistry, commandInstaller, config, notificationManage
|
||||
'editor:newline-below': -> @insertNewlineBelow()
|
||||
'editor:newline-above': -> @insertNewlineAbove()
|
||||
'editor:toggle-line-comments': -> @toggleLineCommentsInSelection()
|
||||
'editor:checkout-head-revision': -> @checkoutHeadRevision()
|
||||
'editor:checkout-head-revision': -> atom.workspace.checkoutHeadRevision(this)
|
||||
'editor:move-line-up': -> @moveLineUp()
|
||||
'editor:move-line-down': -> @moveLineDown()
|
||||
'editor:move-selection-left': -> @moveSelectionLeft()
|
||||
|
||||
@@ -9,7 +9,6 @@ Cursor = require './cursor'
|
||||
Model = require './model'
|
||||
Selection = require './selection'
|
||||
TextMateScopeSelector = require('first-mate').ScopeSelector
|
||||
{Directory} = require "pathwatcher"
|
||||
GutterContainer = require './gutter-container'
|
||||
TextEditorElement = require './text-editor-element'
|
||||
|
||||
@@ -81,7 +80,6 @@ class TextEditor extends Model
|
||||
state.config = atomEnvironment.config
|
||||
state.clipboard = atomEnvironment.clipboard
|
||||
state.grammarRegistry = atomEnvironment.grammars
|
||||
state.project = atomEnvironment.project
|
||||
state.assert = atomEnvironment.assert.bind(atomEnvironment)
|
||||
state.applicationDelegate = atomEnvironment.applicationDelegate
|
||||
editor = new this(state)
|
||||
@@ -97,13 +95,12 @@ class TextEditor extends Model
|
||||
@softTabs, @firstVisibleScreenRow, @firstVisibleScreenColumn, initialLine, initialColumn, tabLength,
|
||||
softWrapped, @displayBuffer, @selectionsMarkerLayer, buffer, suppressCursorCreation,
|
||||
@mini, @placeholderText, lineNumberGutterVisible, largeFileMode, @config, @clipboard, @grammarRegistry,
|
||||
@project, @assert, @applicationDelegate, grammar, showInvisibles, @autoHeight, @scrollPastEnd
|
||||
@assert, @applicationDelegate, grammar, showInvisibles, @autoHeight, @scrollPastEnd
|
||||
} = params
|
||||
|
||||
throw new Error("Must pass a config parameter when constructing TextEditors") unless @config?
|
||||
throw new Error("Must pass a clipboard parameter when constructing TextEditors") unless @clipboard?
|
||||
throw new Error("Must pass a grammarRegistry parameter when constructing TextEditors") unless @grammarRegistry?
|
||||
throw new Error("Must pass a project parameter when constructing TextEditors") unless @project?
|
||||
throw new Error("Must pass an assert parameter when constructing TextEditors") unless @assert?
|
||||
|
||||
@firstVisibleScreenRow ?= 0
|
||||
@@ -166,8 +163,6 @@ class TextEditor extends Model
|
||||
subscribeToBuffer: ->
|
||||
@buffer.retain()
|
||||
@disposables.add @buffer.onDidChangePath =>
|
||||
unless @project.getPaths().length > 0
|
||||
@project.setPaths([path.dirname(@getPath())])
|
||||
@emitter.emit 'did-change-title', @getTitle()
|
||||
@emitter.emit 'did-change-path', @getPath()
|
||||
@disposables.add @buffer.onDidChangeEncoding =>
|
||||
@@ -515,7 +510,7 @@ class TextEditor extends Model
|
||||
@buffer, displayBuffer, selectionsMarkerLayer, @tabLength, softTabs,
|
||||
suppressCursorCreation: true, @config,
|
||||
@firstVisibleScreenRow, @firstVisibleScreenColumn,
|
||||
@clipboard, @grammarRegistry, @project, @assert, @applicationDelegate
|
||||
@clipboard, @grammarRegistry, @assert, @applicationDelegate
|
||||
})
|
||||
newEditor
|
||||
|
||||
@@ -709,25 +704,6 @@ class TextEditor extends Model
|
||||
# via {Pane::saveItemAs}.
|
||||
getSaveDialogOptions: -> {}
|
||||
|
||||
checkoutHeadRevision: ->
|
||||
if @getPath()
|
||||
checkoutHead = =>
|
||||
@project.repositoryForDirectory(new Directory(@getDirectoryPath()))
|
||||
.then (repository) =>
|
||||
repository?.async.checkoutHeadForEditor(this)
|
||||
|
||||
if @config.get('editor.confirmCheckoutHeadRevision')
|
||||
@applicationDelegate.confirm
|
||||
message: 'Confirm Checkout HEAD Revision'
|
||||
detailedMessage: "Are you sure you want to discard all changes to \"#{@getFileName()}\" since the last Git commit?"
|
||||
buttons:
|
||||
OK: checkoutHead
|
||||
Cancel: null
|
||||
else
|
||||
checkoutHead()
|
||||
else
|
||||
Promise.resolve(false)
|
||||
|
||||
###
|
||||
Section: Reading Text
|
||||
###
|
||||
|
||||
@@ -4,6 +4,7 @@ path = require 'path'
|
||||
{join} = path
|
||||
{Emitter, Disposable, CompositeDisposable} = require 'event-kit'
|
||||
fs = require 'fs-plus'
|
||||
{Directory} = require 'pathwatcher'
|
||||
DefaultDirectorySearcher = require './default-directory-searcher'
|
||||
Model = require './model'
|
||||
TextEditor = require './text-editor'
|
||||
@@ -573,7 +574,7 @@ class Workspace extends Model
|
||||
buildTextEditor: (params) ->
|
||||
params = _.extend({
|
||||
@config, @clipboard, @grammarRegistry,
|
||||
@project, @assert, @applicationDelegate
|
||||
@assert, @applicationDelegate
|
||||
}, params)
|
||||
new TextEditor(params)
|
||||
|
||||
@@ -1087,3 +1088,22 @@ class Workspace extends Model
|
||||
|
||||
inProcessFinished = true
|
||||
checkFinished()
|
||||
|
||||
checkoutHeadRevision: (editor) ->
|
||||
if editor.getPath()
|
||||
checkoutHead = =>
|
||||
@project.repositoryForDirectory(new Directory(editor.getDirectoryPath()))
|
||||
.then (repository) =>
|
||||
repository?.async.checkoutHeadForEditor(editor)
|
||||
|
||||
if @config.get('editor.confirmCheckoutHeadRevision')
|
||||
@applicationDelegate.confirm
|
||||
message: 'Confirm Checkout HEAD Revision'
|
||||
detailedMessage: "Are you sure you want to discard all changes to \"#{editor.getFileName()}\" since the last Git commit?"
|
||||
buttons:
|
||||
OK: checkoutHead
|
||||
Cancel: null
|
||||
else
|
||||
checkoutHead()
|
||||
else
|
||||
Promise.resolve(false)
|
||||
|
||||
Reference in New Issue
Block a user