Esanders has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/405752 )
Change subject: Implement simple methods from $.textSelection API
......................................................................
Implement simple methods from $.textSelection API
This should make it easier for some gadgets to work
with NWE.
Change-Id: Ic60440f345b8226fb5acaeb966e25eb003ad7866
---
M modules/ve-mw/ui/ve.ui.MWWikitextSurface.js
1 file changed, 47 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/52/405752/1
diff --git a/modules/ve-mw/ui/ve.ui.MWWikitextSurface.js
b/modules/ve-mw/ui/ve.ui.MWWikitextSurface.js
index 3d6ce6a..d826759 100644
--- a/modules/ve-mw/ui/ve.ui.MWWikitextSurface.js
+++ b/modules/ve-mw/ui/ve.ui.MWWikitextSurface.js
@@ -16,6 +16,8 @@
* @param {Object} [config] Configuration options
*/
ve.ui.MWWikitextSurface = function VeUiMWWikitextSurface() {
+ var surface = this;
+
// Parent constructor
ve.ui.MWWikitextSurface.super.apply( this, arguments );
@@ -27,6 +29,42 @@
this.$element.addClass( 've-ui-mwWikitextSurface' );
this.getView().$element.addClass( 'mw-editfont-' + mw.user.options.get(
'editfont' ) );
this.$placeholder.addClass( 'mw-editfont-' + mw.user.options.get(
'editfont' ) );
+ this.$textbox = $( '#wpTextbox1' );
+
+ if ( !this.$textbox.length ) {
+ this.$textbox = $( '<textarea>' )
+ .attr( 'id', 'wpTextbox1' )
+ .addClass( 've-dummyTextbox oo-ui-element-hidden' );
+ // Append a dummy textbox to the surface, so it gets destroyed
with it
+ this.$element.append( this.$textbox );
+ }
+
+ // Backwards support for the textSelection API
+ this.$textbox.textSelection( 'register', {
+ getContents: function () {
+ return surface.getDom();
+ },
+ setContents: function ( content ) {
+ surface.getModel().getLinearFragment( new ve.Range( 0,
surface.getModel().getDocument().data.getLength() ), true )
+ .insertContent( content );
+ },
+ getSelection: function () {
+ var range =
surface.getModel().getSelection().getCoveringRange();
+ if ( !range ) {
+ return '';
+ }
+ return
surface.getModel().getDocument().data.getSourceText( range );
+ },
+ getCaretPosition: function () {
+ // TODO
+ },
+ encapsulateSelection: function () {
+ // TODO
+ },
+ scrollToCaretPosition: function () {
+ surface.scrollCursorIntoView();
+ }
+ } );
};
/* Inheritance */
@@ -48,3 +86,12 @@
ve.ui.MWWikitextSurface.prototype.createView = function ( model ) {
return new ve.ce.MWWikitextSurface( model, this );
};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWWikitextSurface.prototype.destroy = function () {
+ this.$textbox.textSelection( 'unregister' );
+ // Parent method
+ return ve.ui.MWWikitextSurface.super.prototype.destroy.apply( this,
arguments );
+};
--
To view, visit https://gerrit.wikimedia.org/r/405752
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic60440f345b8226fb5acaeb966e25eb003ad7866
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits