super ugly hack to make pasting files with selection smoother
parent
a6ca86006c
commit
12a5ffab0d
|
@ -486,12 +486,25 @@ function handle_files(input, newfiles) {
|
||||||
ta.value += '\n'
|
ta.value += '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const selection_end = ta.selectionEnd
|
||||||
|
const selected_text = ta.value.substring(ta.selectionStart, selection_end);
|
||||||
|
|
||||||
for (const file of newfiles) {
|
for (const file of newfiles) {
|
||||||
oldfiles[ta.id].push(file)
|
oldfiles[ta.id].push(file)
|
||||||
if (span.innerHTML != ' ') span.innerHTML += ', '
|
if (span.innerHTML != ' ') span.innerHTML += ', '
|
||||||
span.innerHTML += file.name.substr(0, 30);
|
span.innerHTML += file.name.substr(0, 30);
|
||||||
if (location.pathname != '/chat')
|
if (location.pathname != '/chat') {
|
||||||
ta.setRangeText(`[${file.name}]\n`);
|
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)
|
autoExpand(ta)
|
||||||
|
|
Loading…
Reference in New Issue