| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ce.MWWikitextSurface = function VeCeMwWikitextSurface() { |
| 19 |
|
| 20 |
ve.ce.MWWikitextSurface.super.apply( this, arguments ); |
| 21 |
|
| 22 |
this.pasteTargetInput = new OO.ui.MultilineTextInputWidget(); |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.inheritClass( ve.ce.MWWikitextSurface, ve.ce.Surface ); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
ve.ce.MWWikitextSurface.prototype.onCopy = function ( e ) { |
| 33 |
const clipboardData = e.originalEvent.clipboardData, |
| 34 |
text = this.getModel().getFragment().getText( true ).replace( /\n\n/g, '\n' ); |
| 35 |
|
| 36 |
if ( !text ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
if ( clipboardData ) { |
| 41 |
|
| 42 |
e.preventDefault(); |
| 43 |
clipboardData.setData( 'text/plain', text ); |
| 44 |
|
| 45 |
if ( ve.isClipboardDataFormatsSupported( e, true ) ) { |
| 46 |
const slice = this.model.documentModel.shallowCloneFromSelection( this.getModel().getSelection() ); |
| 47 |
this.clipboardIndex++; |
| 48 |
const clipboardKey = this.clipboardId + '-' + this.clipboardIndex; |
| 49 |
this.clipboard = { slice: slice, hash: null }; |
| 50 |
|
| 51 |
slice.data.cloneElements( true ); |
| 52 |
clipboardData.setData( 'text/xcustom', clipboardKey ); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
clipboardData.setData( 'text/x-wiki', text ); |
| 58 |
} |
| 59 |
} else { |
| 60 |
const originalSelection = new ve.SelectionState( this.nativeSelection ); |
| 61 |
|
| 62 |
|
| 63 |
const scrollTop = this.surface.$scrollContainer.scrollTop(); |
| 64 |
|
| 65 |
|
| 66 |
this.surfaceObserver.disable(); |
| 67 |
this.$pasteTarget.empty().append( this.pasteTargetInput.$element ); |
| 68 |
this.pasteTargetInput.setValue( text ).select(); |
| 69 |
|
| 70 |
|
| 71 |
this.surface.$scrollContainer.scrollTop( scrollTop ); |
| 72 |
|
| 73 |
|
| 74 |
setTimeout( () => { |
| 75 |
|
| 76 |
this.$attachedRootNode[ 0 ].focus(); |
| 77 |
this.showSelectionState( originalSelection ); |
| 78 |
|
| 79 |
this.surface.$scrollContainer.scrollTop( scrollTop ); |
| 80 |
this.surfaceObserver.clear(); |
| 81 |
this.surfaceObserver.enable(); |
| 82 |
|
| 83 |
this.pasteTargetInput.$element.detach(); |
| 84 |
} ); |
| 85 |
} |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
ve.ce.MWWikitextSurface.prototype.afterPasteInsertExternalData = function ( targetFragment, pastedDocumentModel, contextRange ) { |
| 92 |
const wasSpecial = this.pasteSpecial, |
| 93 |
|
| 94 |
|
| 95 |
wasPlain = wasSpecial || pastedDocumentModel.data.isPlainText( contextRange, true, undefined, true ); |
| 96 |
|
| 97 |
const plainPastedDocumentModel = pastedDocumentModel.shallowCloneFromRange( contextRange ); |
| 98 |
plainPastedDocumentModel.data.sanitize( { plainText: true, keepEmptyContentBranches: true } ); |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
const plainContextRange = new ve.Range( plainPastedDocumentModel.getDocumentRange().from + 1, plainPastedDocumentModel.getDocumentRange().to - 1 ); |
| 110 |
this.pasteSpecial = true; |
| 111 |
|
| 112 |
|
| 113 |
const promise = ve.ce.MWWikitextSurface.super.prototype.afterPasteInsertExternalData.call( this, targetFragment, plainPastedDocumentModel, plainContextRange ); |
| 114 |
if ( !wasPlain ) { |
| 115 |
promise.then( () => { |
| 116 |
|
| 117 |
|
| 118 |
setTimeout( () => { |
| 119 |
const surface = this.getSurface(), |
| 120 |
context = surface.getContext(); |
| 121 |
|
| 122 |
if ( context.isMobile() ) { |
| 123 |
surface.getView().deactivate(); |
| 124 |
} |
| 125 |
context.addPersistentSource( { |
| 126 |
embeddable: false, |
| 127 |
name: 'wikitextPaste', |
| 128 |
data: { |
| 129 |
doc: pastedDocumentModel, |
| 130 |
contextRange: contextRange, |
| 131 |
fragment: targetFragment |
| 132 |
} |
| 133 |
} ); |
| 134 |
surface.getModel().once( 'select', () => { |
| 135 |
context.removePersistentSource( 'wikitextPaste' ); |
| 136 |
} ); |
| 137 |
} ); |
| 138 |
} ); |
| 139 |
} |
| 140 |
return promise; |
| 141 |
}; |