mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-30 11:05:51 +00:00
Keyboard shortcuts for formatting tools in WikiEditor 2010
Add 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. Bug: T62928 Change-Id: I63414a78ce2546125d557cb37ccb37ea16a15fe1
This commit is contained in:
parent
bf44c2eb3a
commit
250a2a3ff3
|
@ -246,6 +246,7 @@
|
||||||
],
|
],
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"mediawiki.cookie",
|
"mediawiki.cookie",
|
||||||
|
"jquery.client",
|
||||||
"jquery.textSelection",
|
"jquery.textSelection",
|
||||||
"jquery.ui",
|
"jquery.ui",
|
||||||
"mediawiki.api",
|
"mediawiki.api",
|
||||||
|
|
|
@ -42,7 +42,8 @@ module.exports = {
|
||||||
action: {
|
action: {
|
||||||
type: 'dialog',
|
type: 'dialog',
|
||||||
module: 'insert-link'
|
module: 'insert-link'
|
||||||
}
|
},
|
||||||
|
hotkey: 'KeyK'
|
||||||
},
|
},
|
||||||
file: {
|
file: {
|
||||||
label: mw.msg( 'wikieditor-toolbar-tool-file' ),
|
label: mw.msg( 'wikieditor-toolbar-tool-file' ),
|
||||||
|
|
|
@ -45,7 +45,8 @@ toolbarConfig = {
|
||||||
peri: mw.msg( 'wikieditor-toolbar-tool-bold-example' ),
|
peri: mw.msg( 'wikieditor-toolbar-tool-bold-example' ),
|
||||||
post: "'''"
|
post: "'''"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
hotkey: 'KeyB'
|
||||||
},
|
},
|
||||||
italic: {
|
italic: {
|
||||||
section: 'main',
|
section: 'main',
|
||||||
|
@ -61,7 +62,8 @@ toolbarConfig = {
|
||||||
peri: mw.msg( 'wikieditor-toolbar-tool-italic-example' ),
|
peri: mw.msg( 'wikieditor-toolbar-tool-italic-example' ),
|
||||||
post: "''"
|
post: "''"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
hotkey: 'KeyI'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -206,7 +208,8 @@ toolbarConfig = {
|
||||||
peri: mw.msg( 'wikieditor-toolbar-tool-nowiki-example' ),
|
peri: mw.msg( 'wikieditor-toolbar-tool-nowiki-example' ),
|
||||||
post: '</nowiki>'
|
post: '</nowiki>'
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
hotkey: 'Backslash'
|
||||||
},
|
},
|
||||||
newline: {
|
newline: {
|
||||||
label: mw.msg( 'wikieditor-toolbar-tool-newline' ),
|
label: mw.msg( 'wikieditor-toolbar-tool-newline' ),
|
||||||
|
@ -260,7 +263,8 @@ toolbarConfig = {
|
||||||
peri: mw.msg( 'wikieditor-toolbar-tool-superscript-example' ),
|
peri: mw.msg( 'wikieditor-toolbar-tool-superscript-example' ),
|
||||||
post: '</sup>'
|
post: '</sup>'
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
hotkey: 'Period'
|
||||||
},
|
},
|
||||||
subscript: {
|
subscript: {
|
||||||
label: mw.msg( 'wikieditor-toolbar-tool-subscript' ),
|
label: mw.msg( 'wikieditor-toolbar-tool-subscript' ),
|
||||||
|
@ -273,7 +277,8 @@ toolbarConfig = {
|
||||||
peri: mw.msg( 'wikieditor-toolbar-tool-subscript-example' ),
|
peri: mw.msg( 'wikieditor-toolbar-tool-subscript-example' ),
|
||||||
post: '</sub>'
|
post: '</sub>'
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
hotkey: 'Comma'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -359,6 +359,9 @@ var toolbarModule = {
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
if ( 'hotkey' in tool ) {
|
||||||
|
toolbarModule.fn.ctrlShortcuts[ tool.hotkey ] = tool;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $button;
|
return $button;
|
||||||
case 'select':
|
case 'select':
|
||||||
|
@ -786,6 +789,21 @@ var toolbarModule = {
|
||||||
// Use hook for attaching new toolbar tools to avoid race conditions
|
// Use hook for attaching new toolbar tools to avoid race conditions
|
||||||
mw.hook( 'wikiEditor.toolbarReady' ).fire( context.$textarea );
|
mw.hook( 'wikiEditor.toolbarReady' ).fire( context.$textarea );
|
||||||
} );
|
} );
|
||||||
|
toolbarModule.fn.setupShortcuts( context );
|
||||||
|
},
|
||||||
|
ctrlShortcuts: {},
|
||||||
|
setupShortcuts: function ( context ) {
|
||||||
|
var platform = $.client.profile().platform;
|
||||||
|
var modifierKey = platform === 'mac' ? 'metaKey' : 'ctrlKey';
|
||||||
|
|
||||||
|
context.$textarea.on( 'keydown', function ( e ) {
|
||||||
|
// Check if modifier key is pressed and hotkey is recognised
|
||||||
|
var target = e[ modifierKey ] && toolbarModule.fn.ctrlShortcuts[ e.code ];
|
||||||
|
if ( target ) {
|
||||||
|
e.preventDefault();
|
||||||
|
toolbarModule.fn.doAction( context, target.action );
|
||||||
|
}
|
||||||
|
} );
|
||||||
},
|
},
|
||||||
handleKeyDown: function ( $element, event, $parent ) {
|
handleKeyDown: function ( $element, event, $parent ) {
|
||||||
var $currentItem = $element.find( '.wikiEditor-character-highlighted' ),
|
var $currentItem = $element.find( '.wikiEditor-character-highlighted' ),
|
||||||
|
|
Loading…
Reference in a new issue