forked from rDrama/rDrama
stop moving cursor to the end
parent
3324a72985
commit
de18940b9b
|
@ -51,6 +51,16 @@ function close_inline_emoji_modal() {
|
||||||
inline_carot_modal.style.display = "none";
|
inline_carot_modal.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function replaceText(input, current_word, new_text) {
|
||||||
|
const match = new RegExp(current_word+"(?=[^\\w-]|$)", "gi").exec(input.value)
|
||||||
|
if (!match) return
|
||||||
|
input.focus()
|
||||||
|
const start_index = match.index;
|
||||||
|
const end_index = input.selectionStart;
|
||||||
|
input.setRangeText(new_text, start_index, end_index, "end");
|
||||||
|
}
|
||||||
|
|
||||||
function populate_inline_emoji_modal(results, textbox)
|
function populate_inline_emoji_modal(results, textbox)
|
||||||
{
|
{
|
||||||
selecting = true;
|
selecting = true;
|
||||||
|
@ -95,8 +105,7 @@ function populate_inline_emoji_modal(results, textbox)
|
||||||
|
|
||||||
emoji_option.addEventListener('click', () => {
|
emoji_option.addEventListener('click', () => {
|
||||||
close_inline_emoji_modal()
|
close_inline_emoji_modal()
|
||||||
textbox.value = textbox.value.replace(new RegExp(current_word+"(?=[^\\w-]|$)", "gi"), `:${name}: `)
|
replaceText(textbox, current_word, `:${name}: `)
|
||||||
textbox.focus()
|
|
||||||
if (typeof markdown === "function" && textbox.dataset.preview) {
|
if (typeof markdown === "function" && textbox.dataset.preview) {
|
||||||
markdown(textbox)
|
markdown(textbox)
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,7 @@ function populate_inline_group_modal(results, textbox)
|
||||||
|
|
||||||
group_option.addEventListener('click', () => {
|
group_option.addEventListener('click', () => {
|
||||||
close_inline_emoji_modal()
|
close_inline_emoji_modal()
|
||||||
textbox.value = textbox.value.replace(new RegExp(current_word+"(?=[^\\w-]|$)", "gi"), `!${name} `)
|
replaceText(textbox, current_word, `:${name}: `)
|
||||||
textbox.focus()
|
|
||||||
if (typeof markdown === "function" && textbox.dataset.preview) {
|
if (typeof markdown === "function" && textbox.dataset.preview) {
|
||||||
markdown(textbox)
|
markdown(textbox)
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,7 @@ function populate_inline_user_modal(results, textbox)
|
||||||
|
|
||||||
user_option.addEventListener('click', () => {
|
user_option.addEventListener('click', () => {
|
||||||
close_inline_emoji_modal()
|
close_inline_emoji_modal()
|
||||||
textbox.value = textbox.value.replace(new RegExp(current_word+"(?=[^\\w-]|$)", "gi"), `@${name} `)
|
replaceText(textbox, current_word, `:${name}: `)
|
||||||
textbox.focus()
|
|
||||||
if (typeof markdown === "function" && textbox.dataset.preview) {
|
if (typeof markdown === "function" && textbox.dataset.preview) {
|
||||||
markdown(textbox)
|
markdown(textbox)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue