summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Hanzel <mhanzel@gitlab.com>2019-08-01 07:36:30 -0400
committerMartin Hanzel <mhanzel@gitlab.com>2019-08-01 10:09:51 -0400
commitafe11edfe62bde15ddc851d2f9fbebdf2fd9138f (patch)
tree9a50dde4a770714c98435569fee7a5be287064cc
parent0149ebccaba8ee1bae583ccc48947e317319c6e4 (diff)
downloadgitlab-ce-mh/fix-editor-newlines.tar.gz
Autosize editor after indent/newlinemh/fix-editor-newlines
-rw-r--r--app/assets/javascripts/gl_form.js9
-rw-r--r--app/assets/javascripts/helpers/indent_helper.js5
2 files changed, 13 insertions, 1 deletions
diff --git a/app/assets/javascripts/gl_form.js b/app/assets/javascripts/gl_form.js
index b98fe9f6ce2..eafc9c12c51 100644
--- a/app/assets/javascripts/gl_form.js
+++ b/app/assets/javascripts/gl_form.js
@@ -165,8 +165,17 @@ export default class GLForm {
this.indentHelper.newline();
} else if (keystroke(event, keys.BACKSPACE_KEY_CODE)) {
// ==== Auto-delete indents at the beginning of the line ====
+ // Event should not be prevented when not backspacing an indent - this is left to the browser
this.indentHelper.backspace(event);
}
+
+ if (event.defaultPrevented) {
+ // Allow the backing vue app to pick up on the changes
+ this.textarea.trigger('input');
+ this.textarea.trigger('change');
+
+ autosize.update(this.textarea[0]);
+ }
}
handleKeyShortcuts(event) {
diff --git a/app/assets/javascripts/helpers/indent_helper.js b/app/assets/javascripts/helpers/indent_helper.js
index a8815fac04e..d1cfefa4728 100644
--- a/app/assets/javascripts/helpers/indent_helper.js
+++ b/app/assets/javascripts/helpers/indent_helper.js
@@ -20,7 +20,10 @@ export default class IndentHelper {
}
getSelection() {
- return { start: this.element.selectionStart, end: this.element.selectionEnd };
+ return {
+ start: Math.max(0, Math.min(this.element.selectionStart, this.element.value.length)),
+ end: Math.max(0, Math.min(this.element.selectionEnd, this.element.value.length)),
+ };
}
isRangeSelection() {