Update the GenericAppMixin so that it persists focus better
This commit is contained in:
parent
28989c2d35
commit
4a8ce9b099
1 changed files with 38 additions and 2 deletions
|
|
@ -37,6 +37,8 @@ export function GenericAppMixin(HandlebarsApp) {
|
||||||
_popoverManagers = new Map();
|
_popoverManagers = new Map();
|
||||||
/** @type {Map<number, string>} */
|
/** @type {Map<number, string>} */
|
||||||
_hookIDs = new Map();
|
_hookIDs = new Map();
|
||||||
|
/** @type {string | null} */
|
||||||
|
#focus = null;
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region Lifecycle
|
// #region Lifecycle
|
||||||
|
|
@ -53,6 +55,26 @@ export function GenericAppMixin(HandlebarsApp) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* This method overrides Foundry's default behaviour for caching the focused
|
||||||
|
* element so that it actually works when the application has a root partial
|
||||||
|
*/
|
||||||
|
async _preRender(...args) {
|
||||||
|
if (this.rendered) {
|
||||||
|
const target = this.element.querySelector(`:focus`);
|
||||||
|
if (target) {
|
||||||
|
if (target.id) {
|
||||||
|
this.#focus = `#${CSS.escape(target.id)}`;
|
||||||
|
}
|
||||||
|
else if (target.name) {
|
||||||
|
this.#focus = `${target.tagName}[name="${target.name}"]`;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return super._preRender(...args);
|
||||||
|
};
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
async _onRender(...args) {
|
async _onRender(...args) {
|
||||||
await super._onRender(...args);
|
await super._onRender(...args);
|
||||||
|
|
@ -83,11 +105,25 @@ export function GenericAppMixin(HandlebarsApp) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async _prepareContext() {
|
/**
|
||||||
|
* @override
|
||||||
|
* This method overrides Foundry's default behaviour for caching the focused
|
||||||
|
* element so that it actually works when the application has a root partial
|
||||||
|
*/
|
||||||
|
async _postRender(...args) {
|
||||||
|
if (this.rendered) {
|
||||||
|
const target = this.element.querySelector(this.#focus);
|
||||||
|
target?.focus();
|
||||||
|
};
|
||||||
|
this.#focus = null;
|
||||||
|
return super._postRender(...args);
|
||||||
|
};
|
||||||
|
|
||||||
|
async _prepareContext(_options) {
|
||||||
const ctx = {};
|
const ctx = {};
|
||||||
|
|
||||||
ctx.meta ??= {};
|
ctx.meta ??= {};
|
||||||
ctx.meta.idp = this.document?.uuid ?? this.id;
|
ctx.meta.idp = this.id;
|
||||||
if (this.document) {
|
if (this.document) {
|
||||||
ctx.meta.limited = this.document.limited;
|
ctx.meta.limited = this.document.limited;
|
||||||
ctx.meta.editable = this.isEditable || game.user.isGM;
|
ctx.meta.editable = this.isEditable || game.user.isGM;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue