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

Commit

Permalink
select on mouse up
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Sep 10, 2017
1 parent 22c2556 commit 0f7a4b7
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/tree-view.coffee
Expand Up @@ -38,6 +38,7 @@ class TreeView
@emitter = new Emitter
@roots = []
@selectedPath = null
@selectOnMouseUp = false
@ignoredPatterns = []
@useSyncFS = false
@currentlyOpening = new Map
Expand Down Expand Up @@ -139,6 +140,7 @@ class TreeView

@entryClicked(e) unless e.shiftKey or e.metaKey or e.ctrlKey
@element.addEventListener 'mousedown', (e) => @onMouseDown(e)
@element.addEventListener 'mouseup', (e) => @onMouseUp(e)
@element.addEventListener 'dragstart', (e) => @onDragStart(e)
@element.addEventListener 'dragenter', (e) => @onDragEnter(e)
@element.addEventListener 'dragleave', (e) => @onDragLeave(e)
Expand Down Expand Up @@ -794,7 +796,7 @@ class TreeView
return

entryName = path.basename(initialPath)
newPath = "#{newDirectoryPath}/#{entryName}".replace(/\s+$/, '')
newPath = "#{newDirectoryPath}#{path.sep}#{entryName}".replace(/\s+$/, '')

try
fs.makeTreeSync(newDirectoryPath) unless fs.existsSync(newDirectoryPath)
Expand All @@ -821,11 +823,15 @@ class TreeView
e.stopPropagation()

# return early if we're opening a contextual menu (right click) during multi-select mode
if @multiSelectEnabled() and
entryToSelect.classList.contains('selected') and
# mouse right click or ctrl click as right click on darwin platforms
(e.button is 2 or e.ctrlKey and process.platform is 'darwin')
return
if @multiSelectEnabled() and entryToSelect.classList.contains('selected')

# mouse right click or ctrl click as right click on darwin platforms
if (e.button is 2 or e.ctrlKey and process.platform is 'darwin')
return
# stop unselect if dragging
else
@selectOnMouseUp = true
return

if e.shiftKey
@selectContinuousEntries(entryToSelect)
Expand All @@ -840,6 +846,11 @@ class TreeView
@selectEntry(entryToSelect)
@showFullMenu()

onMouseUp: (e) ->
if @selectOnMouseUp
@selectEntry(entryToSelect)
@showFullMenu()

# Public: Return an array of paths from all selected items
#
# Example: @selectedPaths()
Expand Down Expand Up @@ -915,6 +926,7 @@ class TreeView

# Handle entry name object dragstart event
onDragStart: (e) ->
@selectOnMouseUp = false
if entry = e.target.closest('.entry')
e.stopPropagation()

Expand All @@ -923,7 +935,7 @@ class TreeView

initialPaths = []
dragImage = document.createElement("ol")
dragImage.classList.add("entries list-tree")
dragImage.classList.add("entries", "list-tree")
dragImage.style.position = "absolute"
dragImage.style.top = 0
dragImage.style.left = 0
Expand Down

0 comments on commit 0f7a4b7

Please sign in to comment.