User:Bosco/Unsigned helper.js: Difference between revisions

From Test Wiki
Content deleted Content added
doAddUnsignedTemplate: update code comments about CodeMirror support
searchFromIndex: improve error message about incorrect selection
Line 509: Line 509:
*/
*/
let txt = $(wikitextEditor).textSelection('getSelection');
let txt = $(wikitextEditor).textSelection('getSelection');
debug(`doAddUnsignedTemplate: getSelection: '${txt}'`);
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\\)'), '');
txt = txt.replace(/[\s\S]*\n=+.*=+\s*\n/, '');
txt = txt.replace(/[\s\S]*\n=+.*=+\s*\n/, '');
txt = txt.replace(/^\s+|\s+$/g, '');
txt = txt.replace(/^\s+|\s+$/g, '');
debug(`doAddUnsignedTemplate: getSelection filtered: '${txt}'`);


// TODO maybe migrate to https://www.mediawiki.org/wiki/OOUI/Windows/Message_Dialogs
// TODO maybe migrate to https://www.mediawiki.org/wiki/OOUI/Windows/Message_Dialogs
Line 611: Line 613:
function searchFromIndex(index) {
function searchFromIndex(index) {
if (txt == undefined || txt == '') {
if (txt == undefined || txt == '') {
mainDialog.html(formatErrorSpan("Please select an unsigned message"));
mainDialog.html(formatErrorSpan("Please select an unsigned message.") +
" Selected: <code>" + text + "</code>");
return;
return;
}
}