mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Code clean-up
This commit is contained in:
@ -380,6 +380,7 @@ jQuery(function () {
|
||||
$(document).on('click', '.editor_maximize', function () {
|
||||
const broId = $(this).attr('data-for');
|
||||
const bro = $(`#${broId}`);
|
||||
const withTab = $(this).attr('data-tab');
|
||||
|
||||
if (!bro.length) {
|
||||
console.error('Could not find editor with id', broId);
|
||||
@ -392,11 +393,41 @@ jQuery(function () {
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = String(bro.val());
|
||||
textarea.classList.add('height100p', 'wide100p');
|
||||
textarea.oninput = function () {
|
||||
textarea.addEventListener('input', function () {
|
||||
bro.val(textarea.value).trigger('input');
|
||||
};
|
||||
});
|
||||
wrapper.appendChild(textarea);
|
||||
|
||||
if (withTab) {
|
||||
textarea.addEventListener('keydown', (evt) => {
|
||||
if (evt.key == 'Tab' && !evt.shiftKey && !evt.ctrlKey && !evt.altKey) {
|
||||
evt.preventDefault();
|
||||
const start = textarea.selectionStart;
|
||||
const end = textarea.selectionEnd;
|
||||
if (end - start > 0 && textarea.value.substring(start, end).includes('\n')) {
|
||||
const lineStart = textarea.value.lastIndexOf('\n', start);
|
||||
const count = textarea.value.substring(lineStart, end).split('\n').length - 1;
|
||||
textarea.value = `${textarea.value.substring(0, lineStart)}${textarea.value.substring(lineStart, end).replace(/\n/g, '\n\t')}${textarea.value.substring(end)}`;
|
||||
textarea.selectionStart = start + 1;
|
||||
textarea.selectionEnd = end + count;
|
||||
} else {
|
||||
textarea.value = `${textarea.value.substring(0, start)}\t${textarea.value.substring(end)}`;
|
||||
textarea.selectionStart = start + 1;
|
||||
textarea.selectionEnd = end + 1;
|
||||
}
|
||||
} else if (evt.key == 'Tab' && evt.shiftKey && !evt.ctrlKey && !evt.altKey) {
|
||||
evt.preventDefault();
|
||||
const start = textarea.selectionStart;
|
||||
const end = textarea.selectionEnd;
|
||||
const lineStart = textarea.value.lastIndexOf('\n', start);
|
||||
const count = textarea.value.substring(lineStart, end).split('\n\t').length - 1;
|
||||
textarea.value = `${textarea.value.substring(0, lineStart)}${textarea.value.substring(lineStart, end).replace(/\n\t/g, '\n')}${textarea.value.substring(end)}`;
|
||||
textarea.selectionStart = start - 1;
|
||||
textarea.selectionEnd = end - count;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
callPopup(wrapper, 'text', '', { wide: true, large: true });
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user