Jsahleen has uploaded a new change for review.
https://gerrit.wikimedia.org/r/161889
Change subject: Selections: Modify translation editor so it maintains its own
selection
......................................................................
Selections: Modify translation editor so it maintains its own selection
Adds class variable to store selection range
Adds on keyup/mouseup event handlers to capture translation selection range
Adds on focus event handler to restore captured selection range
Sets cursor to beginning of selection postMT
Change-Id: I262d66abc7d5f7bc9daeac89e7a34f27b0a0e3d3
---
M modules/translation/ext.cx.translation.js
1 file changed, 29 insertions(+), 1 deletion(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/89/161889/1
diff --git a/modules/translation/ext.cx.translation.js
b/modules/translation/ext.cx.translation.js
index 907af50..646470a 100644
--- a/modules/translation/ext.cx.translation.js
+++ b/modules/translation/ext.cx.translation.js
@@ -21,6 +21,7 @@
this.options = $.extend( true, {}, $.fn.cxTranslation.defaults,
options );
this.$title = null;
this.$content = null;
+ this.$selectionRange = null;
this.init();
}
@@ -124,6 +125,28 @@
segmentId = $segment.data( 'segmentid' );
$( '[data-segmentid="' + segmentId + '"]'
).toggleClass( 'cx-highlight' );
} );
+
+ this.$container.on( 'keyup mouseup', function () {
+ var $container, selection, anchorNode, focusNode;
+
+ $container = $( this );
+ selection = mw.cx.getSelection();
+ if ( selection ) {
+ anchorNode = selection.anchorNode;
+ focusNode = selection.focusNode;
+
+ if ( $.contains( $container[ 0 ], anchorNode )
||
+ $.contains( $container[ 0 ], focusNode
) ) {
+ cxTranslation.selectionRange =
mw.cx.getSelectionRange();
+ }
+ }
+ } );
+
+ this.$container.on( 'focus', function () {
+ if ( cxTranslation.selectionRange ) {
+ mw.cx.setSelectionRange(
cxTranslation.selectionRange );
+ }
+ } );
};
/**
@@ -131,7 +154,7 @@
* @param {jQuery} $section
*/
ContentTranslationEditor.prototype.postProcessMT = function ( $section
) {
- var $sourceSection = $( '#' + $section.data( 'source' ) );
+ var range, $sourceSection = $( '#' + $section.data( 'source' )
);
mw.hook( 'mw.cx.translation.change' ).fire( $section );
mw.hook( 'mw.cx.translation.focus' ).fire( $section );
@@ -150,6 +173,11 @@
$section.cxEditor();
}
+ range = document.createRange();
+ range.setStart( $section[ 0 ].firstChild, 0 );
+ range.collapse( true );
+ mw.cx.setSelectionRange( range );
+
// Search for text that was selected using the mouse.
// Delay it to run every 250 ms so it won't fire all the time
while typing.
$section.on( 'click keyup', $.debounce( 250, function () {
--
To view, visit https://gerrit.wikimedia.org/r/161889
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I262d66abc7d5f7bc9daeac89e7a34f27b0a0e3d3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Jsahleen <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits