| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.ui.FormatAction = function VeUiFormatAction() { |
| 18 |
|
| 19 |
ve.ui.FormatAction.super.apply( this, arguments ); |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ui.FormatAction, ve.ui.Action ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
ve.ui.FormatAction.static.name = 'format'; |
| 29 |
|
| 30 |
ve.ui.FormatAction.static.methods = [ 'convert' ]; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
ve.ui.FormatAction.prototype.convert = function ( type, attributes ) { |
| 46 |
const surfaceModel = this.surface.getModel(), |
| 47 |
fragment = surfaceModel.getFragment(), |
| 48 |
fragmentSelection = fragment.getSelection(); |
| 49 |
|
| 50 |
if ( !( fragmentSelection instanceof ve.dm.LinearSelection ) ) { |
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
const fragments = []; |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
fragment.getSelectedLeafNodes().forEach( ( node ) => { |
| 59 |
const contentBranch = node.isContent() ? node.getParent() : node; |
| 60 |
|
| 61 |
fragments.push( surfaceModel.getLinearFragment( contentBranch.getOuterRange(), true ) ); |
| 62 |
} ); |
| 63 |
|
| 64 |
fragments.forEach( ( f ) => { |
| 65 |
f.isolateAndUnwrap( type ); |
| 66 |
} ); |
| 67 |
|
| 68 |
fragment.convertNodes( type, attributes ); |
| 69 |
if ( fragmentSelection.isCollapsed() ) { |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
surfaceModel.setSelection( fragmentSelection ); |
| 77 |
} |
| 78 |
this.surface.getView().focus(); |
| 79 |
|
| 80 |
ve.track( 'activity.format', { action: type + ( attributes && attributes.level ? ( '-' + attributes.level ) : '' ) } ); |
| 81 |
|
| 82 |
return true; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
ve.ui.actionFactory.register( ve.ui.FormatAction ); |