mirror of
https://github.com/atom/atom.git
synced 2026-01-22 21:38:10 -05:00
Merge pull request #5722 from atom/mb-search-multiple-root-directories
Never assume that the project only has one root directory or repository
This commit is contained in:
@@ -4018,3 +4018,25 @@ describe "TextEditor", ->
|
||||
editor.setPlaceholderText('OK')
|
||||
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 = new TextEditor({})
|
||||
editor.setText("stuff")
|
||||
editor.checkoutHeadRevision()
|
||||
|
||||
waitsForPromise -> editor.checkoutHeadRevision()
|
||||
|
||||
@@ -854,6 +854,64 @@ describe "Workspace", ->
|
||||
runs ->
|
||||
expect(results).toHaveLength 0
|
||||
|
||||
describe "when the project has multiple root directories", ->
|
||||
[dir1, dir2, file1, file2] = []
|
||||
|
||||
beforeEach ->
|
||||
[dir1] = atom.project.getPaths()
|
||||
file1 = path.join(dir1, "a-dir", "oh-git")
|
||||
|
||||
dir2 = temp.mkdirSync("a-second-dir")
|
||||
aDir2 = path.join(dir2, "a-dir")
|
||||
file2 = path.join(aDir2, "a-file")
|
||||
fs.mkdirSync(aDir2)
|
||||
fs.writeFileSync(file2, "ccc aaaa")
|
||||
|
||||
atom.project.addPath(dir2)
|
||||
|
||||
it "searches matching files in all of the project's root directories", ->
|
||||
resultPaths = []
|
||||
waitsForPromise ->
|
||||
atom.workspace.scan /aaaa/, ({filePath}) ->
|
||||
resultPaths.push(filePath)
|
||||
|
||||
runs ->
|
||||
expect(resultPaths.sort()).toEqual([file1, file2].sort())
|
||||
|
||||
describe "when an inclusion path starts with the basename of a root directory", ->
|
||||
it "interprets the inclusion path as starting from that directory", ->
|
||||
waitsForPromise ->
|
||||
resultPaths = []
|
||||
atom.workspace
|
||||
.scan /aaaa/, paths: ["dir"], ({filePath}) ->
|
||||
resultPaths.push(filePath) unless filePath in resultPaths
|
||||
.then ->
|
||||
expect(resultPaths).toEqual([file1])
|
||||
|
||||
waitsForPromise ->
|
||||
resultPaths = []
|
||||
atom.workspace
|
||||
.scan /aaaa/, paths: [path.join("dir", "a-dir")], ({filePath}) ->
|
||||
resultPaths.push(filePath) unless filePath in resultPaths
|
||||
.then ->
|
||||
expect(resultPaths).toEqual([file1])
|
||||
|
||||
waitsForPromise ->
|
||||
resultPaths = []
|
||||
atom.workspace
|
||||
.scan /aaaa/, paths: [path.basename(dir2)], ({filePath}) ->
|
||||
resultPaths.push(filePath) unless filePath in resultPaths
|
||||
.then ->
|
||||
expect(resultPaths).toEqual([file2])
|
||||
|
||||
waitsForPromise ->
|
||||
resultPaths = []
|
||||
atom.workspace
|
||||
.scan /aaaa/, paths: [path.join(path.basename(dir2), "a-dir")], ({filePath}) ->
|
||||
resultPaths.push(filePath) unless filePath in resultPaths
|
||||
.then ->
|
||||
expect(resultPaths).toEqual([file2])
|
||||
|
||||
describe "::replace(regex, replacementText, paths, iterator)", ->
|
||||
[filePath, commentFilePath, sampleContent, sampleCommentContent] = []
|
||||
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
_ = require "underscore-plus"
|
||||
path = require "path"
|
||||
async = require "async"
|
||||
{PathSearcher, PathScanner, search} = require 'scandal'
|
||||
|
||||
module.exports = (rootPath, regexSource, options) ->
|
||||
module.exports = (rootPaths, regexSource, options) ->
|
||||
callback = @async()
|
||||
|
||||
rootPath = rootPaths[0]
|
||||
|
||||
PATHS_COUNTER_SEARCHED_CHUNK = 50
|
||||
pathsSearched = 0
|
||||
|
||||
searcher = new PathSearcher()
|
||||
scanner = new PathScanner(rootPath, options)
|
||||
|
||||
searcher.on 'file-error', ({code, path, message}) ->
|
||||
emit('scan:file-error', {code, path, message})
|
||||
@@ -15,14 +19,41 @@ module.exports = (rootPath, regexSource, options) ->
|
||||
searcher.on 'results-found', (result) ->
|
||||
emit('scan:result-found', result)
|
||||
|
||||
scanner.on 'path-found', ->
|
||||
pathsSearched++
|
||||
if pathsSearched % PATHS_COUNTER_SEARCHED_CHUNK == 0
|
||||
emit('scan:paths-searched', pathsSearched)
|
||||
|
||||
flags = "g"
|
||||
flags += "i" if options.ignoreCase
|
||||
regex = new RegExp(regexSource, flags)
|
||||
search regex, scanner, searcher, ->
|
||||
emit('scan:paths-searched', pathsSearched)
|
||||
callback()
|
||||
|
||||
async.each(
|
||||
rootPaths,
|
||||
(rootPath, next) ->
|
||||
options2 = _.extend {}, options,
|
||||
inclusions: processPaths(rootPath, options.inclusions)
|
||||
exclusions: processPaths(rootPath, options.exclusions)
|
||||
|
||||
scanner = new PathScanner(rootPath, options2)
|
||||
|
||||
scanner.on 'path-found', ->
|
||||
pathsSearched++
|
||||
if pathsSearched % PATHS_COUNTER_SEARCHED_CHUNK == 0
|
||||
emit('scan:paths-searched', pathsSearched)
|
||||
|
||||
search regex, scanner, searcher, ->
|
||||
emit('scan:paths-searched', pathsSearched)
|
||||
next()
|
||||
callback
|
||||
)
|
||||
|
||||
processPaths = (rootPath, paths) ->
|
||||
return paths unless paths?.length > 0
|
||||
rootPathBase = path.basename(rootPath)
|
||||
results = []
|
||||
for givenPath in paths
|
||||
segments = givenPath.split(path.sep)
|
||||
firstSegment = segments.shift()
|
||||
results.push(givenPath)
|
||||
if firstSegment is rootPathBase
|
||||
if segments.length is 0
|
||||
results.push(path.join("**", "*"))
|
||||
else
|
||||
results.push(path.join(segments...))
|
||||
results
|
||||
|
||||
@@ -337,7 +337,7 @@ atom.commands.add 'atom-text-editor:not([mini])', stopEventPropagationAndGroupUn
|
||||
'editor:newline-below': -> @insertNewlineBelow()
|
||||
'editor:newline-above': -> @insertNewlineAbove()
|
||||
'editor:toggle-line-comments': -> @toggleLineCommentsInSelection()
|
||||
'editor:checkout-head-revision': -> atom.project.getRepositories()[0]?.checkoutHeadForEditor(this)
|
||||
'editor:checkout-head-revision': -> @checkoutHeadRevision()
|
||||
'editor:move-line-up': -> @moveLineUp()
|
||||
'editor:move-line-down': -> @moveLineDown()
|
||||
'editor:duplicate-lines': -> @duplicateLines()
|
||||
|
||||
@@ -12,6 +12,7 @@ DisplayBuffer = require './display-buffer'
|
||||
Cursor = require './cursor'
|
||||
Selection = require './selection'
|
||||
TextMateScopeSelector = require('first-mate').ScopeSelector
|
||||
{Directory} = require "pathwatcher"
|
||||
|
||||
# Public: This class represents all essential editing state for a single
|
||||
# {TextBuffer}, including cursor and selection positions, folds, and soft wraps.
|
||||
@@ -131,7 +132,7 @@ class TextEditor extends Model
|
||||
subscribeToBuffer: ->
|
||||
@buffer.retain()
|
||||
@subscribe @buffer.onDidChangePath =>
|
||||
unless atom.project.getPaths()[0]?
|
||||
unless atom.project.getPaths().length > 0
|
||||
atom.project.setPaths([path.dirname(@getPath())])
|
||||
@emit "title-changed"
|
||||
@emitter.emit 'did-change-title', @getTitle()
|
||||
@@ -647,6 +648,14 @@ class TextEditor extends Model
|
||||
else
|
||||
@isModified() and not @buffer.hasMultipleEditors()
|
||||
|
||||
checkoutHeadRevision: ->
|
||||
if filePath = this.getPath()
|
||||
atom.project.repositoryForDirectory(new Directory(path.dirname(filePath)))
|
||||
.then (repository) =>
|
||||
repository?.checkoutHeadForEditor(this)
|
||||
else
|
||||
Promise.resolve(false)
|
||||
|
||||
###
|
||||
Section: Reading Text
|
||||
###
|
||||
|
||||
@@ -159,16 +159,24 @@ class Workspace extends Model
|
||||
# open.
|
||||
updateWindowTitle: =>
|
||||
appName = 'Atom'
|
||||
if projectPath = atom.project?.getPaths()[0]
|
||||
if item = @getActivePaneItem()
|
||||
document.title = "#{item.getTitle?() ? 'untitled'} - #{projectPath} - #{appName}"
|
||||
atom.setRepresentedFilename(item.getPath?() ? projectPath)
|
||||
else
|
||||
document.title = "#{projectPath} - #{appName}"
|
||||
atom.setRepresentedFilename(projectPath)
|
||||
projectPaths = atom.project?.getPaths() ? []
|
||||
if item = @getActivePaneItem()
|
||||
itemPath = item.getPath?()
|
||||
itemTitle = item.getTitle?()
|
||||
projectPath = _.find projectPaths, (projectPath) ->
|
||||
itemPath is projectPath or itemPath?.startsWith(projectPath + path.sep)
|
||||
itemTitle ?= "untitled"
|
||||
projectPath ?= projectPaths[0]
|
||||
|
||||
if item? and projectPath?
|
||||
document.title = "#{itemTitle} - #{projectPath} - #{appName}"
|
||||
atom.setRepresentedFilename(itemPath ? projectPath)
|
||||
else if projectPath?
|
||||
document.title = "#{projectPath} - #{appName}"
|
||||
atom.setRepresentedFilename(projectPath)
|
||||
else
|
||||
document.title = "untitled - #{appName}"
|
||||
atom.setRepresentedFilename('')
|
||||
document.title = "#{itemTitle} - #{appName}"
|
||||
atom.setRepresentedFilename("")
|
||||
|
||||
# On OS X, fades the application window's proxy icon when the current file
|
||||
# has been modified.
|
||||
@@ -870,8 +878,7 @@ class Workspace extends Model
|
||||
exclusions: atom.config.get('core.ignoredNames')
|
||||
follow: atom.config.get('core.followSymlinks')
|
||||
|
||||
# TODO: need to support all paths in @getPaths()
|
||||
task = Task.once require.resolve('./scan-handler'), atom.project.getPaths()[0], regex.source, searchOptions, ->
|
||||
task = Task.once require.resolve('./scan-handler'), atom.project.getPaths(), regex.source, searchOptions, ->
|
||||
deferred.resolve()
|
||||
|
||||
task.on 'scan:result-found', (result) ->
|
||||
|
||||
Reference in New Issue
Block a user