User:Bosco/Unsigned helper.js: Difference between revisions
From Test Wiki
Content deleted Content added
doAddUnsignedTemplate: in Special:Diff/1238811453 function `applySearcherResult` stopped using variable `pos` => stop using the approach with `getCaretPosition` completely, just use the command `getSelection` |
doAddUnsignedTemplate: update code comments about CodeMirror support |
||
| Line 497: | Line 497: | ||
async function doAddUnsignedTemplate() { |
async function doAddUnsignedTemplate() { |
||
| ⚫ | |||
const form = document.getElementById('editform'); |
const form = document.getElementById('editform'); |
||
const wikitextEditor = form.elements.wpTextbox1; |
const wikitextEditor = form.elements.wpTextbox1; |
||
/* |
|||
* https://doc.wikimedia.org/mediawiki-core/master/js/module-jquery.textSelection.html |
|||
* We cannot use wikitextEditor.value here, because this textarea is hidden and |
|||
* is not updated with CodeMirror. Therefore, the selection in CodeMirror becomes |
|||
* desynced from the text in wikitextEditor. |
|||
* However, CodeMirror does respond to textSelection "commands" sent to wikitextEditor. |
|||
* The responses correspond with up-to-date wikitext in CodeMirror. |
|||
| ⚫ | |||
*/ |
|||
let txt = $(wikitextEditor).textSelection('getSelection'); |
let txt = $(wikitextEditor).textSelection('getSelection'); |
||
txt = txt.replace(new RegExp('[\\s\\S]*\\d\\d:\\d\\d, \\d+ (' + months.join('|') + ') \\d\\d\\d\\d \\(UTC\\)'), ''); |
txt = txt.replace(new RegExp('[\\s\\S]*\\d\\d:\\d\\d, \\d+ (' + months.join('|') + ') \\d\\d\\d\\d \\(UTC\\)'), ''); |
||