Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #96 from atom/bo-find-changes
Browse files Browse the repository at this point in the history
Small find changes
  • Loading branch information
benogle committed Dec 9, 2013
2 parents 021a683 + cb2897c commit 79ad37f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/find-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class FindView extends View
atom.workspaceView.command 'find-and-replace:replace-all', @replaceAll

showFind: =>
unless @findEditor.getText()
editorView = atom.workspaceView.getActiveView()
@findEditor.setText(editorView.getSelectedText()) if editorView

@attach() if not @hasParent()
@findEditor.focus()
@findEditor.selectAll()
Expand Down
5 changes: 5 additions & 0 deletions lib/find.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ module.exports =
@projectFindView.attach()
@projectFindView.findInCurrentlySelectedDirectory($(e.target))

atom.workspaceView.command 'find-and-replace:use-selection-as-find-pattern', =>
return if @projectFindView.isOnDom() or @findView.isOnDom()
@projectFindView.detach()
@findView.showFind()

atom.workspaceView.command 'find-and-replace:show', =>
@projectFindView.detach()
@findView.showFind()
Expand Down
5 changes: 5 additions & 0 deletions lib/project-find-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class ProjectFindView extends View

attach: ->
atom.workspaceView.vertical.append(this) unless @hasParent()

unless @findEditor.getText()
editorView = atom.workspaceView.getActiveView()
@findEditor.setText(editorView.getSelectedText()) if editorView

@findEditor.focus()
@findEditor.selectAll()

Expand Down
13 changes: 13 additions & 0 deletions spec/find-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ describe 'FindView', ->
editor.trigger 'find-and-replace:show'
expect(atom.workspaceView.find('.find-and-replace')).toExist()

it "populates the findEditor with selection when there is a selection", ->
editor.setSelectedBufferRange([[2, 8], [2, 13]])
editor.trigger 'find-and-replace:show'
expect(atom.workspaceView.find('.find-and-replace')).toExist()
expect(findView.findEditor.getText()).toBe('items')

findView.findEditor.setText('')

editor.setSelectedBufferRange([[2, 14], [2, 20]])
editor.trigger 'find-and-replace:show'
expect(atom.workspaceView.find('.find-and-replace')).toExist()
expect(findView.findEditor.getText()).toBe('length')

describe "when FindView's replace editor is visible", ->
it "keeps the replace editor visible when find-and-replace:show is triggered", ->
editor.trigger 'find-and-replace:show-replace'
Expand Down
19 changes: 19 additions & 0 deletions spec/project-find-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ describe 'ProjectFindView', ->
expect(projectFindView.find('.loading')).not.toBeVisible()
expect(projectFindView.findEditor.getSelectedBufferRange()).toEqual [[0, 0], [0, 5]]

describe "with an open buffer", ->
beforeEach ->
projectFindView.findEditor.setText('')
atom.workspaceView.openSync('sample.js')
editor = atom.workspaceView.getActiveView()

it "populates the findEditor with selection when there is a selection", ->
editor.setSelectedBufferRange([[2, 8], [2, 13]])
atom.workspaceView.trigger 'project-find:show'
expect(atom.workspaceView.find('.project-find')).toExist()
expect(projectFindView.findEditor.getText()).toBe('items')

projectFindView.findEditor.setText('')

editor.setSelectedBufferRange([[2, 14], [2, 20]])
atom.workspaceView.trigger 'project-find:show'
expect(atom.workspaceView.find('.project-find')).toExist()
expect(projectFindView.findEditor.getText()).toBe('length')

describe "when thethe ProjectFindView is already attached", ->
beforeEach ->
atom.workspaceView.trigger 'project-find:show'
Expand Down

0 comments on commit 79ad37f

Please sign in to comment.