How to use the @wordpress/dom.computeCaretRect function in @wordpress/dom

To help you get started, we’ve selected a few @wordpress/dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WordPress / gutenberg / packages / block-editor / src / components / writing-flow / index.js View on Github external
this.props.clearSelectedBlock();
				this.appender.current.focus();
			}
			return;
		}

		// When presing any key other than up or down, the initial vertical
		// position must ALWAYS be reset. The vertical position is saved so it
		// can be restored as well as possible on sebsequent vertical arrow key
		// presses. It may not always be possible to restore the exact same
		// position (such as at an empty line), so it wouldn't be good to
		// compute the position right before any vertical arrow key press.
		if ( ! isVertical ) {
			this.verticalRect = null;
		} else if ( ! this.verticalRect ) {
			this.verticalRect = computeCaretRect();
		}

		// This logic inside this condition needs to be checked before
		// the check for event.nativeEvent.defaultPrevented.
		// The logic handles meta+a keypress and this event is default prevented
		// by RichText.
		if ( ! isNav ) {
			// Set immediately before the meta+a combination can be pressed.
			if ( isKeyboardEvent.primary( event ) ) {
				this.isEntirelySelected = isEntirelySelected( target );
			}

			if ( isKeyboardEvent.primary( event, 'a' ) ) {
				// When the target is contentEditable, selection will already
				// have been set by the browser earlier in this call stack. We
				// need check the previous result, otherwise all blocks will be
github WordPress / gutenberg / packages / block-editor / src / components / typewriter / index.js View on Github external
maintainCaretPosition( { keyCode } ) {
		if ( ! this.isSelectionEligibleForScroll() ) {
			return;
		}

		const currentCaretRect = computeCaretRect();

		if ( ! currentCaretRect ) {
			return;
		}

		// If for some reason there is no position set to be scrolled to, let
		// this be the position to be scrolled to in the future.
		if ( ! this.caretRect ) {
			this.caretRect = currentCaretRect;
			return;
		}

		// Even though enabling the typewriter effect for arrow keys results in
		// a pleasant experience, it may not be the case for everyone, so, for
		// now, let's disable it.
		if ( arrowKeyCodes.has( keyCode ) ) {
github WordPress / gutenberg / packages / block-editor / src / components / typewriter / index.js View on Github external
computeCaretRect() {
		if ( this.isSelectionEligibleForScroll() ) {
			this.caretRect = computeCaretRect();
		}
	}