As a beginner in the world of AngularJS
and web development
, I am faced with a challenge. I have a specific string that is currently selected on a tab, like so:
var getSelectedText = function() {
var text = "";
if (typeof window.getSelection !== "undefined") {
text = window.getSelection().toString();
} else if (typeof document.selection !== "undefined" && document.selection.type === "Text") {
text = document.selection.createRange().text;
}
$scope.annotations = annotationList();
return text;
};
This selected string is extracted from the following longer text:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book... etc
Now, my goal is to determine the start and end offsets of this selected text within the larger string.
but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised
Any suggestions on how to achieve this using JavaScript?