Skip to content

Commit

Permalink
Fixes dnd for url bar icon
Browse files Browse the repository at this point in the history
Resolves brave#12476

Auditors:

Test Plan:
  • Loading branch information
NejcZdovc committed Jan 3, 2018
1 parent ab25724 commit 7793647
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 59 deletions.
15 changes: 12 additions & 3 deletions app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const dndData = require('../../../../js/dndData')
const isWindows = require('../../../common/lib/platformUtil').isWindows()
const frameStateUtil = require('../../../../js/state/frameStateUtil')
const bookmarkUtil = require('../../../common/lib/bookmarkUtil')
const bookmarkFoldersUtil = require('../../../common/lib/bookmarkFoldersUtil')
const {elementHasDataset} = require('../../../../js/lib/eventUtil')
const {getCurrentWindowId} = require('../../currentWindow')

Expand Down Expand Up @@ -60,16 +61,24 @@ class BookmarksToolbar extends React.Component {
const bookmark = dnd.prepareBookmarkDataFromCompatible(e.dataTransfer)
if (bookmark) {
// Figure out the droppedOn element filtering out the source drag item
const bookmarkKey = bookmark.get('key')
let bookmarkKey = bookmark.get('key')
if (bookmarkKey == null) {
if (bookmark.get('type') === siteTags.BOOKMARK_FOLDER) {
bookmarkKey = bookmarkFoldersUtil.getKey(bookmark)
} else {
bookmarkKey = bookmarkUtil.getKey(bookmark)
}
}

const droppedOn = getClosestFromPos(e.clientX, bookmarkKey)
if (droppedOn.selectedRef) {
const isRightSide = !dnd.isLeftSide(ReactDOM.findDOMNode(droppedOn.selectedRef), e.clientX)
const droppedOnKey = droppedOn.selectedRef.props.bookmarkKey
const isDestinationParent = droppedOn.selectedRef.state.isFolder && droppedOn && droppedOn.isDroppedOn
if (bookmark.get('type') === siteTags.BOOKMARK_FOLDER) {
appActions.moveBookmarkFolder(bookmark.get('key'), droppedOnKey, isRightSide, isDestinationParent)
appActions.moveBookmarkFolder(bookmarkKey, droppedOnKey, isRightSide, isDestinationParent)
} else {
appActions.moveBookmark(bookmark.get('key'), droppedOnKey, isRightSide, isDestinationParent)
appActions.moveBookmark(bookmarkKey, droppedOnKey, isRightSide, isDestinationParent)
}
dnd.onDragEnd()
}
Expand Down
3 changes: 2 additions & 1 deletion app/renderer/components/navigation/urlBarIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class UrlBarIcon extends React.Component {
onDragStart (e) {
dndData.setupDataTransferURL(e.dataTransfer, this.props.location, this.props.title)
dndData.setupDataTransferBraveData(e.dataTransfer, dragTypes.TAB, {
tabId: this.props.tabId
tabId: this.props.tabId,
location: this.props.location
})
}

Expand Down
6 changes: 6 additions & 0 deletions js/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const windowActions = require('./actions/windowActions')
const appActions = require('./actions/appActions')
const ReactDOM = require('react-dom')
const dndData = require('./dndData')
const Immutable = require('immutable')
const dragTypes = require('./constants/dragTypes')
const siteTags = require('./constants/siteTags')
const appStoreRenderer = require('./stores/appStoreRenderer')
const {getCurrentWindowId} = require('../app/renderer/currentWindow')
const {ESC} = require('../app/common/constants/keyCodes.js')
Expand Down Expand Up @@ -138,6 +140,10 @@ module.exports.prepareBookmarkDataFromCompatible = (dataTransfer) => {
const dragData = dndData.getDragData(dataTransfer, dragTypes.TAB)
if (dragData) {
windowActions.onFrameBookmark(dragData.get('tabId'))
bookmark = Immutable.fromJS({
location: dragData.get('location'),
type: siteTags.BOOKMARK
})
}
}
return bookmark
Expand Down
102 changes: 47 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7793647

Please sign in to comment.