mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Teach Workspace::getActiveTextEditor() to get item from center
This commit is contained in:
parent
61a52d49aa
commit
cf50625cc6
@ -1419,6 +1419,42 @@ describe('Workspace', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('::getActiveTextEditor()', () => {
|
||||
describe("when the workspace center's active pane item is a text editor", () => {
|
||||
describe('when the workspace center has focus', function () {
|
||||
it('returns the text editor', () => {
|
||||
const workspaceCenter = workspace.getCenter()
|
||||
const editor = new TextEditor()
|
||||
workspaceCenter.getActivePane().activateItem(editor)
|
||||
workspaceCenter.activate()
|
||||
|
||||
expect(workspace.getActiveTextEditor()).toBe(editor)
|
||||
})
|
||||
})
|
||||
|
||||
describe('when a dock has focus', function () {
|
||||
it('returns the text editor', () => {
|
||||
const workspaceCenter = workspace.getCenter()
|
||||
const editor = new TextEditor()
|
||||
workspaceCenter.getActivePane().activateItem(editor)
|
||||
workspace.getLeftDock().activate()
|
||||
|
||||
expect(workspace.getActiveTextEditor()).toBe(editor)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("when the workspace center's active pane item is not a text editor", () => {
|
||||
it('returns undefined', () => {
|
||||
const workspaceCenter = workspace.getCenter()
|
||||
const nonEditorItem = document.createElement('div')
|
||||
workspaceCenter.getActivePane().activateItem(nonEditorItem)
|
||||
|
||||
expect(workspace.getActiveTextEditor()).toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('::observeTextEditors()', () => {
|
||||
it('invokes the observer with current and future text editors', () => {
|
||||
const observed = []
|
||||
|
@ -1282,12 +1282,12 @@ module.exports = class Workspace extends Model {
|
||||
return this.getPaneItems().filter(item => item instanceof TextEditor)
|
||||
}
|
||||
|
||||
// Essential: Get the active item if it is an {TextEditor}.
|
||||
// Essential: Get the workspace center's active item if it is a {TextEditor}.
|
||||
//
|
||||
// Returns an {TextEditor} or `undefined` if the current active item is not an
|
||||
// {TextEditor}.
|
||||
// Returns a {TextEditor} or `undefined` if the workspace center's current
|
||||
// active item is not a {TextEditor}.
|
||||
getActiveTextEditor () {
|
||||
const activeItem = this.getActivePaneItem()
|
||||
const activeItem = this.getCenter().getActivePaneItem()
|
||||
if (activeItem instanceof TextEditor) { return activeItem }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user