From 819fd96d1aee35b6fc50d39f94e97f45d1d99733 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 23 Feb 2017 17:48:44 +0000 Subject: Updates SSH key title after pasting key Previously it was listening for focusout, it now listens for blur & paste events Closes #28436 --- app/assets/javascripts/profile/profile.js.es6 | 18 +++++++++++------- changelogs/unreleased/ssh-key-paste.yml | 4 ++++ 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 changelogs/unreleased/ssh-key-paste.yml diff --git a/app/assets/javascripts/profile/profile.js.es6 b/app/assets/javascripts/profile/profile.js.es6 index 81374296522..af86d138c2f 100644 --- a/app/assets/javascripts/profile/profile.js.es6 +++ b/app/assets/javascripts/profile/profile.js.es6 @@ -84,13 +84,17 @@ } $(function() { - $(document).on('focusout.ssh_key', '#key_key', function() { - const $title = $('#key_title'); - const comment = $(this).val().match(/^\S+ \S+ (.+)\n?$/); - if (comment && comment.length > 1 && $title.val() === '') { - return $title.val(comment[1]).change(); - } - // Extract the SSH Key title from its comment + $(document).on('blur.ssh_key paste.ssh_key', '#key_key', function() { + // Need to wait for 100ms for the pasted value to update .val() + setTimeout(() => { + const $title = $('#key_title'); + const comment = $(this).val().match(/^\S+ \S+ (.+)\n?$/); + + // Extract the SSH Key title from its comment + if (comment && comment.length > 1) { + return $title.val(comment[1]).change(); + } + }, 100); }); if (global.utils.getPagePath() === 'profiles') { return new Profile(); diff --git a/changelogs/unreleased/ssh-key-paste.yml b/changelogs/unreleased/ssh-key-paste.yml new file mode 100644 index 00000000000..1e34ef60f6e --- /dev/null +++ b/changelogs/unreleased/ssh-key-paste.yml @@ -0,0 +1,4 @@ +--- +title: SSH key field updates title after pasting key +merge_request: +author: -- cgit v1.2.1