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

Commit

Permalink
Merge pull request #437 from atom/as-fix-drop-indicators-on-new-electron
Browse files Browse the repository at this point in the history
Fix mistakenly shown docks drop indicator on Electron >= 1.4
  • Loading branch information
Antonio Scandurra authored May 5, 2017
2 parents 0fb0ca9 + 84b9b71 commit f5833fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
24 changes: 15 additions & 9 deletions lib/tab-bar-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ class TabBarView
itemURI = item.getUri() ? ''

if typeof item.getAllowedLocations is 'function'
event.dataTransfer.setData 'allowed-locations', item.getAllowedLocations().join('|')
for location in item.getAllowedLocations()
event.dataTransfer.setData("allowed-location-#{location}", 'true')
else
event.dataTransfer.setData 'allow-all-locations', 'true'

if itemURI?
event.dataTransfer.setData 'text/plain', itemURI
Expand Down Expand Up @@ -289,7 +292,7 @@ class TabBarView
@clearDropTarget()

onDragOver: (event) ->
unless @isAtomEvent(event)
unless isAtomEvent(event)
event.preventDefault()
event.stopPropagation()
return
Expand Down Expand Up @@ -507,13 +510,16 @@ class TabBarView
else
currentElement = currentElement.parentElement

isAtomEvent: (event) ->
for item in event.dataTransfer.items
if item.type is 'atom-event'
return true
isAtomEvent = (event) ->
for item in event.dataTransfer.items
if item.type is 'atom-event'
return true

return false
return false

itemIsAllowed = (event, location) ->
allowedLocations = (event.dataTransfer.getData('allowed-locations') or '').trim()
not allowedLocations or allowedLocations.split('|').includes(location)
for item in event.dataTransfer.items
if item.type is 'allow-all-locations' or item.type is "allowed-location-#{location}"
return true

return false
38 changes: 22 additions & 16 deletions spec/tabs-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1061,22 +1061,28 @@ describe "TabBarView", ->
expect(pane2.activeItem).toBe item1
expect(atom.workspace.getLeftDock().isVisible()).toBe(true)

describe "when the tab's item is not allowed in that pane container", ->
it "does not show a placeholder or allow the tab be dropped", ->
item1.getAllowedLocations = -> ['center', 'bottom']

expect(pane.getItems()).toEqual [item1, editor1, item2]
expect(pane2.getItems()).toEqual [dockItem]

[dragStartEvent, dropEvent] = buildDragEvents(tabBar.tabAtIndex(0).element, tabBar2.element)
tabBar.onDragStart(dragStartEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
tabBar2.onDragOver(dropEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
tabBar2.onDrop(dropEvent)

expect(pane.getItems()).toEqual [item1, editor1, item2]
expect(pane2.getItems()).toEqual [dockItem]
it "shows a placeholder and allows the tab be dropped only if the item supports the target pane container location", ->
item1.getAllowedLocations = -> ['center', 'bottom']
[dragStartEvent, dropEvent] = buildDragEvents(tabBar.tabAtIndex(0).element, tabBar2.element)
tabBar.onDragStart(dragStartEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
tabBar2.onDragOver(dropEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
tabBar2.onDrop(dropEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
expect(pane.getItems()).toEqual [item1, editor1, item2]
expect(pane2.getItems()).toEqual [dockItem]

item1.getAllowedLocations = -> ['left']
[dragStartEvent, dropEvent] = buildDragEvents(tabBar.tabAtIndex(0).element, tabBar2.element)
tabBar.onDragStart(dragStartEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
tabBar2.onDragOver(dropEvent)
expect(tabBar2.element.querySelector('.placeholder')).not.toBeNull()
tabBar2.onDrop(dropEvent)
expect(tabBar2.element.querySelector('.placeholder')).toBeNull()
expect(pane.getItems()).toEqual [editor1, item2]
expect(pane2.getItems()).toEqual [dockItem, item1]

describe "when the tab bar is double clicked", ->
it "opens a new empty editor", ->
Expand Down

0 comments on commit f5833fa

Please sign in to comment.