Skip to content

A platform for community discussion. Free, open, simple.

DEV: Ensure sequential `replaceText` calls work correctly (#30951)

David Taylor26134b897a84
diff --git a/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js b/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js
index 2472de72dd6..338f393191b 100644
--- a/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js
+++ b/app/assets/javascripts/discourse/app/lib/textarea-text-manipulation.js
@@ -1,5 +1,5 @@
import { setOwner } from "@ember/owner";
-import { next, schedule } from "@ember/runloop";
+import { schedule } from "@ember/runloop";
import { service } from "@ember/service";
import { isEmpty } from "@ember/utils";
import $ from "jquery";
@@ -127,20 +127,16 @@ export default class TextareaTextManipulation {
}
selectText(from, length, opts = { scroll: true }) {
- next(() => {
- this.textarea.selectionStart = from;
- this.textarea.selectionEnd = from + length;
- if (opts.scroll === true || typeof opts.scroll === "number") {
- const oldScrollPos =
- typeof opts.scroll === "number"
- ? opts.scroll
- : this.textarea.scrollTop;
- if (!this.capabilities.isIOS) {
- this.textarea.focus();
- }
- this.textarea.scrollTop = oldScrollPos;
+ this.textarea.selectionStart = from;
+ this.textarea.selectionEnd = from + length;
+ if (opts.scroll === true || typeof opts.scroll === "number") {
+ const oldScrollPos =
+ typeof opts.scroll === "number" ? opts.scroll : this.textarea.scrollTop;
+ if (!this.capabilities.isIOS) {
+ this.textarea.focus();
}
- });
+ this.textarea.scrollTop = oldScrollPos;
+ }
}
replaceText(oldVal, newVal, opts = {}) {