@@ -22,6 +22,7 @@ export class ChannelLog extends Element {
2222 constructor ( props ) {
2323 super ( ) ;
2424 this . channel = props . channel ;
25+ this . eval_history_index = - 1 ;
2526 }
2627
2728 componentDidMount ( ) {
@@ -54,16 +55,29 @@ export class ChannelLog extends Element {
5455 }
5556
5657 [ "on ^keydown at textarea#toeval" ] ( evt , textarea ) {
58+ if ( evt . code === "ArrowUp" ) {
59+ // populate textarea with the next previous eval (if any)
60+ const prev_eval = this . getNextPrevEval ( ) ;
61+ textarea . value = prev_eval ;
62+ return true ; // consume
63+ } else if ( evt . code === "ArrowDown" ) {
64+ // populate textarea with next eval
65+ const next_eval = this . getNextEval ( ) ;
66+ textarea . value = next_eval ; // set to next eval in history
67+ return true ; // consume
68+ }
5769 if ( evt . code != "Enter" ) return ;
5870 if ( evt . shiftKey || evt . ctrlKey ) return ;
5971 const toeval = textarea . value . trim ( ) ;
60- if ( ! toeval ) return ;
72+ if ( ! toeval ) return ; // don't eval empty string
6173 this . channel . theirLogs . push ( {
6274 severity : 0 ,
6375 subsystem : 4 , // "eval"
6476 items : [ toeval ] ,
6577 } ) ;
6678 this . channel . notify ( "toeval" , toeval ) ;
79+ textarea . value = "" ; // clear textarea after eval
80+ this . eval_history_index = - 1 ; // reset eval history index
6781 return true ; // do not propagate, consumed
6882 }
6983
@@ -76,6 +90,32 @@ export class ChannelLog extends Element {
7690 Clipboard . writeText ( text ) ;
7791 }
7892
93+ get evals ( ) {
94+ return this . channel . theirLogs . map ( ( item ) => {
95+ if ( item . subsystem != 4 ) return null ;
96+ return item . items [ 0 ] ;
97+ } ) . filter ( ( item ) => item ) ;
98+ }
99+
100+ getEvalAtIndex ( index ) {
101+ // get the nth eval from the end
102+ const evals = this . evals ;
103+ if ( ! evals . length ) return null ;
104+ return evals [ evals . length - 1 - index ] ;
105+ }
106+
107+ getNextEval ( ) {
108+ // get the next eval in history
109+ this . eval_history_index = Math . max ( this . eval_history_index - 1 , - 1 ) ; // don't go below -1 (aka. no previous eval)
110+ return this . getEvalAtIndex ( this . eval_history_index ) ;
111+ }
112+
113+ getNextPrevEval ( ) {
114+ // get the next previous eval in history
115+ this . eval_history_index = Math . min ( this . eval_history_index + 1 , this . evals . length - 1 ) ; // don't go above the last eval
116+ return this . getEvalAtIndex ( this . eval_history_index ) ;
117+ }
118+
79119 [ "on keydown" ] ( evt ) {
80120 if ( evt . code === "KeyC" && evt . ctrlKey ) {
81121 this . list2clipboard ( ) ;
0 commit comments