Skip to content

Instantly share code, notes, and snippets.

@Dayjo
Last active May 16, 2018 19:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dayjo/7804066 to your computer and use it in GitHub Desktop.
Save Dayjo/7804066 to your computer and use it in GitHub Desktop.
Make Gist editor automatically resize based on content using a TamperMonkey script
// ==UserScript==
// @name gist-editor-resize-userscript
// @namespace https://gist.github.com/
// @version 0.1
// @description Automatically resize the gist editor for easier editing.
// @match http*://gist.github.com/*
// @copyright 2013+ Joel Day - blog.dayjo.org
// ==/UserScript==
var textareas = document.querySelectorAll('textarea.file_contents');
var span = document.createElement('div');
span.style.visibility = "hidden";
document.body.appendChild(span);
$('textarea.file-contents').keyup(function(){
span.style.width = this.offsetWidth + 'px';
span.style.fontSize = this.style.fontSize;
span.innerText = this.value;
this.style.height = span.offsetHeight + 'px';
});
@dragon788
Copy link

Any chance on getting this updated for Ace, or is it just a pain in the 'ace'?

@Artistan
Copy link

Artistan commented Nov 30, 2017

Recommend setting your namespace to
https://gist.github.com/Dayjo/7804066
So people can come back to this for updates 👍
https://github.com/blog/302-gist-for-greasemonkey

FYI ... errror

ERROR: Execution of script 'gist-editor-resize-userscript' failed! $ is not a function

this may be a relevant reference for a better solution
https://codemirror.net/demo/resize.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment