Skip to content

Commit 4f296f7

Browse files
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 <[email protected]>
1 parent 78b9ef3 commit 4f296f7

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

web_src/js/index.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import ActivityTopAuthors from './components/ActivityTopAuthors.vue';
2525
import {initNotificationsTable, initNotificationCount} from './features/notification.js';
2626
import {createCodeEditor} from './features/codeeditor.js';
2727
import {svg, svgs} from './svg.js';
28+
import {isMobile} from './utils.js';
2829

2930
const {AppSubUrl, StaticUrlPrefix, csrf} = window.config;
3031

@@ -385,8 +386,14 @@ function initCommentForm() {
385386
if ($('.comment.form').length === 0) {
386387
return;
387388
}
388-
389389
autoSimpleMDE = setCommentSimpleMDE($('.comment.form textarea:not(.review-textarea)'));
390+
391+
// Don't use simpleMDE on mobile due to multiple bug reports which go unfixed
392+
// Other sections rely on it being initialized so just set it back to text area here
393+
if (isMobile()) {
394+
autoSimpleMDE.toTextArea();
395+
}
396+
390397
initBranchSelector();
391398
initCommentPreviewTab($('.comment.form'));
392399
initImagePaste($('.comment.form textarea'));
@@ -1214,16 +1221,21 @@ function initPullRequestReview() {
12141221
const form = $(this).parent().find('.comment-form');
12151222
form.removeClass('hide');
12161223
const $textarea = form.find('textarea');
1217-
let $simplemde;
1218-
if ($textarea.data('simplemde')) {
1219-
$simplemde = $textarea.data('simplemde');
1224+
if (!isMobile()) {
1225+
let $simplemde;
1226+
if ($textarea.data('simplemde')) {
1227+
$simplemde = $textarea.data('simplemde');
1228+
} else {
1229+
attachTribute($textarea.get(), {mentions: true, emoji: true});
1230+
$simplemde = setCommentSimpleMDE($textarea);
1231+
$textarea.data('simplemde', $simplemde);
1232+
}
1233+
$textarea.focus();
1234+
$simplemde.codemirror.focus();
12201235
} else {
12211236
attachTribute($textarea.get(), {mentions: true, emoji: true});
1222-
$simplemde = setCommentSimpleMDE($textarea);
1223-
$textarea.data('simplemde', $simplemde);
1237+
$textarea.focus();
12241238
}
1225-
$textarea.focus();
1226-
$simplemde.codemirror.focus();
12271239
assingMenuAttributes(form.find('.menu'));
12281240
});
12291241
// The following part is only for diff views
@@ -1290,9 +1302,13 @@ function initPullRequestReview() {
12901302
const $textarea = commentCloud.find('textarea');
12911303
attachTribute($textarea.get(), {mentions: true, emoji: true});
12921304

1293-
const $simplemde = setCommentSimpleMDE($textarea);
1294-
$textarea.focus();
1295-
$simplemde.codemirror.focus();
1305+
if (!isMobile()) {
1306+
const $simplemde = setCommentSimpleMDE($textarea);
1307+
$textarea.focus();
1308+
$simplemde.codemirror.focus();
1309+
} else {
1310+
$textarea.focus();
1311+
}
12961312
});
12971313
}
12981314

@@ -1338,6 +1354,10 @@ function initWikiForm() {
13381354
const $editArea = $('.repository.wiki textarea#edit_area');
13391355
let sideBySideChanges = 0;
13401356
let sideBySideTimeout = null;
1357+
if ($editArea.length > 0 && isMobile) {
1358+
$editArea.css('display', 'inline-block');
1359+
return;
1360+
}
13411361
if ($editArea.length > 0) {
13421362
const simplemde = new SimpleMDE({
13431363
autoDownloadFontAwesome: false,
@@ -1433,6 +1453,7 @@ function initWikiForm() {
14331453
name: 'revert-to-textarea',
14341454
action(e) {
14351455
e.toTextArea();
1456+
$editArea.css('display', 'inline-block');
14361457
},
14371458
className: 'fa fa-file',
14381459
title: 'Revert to simple textarea',

web_src/js/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export function isDarkTheme() {
1919
return document.documentElement.classList.contains('theme-arc-green');
2020
}
2121

22+
// returns if mobile device
23+
export function isMobile() {
24+
return /Mobi/.test(navigator.userAgent);
25+
}
26+
2227
// removes duplicate elements in an array
2328
export function uniq(arr) {
2429
return Array.from(new Set(arr));

0 commit comments

Comments
 (0)