function edgeGetSelectedCodeLines(selection) {
    // current selected text without line breaks
    let selectionText = selection.toString();

    // get the <td> element wrapping the first line of selected code
    let tdAnchor = selection.anchorNode;
    while (tdAnchor.nodeName !== 'TD') {
        tdAnchor = tdAnchor.parentNode;
    }

    // get the <td> element wrapping the last line of selected code
    let tdFocus = selection.focusNode;
    while (tdFocus.nodeName !== 'TD') {
        tdFocus = tdFocus.parentNode;
    }

    // extract line numbers
    let firstLineNumber = parseInt(tdAnchor.dataset.lineNumber);
    let lastLineNumber = parseInt(tdFocus.dataset.lineNumber);

    // multi-lines copied case
    if (firstLineNumber !== lastLineNumber) {

        let firstLineText = tdAnchor.textContent;
        let lastLineText = tdFocus.textContent;

        // if the selection was made backward, swap values
        if (firstLineNumber > lastLineNumber) {
            let tmp = firstLineNumber;
            firstLineNumber = lastLineNumber;
            lastLineNumber = tmp;
            tmp = firstLineText;
            firstLineText = lastLineText;
            lastLineText = tmp;
        }

        // discard not copied characters in first line
        while (selectionText.indexOf(firstLineText) !== 0) {
            firstLineText = firstLineText.slice(1);
        }

        // discard not copied characters in last line
        while (selectionText.lastIndexOf(lastLineText) === -1) {
            lastLineText = lastLineText.slice(0, -1);
        }

        // reconstruct and return the real copied text
        let selectedText = firstLineText;
        let hljsLnTable = getHljsLnTable(tdAnchor);
        for (let i = firstLineNumber + 1 ; i < lastLineNumber ; ++i) {
            let codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i]);
            let codeLineElt = hljsLnTable.querySelector(codeLineSel);
            selectedText += '\n' + codeLineElt.textContent;
        }
        selectedText += '\n' + lastLineText;
        return selectedText;
        // single copied line case
    } else {
        return selectionText;
    }
}
// rendered code in the DOM as reference.
rendered code in the DOM as reference.
rendered code in the DOM as reference .
function edgeGetSelectedCodeLines(selection) {
    let selectionText = selection.toString();
    let tdAnchor = selection.anchorNode;
    while (tdAnchor.nodeName !== 'TD') {
        tdAnchor = tdAnchor.parentNode;
    }
    let tdFocus = selection.focusNode;
    while (tdFocus.nodeName !== 'TD') {
        tdFocus = tdFocus.parentNode;
    }
    let firstLineNumber = parseInt(tdAnchor.dataset.lineNumber);
    let lastLineNumber = parseInt(tdFocus.dataset.lineNumber);
    if (firstLineNumber !== lastLineNumber) {
        let firstLineText = tdAnchor.textContent;
        let lastLineText = tdFocus.textContent;
        if (firstLineNumber > lastLineNumber) {
            let tmp = firstLineNumber;
            firstLineNumber = lastLineNumber;
            lastLineNumber = tmp;
            tmp = firstLineText;
            firstLineText = lastLineText;
            lastLineText = tmp;
        }
        while (selectionText.indexOf(firstLineText) !== 0) {
            firstLineText = firstLineText.slice(1);
        }
        while (selectionText.lastIndexOf(lastLineText) === -1) {
            lastLineText = lastLineText.slice(0, -1);
        }
        let selectedText = firstLineText;
        let hljsLnTable = getHljsLnTable(tdAnchor);
        for (let i = firstLineNumber + 1 ; i < lastLineNumber ; ++i) {
            let codeLineSel = format('.{0}[{1}="{2}"]', [CODE_BLOCK_NAME, DATA_ATTR_NAME, i]);
            let codeLineElt = hljsLnTable.querySelector(codeLineSel);
            selectedText += '\n' + codeLineElt.textContent;
        }
        selectedText += '\n' + lastLineText;
        return selectedText;
    } else {
        return selectionText;
    }
}
function edgeGetSelectedCodeLines ( selection ) { let selectionText = selection . toString ( ) ; let tdAnchor = selection . anchorNode ; while ( tdAnchor . nodeName !== 'TD' ) { tdAnchor = tdAnchor . parentNode ; } let tdFocus = selection . focusNode ; while ( tdFocus . nodeName !== 'TD' ) { tdFocus = tdFocus . parentNode ; } let firstLineNumber = parseInt ( tdAnchor . dataset . lineNumber ) ; let lastLineNumber = parseInt ( tdFocus . dataset . lineNumber ) ; if ( firstLineNumber !== lastLineNumber ) { let firstLineText = tdAnchor . textContent ; let lastLineText = tdFocus . textContent ; if ( firstLineNumber > lastLineNumber ) { let tmp = firstLineNumber ; firstLineNumber = lastLineNumber ; lastLineNumber = tmp ; tmp = firstLineText ; firstLineText = lastLineText ; lastLineText = tmp ; } while ( selectionText . indexOf ( firstLineText ) !== 0 ) { firstLineText = firstLineText . slice ( 1 ) ; } while ( selectionText . lastIndexOf ( lastLineText ) === - 1 ) { lastLineText = lastLineText . slice ( 0 , - 1 ) ; } let selectedText = firstLineText ; let hljsLnTable = getHljsLnTable ( tdAnchor ) ; for ( let i = firstLineNumber + 1 ; i < lastLineNumber ; ++ i ) { let codeLineSel = format ( '.{0}[{1}="{2}"]' , [ CODE_BLOCK_NAME , DATA_ATTR_NAME , i ] ) ; let codeLineElt = hljsLnTable . querySelector ( codeLineSel ) ; selectedText += '\n' + codeLineElt . textContent ; } selectedText += '\n' + lastLineText ; return selectedText ; } else { return selectionText ; } }
rendered code in the DOM as reference.
rendered code in the DOM as reference .
// current selected text without line breaks // get the <td> element wrapping the first line of selected code // get the <td> element wrapping the last line of selected code // extract line numbers // multi-lines copied case // if the selection was made backward, swap values // discard not copied characters in first line // discard not copied characters in last line // reconstruct and return the real copied text // single copied line case