Skip to content

Commit

Permalink
Merge pull request hyperaudio#152 from hyperaudio/150-fragment-selection
Browse files Browse the repository at this point in the history
150 fragment selection
  • Loading branch information
maboa authored May 3, 2023
2 parents aaee07a + 9ac0432 commit d27d06c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions js/hyperaudio-lite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 2.1.2 */
/*! Version 2.1.3 */

'use strict';

Expand Down Expand Up @@ -330,7 +330,18 @@ class HyperaudioLite {
selection = document.selection.createRange();
}

if (selection.toString() !== '' && selection.focusNode !== null && selection.anchorNode !== null) {
// check to see if selection is actually inside the transcript
let insideTranscript = false;
let parentElement = selection.focusNode;
while (parentElement !== null) {
if (parentElement.id === this.transcript.id) {
insideTranscript = true;
break;
}
parentElement = parentElement.parentElement;
}

if (selection.toString() !== '' && insideTranscript === true && selection.focusNode !== null && selection.anchorNode !== null) {

let fNode = selection.focusNode.parentNode;
let aNode = selection.anchorNode.parentNode;
Expand All @@ -352,7 +363,7 @@ class HyperaudioLite {
}

// if the selection starts with a space we want the next element
if(selection.toString().charAt(0) == " ") {
if(selection.toString().charAt(0) == " " && aNode !== null) {
aNode = aNode.nextElementSibling;
}

Expand Down

0 comments on commit d27d06c

Please sign in to comment.