Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Markdown autoresize box quirky on enter

Open
#8 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
frontend

Research direction

Start in models/Document.bones at the updateSize function and reproduce the autoresize behavior by pressing Enter in the markdown textarea in Chrome and Firefox. Compare the textarea and clone values during keydown; done means the textarea resizes without jumping up before the new line appears.

Written by the indexing model from the issue text.

Description

When hitting enter in a markdown autoresize textarea, the textarea is not resized until the enter key is released which leads to the text jumping up one line before it drops down again. I have observed this behavior in Chrome and FF. While the browser adds the new character to the textarea, it does not make it available via .val() until the key is released.

The following code is hideous, but addresses the issue. I wonder whether there are more elegante ways around this.

diff --git a/models/Document.bones b/models/Document.bones
index 23c2044..6f5bec9 100644
--- a/models/Document.bones
+++ b/models/Document.bones
@@ -202,9 +202,14 @@ model = Backbone.Model.extend({
                             letterSpacing: textarea.css('letterSpacing')
                         }).attr('tabIndex','-1').insertBefore(textarea);
                     })(),
-                    updateSize = function() {
+                    updateSize = function(ev) {
                         // Update clone.
-                        clone.val($(this).val()).scrollTop(10000);
+                        var val = $(this).val();
+                        On keydown, the newest character is not in .val().
+                        if (ev && ev.type == 'keydown') {
+                            val += String.fromCharCode(ev.keyCode);
+                        }
+                        clone.val(val).scrollTop(10000);
                         // Find scrolling height of text in clone and update
                         var height = clone.scrollTop();
                         if (!$.browser.msie) {
Dominant language
JavaScript
Stars
4
Forks
2
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from developmentseed/bones-document

All issues in developmentseed/bones-document

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.