Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[filter] Bug fixes + Open item on enter if only one item is displayed #31

Merged
merged 6 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Show open (downloaded) remote files.
Give focus to the remote-edit file browser. This allows you to navigate with
keyboard (up/down/enter/backspace/escape)

- <kbd>Alt+r l</kbd> / <kbd>&#8984;+r l</kbd> -
Give focus to the remote-edit file browser's filter bar which can also be used
for navigation to a different folder

- <kbd>Alt+r d</kbd> / <kbd>&#8984;+r d</kbd> -
Disconnect all open server connections. Server connections are normally kept open to improve save and browse performance.

Expand Down
2 changes: 2 additions & 0 deletions keymaps/remote-edit.cson
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'cmd-r o': 'remote-edit:show-open-files'
'cmd-r v': 'remote-edit:toggle-files-view'
'cmd-r f': 'filesview:list-focus'
'cmd-r l': 'filesview:list-filter-focus'
'cmd-r m': 'remote-edit:browse-more'
'cmd-r d': 'remote-edit:close-all-connections'

Expand All @@ -20,6 +21,7 @@
'alt-r o': 'remote-edit:show-open-files'
'alt-r v': 'remote-edit:toggle-files-view'
'alt-r f': 'filesview:list-focus'
'alt-r l': 'filesview:list-filter-focus'
'alt-r m': 'remote-edit:browse-more'
'alt-r d': 'remote-edit:close-all-connections'

Expand Down
106 changes: 84 additions & 22 deletions lib/view/files-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,66 @@ module.exports =
@ol class: 'list-tree full-menu focusable-panel', tabindex: 1, outlet: 'list'
@div class: 'remote-edit-resize-handle', outlet: 'resizeHandle'


# Return a list with items currently shown/allowed by the filter
getFilteredItems: ->
return @list.find('li').not('.hidden')


# Handle enter in filter - split to simplify doFilter
handleFilterEnter: ->
listedItems = @getFilteredItems()

# If only one item is in the list, open it
# if listedItems.length == 1
# @confirmed(listedItems.first().data('select-list-item'))
#
# # Looks like a path, treat it as a chdir
# else
if @filter.val().indexOf("/") > -1

toOpen = @filter.val()
if @filter.val()[0] == "." or @filter.val()[0] != "/"
toOpen = @path + "/" + @filter.val()

@openDirectory(toOpen, (err) =>
if err?
@setError("Could not open location")
else
@filter.val("")
@deselect()
)
# Jump to the list
else if @getFilteredItems().length > 0
@selectInitialItem()
@list.focus()


doFilter: (e) ->
switch e.keyCode
# we have an enter
when 13
toOpen = @filter.val()
if @filter.val()[0] == "." or @filter.val()[0] != "/"
toOpen = @path + "/" + @filter.val()

@openDirectory(toOpen, (err) =>
if err?
@setError("Could not open location")
else
@filter.val("")
)
@handleFilterEnter()
return
# we have keydown
when 40
@selectInitialItem()
@list.focus()
return

# Hide the elements that do not match the filter's value
if @filter.val().length > 0
@list.find('li span').each (index, item) =>
if ! $(item).text().match(@filter.val())
@list.find('li').each (index, item) =>
# Escape regex
# re = @filter.val().replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
if !$(item).text().includes(@filter.val())
$(item).addClass('hidden')
else
$(item).removeClass('hidden')
else
@list.find('li span').removeClass('hidden')
@list.find('li').removeClass('hidden')

@deselect()
e.preventDefault()


Expand Down Expand Up @@ -362,6 +397,7 @@ module.exports =
@openFile(item)
else if item.isDir
@host.invalidate()
@filter.val("")
@openDirectory(item.path, () => @selectInitialItem())
else if item.isLink
if atom.config.get('remote-edit-ni.followLinks')
Expand Down Expand Up @@ -428,25 +464,43 @@ module.exports =

listSelectNext: =>
item = @getSelectedItem()
if item.next('li').length == 0
next = item.next('li')

# Look for the next item that is not filtered
while next.length != 0
if !next.hasClass('hidden')
break
next = next.next('li')

if next.length == 0
return

@deselect()
item.next('li').addClass('selected').data('select-list-item')
next.addClass('selected')
@scrollToView(@getSelectedItem(), @scroller)

listSelectPrev: =>
item = @getSelectedItem()
if item.prev('li').length == 0
prev = item.prev('li')

# Look for the previous item that is not filtered
while prev.length != 0
if !prev.hasClass('hidden')
break
prev = prev.prev('li')

if prev.length == 0
# We are at the top - focus on the filter
@filter.focus()
return

@deselect()
item.prev('li').addClass('selected').data('select-list-item')
prev.addClass('selected')
@scrollToView(@getSelectedItem(), @scroller)

listEnter: =>
item = @getSelectedItem()
if !item
if item.length == 0
return
@confirmed(item.data('select-list-item'))
@list.focus()
Expand Down Expand Up @@ -538,6 +592,7 @@ module.exports =
@disposables.add atom.commands.add 'atom-workspace', 'filesview:list-focus', =>
@selectInitialItem()
@list.focus()
@disposables.add atom.commands.add 'atom-workspace', 'filesview:list-filter-focus', => @filter.focus()
@disposables.add atom.commands.add 'atom-workspace', 'filesview:hide', => @hide()

# Remote-edit Commands
Expand Down Expand Up @@ -585,18 +640,25 @@ module.exports =
@setHost(host, folder, () => @selectInitialItem())



# Default selection on focus or on enter directory
selectInitialItem: () =>
# Refuse to select if something already selected
if @getSelectedItem().length
return

# Use filtered items instead of all items
listedItems = @getFilteredItems()
if !listedItems || !listedItems.length
return

first = listedItems.first()
firstText = first.find("span").text()

# Ensure we are not in a empty directory
if @list.children().length > 1
@list.children().first().next().addClass('selected')
if listedItems.length > 1 && firstText == ".."
first.next().addClass('selected')
else
@list.children().first().addClass('selected')
first.addClass('selected')

selectItemByPath: (path) ->
@deselect()
Expand Down