From 0021b378b3edf3ebd36df174666b10174296d97d Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Sun, 3 Jul 2022 16:01:58 -0700 Subject: [PATCH] Add a carriage-return to the mouse hotspot value when needed For program listings, if the program number is fewer digits than the total program list count (number of digits), then a carriage return is required to launch that program. Automate this for the mouse hotspot value, so clicking Program #1 in a list of 10+ will just run that program and not require the user to hit the Enter key. --- exec/xtrn_sec.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/exec/xtrn_sec.js b/exec/xtrn_sec.js index 428f01c60f..03c2b9175e 100644 --- a/exec/xtrn_sec.js +++ b/exec/xtrn_sec.js @@ -92,6 +92,13 @@ function sort_by_name(a, b) return 0; } +function digits(n) +{ + if (n/10 == 0) + return 1; + return 1 + digits(n / 10); +} + function external_program_menu(xsec) { var i,j; @@ -172,7 +179,10 @@ function external_program_menu(xsec) for(i=0;i<n && !console.aborted;i++) { write(margin); - console.add_hotspot(i+1); + var hotspot = i+1; + if(digits(hotspot) < digits(prog_list.length)) + hotspot += '\r'; + console.add_hotspot(hotspot); printf(multicolumn ? options.multicolumn_fmt : options.singlecolumn_fmt ,i+1 ,prog_list[i].name @@ -182,7 +192,10 @@ function external_program_menu(xsec) j=Math.floor(prog_list.length/2)+i+(prog_list.length&1); if(j<prog_list.length) { write(options.multicolumn_separator); - console.add_hotspot(j+1); + hotspot = j+1; + if(digits(hotspot) < digits(prog_list.length)) + hotspot += '\r'; + console.add_hotspot(hotspot); printf(options.multicolumn_fmt, j+1 ,prog_list[j].name ,prog_list[j].cost); -- GitLab