From c46b55dc3bd7df0c03bdd959c5e18b01b22938cf Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 1 Feb 2022 11:28:07 +0100 Subject: [PATCH] PERF: prevents any fast edit work if you can't edit (#15759) --- .../discourse/app/components/quote-button.js | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/quote-button.js b/app/assets/javascripts/discourse/app/components/quote-button.js index f3af1940fdc..0c1ba275ca3 100644 --- a/app/assets/javascripts/discourse/app/components/quote-button.js +++ b/app/assets/javascripts/discourse/app/components/quote-button.js @@ -192,22 +192,24 @@ export default Component.extend(KeyEnterEscape, { this.topic.postStream.findLoadedPost(postId)?.can_edit ); - const regexp = new RegExp(regexSafeStr(quoteState.buffer), "gi"); - const matches = postBody.match(regexp); + if (this._canEditPost) { + const regexp = new RegExp(regexSafeStr(quoteState.buffer), "gi"); + const matches = postBody.match(regexp); - if ( - quoteState.buffer.length < 1 || - quoteState.buffer.includes("|") || // tables are too complex - quoteState.buffer.match(/\n/g) || // linebreaks are too complex - matches?.length > 1 // duplicates are too complex - ) { - this.set("_isFastEditable", false); - this.set("_fastEditInitalSelection", null); - this.set("_fastEditNewSelection", null); - } else if (matches?.length === 1) { - this.set("_isFastEditable", true); - this.set("_fastEditInitalSelection", quoteState.buffer); - this.set("_fastEditNewSelection", quoteState.buffer); + if ( + quoteState.buffer.length < 1 || + quoteState.buffer.includes("|") || // tables are too complex + quoteState.buffer.match(/\n/g) || // linebreaks are too complex + matches?.length > 1 // duplicates are too complex + ) { + this.set("_isFastEditable", false); + this.set("_fastEditInitalSelection", null); + this.set("_fastEditNewSelection", null); + } else if (matches?.length === 1) { + this.set("_isFastEditable", true); + this.set("_fastEditInitalSelection", quoteState.buffer); + this.set("_fastEditNewSelection", quoteState.buffer); + } } }