How to use the @ckeditor/ckeditor5-engine/src/view/range function in @ckeditor/ckeditor5-engine

To help you get started, we’ve selected a few @ckeditor/ckeditor5-engine 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 ckeditor / ckeditor5-image / src / widget / widgetengine.js View on Github external
for ( let range of newSelection.getRanges() ) {
				const start = range.start;
				const end = range.end;
				const startWidget = getWidgetAncestor( start.parent );
				const endWidget = getWidgetAncestor( end.parent );

				// Whole range is placed inside widget - put selection around that widget.
				if ( startWidget !== null && startWidget == endWidget ) {
					newRanges.push( ViewRange.createOn( startWidget ) );

					continue;
				}

				// Range start is placed inside the widget - start selection after the widget.
				if ( startWidget !== null ) {
					newRanges.push( new ViewRange( ViewPosition.createAfter( startWidget ), end ) );

					continue;
				}

				// Range end is placed inside widget - end selection before the widget.
				if ( endWidget !== null ) {
					newRanges.push( new ViewRange( start, ViewPosition.createBefore( endWidget ) ) );

					continue;
				}

				newRanges.push( range );
			}

			if ( newRanges.length ) {
				newSelection.setRanges( newRanges, newSelection.isBackward );
github ckeditor / ckeditor5-image / src / widget / widgetengine.js View on Github external
if ( startWidget !== null && startWidget == endWidget ) {
					newRanges.push( ViewRange.createOn( startWidget ) );

					continue;
				}

				// Range start is placed inside the widget - start selection after the widget.
				if ( startWidget !== null ) {
					newRanges.push( new ViewRange( ViewPosition.createAfter( startWidget ), end ) );

					continue;
				}

				// Range end is placed inside widget - end selection before the widget.
				if ( endWidget !== null ) {
					newRanges.push( new ViewRange( start, ViewPosition.createBefore( endWidget ) ) );

					continue;
				}

				newRanges.push( range );
			}

			if ( newRanges.length ) {
				newSelection.setRanges( newRanges, newSelection.isBackward );
			}
		}, { priority: 'high' } );
	}
github centaur54dev / ckeditor5-math-preview / src / mathpreview_utils.js View on Github external
}

	const start = findMarkPos(view, position, MATHCONFIG.STARTMARKS, false);
	const end   = findMarkPos(view, position, MATHCONFIG.ENDMARKS,   true);

	if (start.pos !== null && end.pos !== null){
		const closerEnd = findMarkPos(view, position, MATHCONFIG.ENDMARKS, false);
		if (closerEnd.pos!==null){
			if (closerEnd.pos.isAfter(start.pos)) return out; //not valid
		}
		const closerStart = findMarkPos(view, position, MATHCONFIG.STARTMARKS, true);
		if (closerStart.pos!==null){
			if (closerStart.pos.isBefore(end.pos)) return out; //not valid
		}
		if (start.mark===end.mark){
			out.range = new ViewRange(start.pos, end.pos);
			out.outerRange = new ViewRange(start.markPos, end.markPos);
			out.mode  = MATHCONFIG.MODES[start.mark];
		}
	}
	return out;
}
github centaur54dev / ckeditor5-math-preview / src / mathpreview_utils.js View on Github external
const start = findMarkPos(view, position, MATHCONFIG.STARTMARKS, false);
	const end   = findMarkPos(view, position, MATHCONFIG.ENDMARKS,   true);

	if (start.pos !== null && end.pos !== null){
		const closerEnd = findMarkPos(view, position, MATHCONFIG.ENDMARKS, false);
		if (closerEnd.pos!==null){
			if (closerEnd.pos.isAfter(start.pos)) return out; //not valid
		}
		const closerStart = findMarkPos(view, position, MATHCONFIG.STARTMARKS, true);
		if (closerStart.pos!==null){
			if (closerStart.pos.isBefore(end.pos)) return out; //not valid
		}
		if (start.mark===end.mark){
			out.range = new ViewRange(start.pos, end.pos);
			out.outerRange = new ViewRange(start.markPos, end.markPos);
			out.mode  = MATHCONFIG.MODES[start.mark];
		}
	}
	return out;
}