From 4d1878253e228db55485dae9e4ad66aebe009040 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 18 Apr 2015 15:20:15 -0400 Subject: Typo: Issueable -> Issuable --- app/assets/javascripts/application.js.coffee | 2 +- app/assets/javascripts/dispatcher.js.coffee | 4 +- app/assets/javascripts/shortcuts_issuable.coffee | 48 +++++++++++++ app/assets/javascripts/shortcuts_issueable.coffee | 48 ------------- spec/javascripts/shortcuts_issuable_spec.js.coffee | 83 ++++++++++++++++++++++ .../javascripts/shortcuts_issueable_spec.js.coffee | 83 ---------------------- 6 files changed, 134 insertions(+), 134 deletions(-) create mode 100644 app/assets/javascripts/shortcuts_issuable.coffee delete mode 100644 app/assets/javascripts/shortcuts_issueable.coffee create mode 100644 spec/javascripts/shortcuts_issuable_spec.js.coffee delete mode 100644 spec/javascripts/shortcuts_issueable_spec.js.coffee diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index bd52d3d4d70..1a71f853b4d 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -38,7 +38,7 @@ #= require shortcuts #= require shortcuts_navigation #= require shortcuts_dashboard_navigation -#= require shortcuts_issueable +#= require shortcuts_issuable #= require shortcuts_network #= require cal-heatmap #= require_tree . diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index 330ebac6f75..9aee3b281f3 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -22,7 +22,7 @@ class Dispatcher shortcut_handler = new ShortcutsNavigation() when 'projects:issues:show' new Issue() - shortcut_handler = new ShortcutsIssueable() + shortcut_handler = new ShortcutsIssuable() new ZenMode() when 'projects:milestones:show' new Milestone() @@ -47,7 +47,7 @@ class Dispatcher new IssuableForm($('.merge-request-form')) when 'projects:merge_requests:show' new Diff() - shortcut_handler = new ShortcutsIssueable() + shortcut_handler = new ShortcutsIssuable() new ZenMode() when "projects:merge_requests:diffs" new Diff() diff --git a/app/assets/javascripts/shortcuts_issuable.coffee b/app/assets/javascripts/shortcuts_issuable.coffee new file mode 100644 index 00000000000..6b534f29218 --- /dev/null +++ b/app/assets/javascripts/shortcuts_issuable.coffee @@ -0,0 +1,48 @@ +#= require jquery +#= require mousetrap + +#= require shortcuts_navigation + +class @ShortcutsIssuable extends ShortcutsNavigation + constructor: (isMergeRequest) -> + super() + Mousetrap.bind('a', -> + $('.js-assignee').select2('open') + return false + ) + Mousetrap.bind('m', -> + $('.js-milestone').select2('open') + return false + ) + Mousetrap.bind('r', => + @replyWithSelectedText() + return false + ) + + if isMergeRequest + @enabledHelp.push('.hidden-shortcut.merge_requests') + else + @enabledHelp.push('.hidden-shortcut.issues') + + replyWithSelectedText: -> + if window.getSelection + selected = window.getSelection().toString() + replyField = $('.js-main-target-form #note_note') + + return if selected.trim() == "" + + # Put a '>' character before each non-empty line in the selection + quote = _.map selected.split("\n"), (val) -> + "> #{val}\n" if val.trim() != '' + + # If replyField already has some content, add a newline before our quote + separator = replyField.val().trim() != "" and "\n" or '' + + replyField.val (_, current) -> + current + separator + quote.join('') + "\n" + + # Trigger autosave for the added text + replyField.trigger('input') + + # Focus the input field + replyField.focus() diff --git a/app/assets/javascripts/shortcuts_issueable.coffee b/app/assets/javascripts/shortcuts_issueable.coffee deleted file mode 100644 index 939004cbf76..00000000000 --- a/app/assets/javascripts/shortcuts_issueable.coffee +++ /dev/null @@ -1,48 +0,0 @@ -#= require jquery -#= require mousetrap - -#= require shortcuts_navigation - -class @ShortcutsIssueable extends ShortcutsNavigation - constructor: (isMergeRequest) -> - super() - Mousetrap.bind('a', -> - $('.js-assignee').select2('open') - return false - ) - Mousetrap.bind('m', -> - $('.js-milestone').select2('open') - return false - ) - Mousetrap.bind('r', => - @replyWithSelectedText() - return false - ) - - if isMergeRequest - @enabledHelp.push('.hidden-shortcut.merge_requests') - else - @enabledHelp.push('.hidden-shortcut.issues') - - replyWithSelectedText: -> - if window.getSelection - selected = window.getSelection().toString() - replyField = $('.js-main-target-form #note_note') - - return if selected.trim() == "" - - # Put a '>' character before each non-empty line in the selection - quote = _.map selected.split("\n"), (val) -> - "> #{val}\n" if val.trim() != '' - - # If replyField already has some content, add a newline before our quote - separator = replyField.val().trim() != "" and "\n" or '' - - replyField.val (_, current) -> - current + separator + quote.join('') + "\n" - - # Trigger autosave for the added text - replyField.trigger('input') - - # Focus the input field - replyField.focus() diff --git a/spec/javascripts/shortcuts_issuable_spec.js.coffee b/spec/javascripts/shortcuts_issuable_spec.js.coffee new file mode 100644 index 00000000000..57dcc2161d3 --- /dev/null +++ b/spec/javascripts/shortcuts_issuable_spec.js.coffee @@ -0,0 +1,83 @@ +#= require jquery +#= require jasmine-fixture + +#= require shortcuts_issuable + +describe 'ShortcutsIssuable', -> + beforeEach -> + @shortcut = new ShortcutsIssuable() + + describe '#replyWithSelectedText', -> + # Stub window.getSelection to return the provided String. + stubSelection = (text) -> + window.getSelection = -> text + + beforeEach -> + @selector = 'form.js-main-target-form textarea#note_note' + affix(@selector) + + describe 'with empty selection', -> + it 'does nothing', -> + stubSelection('') + @shortcut.replyWithSelectedText() + expect($(@selector).val()).toBe('') + + describe 'with any selection', -> + beforeEach -> + stubSelection('Selected text.') + + it 'leaves existing input intact', -> + $(@selector).val('This text was already here.') + expect($(@selector).val()).toBe('This text was already here.') + + @shortcut.replyWithSelectedText() + expect($(@selector).val()). + toBe("This text was already here.\n> Selected text.\n\n") + + it 'triggers `input`', -> + triggered = false + $(@selector).on 'input', -> triggered = true + @shortcut.replyWithSelectedText() + + expect(triggered).toBe(true) + + it 'triggers `focus`', -> + focused = false + $(@selector).on 'focus', -> focused = true + @shortcut.replyWithSelectedText() + + expect(focused).toBe(true) + + describe 'with a one-line selection', -> + it 'quotes the selection', -> + stubSelection('This text has been selected.') + + @shortcut.replyWithSelectedText() + + expect($(@selector).val()). + toBe("> This text has been selected.\n\n") + + describe 'with a multi-line selection', -> + it 'quotes the selected lines as a group', -> + stubSelection( + """ + Selected line one. + + Selected line two. + Selected line three. + + """ + ) + + @shortcut.replyWithSelectedText() + + expect($(@selector).val()). + toBe( + """ + > Selected line one. + > Selected line two. + > Selected line three. + + + """ + ) diff --git a/spec/javascripts/shortcuts_issueable_spec.js.coffee b/spec/javascripts/shortcuts_issueable_spec.js.coffee deleted file mode 100644 index 5f206ddfda6..00000000000 --- a/spec/javascripts/shortcuts_issueable_spec.js.coffee +++ /dev/null @@ -1,83 +0,0 @@ -#= require jquery -#= require jasmine-fixture - -#= require shortcuts_issueable - -describe 'ShortcutsIssueable', -> - beforeEach -> - @shortcut = new ShortcutsIssueable() - - describe '#replyWithSelectedText', -> - # Stub window.getSelection to return the provided String. - stubSelection = (text) -> - window.getSelection = -> text - - beforeEach -> - @selector = 'form.js-main-target-form textarea#note_note' - affix(@selector) - - describe 'with empty selection', -> - it 'does nothing', -> - stubSelection('') - @shortcut.replyWithSelectedText() - expect($(@selector).val()).toBe('') - - describe 'with any selection', -> - beforeEach -> - stubSelection('Selected text.') - - it 'leaves existing input intact', -> - $(@selector).val('This text was already here.') - expect($(@selector).val()).toBe('This text was already here.') - - @shortcut.replyWithSelectedText() - expect($(@selector).val()). - toBe("This text was already here.\n> Selected text.\n\n") - - it 'triggers `input`', -> - triggered = false - $(@selector).on 'input', -> triggered = true - @shortcut.replyWithSelectedText() - - expect(triggered).toBe(true) - - it 'triggers `focus`', -> - focused = false - $(@selector).on 'focus', -> focused = true - @shortcut.replyWithSelectedText() - - expect(focused).toBe(true) - - describe 'with a one-line selection', -> - it 'quotes the selection', -> - stubSelection('This text has been selected.') - - @shortcut.replyWithSelectedText() - - expect($(@selector).val()). - toBe("> This text has been selected.\n\n") - - describe 'with a multi-line selection', -> - it 'quotes the selected lines as a group', -> - stubSelection( - """ - Selected line one. - - Selected line two. - Selected line three. - - """ - ) - - @shortcut.replyWithSelectedText() - - expect($(@selector).val()). - toBe( - """ - > Selected line one. - > Selected line two. - > Selected line three. - - - """ - ) -- cgit v1.2.1