From 359ec42754d74206140e8e0c4bb0129e15f824d7 Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Thu, 9 Jun 2016 17:56:15 +0100 Subject: [PATCH 1/2] Added shortcut to focus all search tags apart from the top nav search Updated CHANGELOG Added docs for filter shortcut Moved CHANGELOG entry Added phils fixes Fixed search form submitting with empty input Added review fixes Readability and selector perf fix --- CHANGELOG | 1 + app/assets/javascripts/issuable.js.coffee | 4 +--- app/assets/javascripts/projects_list.js.coffee | 11 +++++------ app/assets/javascripts/shortcuts.js.coffee | 6 ++++++ app/views/help/_shortcuts.html.haml | 4 ++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0eb7595fbfa..15a94a3b8cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -222,6 +222,7 @@ v 8.9.0 - Add rake task 'gitlab:db:configure' for conditionally seeding or migrating the database - Changed the Slack build message to use the singular duration if necessary (Aran Koning) - Fix race condition on merge when build succeeds + - Added shortcut to focus filter search fields and added documentation #18120 - Links from a wiki page to other wiki pages should be rewritten as expected - Add option to project to only allow merge requests to be merged if the build succeeds (Rui Santos) - Added navigation shortcuts to the project pipelines, milestones, builds and forks page. !4393 diff --git a/app/assets/javascripts/issuable.js.coffee b/app/assets/javascripts/issuable.js.coffee index c71d4ecf505..7f795f8096b 100644 --- a/app/assets/javascripts/issuable.js.coffee +++ b/app/assets/javascripts/issuable.js.coffee @@ -32,13 +32,11 @@ issuable_created = false $search = $('#issue_search') $form = $('.js-filter-form') $input = $("input[name='#{$search.attr('name')}']", $form) - if $input.length is 0 $form.append "" else $input.val $search.val() - - Issuable.filterResults $form + Issuable.filterResults $form if $search.val() isnt '' , 500) initLabelFilterRemove: -> diff --git a/app/assets/javascripts/projects_list.js.coffee b/app/assets/javascripts/projects_list.js.coffee index e4c4bf3b273..9d34aebbf02 100644 --- a/app/assets/javascripts/projects_list.js.coffee +++ b/app/assets/javascripts/projects_list.js.coffee @@ -5,13 +5,12 @@ this.initPagination() initSearch: -> - @timer = null - $(".projects-list-filter").on('keyup', -> - clearTimeout(@timer) - @timer = setTimeout(ProjectsList.filterResults, 500) - ) + projectsListFilter = $('.projects-list-filter') + projectsListFilter.on 'keyup', (e) => + clearTimeout(@timer) if @timer + @timer = setTimeout(ProjectsList.filterResults, 500) if projectsListFilter.val() isnt '' - filterResults: => + filterResults: -> $('.projects-list-holder').fadeTo(250, 0.5) form = null diff --git a/app/assets/javascripts/shortcuts.js.coffee b/app/assets/javascripts/shortcuts.js.coffee index 3319a67a79d..04eba43d54c 100644 --- a/app/assets/javascripts/shortcuts.js.coffee +++ b/app/assets/javascripts/shortcuts.js.coffee @@ -4,6 +4,7 @@ class @Shortcuts Mousetrap.reset() if not skipResetBindings Mousetrap.bind('?', @onToggleHelp) Mousetrap.bind('s', Shortcuts.focusSearch) + Mousetrap.bind 'f', @focusFilter Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview) Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL? @@ -32,10 +33,15 @@ class @Shortcuts $('.js-more-help-button').remove() ) + focusFilter: (e) -> + $('input[type=search]', '.nav-controls .block-controls').focus() + e.preventDefault() + @focusSearch: (e) -> $('#search').focus() e.preventDefault() + $(document).on 'click.more_help', '.js-more-help-button', (e) -> $(@).remove() $('.hidden-shortcut').show() diff --git a/app/views/help/_shortcuts.html.haml b/app/views/help/_shortcuts.html.haml index 8cc0b59edeb..ce4536ebdc6 100644 --- a/app/views/help/_shortcuts.html.haml +++ b/app/views/help/_shortcuts.html.haml @@ -18,6 +18,10 @@ %td.shortcut .key s %td Focus Search + %tr + %td.shortcut + .key f + %td Focus Filter %tr %td.shortcut .key ? From e0f3b66c38e574e084e0448a7fdd5430ba58fbda Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Mon, 11 Jul 2016 17:06:31 +0100 Subject: [PATCH 2/2] Review changes --- app/assets/javascripts/projects_list.js.coffee | 6 +++--- app/assets/javascripts/shortcuts.js.coffee | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/projects_list.js.coffee b/app/assets/javascripts/projects_list.js.coffee index 9d34aebbf02..a7d78d9e461 100644 --- a/app/assets/javascripts/projects_list.js.coffee +++ b/app/assets/javascripts/projects_list.js.coffee @@ -6,9 +6,9 @@ initSearch: -> projectsListFilter = $('.projects-list-filter') - projectsListFilter.on 'keyup', (e) => - clearTimeout(@timer) if @timer - @timer = setTimeout(ProjectsList.filterResults, 500) if projectsListFilter.val() isnt '' + debounceFilter = _.debounce ProjectsList.filterResults, 500 + projectsListFilter.on 'keyup', (e) -> + debounceFilter() if projectsListFilter.val() isnt '' filterResults: -> $('.projects-list-holder').fadeTo(250, 0.5) diff --git a/app/assets/javascripts/shortcuts.js.coffee b/app/assets/javascripts/shortcuts.js.coffee index 04eba43d54c..8c8689bacee 100644 --- a/app/assets/javascripts/shortcuts.js.coffee +++ b/app/assets/javascripts/shortcuts.js.coffee @@ -2,10 +2,10 @@ class @Shortcuts constructor: (skipResetBindings) -> @enabledHelp = [] Mousetrap.reset() if not skipResetBindings - Mousetrap.bind('?', @onToggleHelp) - Mousetrap.bind('s', Shortcuts.focusSearch) - Mousetrap.bind 'f', @focusFilter - Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview) + Mousetrap.bind '?', @onToggleHelp + Mousetrap.bind 's', Shortcuts.focusSearch + Mousetrap.bind 'f', (e) => @focusFilter e + Mousetrap.bind ['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL? onToggleHelp: (e) => @@ -34,7 +34,8 @@ class @Shortcuts ) focusFilter: (e) -> - $('input[type=search]', '.nav-controls .block-controls').focus() + @filterInput ?= $('input[type=search]', '.nav-controls') + @filterInput.focus() e.preventDefault() @focusSearch: (e) ->