From 94207e27d16f120fe8ce01e9542ded41118bccbc Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 28 Mar 2022 13:23:50 +1000 Subject: [PATCH] DEV: Remove underscore versions of TextareaTextManipulation functions (#16285) Since 6a5ef27, we made public versions of some TextareaTextManipulation methods. This commit removes the old underscore versions of these methods: _focusTextArea _insertBlock _insertText _getSelected _selectText _replaceText _applySurround _addText _extractTable _isInside --- .../app/mixins/textarea-text-manipulation.js | 81 +++---------------- 1 file changed, 10 insertions(+), 71 deletions(-) diff --git a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js index bb5c5dfd2d5..443250751b8 100644 --- a/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js +++ b/app/assets/javascripts/discourse/app/mixins/textarea-text-manipulation.js @@ -48,14 +48,7 @@ export default Mixin.create({ }, // ensures textarea scroll position is correct - // - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase focusTextArea() { - this._focusTextArea(); - }, - - _focusTextArea() { if (!this.element || this.isDestroying || this.isDestroyed) { return; } @@ -68,33 +61,15 @@ export default Mixin.create({ this._textarea.focus(); }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase insertBlock(text) { - this._insertBlock(text); - }, - - _insertBlock(text) { this._addBlock(this.getSelected(), text); }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase insertText(text, options) { - this._insertText(text, options); + this.addText(this.getSelected(), text, options); }, - _insertText(text, options) { - this._addText(this.getSelected(), text, options); - }, - - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase getSelected(trimLeading, opts) { - return this._getSelected(trimLeading, opts); - }, - - _getSelected(trimLeading, opts) { if (!this.ready || !this.element) { return; } @@ -129,13 +104,7 @@ export default Mixin.create({ } }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase selectText(from, length, opts = { scroll: true }) { - this._selectText(from, length, opts); - }, - - _selectText(from, length, opts = { scroll: true }) { next(() => { if (!this.element) { return; @@ -154,13 +123,7 @@ export default Mixin.create({ }); }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase replaceText(oldVal, newVal, opts = {}) { - this._replaceText(oldVal, newVal, opts); - }, - - _replaceText(oldVal, newVal, opts = {}) { const val = this.value; const needleStart = val.indexOf(oldVal); @@ -203,13 +166,7 @@ export default Mixin.create({ } }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase applySurround(sel, head, tail, exampleKey, opts) { - this._applySurround(sel, head, tail, exampleKey, opts); - }, - - _applySurround(sel, head, tail, exampleKey, opts) { const pre = sel.pre; const post = sel.post; @@ -344,16 +301,10 @@ export default Mixin.create({ this._$textarea.prop("selectionStart", (pre + text).length + 2); this._$textarea.prop("selectionEnd", (pre + text).length + 2); - schedule("afterRender", this, this._focusTextArea); + schedule("afterRender", this, this.focusTextArea); }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase addText(sel, text, options) { - this._addText(sel, text, options); - }, - - _addText(sel, text, options) { if (options && options.ensureSpace) { if ((sel.pre + "").length > 0) { if (!sel.pre.match(/\s$/)) { @@ -374,16 +325,10 @@ export default Mixin.create({ this._$textarea.prop("selectionStart", insert.length); this._$textarea.prop("selectionEnd", insert.length); next(() => this._$textarea.trigger("change")); - this._focusTextArea(); + this.focusTextArea(); }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase extractTable(text) { - return this._extractTable(text); - }, - - _extractTable(text) { if (text.endsWith("\n")) { text = text.substring(0, text.length - 1); } @@ -420,13 +365,7 @@ export default Mixin.create({ return null; }, - // TODO (martin) clean up this indirection, functions used outside this - // file should not be prefixed with lowercase isInside(text, regex) { - return this._isInside(text, regex); - }, - - _isInside(text, regex) { const matches = text.match(regex); return matches && matches.length % 2; }, @@ -452,7 +391,7 @@ export default Mixin.create({ const selected = this.getSelected(null, { lineVal: true }); const { pre, value: selectedValue, lineVal } = selected; const isInlinePasting = pre.match(/[^\n]$/); - const isCodeBlock = this._isInside(pre, /(^|\n)```/g); + const isCodeBlock = this.isInside(pre, /(^|\n)```/g); if ( plainText && @@ -461,7 +400,7 @@ export default Mixin.create({ !isCodeBlock ) { plainText = plainText.replace(/\r/g, ""); - const table = this._extractTable(plainText); + const table = this.extractTable(plainText); if (table) { this.appEvents.trigger( `${this.composerEventPrefix}:insert-text`, @@ -475,7 +414,7 @@ export default Mixin.create({ if (isInlinePasting) { canPasteHtml = !( lineVal.match(/^```/) || - this._isInside(pre, /`/g) || + this.isInside(pre, /`/g) || lineVal.match(/^ /) ); } else { @@ -502,7 +441,7 @@ export default Mixin.create({ ) { // When specified, linkify supports fuzzy links and emails. Prefer providing the protocol. // eg: pasting "example@discourse.org" may apply a link format of "mailto:example@discourse.org" - this._addText(selected, `[${selectedValue}](${match.url})`); + this.addText(selected, `[${selectedValue}](${match.url})`); handled = true; } } @@ -627,9 +566,9 @@ export default Mixin.create({ if (isEmpty(captures)) { if (selected.pre.match(/\S$/)) { - this._addText(selected, ` :${code}:`); + this.addText(selected, ` :${code}:`); } else { - this._addText(selected, `:${code}:`); + this.addText(selected, `:${code}:`); } } else { let numOfRemovedChars = selected.pre.length - captures[1].length; @@ -639,7 +578,7 @@ export default Mixin.create({ ); selected.start -= numOfRemovedChars; selected.end -= numOfRemovedChars; - this._addText(selected, `${code}:`); + this.addText(selected, `${code}:`); } }, });