Don't use simpleMDE editor on mobile devices for 1.13 (#14029)
* Don't use simpleMDE editor on mobile devices simpleMDE doesn't work properly on mobile devices -- We've replaced it with the slightly more working easyMDE in 1.14 but since that change can't be backported to 1.13 we will just disable the editor on mobile here. * make isMobile function per code review -- disable simpleMDE for code review and replies * Fix issue with plain text and wiki Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
78b9ef3586
commit
4f296f7436
2 changed files with 37 additions and 11 deletions
|
@ -25,6 +25,7 @@ import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
|
||||||
import {initNotificationsTable, initNotificationCount} from './features/notification.js';
|
import {initNotificationsTable, initNotificationCount} from './features/notification.js';
|
||||||
import {createCodeEditor} from './features/codeeditor.js';
|
import {createCodeEditor} from './features/codeeditor.js';
|
||||||
import {svg, svgs} from './svg.js';
|
import {svg, svgs} from './svg.js';
|
||||||
|
import {isMobile} from './utils.js';
|
||||||
|
|
||||||
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
|
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
|
||||||
|
|
||||||
|
@ -385,8 +386,14 @@ function initCommentForm() {
|
||||||
if ($('.comment.form').length === 0) {
|
if ($('.comment.form').length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
|
autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
|
||||||
|
|
||||||
|
// Don't use simpleMDE on mobile due to multiple bug reports which go unfixed
|
||||||
|
// Other sections rely on it being initialized so just set it back to text area here
|
||||||
|
if (isMobile()) {
|
||||||
|
autoSimpleMDE.toTextArea();
|
||||||
|
}
|
||||||
|
|
||||||
initBranchSelector();
|
initBranchSelector();
|
||||||
initCommentPreviewTab($('.comment.form'));
|
initCommentPreviewTab($('.comment.form'));
|
||||||
initImagePaste($('.comment.form textarea'));
|
initImagePaste($('.comment.form textarea'));
|
||||||
|
@ -1214,6 +1221,7 @@ function initPullRequestReview() {
|
||||||
const form = $(this).parent().find('.comment-form');
|
const form = $(this).parent().find('.comment-form');
|
||||||
form.removeClass('hide');
|
form.removeClass('hide');
|
||||||
const $textarea = form.find('textarea');
|
const $textarea = form.find('textarea');
|
||||||
|
if (!isMobile()) {
|
||||||
let $simplemde;
|
let $simplemde;
|
||||||
if ($textarea.data('simplemde')) {
|
if ($textarea.data('simplemde')) {
|
||||||
$simplemde = $textarea.data('simplemde');
|
$simplemde = $textarea.data('simplemde');
|
||||||
|
@ -1224,6 +1232,10 @@ function initPullRequestReview() {
|
||||||
}
|
}
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
$simplemde.codemirror.focus();
|
$simplemde.codemirror.focus();
|
||||||
|
} else {
|
||||||
|
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
||||||
|
$textarea.focus();
|
||||||
|
}
|
||||||
assingMenuAttributes(form.find('.menu'));
|
assingMenuAttributes(form.find('.menu'));
|
||||||
});
|
});
|
||||||
// The following part is only for diff views
|
// The following part is only for diff views
|
||||||
|
@ -1290,9 +1302,13 @@ function initPullRequestReview() {
|
||||||
const $textarea = commentCloud.find('textarea');
|
const $textarea = commentCloud.find('textarea');
|
||||||
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
attachTribute($textarea.get(), {mentions: true, emoji: true});
|
||||||
|
|
||||||
|
if (!isMobile()) {
|
||||||
const $simplemde = setCommentSimpleMDE($textarea);
|
const $simplemde = setCommentSimpleMDE($textarea);
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
$simplemde.codemirror.focus();
|
$simplemde.codemirror.focus();
|
||||||
|
} else {
|
||||||
|
$textarea.focus();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1338,6 +1354,10 @@ function initWikiForm() {
|
||||||
const $editArea = $('.repository.wiki textarea#edit_area');
|
const $editArea = $('.repository.wiki textarea#edit_area');
|
||||||
let sideBySideChanges = 0;
|
let sideBySideChanges = 0;
|
||||||
let sideBySideTimeout = null;
|
let sideBySideTimeout = null;
|
||||||
|
if ($editArea.length > 0 && isMobile) {
|
||||||
|
$editArea.css('display', 'inline-block');
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ($editArea.length > 0) {
|
if ($editArea.length > 0) {
|
||||||
const simplemde = new SimpleMDE({
|
const simplemde = new SimpleMDE({
|
||||||
autoDownloadFontAwesome: false,
|
autoDownloadFontAwesome: false,
|
||||||
|
@ -1433,6 +1453,7 @@ function initWikiForm() {
|
||||||
name: 'revert-to-textarea',
|
name: 'revert-to-textarea',
|
||||||
action(e) {
|
action(e) {
|
||||||
e.toTextArea();
|
e.toTextArea();
|
||||||
|
$editArea.css('display', 'inline-block');
|
||||||
},
|
},
|
||||||
className: 'fa fa-file',
|
className: 'fa fa-file',
|
||||||
title: 'Revert to simple textarea',
|
title: 'Revert to simple textarea',
|
||||||
|
|
|
@ -19,6 +19,11 @@ export function isDarkTheme() {
|
||||||
return document.documentElement.classList.contains('theme-arc-green');
|
return document.documentElement.classList.contains('theme-arc-green');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns if mobile device
|
||||||
|
export function isMobile() {
|
||||||
|
return /Mobi/.test(navigator.userAgent);
|
||||||
|
}
|
||||||
|
|
||||||
// removes duplicate elements in an array
|
// removes duplicate elements in an array
|
||||||
export function uniq(arr) {
|
export function uniq(arr) {
|
||||||
return Array.from(new Set(arr));
|
return Array.from(new Set(arr));
|
||||||
|
|
Reference in a new issue