diff options
Diffstat (limited to 'app/assets/javascripts/behaviors')
7 files changed, 57 insertions, 45 deletions
diff --git a/app/assets/javascripts/behaviors/gl_emoji.js b/app/assets/javascripts/behaviors/gl_emoji.js index 8fd03d3132d..29204020058 100644 --- a/app/assets/javascripts/behaviors/gl_emoji.js +++ b/app/assets/javascripts/behaviors/gl_emoji.js @@ -1,10 +1,4 @@ -import { - initEmojiMap, - getEmojiInfo, - emojiFallbackImageSrc, - emojiImageTag, - FALLBACK_EMOJI_KEY, -} from '../emoji'; +import { initEmojiMap, getEmojiInfo, emojiFallbackImageSrc, emojiImageTag } from '../emoji'; import isEmojiUnicodeSupported from '../emoji/support'; class GlEmoji extends HTMLElement { @@ -22,10 +16,6 @@ class GlEmoji extends HTMLElement { if (emojiInfo) { if (name !== emojiInfo.name) { - if (emojiInfo.name === FALLBACK_EMOJI_KEY && this.innerHTML) { - return; // When fallback emoji is used, but there is a <img> provided, use the <img> instead - } - ({ name } = emojiInfo); this.dataset.name = emojiInfo.name; } @@ -43,34 +33,29 @@ class GlEmoji extends HTMLElement { this.childNodes && Array.prototype.every.call(this.childNodes, (childNode) => childNode.nodeType === 3); - if ( - emojiUnicode && - isEmojiUnicode && - !isEmojiUnicodeSupported(emojiUnicode, unicodeVersion) - ) { - const hasImageFallback = fallbackSrc && fallbackSrc.length > 0; - const hasCssSpriteFallback = fallbackSpriteClass && fallbackSpriteClass.length > 0; + const hasImageFallback = fallbackSrc?.length > 0; + const hasCssSpriteFallback = fallbackSpriteClass?.length > 0; - // CSS sprite fallback takes precedence over image fallback - if (hasCssSpriteFallback) { - if (!gon.emoji_sprites_css_added && gon.emoji_sprites_css_path) { - const emojiSpriteLinkTag = document.createElement('link'); - emojiSpriteLinkTag.setAttribute('rel', 'stylesheet'); - emojiSpriteLinkTag.setAttribute('href', gon.emoji_sprites_css_path); - document.head.appendChild(emojiSpriteLinkTag); - gon.emoji_sprites_css_added = true; - } - // IE 11 doesn't like adding multiple at once :( - this.classList.add('emoji-icon'); - this.classList.add(fallbackSpriteClass); - } else if (hasImageFallback) { - this.innerHTML = ''; - this.appendChild(emojiImageTag(name, fallbackSrc)); - } else { - const src = emojiFallbackImageSrc(name); - this.innerHTML = ''; - this.appendChild(emojiImageTag(name, src)); + if (emojiUnicode && isEmojiUnicode && isEmojiUnicodeSupported(emojiUnicode, unicodeVersion)) { + // noop + } else if (hasCssSpriteFallback) { + if (!gon.emoji_sprites_css_added && gon.emoji_sprites_css_path) { + const emojiSpriteLinkTag = document.createElement('link'); + emojiSpriteLinkTag.setAttribute('rel', 'stylesheet'); + emojiSpriteLinkTag.setAttribute('href', gon.emoji_sprites_css_path); + document.head.appendChild(emojiSpriteLinkTag); + gon.emoji_sprites_css_added = true; } + // IE 11 doesn't like adding multiple at once :( + this.classList.add('emoji-icon'); + this.classList.add(fallbackSpriteClass); + } else if (hasImageFallback) { + this.innerHTML = ''; + this.appendChild(emojiImageTag(name, fallbackSrc)); + } else { + const src = emojiFallbackImageSrc(name); + this.innerHTML = ''; + this.appendChild(emojiImageTag(name, src)); } }); } diff --git a/app/assets/javascripts/behaviors/markdown/render_gfm.js b/app/assets/javascripts/behaviors/markdown/render_gfm.js index 6236e3bdefc..063393c9cd1 100644 --- a/app/assets/javascripts/behaviors/markdown/render_gfm.js +++ b/app/assets/javascripts/behaviors/markdown/render_gfm.js @@ -26,7 +26,7 @@ $.fn.renderGFM = function renderGFM() { const mrPopoverElements = this.find('.gfm-merge_request').get(); if (mrPopoverElements.length) { - import(/* webpackChunkName: 'MrPopoverBundle' */ '../../mr_popover') + import(/* webpackChunkName: 'MrPopoverBundle' */ '~/mr_popover') .then(({ default: initMRPopovers }) => { initMRPopovers(mrPopoverElements); }) diff --git a/app/assets/javascripts/behaviors/markdown/render_kroki.js b/app/assets/javascripts/behaviors/markdown/render_kroki.js index 7843df0cd8e..abe71694d73 100644 --- a/app/assets/javascripts/behaviors/markdown/render_kroki.js +++ b/app/assets/javascripts/behaviors/markdown/render_kroki.js @@ -51,7 +51,7 @@ export function renderKroki(krokiImages) { return; } - const parent = krokiImage.closest('.js-markdown-code'); + const parent = krokiImage.parentElement; // A single Kroki image is processed multiple times for some reason, // so this condition ensures we only create one alert per Kroki image diff --git a/app/assets/javascripts/behaviors/secret_values.js b/app/assets/javascripts/behaviors/secret_values.js index a34d5dcaef8..b6ed14611cd 100644 --- a/app/assets/javascripts/behaviors/secret_values.js +++ b/app/assets/javascripts/behaviors/secret_values.js @@ -1,5 +1,5 @@ -import { parseBoolean } from '../lib/utils/common_utils'; -import { n__ } from '../locale'; +import { parseBoolean } from '~/lib/utils/common_utils'; +import { n__ } from '~/locale'; export default class SecretValues { constructor({ diff --git a/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js b/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js index e58c51104c5..6124befd3b6 100644 --- a/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js +++ b/app/assets/javascripts/behaviors/shortcuts/shortcuts_issuable.js @@ -4,7 +4,7 @@ import { clickCopyToClipboardButton } from '~/behaviors/copy_to_clipboard'; import { getSelectedFragment } from '~/lib/utils/common_utils'; import { isElementVisible } from '~/lib/utils/dom_utils'; import { DEBOUNCE_DROPDOWN_DELAY } from '~/vue_shared/components/sidebar/labels_select_widget/constants'; -import Sidebar from '../../right_sidebar'; +import Sidebar from '~/right_sidebar'; import { CopyAsGFM } from '../markdown/copy_as_gfm'; import { keysFor, @@ -33,10 +33,37 @@ export default class ShortcutsIssuable extends Shortcuts { Mousetrap.bind(keysFor(ISSUABLE_COMMENT_OR_REPLY), ShortcutsIssuable.replyWithSelectedText); Mousetrap.bind(keysFor(ISSUABLE_EDIT_DESCRIPTION), ShortcutsIssuable.editIssue); Mousetrap.bind(keysFor(MR_COPY_SOURCE_BRANCH_NAME), ShortcutsIssuable.copyBranchName); + + /** + * We're attaching a global focus event listener on document for + * every markdown input field. + */ + $(document).on( + 'focus', + '.js-vue-markdown-field .js-gfm-input', + ShortcutsIssuable.handleMarkdownFieldFocus, + ); + } + + /** + * This event handler preserves last focused markdown input field. + * @param {Object} event + */ + static handleMarkdownFieldFocus({ currentTarget }) { + ShortcutsIssuable.$lastFocusedReplyField = $(currentTarget); } static replyWithSelectedText() { - const $replyField = $('.js-main-target-form .js-vue-comment-form'); + let $replyField = $('.js-main-target-form .js-vue-comment-form'); + + // Ensure that markdown input is still present in the DOM + // otherwise fall back to main comment input field. + if ( + ShortcutsIssuable.$lastFocusedReplyField && + isElementVisible(ShortcutsIssuable.$lastFocusedReplyField?.get(0)) + ) { + $replyField = ShortcutsIssuable.$lastFocusedReplyField; + } if (!$replyField.length || $replyField.is(':hidden') /* Other tab selected in MR */) { return false; diff --git a/app/assets/javascripts/behaviors/shortcuts/shortcuts_navigation.js b/app/assets/javascripts/behaviors/shortcuts/shortcuts_navigation.js index 7d8e4dd490c..e0ef49b60d3 100644 --- a/app/assets/javascripts/behaviors/shortcuts/shortcuts_navigation.js +++ b/app/assets/javascripts/behaviors/shortcuts/shortcuts_navigation.js @@ -1,6 +1,6 @@ import Mousetrap from 'mousetrap'; import { visitUrl, constructWebIDEPath } from '~/lib/utils/url_utility'; -import findAndFollowLink from '../../lib/utils/navigation_utility'; +import findAndFollowLink from '~/lib/utils/navigation_utility'; import { keysFor, GO_TO_PROJECT_OVERVIEW, diff --git a/app/assets/javascripts/behaviors/shortcuts/shortcuts_wiki.js b/app/assets/javascripts/behaviors/shortcuts/shortcuts_wiki.js index 59c1d2654bc..b2801f9118d 100644 --- a/app/assets/javascripts/behaviors/shortcuts/shortcuts_wiki.js +++ b/app/assets/javascripts/behaviors/shortcuts/shortcuts_wiki.js @@ -1,5 +1,5 @@ import Mousetrap from 'mousetrap'; -import findAndFollowLink from '../../lib/utils/navigation_utility'; +import findAndFollowLink from '~/lib/utils/navigation_utility'; import { keysFor, EDIT_WIKI_PAGE } from './keybindings'; import ShortcutsNavigation from './shortcuts_navigation'; |