mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 14:33:59 +00:00
Merge "Modify rangeChange event to save selection direction. Renamed Selection method to more suitable name. Misc cleanup Patchset 2, whitespace cleanup Patchset 3: Change values used with selection direction to -1 or 1 1 for left to right (normal) -1 for right to left (opposite) Change-Id: If9ecc721ace1c7550903170f92395947f1ccc22c"
This commit is contained in:
commit
8ce68e1ac8
|
@ -18,6 +18,7 @@ ve.ce.Surface = function( $container, model ) {
|
|||
// Properties
|
||||
this.model = model;
|
||||
this.currentSelection = new ve.Range();
|
||||
this.selectionDirection = null;
|
||||
this.documentView = new ve.ce.DocumentNode( this.model.getDocument(), this );
|
||||
this.contextView = null;
|
||||
this.$ = $container
|
||||
|
@ -96,9 +97,23 @@ ve.ce.Surface = function( $container, model ) {
|
|||
} );
|
||||
|
||||
this.on( 'rangeChange', function( e ) {
|
||||
|
||||
/* Save selection direction only
|
||||
if selection start and end have changed */
|
||||
if( e.new && e.old ) {
|
||||
if( e.new.start !== e.old.start || e.new.end !== e.old.end ) {
|
||||
this.selectionDirection = ( e.new.to < e.new.from ) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( e.new !== null ) {
|
||||
/* Set selection in the model */
|
||||
_this.model.setSelection( e.new );
|
||||
_this.Selection();
|
||||
|
||||
/* Hide or show context view icon */
|
||||
_this.toggleContextView();
|
||||
|
||||
/* Load or clear annotations */
|
||||
if ( e.new.getLength() === 0 ) {
|
||||
_this.loadInsertionAnnotations();
|
||||
} else {
|
||||
|
@ -453,8 +468,7 @@ ve.ce.Surface.prototype.getModel = function() {
|
|||
return this.model;
|
||||
};
|
||||
|
||||
ve.ce.Surface.prototype.
|
||||
Selection = function( delay ) {
|
||||
ve.ce.Surface.prototype.toggleContextView = function( delay ) {
|
||||
var _this = this,
|
||||
selection = this.model.getSelection();
|
||||
|
||||
|
@ -710,6 +724,7 @@ ve.ce.Surface.prototype.showSelection = function( range ) {
|
|||
var start = this.getDOMNodeAndOffset( range.start ),
|
||||
stop = this.getDOMNodeAndOffset( range.end ),
|
||||
sel = rangy.getSelection();
|
||||
|
||||
// FIXME: Shadowing range, really?
|
||||
range = rangy.createRange();
|
||||
range.setStart( start.node, start.offset );
|
||||
|
|
|
@ -92,15 +92,16 @@ ve.ui.Context.prototype.set = function() {
|
|||
|
||||
ve.ui.Context.prototype.positionIcon = function() {
|
||||
this.$.removeClass( 'es-contextView-position-start es-contextView-position-end' );
|
||||
var selection = this.surfaceView.getSelectionRange(),
|
||||
selectionRect = this.surfaceView.getSelectionRect();
|
||||
var selection = this.surfaceView.model.getSelection(),
|
||||
selectionRect = this.surfaceView.getSelectionRect(),
|
||||
selectionDirection = this.surfaceView.selectionDirection;
|
||||
this.position = null;
|
||||
|
||||
if ( selection.from < selection.to ) {
|
||||
if( selectionDirection === 1 ) {
|
||||
this.position = new ve.Position( selectionRect.end.x, selectionRect.end.y );
|
||||
this.$.addClass( 'es-contextView-position-end' );
|
||||
|
||||
} else if ( selection.from > selection.to ) {
|
||||
} else if ( selectionDirection === -1 ) {
|
||||
this.position = new ve.Position( selectionRect.start.x, selectionRect.start.y );
|
||||
this.$.addClass( 'es-contextView-position-start' );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue