Skip to content

Commit f0ecb3e

Browse files
committed
Fixes #85 by reworking logic to get path from event elem
1 parent b8ec437 commit f0ecb3e

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 1.4.1 - 2017-06-11
22
* Fixed ctrl-alt-t keybinding conflict in Linux with terminal shortcut (changed to ctrl-alt-d) #98
3+
* Fixed uncaught type error for "Diff With Active File" when using Nuclide package #85
4+
* Fixed error for "Diff With Active File" when selected for a tab not saved on disk
35

46
## 1.4.0 - 2017-05-17
57
* Added option to override diff highlight colors #78

lib/split-diff.coffee

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ module.exports = SplitDiff =
175175
@editorSubscriptions = new CompositeDisposable()
176176

177177
if !editorsPromise
178-
if event?.currentTarget.classList.contains('tab')
179-
filePath = event.currentTarget.path
180-
editorsPromise = @_getEditorsForDiffWithActive(filePath)
181-
else if event?.currentTarget.classList.contains('list-item') && event?.currentTarget.classList.contains('file')
182-
filePath = event.currentTarget.getPath()
183-
editorsPromise = @_getEditorsForDiffWithActive(filePath)
178+
if event?.currentTarget.classList.contains('tab') || event?.currentTarget.classList.contains('file')
179+
elemWithPath = event.currentTarget.querySelector('[data-path]')
180+
params = {}
181+
182+
if elemWithPath
183+
params.path = elemWithPath.dataset.path
184+
else if event.currentTarget.item
185+
params.editor = event.currentTarget.item
186+
187+
editorsPromise = @_getEditorsForDiffWithActive(params)
184188
else
185189
editorsPromise = @_getEditorsForQuickDiff()
186190

@@ -370,8 +374,11 @@ module.exports = SplitDiff =
370374

371375
# Gets the active editor and opens the specified file to the right of it
372376
# Returns a Promise which yields a value of {editor1: TextEditor, editor2: TextEditor}
373-
_getEditorsForDiffWithActive: (filePath) ->
377+
_getEditorsForDiffWithActive: (params) ->
378+
filePath = params.path
379+
editorWithoutPath = params.editor
374380
activeEditor = atom.workspace.getCenter().getActiveTextEditor()
381+
375382
if activeEditor?
376383
editor1 = activeEditor
377384
@wasEditor2Created = true
@@ -380,14 +387,22 @@ module.exports = SplitDiff =
380387
rightPaneIndex = panes.indexOf(atom.workspace.paneForItem(editor1)) + 1
381388
# pane is created if there is not one to the right of the active editor
382389
rightPane = panes[rightPaneIndex] || atom.workspace.paneForItem(editor1).splitRight()
383-
if editor1.getPath() == filePath
384-
# if diffing with itself, set filePath to null so an empty editor is
385-
# opened, which will cause a git diff
386-
filePath = null
387-
editor2Promise = atom.workspace.openURIInPane(filePath, rightPane)
388-
389-
return editor2Promise.then (editor2) ->
390-
return {editor1: editor1, editor2: editor2}
390+
391+
if params.path
392+
filePath = params.path
393+
if editor1.getPath() == filePath
394+
# if diffing with itself, set filePath to null so an empty editor is
395+
# opened, which will cause a git diff
396+
filePath = null
397+
editor2Promise = atom.workspace.openURIInPane(filePath, rightPane)
398+
399+
return editor2Promise.then (editor2) ->
400+
return {editor1: editor1, editor2: editor2}
401+
else if editorWithoutPath
402+
editor2 = editorWithoutPath.copy()
403+
rightPane.addItem(editor2)
404+
405+
return Promise.resolve({editor1: editor1, editor2: editor2})
391406
else
392407
noActiveEditorMsg = 'No active file found! (Try focusing a text editor)'
393408
atom.notifications.addWarning('Split Diff', {detail: noActiveEditorMsg, dismissable: false, icon: 'diff'})

0 commit comments

Comments
 (0)