diff --git a/regex.html b/regex.html index 2c215a0..b60e6a0 100644 --- a/regex.html +++ b/regex.html @@ -57,6 +57,10 @@ pre { min-height: 1em; display: flow-root; } +.samptxt_outer { + display: block; + overflow: auto; +} pre.samptxt { padding: 2px; display: inline-block; @@ -64,14 +68,16 @@ pre.samptxt { textarea.samp_ta { min-width: 10em; min-height: 1em; - max-width: calc(100% - 1.5em); - width: 100%; + width: calc(100% - 1.7em); + height: 1.1em; border: 1px solid grey; padding: 1px; display: inline-block; + resize: vertical; } .closebtn { float: right; + margin-left: 5px; cursor: pointer; } .re_output { @@ -223,33 +229,37 @@ sub sample_init { my $samp = shift; state $samp_id = 'a'; $samp->attr('id',"samp_".$samp_id++) unless $samp->attr('id'); - my $samptxt = $samp->children(".samptxt"); + my $samptxt = $samp->find(".samptxt"); + my $samptxt_outer = $jq->('
',{class=>"samptxt_outer"}); + $samptxt->wrap($samptxt_outer); my $samp_ta = $jq->('', {class=>"samp_ta"}); $samp_ta->hide(); $samp_ta->appendTo($samp); my $closebtn = $jq->('', {html=>"❎",class=>"closebtn", title=>"Delete Sample"}); - $closebtn->appendTo($samp); + $closebtn->prependTo($samp); $jq->('', {class=>'re_output'})->appendTo($samp); $jq->('', {class=>'re_warns'})->appendTo($samp); $jq->('', {class=>'re_errors'})->appendTo($samp); $samp->click(sub { return if $samp_ta->is(':visible'); - $samp_ta->height($samptxt->height); $samp_ta->val($samptxt->text); + my $th = $samptxt->height; $samptxt->hide; $samp_ta->show; + my $sh = $samp_ta->[0]{scrollHeight}-2; # subtract padding + # I'm not quite sure of the rounding that's happening in the browser yet... + $samp_ta->height( int($sh) > int($th)+1 ? $sh : $th ); $samp_ta->focus; }); $samp_ta->focusout(sub { $samptxt->text($samp_ta->val); - $samptxt->height($samp_ta->height); $samp_ta->hide; $samptxt->show; update(); }); - $samp_ta->on('input', sub { - $samp_ta->height($samp_ta->[0]->{scrollHeight}-2); # subtract padding + $samp_ta->on('input', sub { # autoexpand for new lines + $samp_ta->height($samp_ta->[0]{scrollHeight}-2); # subtract padding }); $closebtn->click(sub { $samp->remove; update() }); } @@ -333,8 +343,8 @@ $ta_flags->keyup( \&update); js('$(window)')->on('hashchange',\&hashchange); -$ta_regex->on('input', sub { - $ta_regex->height($ta_regex->[0]->{scrollHeight}); +$ta_regex->on('input', sub { # autoexpand for new lines + $ta_regex->height($ta_regex->[0]{scrollHeight}); }); hashchange(); @@ -378,7 +388,7 @@ sub actual_update { my @samps; for my $sample (map {$jq->($_)} $jq->('.sample')->@*) { - my $samptxt = $sample->children('.samptxt'); + my $samptxt = $sample->find('.samptxt'); my $text = $samptxt->text; push @samps, $text; # for use below my $code = $precode . ( $re_debug ? "use re \"debug\";\n" : '' ) @@ -454,7 +464,7 @@ sub run_code_callback { if (!$sample->{length}) { warn "got callback for nonexistent sample ".$rv->{context}; return } - my $samptxt = $sample->children('.samptxt'); + my $samptxt = $sample->find('.samptxt'); my $text = $samptxt->text; my $errs = ''; if ( $rv->{out} && $rv->{out}->@* ) { @@ -529,6 +539,7 @@ sub run_code_callback { $sample->children('.re_warns')->text( join "\n", $rv->{warns}->@* ); $errs = "### Errors ###\n$errs" if $errs=~/\S/; $sample->children('.re_errors')->text($errs); + state $loading = 1; if ($loading) { $jq->('#loading')->remove; $loading=0 } } sub escape_html { # apparently no built-in JS function for this (?), so do it manually @@ -547,7 +558,7 @@ sub hashchange { } if (exists $res{regex} && exists $res{flags}) { $ta_regex->val($res{regex}); - $ta_regex->height($ta_regex->[0]->{scrollHeight}); + $ta_regex->height($ta_regex->[0]{scrollHeight}); $ta_flags->val($res{flags}); sampcode_show() if $res{showsampcode}; precode_show($res{pre}) if exists $res{pre}; @@ -567,22 +578,26 @@ sub hashchange { -Oh, what a wonderful world!
perl v?, WebPerl v?+
perl v?, WebPerl v?-