Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove need to click before typing when activating a range via a drawing-launched script

I am writing a simple script for a Google Sheet. I have a button labeled "New Entry" (the button is actually a drawing with my script assigned to it). When the user clicks the button, the script inserts an empty row at a specified location and activates the first column so that the user can begin typing.

Everything works great except that after the script finishes, the keyboard doesn't work until after the user manually clicks in the sheet. The correct cell is visibly activated, but I suspect the focus is still (secretly) on the drawing. This theory is supported by the fact that if the user hits the escape key, he can then begin typing in the active cell as desired.

Is there any way to automate this final step so that the user does not need to hit ESC or click into the sheet before begining to type?

Here is the relevant line of code I am using:

this_sheet.getRange(new_row_num, start_col + 1).activate();   // activate the appropriate cell for convenient data entry

I have tried a few other functions in combination with and/or instead of the line of code shown above, but always with the same result. These other functions include Sheet.activate() and Spreadsheet.setActiveSelection(range).

like image 636
Andrew Avatar asked Oct 31 '22 01:10

Andrew


1 Answers

If these functions are not working the way as desired, then a workaround to get focus would be to write to the target cell using

this_sheet.getRange(new_row_num, start_col + 1).setValue("");//for blank cell

and if it is not a blank cell but having some existing value then you can use getValue() first and then setValue() so as to keep the same value.

like image 188
Fi Teach Avatar answered Nov 09 '22 14:11

Fi Teach