Skip to content

Commit 1f472d8

Browse files
undo editor shortcuts
1 parent acd8ba7 commit 1f472d8

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

assets/javascripts/view_layouts_base_body_bottom_markdown.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ function styleSelectedText(textarea, prepend, append) {
66
$start = textarea.prop('selectionStart');
77
$end = textarea.prop('selectionEnd');
88
$content = textarea.val();
9-
$content = $content.slice(0, $start) + prepend + $content.slice($start, $end) + append + $content.slice($end, $content.length);
10-
textarea.val($content);
11-
textarea.focus();
12-
textarea.prop('selectionStart', $start + prepend.length);
13-
textarea.prop('selectionEnd', $end + append.length);
9+
if ($content.slice(0, $start).endsWith(prepend) && $content.slice($end, $content.length).replace("\n", '').startsWith(append.replace("\n", ''))) {
10+
$content = $content.slice(0, $start - prepend.length) + $content.slice($start, $end) + $content.slice($end + append.length, $content.length);
11+
textarea.val($content);
12+
textarea.focus();
13+
textarea.prop('selectionStart', $start - prepend.length);
14+
textarea.prop('selectionEnd', $end - append.length);
15+
} else {
16+
$content = $content.slice(0, $start) + prepend + $content.slice($start, $end) + append + $content.slice($end, $content.length);
17+
textarea.val($content);
18+
textarea.focus();
19+
textarea.prop('selectionStart', $start + prepend.length);
20+
textarea.prop('selectionEnd', $end + append.length);
21+
}
1422
}
1523

1624
$(document).keydown(function (e) {

assets/javascripts/view_layouts_base_body_bottom_textile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ function styleSelectedText(textarea, prepend, append) {
66
$start = textarea.prop('selectionStart');
77
$end = textarea.prop('selectionEnd');
88
$content = textarea.val();
9-
$content = $content.slice(0, $start) + prepend + $content.slice($start, $end) + append + $content.slice($end, $content.length);
10-
textarea.val($content);
11-
textarea.focus();
12-
textarea.prop('selectionStart', $start + prepend.length);
13-
textarea.prop('selectionEnd', $end + append.length);
9+
if ($content.slice(0, $start).endsWith(prepend) && $content.slice($end, $content.length).replace("\n", '').startsWith(append.replace("\n", ''))) {
10+
$content = $content.slice(0, $start - prepend.length) + $content.slice($start, $end) + $content.slice($end + append.length, $content.length);
11+
textarea.val($content);
12+
textarea.focus();
13+
textarea.prop('selectionStart', $start - prepend.length);
14+
textarea.prop('selectionEnd', $end - append.length);
15+
} else {
16+
$content = $content.slice(0, $start) + prepend + $content.slice($start, $end) + append + $content.slice($end, $content.length);
17+
textarea.val($content);
18+
textarea.focus();
19+
textarea.prop('selectionStart', $start + prepend.length);
20+
textarea.prop('selectionEnd', $end + append.length);
21+
}
1422
}
1523

1624
$(document).keydown(function (e) {

0 commit comments

Comments
 (0)