User:Bosco/Unsigned helper.js: Difference between revisions
From Test Wiki
Content deleted Content added
LazyRevisionIdsLoader#loadIntervalsRecursive: restore the stopper when .batchcomplete==true is returned from API, but we haven't found `targetIndex` yet |
doAddUnsignedTemplate: in Special:Diff/1238811453 function `applySearcherResult` stopped using variable `pos` => stop using the approach with `getCaretPosition` completely, just use the command `getSelection` |
||
| Line 497: | Line 497: | ||
async function doAddUnsignedTemplate() { |
async function doAddUnsignedTemplate() { |
||
// for CodeMirror reference, see https://en.wikipedia.org/wiki/MediaWiki:Gadget-charinsert-core.js#L-251--L-258 |
|||
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 |
|||
let |
let txt = $(wikitextEditor).textSelection('getSelection'); |
||
let txt; |
|||
| ⚫ | |||
if (pos[0] != pos[1]) { |
|||
txt = txt.replace(/[\s\S]*\n=+.*=+\s*\n/, ''); |
|||
pos = pos[1]; |
|||
} else { |
|||
pos = pos[1]; |
|||
if (pos <= 0) { |
|||
pos = wikitextEditor.value.length; |
|||
| ⚫ | |||
txt = wikitextEditor.value.substr(0, pos); |
|||
| ⚫ | |||
txt = txt.replace(/[\s\S]*\n=+.*=+\s*\n/, ''); |
|||
} |
|||
txt = txt.replace(/^\s+|\s+$/g, ''); |
txt = txt.replace(/^\s+|\s+$/g, ''); |
||
| Line 612: | Line 603: | ||
function searchFromIndex(index) { |
function searchFromIndex(index) { |
||
if (txt == undefined || txt == '') { |
|||
mainDialog.html(formatErrorSpan("Please select an unsigned message")); |
|||
return; |
|||
| ⚫ | |||
searcher.findRevisionWhenTextAdded(txt, index).then(searcherResult => { |
searcher.findRevisionWhenTextAdded(txt, index).then(searcherResult => { |
||
if (!mainDialog.dialog('isOpen')) { |
if (!mainDialog.dialog('isOpen')) { |
||