0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -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 ) {
keyHandlers[ 'meta-left' ] = function ( self, event ) {
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 ) {
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 );
};
var getWindowSelection = function ( self ) {
return self._win.getSelection() || null;
};
proto.setSelection = function ( range ) {
if ( range ) {
// iOS bug: if you don't focus the iframe before setting the
@ -2473,7 +2483,7 @@ proto.setSelection = function ( range ) {
if ( isIOS ) {
this._win.focus();
}
var sel = this._getWindowSelection();
var sel = getWindowSelection( this );
if ( sel ) {
sel.removeAllRanges();
sel.addRange( range );
@ -2483,12 +2493,8 @@ proto.setSelection = function ( range ) {
return this;
};
proto._getWindowSelection = function () {
return this._win.getSelection() || null;
};
proto.getSelection = function () {
var sel = this._getWindowSelection(),
var sel = getWindowSelection( this ),
selection, startContainer, endContainer;
if ( sel && sel.rangeCount ) {
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 );
};
var getWindowSelection = function ( self ) {
return self._win.getSelection() || null;
};
proto.setSelection = function ( range ) {
if ( range ) {
// iOS bug: if you don't focus the iframe before setting the
@ -351,7 +355,7 @@ proto.setSelection = function ( range ) {
if ( isIOS ) {
this._win.focus();
}
var sel = this._getWindowSelection();
var sel = getWindowSelection( this );
if ( sel ) {
sel.removeAllRanges();
sel.addRange( range );
@ -361,12 +365,8 @@ proto.setSelection = function ( range ) {
return this;
};
proto._getWindowSelection = function () {
return this._win.getSelection() || null;
};
proto.getSelection = function () {
var sel = this._getWindowSelection(),
var sel = getWindowSelection( this ),
selection, startContainer, endContainer;
if ( sel && sel.rangeCount ) {
selection = sel.getRangeAt( 0 ).cloneRange();

View file

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