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

Commit

Permalink
Always return an object from getEditorDetails
Browse files Browse the repository at this point in the history
Resolves #74
  • Loading branch information
thomasjo committed Apr 21, 2015
1 parent b0e5924 commit c6b2dcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/composer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Composer

build: ->
{editor, filePath} = @getEditorDetails()
return Promise.reject(false) unless editor?

unless filePath?
latex.log.warning('File needs to be saved to disk before it can be TeXified.')
Expand Down Expand Up @@ -150,12 +151,10 @@ class Composer

getEditorDetails: ->
editor = atom.workspace.getActiveTextEditor()
return unless editor?

editorDetails =
editor: editor
filePath: editor.getPath()
lineNumber: editor.getCursorBufferPosition().row + 1
filePath: editor?.getPath()
lineNumber: editor?.getCursorBufferPosition()?.row + 1

alterParentPath: (targetPath, originalPath) ->
targetDir = path.dirname(targetPath)
Expand Down
10 changes: 10 additions & 0 deletions spec/composer-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ describe "Composer", ->
runs ->
expect(composer.showError).toHaveBeenCalled()

it "handles active item not being a text editor", ->
spyOn(atom.workspace, 'getActiveTextEditor').andReturn()
spyOn(composer, 'getEditorDetails').andCallThrough()

waitsForPromise shouldReject: true, ->
composer.build()

runs ->
expect(composer.getEditorDetails).toHaveBeenCalled()

describe "clean", ->
extensions = ['.bar', '.baz', '.quux']
fakeFilePaths = (filePath) ->
Expand Down

0 comments on commit c6b2dcf

Please sign in to comment.