FIX: Improve selecting text over line breaks

This commit is contained in:
Robin Ward
2016-09-13 11:36:17 -04:00
parent e46204d195
commit aa7c735d34
2 changed files with 38 additions and 46 deletions

View File

@ -102,14 +102,18 @@ export function selectedText() {
}
}
html = html.replace(/<br>/g, "\n");
// Strip out any .click elements from the HTML before converting it to text
var div = document.createElement('div');
const div = document.createElement('div');
div.innerHTML = html;
var $div = $(div);
const $div = $(div);
// Find all emojis and replace with its title attribute.
$div.find('img.emoji').replaceWith(function() { return this.title; });
$div.find('img.emoji').replaceWith(() => this.title);
$('.clicks', $div).remove();
var text = div.textContent || div.innerText || "";
const text = div.textContent || div.innerText || "";
return String(text).trim();
}