Skip to content

Commit 0f265a2

Browse files
GiteaBotsilverwind
andauthored
Don't autosize textarea in diff view (#26233) (#26244)
Backport #26233 by @silverwind Resizing the comment editor can be a very expensive operation because it triggers page reflows, which on large PRs can take upwards of seconds to complete. Disable this mechanism on the diff page only where we know that the page can get large. Fixes #26201 for the textarea editor. I don't think this can be fixed for EasyMDE because as far as I can tell, it exposes no option to disable this resizing. Co-authored-by: silverwind <[email protected]>
1 parent 0d04f70 commit 0f265a2

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

templates/repo/diff/comment_form.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"TextareaName" "content"
1818
"TextareaPlaceholder" ($.locale.Tr "repo.diff.comment.placeholder")
1919
"DropzoneParentContainer" "form"
20+
"DisableAutosize" "true"
2021
)}}
2122

2223
<div class="field footer gt-mx-3">

templates/shared/combomarkdowneditor.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Template Attributes:
1010
* TextareaPlaceholder: placeholder attribute for the textarea
1111
* TextareaAriaLabel: aria-label attribute for the textarea
1212
* DropzoneParentContainer: container for file upload (leave it empty if no upload)
13+
* DisableAutosize: whether to disable automatic height resizing
1314
*/}}
1415
<div {{if .ContainerId}}id="{{.ContainerId}}"{{end}} class="combo-markdown-editor {{.ContainerClasses}}" data-dropzone-parent-container="{{.DropzoneParentContainer}}">
1516
{{if .MarkdownPreviewUrl}}
@@ -45,7 +46,7 @@ Template Attributes:
4546
</div>
4647
</markdown-toolbar>
4748
<text-expander keys=": @" suffix="">
48-
<textarea class="markdown-text-editor js-quick-submit"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}>{{.TextareaContent}}</textarea>
49+
<textarea class="markdown-text-editor js-quick-submit"{{if .TextareaName}} name="{{.TextareaName}}"{{end}}{{if .TextareaPlaceholder}} placeholder="{{.TextareaPlaceholder}}"{{end}}{{if .TextareaAriaLabel}} aria-label="{{.TextareaAriaLabel}}"{{end}}{{if .DisableAutosize}} data-disable-autosize="{{.DisableAutosize}}"{{end}}>{{.TextareaContent}}</textarea>
4950
</text-expander>
5051
<script>
5152
if (localStorage?.getItem('markdown-editor-monospace') === 'true') {

web_src/js/features/comp/ComboMarkdownEditor.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ class ComboMarkdownEditor {
6868
this.textarea.id = `_combo_markdown_editor_${String(elementIdCounter++)}`;
6969
this.textarea.addEventListener('input', (e) => this.options?.onContentChanged?.(this, e));
7070
this.applyEditorHeights(this.textarea, this.options.editorHeights);
71-
this.textareaAutosize = autosize(this.textarea, {viewportMarginBottom: 130});
71+
72+
if (this.textarea.getAttribute('data-disable-autosize') !== 'true') {
73+
this.textareaAutosize = autosize(this.textarea, {viewportMarginBottom: 130});
74+
}
7275

7376
this.textareaMarkdownToolbar = this.container.querySelector('markdown-toolbar');
7477
this.textareaMarkdownToolbar.setAttribute('for', this.textarea.id);
@@ -246,7 +249,7 @@ class ComboMarkdownEditor {
246249
} else {
247250
this.textarea.value = v;
248251
}
249-
this.textareaAutosize.resizeToFit();
252+
this.textareaAutosize?.resizeToFit();
250253
}
251254

252255
focus() {

0 commit comments

Comments
 (0)