Resolve "When editing a comment in an issue, the preview mode is toggled in the main textarea"
This commit is contained in:
parent
2a7d011afd
commit
242820e276
3 changed files with 29 additions and 19 deletions
|
@ -27,20 +27,22 @@
|
|||
$(document).off('markdown-preview:hide.vue', this.writeMarkdownTab);
|
||||
},
|
||||
methods: {
|
||||
isMarkdownForm(form) {
|
||||
return form && !form.find('.js-vue-markdown-field').length;
|
||||
isValid(form) {
|
||||
return !form ||
|
||||
form.find('.js-vue-markdown-field').length ||
|
||||
$(this.$el).closest('form') === form[0];
|
||||
},
|
||||
|
||||
previewMarkdownTab(event, form) {
|
||||
if (event.target.blur) event.target.blur();
|
||||
if (this.isMarkdownForm(form)) return;
|
||||
if (!this.isValid(form)) return;
|
||||
|
||||
this.$emit('preview-markdown');
|
||||
},
|
||||
|
||||
writeMarkdownTab(event, form) {
|
||||
if (event.target.blur) event.target.blur();
|
||||
if (this.isMarkdownForm(form)) return;
|
||||
if (!this.isValid(form)) return;
|
||||
|
||||
this.$emit('write-markdown');
|
||||
},
|
||||
|
|
5
changelogs/unreleased/44697-prevue.yml
Normal file
5
changelogs/unreleased/44697-prevue.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Make toggle markdown preview shortcut only toggle selected field
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -1,10 +1,11 @@
|
|||
import Vue from 'vue';
|
||||
import $ from 'jquery';
|
||||
import headerComponent from '~/vue_shared/components/markdown/header.vue';
|
||||
|
||||
describe('Markdown field header component', () => {
|
||||
let vm;
|
||||
|
||||
beforeEach((done) => {
|
||||
beforeEach(done => {
|
||||
const Component = Vue.extend(headerComponent);
|
||||
|
||||
vm = new Component({
|
||||
|
@ -17,24 +18,18 @@ describe('Markdown field header component', () => {
|
|||
});
|
||||
|
||||
it('renders markdown buttons', () => {
|
||||
expect(
|
||||
vm.$el.querySelectorAll('.js-md').length,
|
||||
).toBe(7);
|
||||
expect(vm.$el.querySelectorAll('.js-md').length).toBe(7);
|
||||
});
|
||||
|
||||
it('renders `write` link as active when previewMarkdown is false', () => {
|
||||
expect(
|
||||
vm.$el.querySelector('li:nth-child(1)').classList.contains('active'),
|
||||
).toBeTruthy();
|
||||
expect(vm.$el.querySelector('li:nth-child(1)').classList.contains('active')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('renders `preview` link as active when previewMarkdown is true', (done) => {
|
||||
it('renders `preview` link as active when previewMarkdown is true', done => {
|
||||
vm.previewMarkdown = true;
|
||||
|
||||
Vue.nextTick(() => {
|
||||
expect(
|
||||
vm.$el.querySelector('li:nth-child(2)').classList.contains('active'),
|
||||
).toBeTruthy();
|
||||
expect(vm.$el.querySelector('li:nth-child(2)').classList.contains('active')).toBeTruthy();
|
||||
|
||||
done();
|
||||
});
|
||||
|
@ -52,16 +47,24 @@ describe('Markdown field header component', () => {
|
|||
expect(vm.$emit).toHaveBeenCalledWith('write-markdown');
|
||||
});
|
||||
|
||||
it('blurs preview link after click', (done) => {
|
||||
it('does not emit toggle markdown event when triggered from another form', () => {
|
||||
spyOn(vm, '$emit');
|
||||
|
||||
$(document).triggerHandler('markdown-preview:show', [
|
||||
$('<form><textarea class="markdown-area"></textarea></textarea></form>'),
|
||||
]);
|
||||
|
||||
expect(vm.$emit).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('blurs preview link after click', done => {
|
||||
const link = vm.$el.querySelector('li:nth-child(2) a');
|
||||
spyOn(HTMLElement.prototype, 'blur');
|
||||
|
||||
link.click();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(
|
||||
link.blur,
|
||||
).toHaveBeenCalled();
|
||||
expect(link.blur).toHaveBeenCalled();
|
||||
|
||||
done();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue