Merge "Add user mention tool"

This commit is contained in:
jenkins-bot 2020-06-15 19:46:19 +00:00 committed by Gerrit Code Review
commit c678fffd49
7 changed files with 43 additions and 6 deletions

View file

@ -97,6 +97,7 @@
"discussiontools-replywidget-anon-warning",
"discussiontools-replywidget-cancel",
"discussiontools-replywidget-feedback",
"discussiontools-replywidget-mention-tool-title",
"discussiontools-replywidget-mode-source",
"discussiontools-replywidget-mode-visual",
"discussiontools-replywidget-placeholder-reply",
@ -131,7 +132,8 @@
"dt.ui.ReplyWidgetVisual.js",
"CommentTarget.js",
"CommentTargetWidget.js",
"dt.ui.UsernameCompletion.js"
"dt.ui.UsernameCompletionAction.js",
"dt.ui.UsernameCompletionTool.js"
],
"styles": [
"CommentTargetWidget.less"

View file

@ -15,6 +15,7 @@
"discussiontools-replywidget-feedback": "Share feedback about this feature",
"discussiontools-replywidget-feedback-link": "https:\/\/mediawiki.org\/wiki\/Talk:Talk_pages_project\/replying",
"discussiontools-replywidget-loading": "Loading…",
"discussiontools-replywidget-mention-tool-title": "Mention a user",
"discussiontools-replywidget-mode-source": "Source",
"discussiontools-replywidget-mode-visual": "Visual",
"discussiontools-replywidget-placeholder-reply": "Reply to {{BIDI:$1}}",

View file

@ -20,6 +20,7 @@
"discussiontools-replywidget-feedback": "Label for link to share feedback about the reply widget",
"discussiontools-replywidget-feedback-link": "{{optional|Link to a page where users can share feedback about the reply widget. Defaults to a page on MediaWiki.org.}}",
"discussiontools-replywidget-loading": "Message shown while the reply widget is loading",
"discussiontools-replywidget-mention-tool-title": "Title text for the user mention tool.",
"discussiontools-replywidget-mode-source": "Label for source mode (wikitext) editor",
"discussiontools-replywidget-mode-visual": "Label for visual mode editor",
"discussiontools-replywidget-placeholder-reply": "Placeholder describing who is being replied to.\n\nParameters:\n* $1 username of the person who wrote the previous comment",

View file

@ -34,8 +34,11 @@ CommentTarget.static.toolbarGroups = [
{
name: 'link',
include: [ 'link' ]
},
{
name: 'other',
include: [ 'usernameCompletion' ]
}
// Mention?
];
CommentTarget.static.importRules = ve.copy( CommentTarget.static.importRules );

View file

@ -1,6 +1,7 @@
var CommentTargetWidget = require( './CommentTargetWidget.js' );
require( './dt.ui.UsernameCompletion.js' );
require( './dt.ui.UsernameCompletionAction.js' );
require( './dt.ui.UsernameCompletionTool.js' );
/**
* DiscussionTools ReplyWidgetVisual class

View file

@ -42,6 +42,9 @@ OO.inheritClass( MWUsernameCompletionAction, ve.ui.CompletionAction );
MWUsernameCompletionAction.static.name = 'mwUsernameCompletion';
MWUsernameCompletionAction.static.methods = OO.copy( MWUsernameCompletionAction.static.methods );
MWUsernameCompletionAction.static.methods.push( 'insertAndOpen' );
/* Methods */
MWUsernameCompletionAction.prototype.open = function () {
@ -63,6 +66,12 @@ MWUsernameCompletionAction.prototype.open = function () {
return MWUsernameCompletionAction.super.prototype.open.apply( this, arguments );
};
MWUsernameCompletionAction.prototype.insertAndOpen = function () {
this.surface.getModel().getFragment().insertContent( '@' ).collapseToEnd().select();
// Skip precedingCharacter check in #open as we know the user intention
return MWUsernameCompletionAction.super.prototype.open.apply( this, arguments );
};
MWUsernameCompletionAction.prototype.getSuggestions = function ( input ) {
var capitalizedInput = input.length > 0 && input[ 0 ].toUpperCase() + input.slice( 1 ),
action = this;
@ -139,15 +148,21 @@ ve.ui.actionFactory.register( MWUsernameCompletionAction );
ve.ui.commandRegistry.register(
new ve.ui.Command(
'showMWUsernameCompletions', MWUsernameCompletionAction.static.name, 'open',
'openMWUsernameCompletions', MWUsernameCompletionAction.static.name, 'open',
{ supportedSelections: [ 'linear' ] }
)
);
ve.ui.commandRegistry.register(
new ve.ui.Command(
'insertAndOpenMWUsernameCompletions', MWUsernameCompletionAction.static.name, 'insertAndOpen',
{ supportedSelections: [ 'linear' ] }
)
);
ve.ui.sequenceRegistry.register(
new ve.ui.Sequence( 'autocompleteMWUsernames', 'showMWUsernameCompletions', '@', 0, false, false, true )
new ve.ui.Sequence( 'autocompleteMWUsernames', 'openMWUsernameCompletions', '@', 0, false, false, true )
);
ve.ui.wikitextSequenceRegistry.register(
new ve.ui.Sequence( 'autocompleteMWUsernamesWikitext', 'showMWUsernameCompletions', '@', 0, false, false, true )
new ve.ui.Sequence( 'autocompleteMWUsernamesWikitext', 'openMWUsernameCompletions', '@', 0, false, false, true )
);
module.exports = MWUsernameCompletionAction;

View file

@ -0,0 +1,14 @@
function MWUsernameCompletionTool() {
// Parent constructor
MWUsernameCompletionTool.super.apply( this, arguments );
}
OO.inheritClass( MWUsernameCompletionTool, ve.ui.Tool );
// Static
MWUsernameCompletionTool.static.commandName = 'insertAndOpenMWUsernameCompletions';
MWUsernameCompletionTool.static.name = 'usernameCompletion';
MWUsernameCompletionTool.static.icon = 'userAvatar'; // TODO: should be 'userAdd';
MWUsernameCompletionTool.static.title = OO.ui.deferMsg( 'discussiontools-replywidget-mention-tool-title' );
ve.ui.toolFactory.register( MWUsernameCompletionTool );