diff --git a/app/js/emoji/default-emoji.js b/app/js/emoji/default-emoji.js index 62f1bebf..35b1c999 100644 --- a/app/js/emoji/default-emoji.js +++ b/app/js/emoji/default-emoji.js @@ -50,6 +50,10 @@ function customEmoji() { emojiList('home') } function defEmoji(target) { + var selin = $("#textarea").prop('selectionStart'); + if (!selin) { + selin = 0; + } var emojiraw = newpack.filter(function (item, index) { if (item.short_name == target) return true; }); @@ -60,22 +64,11 @@ function defEmoji(target) { emoji = twemoji.convert.fromCodePoint(hex[0]); } var now = $("#textarea").val(); - var selin = localStorage.getItem("cursor"); - var now = $("#textarea").val(); - if (selin > 0) { - var before = now.substr(0, selin); - var after = now.substr(selin, now.length); - newt = before + emoji + after; - } else { - newt = emoji + now; - } + var before = now.substr(0, selin); + var after = now.substr(selin, now.length); + newt = before + emoji + after; $("#textarea").val(newt); $("#textarea").focus(); - var selin = $("#textarea").prop('selectionStart'); - if (!selin) { - selin = 0; - } - localStorage.setItem("cursor", selin); } function faicon() { var json = faicons; diff --git a/app/js/post/emoji.js b/app/js/post/emoji.js index 5edeea68..fdfa77ec 100644 --- a/app/js/post/emoji.js +++ b/app/js/post/emoji.js @@ -10,8 +10,6 @@ function emojiToggle(reaction) { if (!selin) { selin = 0; } - localStorage.setItem("cursor", selin); - if ($("#emoji").hasClass("hide")) { $("#emoji").removeClass("hide") $("#right-side").show() @@ -173,35 +171,31 @@ function emojiList(target, reaction) { //絵文字など様々なものをテキストボックスに挿入 function emojiInsert(code, del) { var now = $("#textarea").val(); - var selin = localStorage.getItem("cursor"); + var selin = $("#textarea").prop('selectionStart'); if (localStorage.getItem("emoji-zero-width") == "yes") { - var brank = "​"; + var blank = "​"; } else { - var brank = " "; + var blank = " "; } - var now = $("#textarea").val(); - if (selin > 0) { - var before = now.substr(0, selin); - var after = now.substr(selin, now.length); - newt = before + brank + code + brank + after; - } else { - newt = code + brank; + var before = now.substr(0, selin); + if (before.slice(-1) != " ") { + before = before + blank } + var after = now.substr(selin, now.length); + if (after.slice(-1) != " ") { + after = blank + after + } + newt = before + code + after; if (!del) { $("#textarea").val(newt); //emoji(); } else { var regExp = new RegExp(del.replace(/[.*+?^=!:${}()|[\]\/\\]/g, "\\$&"), "g"); var now = now.replace(regExp, ""); - $("#textarea").val(now + brank + code); + $("#textarea").val(now + blank + code); } $("#textarea").focus(); - var selin = $("#textarea").prop('selectionStart'); - if (!selin) { - selin = 0; - } - localStorage.setItem("cursor", selin); } //改行挿入 function brInsert(code) { diff --git a/app/js/post/suggest.js b/app/js/post/suggest.js index 1b5155a1..a58a9dd6 100644 --- a/app/js/post/suggest.js +++ b/app/js/post/suggest.js @@ -8,6 +8,7 @@ var oldSuggest; var suggest; input.addEventListener("focus", function () { + localStorage.removeItem("cursor"); var acct_id = $("#post-acct-sel").val(); $("#suggest").html(""); window.clearInterval(timer);