Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions inst/app/www/document_code_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ function getCaretCharacterOffsetWithin(element) {
return caretOffset;
}

// Function to send calculated positions to Shiny
$( document ).ready(function() {
document.addEventListener('mouseup', function () {
var sel = window.getSelection();
function updateSelection() {
var sel = window.getSelection();
// if(window.getSelection().baseNode.parentNode.id != "document_code_ui_1-focal_text") return;

if(sel.rangeCount > 0){
Expand Down Expand Up @@ -68,8 +66,15 @@ document.addEventListener('mouseup', function () {
console.log("tag_position" + tag_position_value)
Shiny.setInputValue('document_code_ui_1-tag_position', tag_position_value);
}
}, false);
}

// Function to send calculated positions to Shiny
$( document ).ready(function() {
document.addEventListener('mouseup', updateSelection);
document.addEventListener('keyup', updateSelection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyup tady není moc dobrej, volá tu funkci furt, i když třeba píšeš jméno kódu v jiným tabu
asi něco jako $('#document_code_ui_1-focal_text').on('mouseup keyup touchend', updateSelection); bude lepší?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hlageek check it out now

document.addEventListener('touchend', updateSelection);
})

// Obtain information from iframe and send to Shiny
$(document).ready(function() {
var iframe = document.getElementsByTagName('iframe')[0];
Expand Down