0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-03 13:16:31 -05:00

Fix Meta-Left/Right handling in Firefox.

Fixes #167.
This commit is contained in:
Neil Jenkins 2015-12-29 11:15:01 +11:00
parent 8b183c6ef6
commit 93f7867214
4 changed files with 30 additions and 18 deletions

View file

@ -1580,11 +1580,17 @@ var keyHandlers = {
if ( isMac && isGecko && win.getSelection().modify ) { if ( isMac && isGecko && win.getSelection().modify ) {
keyHandlers[ 'meta-left' ] = function ( self, event ) { keyHandlers[ 'meta-left' ] = function ( self, event ) {
event.preventDefault(); event.preventDefault();
self._sel.modify( 'move', 'backward', 'lineboundary' ); var sel = getWindowSelection( self );
if ( sel ) {
sel.modify( 'move', 'backward', 'lineboundary' );
}
}; };
keyHandlers[ 'meta-right' ] = function ( self, event ) { keyHandlers[ 'meta-right' ] = function ( self, event ) {
event.preventDefault(); event.preventDefault();
self._sel.modify( 'move', 'forward', 'lineboundary' ); var sel = getWindowSelection( self );
if ( sel ) {
sel.modify( 'move', 'forward', 'lineboundary' );
}
}; };
} }
@ -2464,6 +2470,10 @@ proto.moveCursorToEnd = function () {
return this._moveCursorTo( false ); return this._moveCursorTo( false );
}; };
var getWindowSelection = function ( self ) {
return self._win.getSelection() || null;
};
proto.setSelection = function ( range ) { proto.setSelection = function ( range ) {
if ( range ) { if ( range ) {
// iOS bug: if you don't focus the iframe before setting the // iOS bug: if you don't focus the iframe before setting the
@ -2473,7 +2483,7 @@ proto.setSelection = function ( range ) {
if ( isIOS ) { if ( isIOS ) {
this._win.focus(); this._win.focus();
} }
var sel = this._getWindowSelection(); var sel = getWindowSelection( this );
if ( sel ) { if ( sel ) {
sel.removeAllRanges(); sel.removeAllRanges();
sel.addRange( range ); sel.addRange( range );
@ -2483,12 +2493,8 @@ proto.setSelection = function ( range ) {
return this; return this;
}; };
proto._getWindowSelection = function () {
return this._win.getSelection() || null;
};
proto.getSelection = function () { proto.getSelection = function () {
var sel = this._getWindowSelection(), var sel = getWindowSelection( this ),
selection, startContainer, endContainer; selection, startContainer, endContainer;
if ( sel && sel.rangeCount ) { if ( sel && sel.rangeCount ) {
selection = sel.getRangeAt( 0 ).cloneRange(); selection = sel.getRangeAt( 0 ).cloneRange();

File diff suppressed because one or more lines are too long

View file

@ -342,6 +342,10 @@ proto.moveCursorToEnd = function () {
return this._moveCursorTo( false ); return this._moveCursorTo( false );
}; };
var getWindowSelection = function ( self ) {
return self._win.getSelection() || null;
};
proto.setSelection = function ( range ) { proto.setSelection = function ( range ) {
if ( range ) { if ( range ) {
// iOS bug: if you don't focus the iframe before setting the // iOS bug: if you don't focus the iframe before setting the
@ -351,7 +355,7 @@ proto.setSelection = function ( range ) {
if ( isIOS ) { if ( isIOS ) {
this._win.focus(); this._win.focus();
} }
var sel = this._getWindowSelection(); var sel = getWindowSelection( this );
if ( sel ) { if ( sel ) {
sel.removeAllRanges(); sel.removeAllRanges();
sel.addRange( range ); sel.addRange( range );
@ -361,12 +365,8 @@ proto.setSelection = function ( range ) {
return this; return this;
}; };
proto._getWindowSelection = function () {
return this._win.getSelection() || null;
};
proto.getSelection = function () { proto.getSelection = function () {
var sel = this._getWindowSelection(), var sel = getWindowSelection( this ),
selection, startContainer, endContainer; selection, startContainer, endContainer;
if ( sel && sel.rangeCount ) { if ( sel && sel.rangeCount ) {
selection = sel.getRangeAt( 0 ).cloneRange(); selection = sel.getRangeAt( 0 ).cloneRange();

View file

@ -431,11 +431,17 @@ var keyHandlers = {
if ( isMac && isGecko && win.getSelection().modify ) { if ( isMac && isGecko && win.getSelection().modify ) {
keyHandlers[ 'meta-left' ] = function ( self, event ) { keyHandlers[ 'meta-left' ] = function ( self, event ) {
event.preventDefault(); event.preventDefault();
self._sel.modify( 'move', 'backward', 'lineboundary' ); var sel = getWindowSelection( self );
if ( sel ) {
sel.modify( 'move', 'backward', 'lineboundary' );
}
}; };
keyHandlers[ 'meta-right' ] = function ( self, event ) { keyHandlers[ 'meta-right' ] = function ( self, event ) {
event.preventDefault(); event.preventDefault();
self._sel.modify( 'move', 'forward', 'lineboundary' ); var sel = getWindowSelection( self );
if ( sel ) {
sel.modify( 'move', 'forward', 'lineboundary' );
}
}; };
} }