From 0b1c342ecfc0302306aa753a09c71f1cb0a4d1b2 Mon Sep 17 00:00:00 2001 From: Gesina Schwalbe Date: Sun, 24 Jan 2021 13:11:08 +0100 Subject: [PATCH] select text of input fields when focused - the content of input fields of relevant sheets and dialogs are now selected upon focus - autofocus the Gamemaster roll modifier in the roll dialog --- src/module/ds4.ts | 18 ++++++++++++++++++ src/templates/roll/roll-options.hbs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/module/ds4.ts b/src/module/ds4.ts index 81115a4c..a20f18e5 100644 --- a/src/module/ds4.ts +++ b/src/module/ds4.ts @@ -133,3 +133,21 @@ Hooks.once("setup", function () { Hooks.once("ready", function () { migration.migrate(); }); + +/** + * Select the text of input elements in given sheets via onfocus listener. + * The hook names are of the form "render"+sheet_superclassname and are called within + * the render() method of the foundry Application class. + * Note: The render hooks of all classes in the class hierarchy are called, + * so e.g. for a Dialog, both "renderDialog" and "renderApplication" are called + * (in this order). + */ +["renderApplication", "renderActorSheet", "renderItemSheet"].forEach((hookName: string) => { + Hooks.on(hookName, (app: Dialog, html: JQueryStatic, data: any) => { + $(html) + .find("input") + .on("focus", (ev: JQuery.FocusEvent) => { + ev.currentTarget.select(); + }); + }); +}); diff --git a/src/templates/roll/roll-options.hbs b/src/templates/roll/roll-options.hbs index 8c3e7dc3..153d463d 100644 --- a/src/templates/roll/roll-options.hbs +++ b/src/templates/roll/roll-options.hbs @@ -2,7 +2,7 @@ - +