mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-23 15:57:15 +00:00
Retry adding keyboard shortcuts for formatting tools in WikiEditor 2010
Retry I63414a78ce2546125d557cb37ccb37ea16a15fe1: adds shortcuts for bold, italic, subscript, superscript and nowiki options, and the link insertion tool in WikiEditor. The hotkeys match the ones used in VisualEditor and NWE 2017. jQuery event.which is used instead of event.code or event.key for compatibility with alternative keyboard layouts and non-English keyboards. Bug: T62928 Change-Id: I18db5b6c53000457524573a9ae06939e8df0dc4f
This commit is contained in:
parent
718297c26f
commit
5413262fee
|
@ -246,6 +246,7 @@
|
|||
],
|
||||
"dependencies": [
|
||||
"mediawiki.cookie",
|
||||
"jquery.client",
|
||||
"jquery.textSelection",
|
||||
"jquery.ui",
|
||||
"mediawiki.api",
|
||||
|
|
|
@ -42,7 +42,8 @@ module.exports = {
|
|||
action: {
|
||||
type: 'dialog',
|
||||
module: 'insert-link'
|
||||
}
|
||||
},
|
||||
hotkey: 75 // K
|
||||
},
|
||||
file: {
|
||||
label: mw.msg( 'wikieditor-toolbar-tool-file' ),
|
||||
|
|
|
@ -45,7 +45,8 @@ toolbarConfig = {
|
|||
peri: mw.msg( 'wikieditor-toolbar-tool-bold-example' ),
|
||||
post: "'''"
|
||||
}
|
||||
}
|
||||
},
|
||||
hotkey: 66 // B
|
||||
},
|
||||
italic: {
|
||||
section: 'main',
|
||||
|
@ -61,7 +62,8 @@ toolbarConfig = {
|
|||
peri: mw.msg( 'wikieditor-toolbar-tool-italic-example' ),
|
||||
post: "''"
|
||||
}
|
||||
}
|
||||
},
|
||||
hotkey: 73 // I
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -206,7 +208,8 @@ toolbarConfig = {
|
|||
peri: mw.msg( 'wikieditor-toolbar-tool-nowiki-example' ),
|
||||
post: '</nowiki>'
|
||||
}
|
||||
}
|
||||
},
|
||||
hotkey: 220 // Backslash (\)
|
||||
},
|
||||
newline: {
|
||||
label: mw.msg( 'wikieditor-toolbar-tool-newline' ),
|
||||
|
@ -260,7 +263,8 @@ toolbarConfig = {
|
|||
peri: mw.msg( 'wikieditor-toolbar-tool-superscript-example' ),
|
||||
post: '</sup>'
|
||||
}
|
||||
}
|
||||
},
|
||||
hotkey: 190 // Period (.)
|
||||
},
|
||||
subscript: {
|
||||
label: mw.msg( 'wikieditor-toolbar-tool-subscript' ),
|
||||
|
@ -273,7 +277,8 @@ toolbarConfig = {
|
|||
peri: mw.msg( 'wikieditor-toolbar-tool-subscript-example' ),
|
||||
post: '</sub>'
|
||||
}
|
||||
}
|
||||
},
|
||||
hotkey: 188 // Comma (,)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -359,6 +359,9 @@ var toolbarModule = {
|
|||
}
|
||||
} );
|
||||
}
|
||||
if ( 'hotkey' in tool ) {
|
||||
toolbarModule.fn.ctrlShortcuts[ tool.hotkey ] = tool;
|
||||
}
|
||||
}
|
||||
return $button;
|
||||
case 'select':
|
||||
|
@ -786,6 +789,23 @@ var toolbarModule = {
|
|||
// Use hook for attaching new toolbar tools to avoid race conditions
|
||||
mw.hook( 'wikiEditor.toolbarReady' ).fire( context.$textarea );
|
||||
} );
|
||||
toolbarModule.fn.setupShortcuts( context );
|
||||
},
|
||||
ctrlShortcuts: {},
|
||||
setupShortcuts: function ( context ) {
|
||||
var platform = $.client.profile().platform;
|
||||
var platformModifier = platform === 'mac' ? 'metaKey' : 'ctrlKey';
|
||||
var otherModifier = platform === 'mac' ? 'ctrlKey' : 'metaKey';
|
||||
|
||||
context.$textarea.on( 'keydown', function ( e ) {
|
||||
// Check if the primary modifier key is pressed and that others aren't
|
||||
var target = e[ platformModifier ] && !e[ otherModifier ] && !e.altKey && !e.shiftKey &&
|
||||
toolbarModule.fn.ctrlShortcuts[ e.which ];
|
||||
if ( target ) {
|
||||
e.preventDefault();
|
||||
toolbarModule.fn.doAction( context, target.action );
|
||||
}
|
||||
} );
|
||||
},
|
||||
handleKeyDown: function ( $element, event, $parent ) {
|
||||
var $currentItem = $element.find( '.wikiEditor-character-highlighted' ),
|
||||
|
|
Loading…
Reference in a new issue