[Greasemonkey] Patterns

Edward Lee edilee at gmail.com
Fri Apr 15 00:56:08 EDT 2005


On 4/14/05, Julien Couvreur <julien.couvreur at gmail.com> wrote:
> Next step is to make the textarea change size as you press "ctrl-enter" ;-)

http://ed.agadak.net/jsshell.php

I made it so that the textarea changes size based on how many lines
there are in there, so it'll expand on ctrl-enter/pastes and shrink
when deleting those lines. Also wrapping is off, so it's back to how
the shell worked before with the infinite width line, but now you can
use a scrollbar to move left/right. I also combined the inputkey
function with the anonymous one I add for the keydown event handler.

setTimeout(function() {
  with(_in.value.split(/\\n/)) {
    _in.rows = length + Math.ceil(length/20); // extra ceil term to
fix sizing issues
  }
}, 0); // automatically change the size of the textarea

I used the timeout because deleting lines didn't seem to update the
size until the next keypress. Split defaults to 1 item if it doesn't
find anything to split, so length is always at least 1, and the extra
term is added because after every 20 or so lines, the scrollbar
appeared because rows werent exactly the same as lines.

Scrolling up in history now requires 2 up's for single line inputs
because up moves the cursor to the top of the entry then up goes back
in history, but then you could just do ctrl-up to skip past that
double up issue.

The version is still 1.1, and I haven't tested it on other browsers. I
noticed that there was some special keycodes for Opera used elsewhere
in the code, but I didn't check for those in the event handler. On a
side note, there seems to be some commented out sections of tab
completion just sitting in the shell code taking up space, but that's
not a big issue.


Jesse: sorry ahead of time if you don't want these messages. I'll stop
if you say so.
GM people: sorry to you people too because this isn't directly
greasemonkey related..

Suggestions to where I should bring this? :)

-- 
Ed


More information about the Greasemonkey mailing list