It’s not exactly 15 seconds, but it appears that Apple’s auto-save is kicking in and closing the editor. I don’t think this can be disabled. I’m not sure why auto-save is kicking in, since the document hasn’t actually been modified yet, but it is. (Addendum - now I can’t duplicate this, but I definitely got it to happen once.)
Normally this is fine, but you have purposefully written code to make sure that the changes aren’t saved in this situation. The second line of your code is:
if info("keyboard")="" rtn endif
When auto-save ends the editing (or if you click outside of the text editor, which also ends editing), this will be triggered, and your changes will be lost.
In fact, the whole first part of your code should be removed. The code should only be:
First = firstword(TextEditingResult)
Last = lastword(TextEditingResult)
Ok, I think you were using focusobject, mousedown etc to try to see what type of operation triggered the procedure. Then you were trying to fix the bug that Field Editing Attributes doesn’t work in Formula mode. That bug has been fixed, so you won’t need this, but in any case, there is an official, approved way to trigger different code depending on what has happened, as explained in the documentation.
So the “correct” way to do what you were trying to do is:
return
finishEditing:
startdatabasechange "CurrentRecord","Edit Name"
First = firstword(TextEditingResult)
Last = lastword(TextEditingResult)
return
mostKeys:
local s,e,idata
let allowedChars = "AZaz. " // I didn't feel like typing in the complete list, knock yourself out
activeobjectaction "getselection",s,e
activeobjectaction "gettext",idata
if upperword(stripchar(idata,allowedChars))<>idata
activeobjectaction "settext",upperword(stripchar(idata,allowedChars))
activeobjectaction "setselection",s,e
endif
return
When I say that this version is “correct”, I mean that it will never lose data no matter how you terminate editing, including auto-save or clicking. I’ve also added the startdatabasechange statement so that editing can be undone.
You might want to use everyKeys instead of mostKeys, but I think mostKeys would be better. In any case, that entire section of this code will be unnecessary once the next version of Panorama X comes out which fixes the Field Editing Attributes problem.