@@ -175,12 +175,16 @@ module.exports = SplitDiff =
175
175
@editorSubscriptions = new CompositeDisposable ()
176
176
177
177
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)
184
188
else
185
189
editorsPromise = @ _getEditorsForQuickDiff ()
186
190
@@ -370,8 +374,11 @@ module.exports = SplitDiff =
370
374
371
375
# Gets the active editor and opens the specified file to the right of it
372
376
# 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
374
380
activeEditor = atom .workspace .getCenter ().getActiveTextEditor ()
381
+
375
382
if activeEditor?
376
383
editor1 = activeEditor
377
384
@wasEditor2Created = true
@@ -380,14 +387,22 @@ module.exports = SplitDiff =
380
387
rightPaneIndex = panes .indexOf (atom .workspace .paneForItem (editor1)) + 1
381
388
# pane is created if there is not one to the right of the active editor
382
389
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})
391
406
else
392
407
noActiveEditorMsg = ' No active file found! (Try focusing a text editor)'
393
408
atom .notifications .addWarning (' Split Diff' , {detail : noActiveEditorMsg, dismissable : false , icon : ' diff' })
0 commit comments