From 82115ed8d7d61556150e71ea410a3e3db8572268 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 26 Aug 2022 22:21:25 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20recherche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La recherche de compétence fonctionne sur timer --- module/actor-sheet.js | 44 ++++++++++++++++++++++++++++++-------- templates/actor-sheet.html | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 57ee081c..09f497c9 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -37,8 +37,7 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ async getData() { const objectData = Misc.data(this.object); - - //this.actor.checkMonnaiePresence(this.actor.data.items); // Always check + this.timerRecherche = undefined; let formData = { title: this.title, @@ -78,8 +77,8 @@ export class RdDActorSheet extends ActorSheet { }; formData.competences.forEach(item => { - item.visible = this.options.cherchercompetence - ? RdDItemCompetence.nomContientTexte(item, this.options.cherchercompetence) + item.visible = this.options.recherche + ? RdDItemCompetence.nomContientTexte(item, this.options.recherche.text) : (!this.options.showCompNiveauBase || !RdDItemCompetence.isNiveauBase(item)); RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value); }); @@ -424,12 +423,28 @@ export class RdDActorSheet extends ActorSheet { this.options.editCaracComp = !this.options.editCaracComp; this.render(true); }); - html.find('.cherchercompetence').change(async event => { - this.options.cherchercompetence = event.currentTarget.value; - this.render(true); - }); + + html.find('.recherche') + .each((index, field) => { + if (this.options.recherche) { + field.focus(); + field.setSelectionRange(this.options.recherche.start, this.options.recherche.end); + } + }) + .keyup(async event => { + this.options.recherche = this._optionRecherche(event.currentTarget) + if (this.timerRecherche) { + clearTimeout(this.timerRecherche); + } + this.timerRecherche = setTimeout(() => { + this.timerRecherche = undefined; + this.render(true); + }, 500); + }) + .change(async event => + this.options.recherche = this._optionRecherche(event.currentTarget) + ); html.find('.vue-detaillee').click(async event => { - console.log("CONTROLS", this.options.vueDetaillee) this.options.vueDetaillee = !this.options.vueDetaillee; this.render(true); }); @@ -515,6 +530,17 @@ export class RdDActorSheet extends ActorSheet { }); } + _optionRecherche(target) { + if (!target.value?.length){ + return undefined; + } + return { + text: target.value, + start: target.selectionStart, + end: target.selectionEnd, + }; + } + _getEventArmeCombat(event) { const li = $(event.currentTarget)?.parents(".item"); let armeName = li.data("arme-name"); diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index dd4e86f8..1ea3be42 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -217,7 +217,7 @@ {{#if options.editCaracComp}}Verrouiller{{else}}Déverrouiller{{/if}} -