super ugly hack to make pasting files with selection smoother

pull/136/head
Aevann 2023-03-02 00:11:17 +02:00
parent a6ca86006c
commit 12a5ffab0d
1 changed files with 15 additions and 2 deletions

View File

@ -486,12 +486,25 @@ function handle_files(input, newfiles) {
ta.value += '\n'
}
const selection_end = ta.selectionEnd
const selected_text = ta.value.substring(ta.selectionStart, selection_end);
for (const file of newfiles) {
oldfiles[ta.id].push(file)
if (span.innerHTML != ' ') span.innerHTML += ', '
span.innerHTML += file.name.substr(0, 30);
if (location.pathname != '/chat')
ta.setRangeText(`[${file.name}]\n`);
if (location.pathname != '/chat') {
const file_entry = `[${file.name}]`
if (selected_text) {
let old_value = ta.value
ta.value = old_value.replace(selected_text, file_entry);
ta.selectionEnd = selection_end + ta.value.length - old_value.length;
}
else {
ta.setRangeText(`${file_entry}\n`);
}
}
}
autoExpand(ta)