Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/find.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports =
@subscriptions.add atom.workspace.getCenter().observeActivePaneItem (paneItem) =>
if atom.workspace.isTextEditor(paneItem)
@findModel.setEditor(paneItem)
else if paneItem?.getEmbeddedTextEditor?
@findModel.setEditor(paneItem.getEmbeddedTextEditor())
else
@findModel.setEditor(null)

Expand Down
14 changes: 11 additions & 3 deletions spec/find-spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const {it, fit, ffit, beforeEach, afterEach} = require('./async-spec-helpers') // eslint-disable-line no-unused-vars

const BufferSearch = require('../lib/buffer-search')
const EmbeddedEditorItem = require('./item/embedded-editor-item')
const UnrecognizedItem = require('./item/unrecognized-item');

describe('Find', () => {
describe('updating the find model', () => {
beforeEach(async () => {
atom.workspace.addOpener(EmbeddedEditorItem.opener)
atom.workspace.addOpener(UnrecognizedItem.opener)

const activationPromise = atom.packages.activatePackage('find-and-replace')
atom.commands.dispatch(atom.views.getView(atom.workspace), 'find-and-replace:show')
await activationPromise
Expand All @@ -20,10 +25,13 @@ describe('Find', () => {
expect(BufferSearch.prototype.setEditor).toHaveBeenCalledWith(editor)
})

it("sets the find model's editor to null if a non-editor is focused", async () => {
spyOn(atom.workspace, 'isTextEditor').andReturn(false)
it("sets the find model's editor to an embedded text editor", async () => {
const embedded = await atom.workspace.open(EmbeddedEditorItem.uri)
expect(BufferSearch.prototype.setEditor).toHaveBeenCalledWith(embedded.refs.theEditor)
})

await atom.workspace.open()
it("sets the find model's editor to null if a non-editor is focused", async () => {
await atom.workspace.open(UnrecognizedItem.uri)
expect(BufferSearch.prototype.setEditor).toHaveBeenCalledWith(null)
})
})
Expand Down
38 changes: 38 additions & 0 deletions spec/item/embedded-editor-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// An active workspace item that embeds an AtomTextEditor we wish to expose to Find and Replace.

const etch = require('etch');
const $ = etch.dom;

const { TextEditor } = require('atom');

class EmbeddedEditorItem {
static opener(u) {
if (u === EmbeddedEditorItem.uri) {
return new EmbeddedEditorItem();
} else {
return undefined;
}
}

constructor() {
etch.initialize(this);
}

render() {
return (
$.div({className: 'wrapper'},
etch.dom(TextEditor, {ref: 'theEditor'})
)
)
}

update() {}

getEmbeddedTextEditor() {
return this.refs.theEditor
}
}

EmbeddedEditorItem.uri = 'atom://find-and-replace/spec/embedded-editor'

module.exports = EmbeddedEditorItem
30 changes: 30 additions & 0 deletions spec/item/unrecognized-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// An active workspace item that doesn't contain a TextEditor.

const etch = require('etch');
const $ = etch.dom;

class UnrecognizedItem {
static opener(u) {
if (u === UnrecognizedItem.uri) {
return new UnrecognizedItem();
} else {
return undefined;
}
}

constructor() {
etch.initialize(this);
}

render() {
return (
$.div({className: 'wrapper'}, 'Some text')
)
}

update() {}
}

UnrecognizedItem.uri = 'atom://find-and-replace/spec/unrecognized'

module.exports = UnrecognizedItem