-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Writing flow: fix vertical arrow keys not moving (#53454)
- Loading branch information
Showing
6 changed files
with
51 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* If no range range can be created or it is outside the container, the element | ||
* may be out of view, so scroll it into view and try again. | ||
* | ||
* @param {HTMLElement} container The container to scroll. | ||
* @param {boolean} alignToTop True to align to top, false to bottom. | ||
* @param {Function} callback The callback to create the range. | ||
* | ||
* @return {?Range} The range returned by the callback. | ||
*/ | ||
export function scrollIfNoRange( container, alignToTop, callback ) { | ||
let range = callback(); | ||
|
||
// If no range range can be created or it is outside the container, the | ||
// element may be out of view. | ||
if ( | ||
! range || | ||
! range.startContainer || | ||
! container.contains( range.startContainer ) | ||
) { | ||
container.scrollIntoView( alignToTop ); | ||
range = callback(); | ||
|
||
if ( | ||
! range || | ||
! range.startContainer || | ||
! container.contains( range.startContainer ) | ||
) { | ||
return null; | ||
} | ||
} | ||
|
||
return range; | ||
} |