Fix emoji editor

This commit is contained in:
cuom1999 2021-07-26 15:46:27 -05:00
parent 26248b9eb8
commit 850076b444
3 changed files with 26 additions and 19 deletions

View file

@ -32,10 +32,6 @@
.big-emoji { .big-emoji {
font-size: 16px; font-size: 16px;
} }
#chat-input, #chat-log .content-message {
font-family: "Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Twemoji Mozilla","Noto Color Emoji", "EmojiOne Color","Android Emoji", "Segoe UI", "Lucida Grande", Arial, sans-serif;
}
#chat-online { #chat-online {
border-right: 1px solid #ccc; border-right: 1px solid #ccc;
padding-bottom: 0 !important; padding-bottom: 0 !important;

View file

@ -146,6 +146,25 @@
element.html(html); element.html(html);
} }
function insert_char_after_cursor(elem, char) {
var val = elem.value;
if (typeof elem.selectionStart == "number" && typeof elem.selectionEnd == "number") {
var start = elem.selectionStart;
var prefix = elem.value.slice(0, start);
var prefix_added = prefix + char;
var chars = [...val];
chars.splice([...prefix].length, 0, char);
elem.value = chars.join('');
elem.selectionStart = elem.selectionEnd = prefix_added.length;
} else if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
elem.focus();
range.text = char;
range.collapse(false);
range.select();
}
}
$(function() { $(function() {
$('#loader').hide(); $('#loader').hide();
merge_authors(); merge_authors();
@ -191,18 +210,7 @@
$('#chat-input').keydown(function(e) { $('#chat-input').keydown(function(e) {
if (e.keyCode === 13) { if (e.keyCode === 13) {
if (e.ctrlKey || e.shiftKey) { if (e.ctrlKey || e.shiftKey) {
var val = this.value; insert_char_after_cursor(this, "\n");
if (typeof this.selectionStart == "number" && typeof this.selectionEnd == "number") {
var start = this.selectionStart;
this.value = val.slice(0, start) + "\n" + val.slice(this.selectionEnd);
this.selectionStart = this.selectionEnd = start + 1;
} else if (document.selection && document.selection.createRange) {
this.focus();
var range = document.selection.createRange();
range.text = "\r\n";
range.collapse(false);
range.select();
}
} }
else { else {
e.preventDefault(); e.preventDefault();
@ -266,9 +274,9 @@
}); });
$('emoji-picker').on('emoji-click', function(e) { $('emoji-picker').on('emoji-click', function(e) {
var $chat = $('#chat-input'); var $chat = $('#chat-input').get(0);
var text = $chat.val(); insert_char_after_cursor($chat, e.detail.unicode);
$chat.val(text + e.detail.unicode); $chat.focus();
}) })
document.addEventListener('keydown', function(e) { document.addEventListener('keydown', function(e) {

View file

@ -143,6 +143,9 @@
.body-block:hover { .body-block:hover {
background: #eee; background: #eee;
} }
#chat-input, #chat-log .content-message {
font-family: "Apple Color Emoji", "Segoe UI", "Lucida Grande", Arial, sans-serif;
}
@media (min-width: 800px) { @media (min-width: 800px) {
#page-container { #page-container {
position:fixed; position:fixed;