Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbth committed Mar 5, 2021
2 parents 10b0b12 + c9daffd commit c816b67
Show file tree
Hide file tree
Showing 23 changed files with 394 additions and 393 deletions.
1 change: 1 addition & 0 deletions buildConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function getStrings() {
return lang !== 'en';
})
.map((lang) => mw.loader.getScript('https://commons.wikimedia.org/w/index.php?title=User:Jack_who_built_the_house/convenientDiscussions-i18n/' + lang + '.js&action=raw&ctype=text/javascript'));
// We assume it's OK to fall back to English if the translation is unavailable for any reason.
return Promise.all(requests).catch(function () {});
}
Expand Down
13 changes: 8 additions & 5 deletions src/js/defaultConfig.js → config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ export default {
/**
* Pages where the script should run. If `[]`, all pages in the {@link
* module:defaultConfig.customTalkNamespaces} namespaces will pass. If you add at least one value,
* {@link module:defaultConfig.customTalkNamespaces} will not be used. In this case, you may
* specify entire namespaces in this value, e.g., /^Wikipedia:/. The blacklist has priority over
* the whitelist.
* {@link module:defaultConfig.customTalkNamespaces} will not be used. You may specify entire
* namespaces in this value, e.g., /^Wikipedia:/. The blacklist has priority over the whitelist.
*
* @type {RegExp[]}
* @default []
Expand Down Expand Up @@ -314,7 +313,7 @@ export default {
* https://en.wikipedia.org/wiki/Template:Smalldiv}. Used when the whole comment is wrapped in
* `<small></small>` (with some exceptions when that could break the layout).
*
* @type {?string}
* @type {string[]}
* @default []
*/
smallDivTemplates: [],
Expand Down Expand Up @@ -630,7 +629,11 @@ export default {
* module:defaultConfig.customBadCommentBeginnings}.
*
* The second parameter is a "context", i.e., a collection of classes, functions, and other
* properties that perform the tasks we need in the current context (window or worker).
* properties that perform the tasks we need in the current context (window or worker). Examples
* are the name of the child elements property (the worker context uses `childElements` instead of
* `children`) and the document element. Contexts are predefined in the script like {@link
* https://github.com/jwbth/convenient-discussions/blob/c6b177bce7588949b46e0e8d52c5e0f4e76cb3ee/src/js/processPage.js#L885}
* this.
*
* @type {?Function}
* @kind function
Expand Down
6 changes: 3 additions & 3 deletions config/w-ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default {
/^Википедия:К объединению\//,
/^Википедия:К оценке источников/,
/^Википедия:К переименованию\//,
/^Википедия:К посредничеству\//,
/^Википедия:К посредничеству/,
/^Википедия:К разделению\//,
/^Википедия:К удалению\//,
/^Википедия:К улучшению\//,
Expand Down Expand Up @@ -406,7 +406,7 @@ mw.hook('convenientDiscussions.pageReady').add(function () {
mw.notify($text, { autoHide: false } );
mw.cookie.set('cd-hlmConflict', '1', {
path: '/',
expires: cd.g.SECONDS_IN_A_DAY * 30,
expires: cd.g.SECONDS_IN_DAY * 30,
});
}

Expand All @@ -415,7 +415,7 @@ mw.hook('convenientDiscussions.pageReady').add(function () {
mw.notify($text, { autoHide: false });
mw.cookie.set('cd-ptaConflict', '1', {
path: '/',
expires: cd.g.SECONDS_IN_A_DAY * 30,
expires: cd.g.SECONDS_IN_DAY * 30,
});
}

Expand Down
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"navpanel-newcomments-names": "$1 → $2",
"navpanel-newcomments-unknowndate": "unknown date",
"navpanel-newcomments-refresh": "Click to refresh the page",
"navpanel-markasread": "Hold Ctrl to mark all comments as read",
"navpanel-markasread": "Hold Ctrl to mark all currently visible comments as read",

"toc-more": "…$1 more",
"toc-watched": "You watch this section",
Expand Down
2 changes: 1 addition & 1 deletion src/js/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ export default class Autocomplete {
config.default.sort((item1, item2) => {
const s1 = typeof item1 === 'string' ? item1 : item1[0];
const s2 = typeof item2 === 'string' ? item2 : item2[0];
return s1 < s2;
return s1 > s2;
});
break;
}
Expand Down
15 changes: 11 additions & 4 deletions src/js/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function cleanUpThanks(data) {
Object.keys(newData).forEach((key) => {
if (
!newData[key].thankUnixTime ||
newData[key].thankUnixTime < Date.now() - 60 * cd.g.SECONDS_IN_A_DAY * 1000
newData[key].thankUnixTime < Date.now() - 60 * cd.g.SECONDS_IN_DAY * 1000
) {
delete newData[key];
}
Expand Down Expand Up @@ -531,6 +531,8 @@ export default class Comment extends CommentSkeleton {
options.update = true;
}

// FIXME: it is possible that a floating element that is on above in the DOM is below spacially.
// In this case, rectTop and rectBottom will be swapped.
options.rectTop = this.highlightables[0].getBoundingClientRect();
options.rectBottom = this.elements.length === 1 ?
options.rectTop :
Expand Down Expand Up @@ -1115,8 +1117,8 @@ export default class Comment extends CommentSkeleton {
}

// Search for the edit in the range of 2 minutes before to 2 minutes later.
const rvstart = new Date(this.date.getTime() - cd.g.MILLISECONDS_IN_A_MINUTE * 2).toISOString();
const rvend = new Date(this.date.getTime() + cd.g.MILLISECONDS_IN_A_MINUTE * 2).toISOString();
const rvstart = new Date(this.date.getTime() - cd.g.MILLISECONDS_IN_MINUTE * 2).toISOString();
const rvend = new Date(this.date.getTime() + cd.g.MILLISECONDS_IN_MINUTE * 2).toISOString();
const revisions = await this.getSourcePage().getArchivedPage().getRevisions({
rvprop: ['ids', 'comment', 'parsedcomment', 'timestamp'],
rvdir: 'newer',
Expand Down Expand Up @@ -1511,6 +1513,7 @@ export default class Comment extends CommentSkeleton {
.replace(/^(?![:*# ]).*<br[ \n]*\/?>.*$/gmi, (s) => (
s.replace(/<br[ \n]*\/?>\n? */gi, () => '\n')
))

// Remove indentation characters
.replace(/\n([:*#]*[:*])([ \t]*)/g, (s, chars, spacing) => {
const newChars = chars.slice(indentationChars.length);
Expand All @@ -1536,6 +1539,10 @@ export default class Comment extends CommentSkeleton {
text = text.replace(lineRegexp, (s) => s.replace(regexp, '\n\n'));
}

if (this.level !== 0) {
text = text.replace(/\n\n+/g, '\n\n');
}

return text.trim();
}

Expand Down Expand Up @@ -1928,7 +1935,7 @@ export default class Comment extends CommentSkeleton {
start: /^<small>/,
end: /<\/small>[ \u00A0\t]*$/,
}];
if (cd.config.smallDivTemplates?.[0]) {
if (cd.config.smallDivTemplates.length) {
smallWrappers.push({
start: new RegExp(
`^(?:\\{\\{(${cd.config.smallDivTemplates.join('|')})\\|(?: *1 *= *|(?![^{]*=)))`,
Expand Down
58 changes: 25 additions & 33 deletions src/js/CommentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,20 +659,18 @@ export default class CommentForm {
.toLowerCase();
}

this.editingSectionOpeningComment = this.mode === 'edit' && this.target.isOpeningSection;
this.isSectionOpeningCommentEdited = this.mode === 'edit' && this.target.isOpeningSection;

/**
* The main form element.
*
* @type {JQuery}
*/
this.$element = $('<div>')
.addClass('cd-commentForm')
.addClass(`cd-commentForm-${this.mode}`);
this.$element = $('<div>').addClass(`cd-commentForm cd-commentForm-${this.mode}`);
if (this.containerListType === 'ol') {
this.$element.addClass('cd-commentForm-inNumberedList');
}
if (this.editingSectionOpeningComment) {
if (this.isSectionOpeningCommentEdited) {
this.$element.addClass('cd-commentForm-sectionOpeningComment');
}
if (this.mode === 'addSubsection') {
Expand All @@ -693,7 +691,7 @@ export default class CommentForm {

if (
(['addSection', 'addSubsection'].includes(this.mode) && !this.preloadConfig?.noHeadline) ||
this.editingSectionOpeningComment
this.isSectionOpeningCommentEdited
) {
if (this.mode === 'addSubsection') {
this.headlineInputPurpose = cd.s('cf-headline-subsection', this.targetSection.headline);
Expand Down Expand Up @@ -2323,21 +2321,24 @@ export default class CommentForm {

// Add the headline
if (this.headlineInput) {
let level;
if (this.mode === 'addSection') {
level = 2;
} else if (this.mode === 'addSubsection') {
level = this.target.level + 1;
} else {
level = this.target.inCode.headingLevel;
}
const equalSigns = '='.repeat(level);
const headline = this.headlineInput.getValue().trim();
if (headline) {
let level;
if (this.mode === 'addSection') {
level = 2;
} else if (this.mode === 'addSubsection') {
level = this.target.level + 1;
} else {
level = this.target.inCode.headingLevel;
}
const equalSigns = '='.repeat(level);

if (this.editingSectionOpeningComment && /^\n/.test(this.target.inCode.code)) {
// To have pretty diffs.
code = '\n' + code;
if (this.isSectionOpeningCommentEdited && /^\n/.test(this.target.inCode.code)) {
// To have pretty diffs.
code = '\n' + code;
}
code = `${equalSigns} ${headline} ${equalSigns}\n${code}`;
}
code = `${equalSigns} ${this.headlineInput.getValue().trim()} ${equalSigns}\n${code}`;
}

// Add the signature
Expand All @@ -2364,7 +2365,7 @@ export default class CommentForm {
} else {
before = '';
}
if (cd.config.smallDivTemplates?.[0] && !/^[:*#;]/m.test(code)) {
if (cd.config.smallDivTemplates.length && !/^[:*#;]/m.test(code)) {
const adjustedCode = code.replace(/\|/g, '{{!}}') + signature;
code = `{{${cd.config.smallDivTemplates[0]}|1=${adjustedCode}}}`;
} else {
Expand Down Expand Up @@ -2732,11 +2733,7 @@ export default class CommentForm {
.html(html)
.prepend($label)
.cdAddCloseButton();
if (imitateList) {
this.$previewArea.addClass('cd-previewArea-indentedComment');
} else {
this.$previewArea.removeClass('cd-previewArea-indentedComment');
}
this.$previewArea.toggleClass('cd-previewArea-indentedComment', imitateList);

/**
* A comment preview has been rendered.
Expand Down Expand Up @@ -3063,7 +3060,7 @@ export default class CommentForm {
if (this.watchSectionCheckbox) {
if (this.watchSectionCheckbox.isSelected()) {
const isHeadlineAltered = (
this.editingSectionOpeningComment &&
this.isSectionOpeningCommentEdited &&
this.headlineInput.getValue() !== this.originalHeadline
);
if (this.mode === 'addSection' || this.mode === 'addSubsection' || isHeadlineAltered) {
Expand Down Expand Up @@ -3428,10 +3425,11 @@ export default class CommentForm {
* selection is empty.
*/
quote(allowEmptySelection = true) {
const selection = isInputFocused() ?
let selection = isInputFocused() ?
document.activeElement.value
.substring(document.activeElement.selectionStart, document.activeElement.selectionEnd) :
window.getSelection().toString();
selection = selection.trim();

// With just "Q" pressed, empty selection doesn't count.
if (selection || allowEmptySelection) {
Expand All @@ -3452,7 +3450,6 @@ export default class CommentForm {
peri: cd.s('cf-quote-placeholder'),
post: cd.config.quoteFormatting[1],
selection,
trim: true,
ownline: true,
});
}
Expand All @@ -3470,7 +3467,6 @@ export default class CommentForm {
* @param {string} [options.replace=false] If there is a selection, replace it with pre, peri,
* post instead of leaving it alone.
* @param {string} [options.selection] The selected text. Use if it is out of the input.
* @param {boolean} [options.trim=false] Trim the selection.
* @param {boolean} [options.ownline=false] Put the inserted text on a line of its own.
*/
encapsulateSelection({
Expand All @@ -3479,7 +3475,6 @@ export default class CommentForm {
post = '',
selection,
replace = false,
trim = false,
ownline = false,
}) {
const range = this.commentInput.getRange();
Expand All @@ -3503,9 +3498,6 @@ export default class CommentForm {
} else {
selection = selection || '';
}
if (trim) {
selection = selection.trim();
}

// Wrap text moving the leading and trailing spaces to the sides of the resulting text.
const [leadingSpace] = selection.match(/^ */);
Expand Down
Loading

0 comments on commit c816b67

Please sign in to comment.