post selectText message

This commit is contained in:
rlx 2019-01-25 11:53:56 +05:30
parent ebab25c47d
commit b4434ec404

View file

@ -345,6 +345,7 @@ txtjs.renderText = function(text) {
html = text.replace(/</g, '&lt;').replace(/>/g, '&gt;') html = text.replace(/</g, '&lt;').replace(/>/g, '&gt;')
html = html.replace().replace(/\r\n/g, '\n').replace(/[\r\n]/g, '<br>') html = html.replace().replace(/\r\n/g, '\n').replace(/[\r\n]/g, '<br>')
txtjs.html = Ox.encodeHTMLEntities(text).replace(/\r\n/g, '\n').replace(/[\r\n]/g, '<br>') txtjs.html = Ox.encodeHTMLEntities(text).replace(/\r\n/g, '\n').replace(/[\r\n]/g, '<br>')
window.addEventListener('mouseup', onMouseup)
window.addEventListener('resize', onResize) window.addEventListener('resize', onResize)
window.addEventListener('scroll', onScroll) window.addEventListener('scroll', onScroll)
document.addEventListener('keydown', function(e) { document.addEventListener('keydown', function(e) {
@ -418,6 +419,13 @@ txtjs.renderText = function(text) {
txtjs.renderSVGs() txtjs.renderSVGs()
let factor, margin let factor, margin
onResize() onResize()
function onMouseup() {
let note = txtjs.getNoteFromSelection()
if (!note || txtjs.noteExists(note)) {
txtjs.postMessage('selectText', null)
}
txtjs.postMessage('selectText', note)
}
function onResize() { function onResize() {
factor = scrollTextElement.clientHeight / textElement.clientHeight factor = scrollTextElement.clientHeight / textElement.clientHeight
margin = textElement.offsetWidth * 0.1 margin = textElement.offsetWidth * 0.1