PERF: prevents any fast edit work if you can't edit (#15759)

This commit is contained in:
Joffrey JAFFEUX 2022-02-01 11:28:07 +01:00 committed by GitHub
parent 48cf5e2fbc
commit c46b55dc3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 15 deletions

View File

@ -192,22 +192,24 @@ export default Component.extend(KeyEnterEscape, {
this.topic.postStream.findLoadedPost(postId)?.can_edit this.topic.postStream.findLoadedPost(postId)?.can_edit
); );
const regexp = new RegExp(regexSafeStr(quoteState.buffer), "gi"); if (this._canEditPost) {
const matches = postBody.match(regexp); const regexp = new RegExp(regexSafeStr(quoteState.buffer), "gi");
const matches = postBody.match(regexp);
if ( if (
quoteState.buffer.length < 1 || quoteState.buffer.length < 1 ||
quoteState.buffer.includes("|") || // tables are too complex quoteState.buffer.includes("|") || // tables are too complex
quoteState.buffer.match(/\n/g) || // linebreaks are too complex quoteState.buffer.match(/\n/g) || // linebreaks are too complex
matches?.length > 1 // duplicates are too complex matches?.length > 1 // duplicates are too complex
) { ) {
this.set("_isFastEditable", false); this.set("_isFastEditable", false);
this.set("_fastEditInitalSelection", null); this.set("_fastEditInitalSelection", null);
this.set("_fastEditNewSelection", null); this.set("_fastEditNewSelection", null);
} else if (matches?.length === 1) { } else if (matches?.length === 1) {
this.set("_isFastEditable", true); this.set("_isFastEditable", true);
this.set("_fastEditInitalSelection", quoteState.buffer); this.set("_fastEditInitalSelection", quoteState.buffer);
this.set("_fastEditNewSelection", quoteState.buffer); this.set("_fastEditNewSelection", quoteState.buffer);
}
} }
} }