Use CSS.supports to determine auto-fit validity

ac0c33eb7669cfbbb7b8cd8460a94e9c6dca5135

Cohee <18619528+Cohee1207@users.noreply.github.com>

6 files changed, +18 -25Ignore whitespace
public/script.js+2 -6
@@ -10577,9 +10577,6 @@ jQuery(async function () {
1057710577 stopScriptExecution();
1057810578 });
1057910579
10580- const chromeUaIdx = navigator.userAgent.lastIndexOf('Chrome/');
10581- const chromeVersion = navigator.userAgent.substring(chromeUaIdx + 7, navigator.userAgent.indexOf('.', chromeUaIdx));
10582-
1058310580 $('.drawer-toggle').on('click', function () {
1058410581 var icon = $(this).find('.drawer-icon');
1058510582 var drawer = $(this).parent().find('.drawer-content');
@@ -10619,8 +10616,7 @@ jQuery(async function () {
1061910616 }
1062010617
1062110618 // Set the height of "autoSetHeight" textareas within the drawer to their scroll height
10622-
10619+ if (!CSS.supports('field-sizing', 'content')) {
10623- if (chromeUaIdx == -1 || Number(chromeVersion) < 123) {
1062410620 $(this).closest('.drawer').find('.drawer-content textarea.autoSetHeight').each(async function () {
1062510621 await resetScrollHeight($(this));
1062610622 return;
@@ -10697,7 +10693,7 @@ jQuery(async function () {
1069710693 $(this).closest('.inline-drawer').find('.inline-drawer-content').stop().slideToggle();
1069810694
1069910695 // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
10700- if (chromeUaIdx == -1 || Number(chromeVersion) < 123) {
10696+ if (!CSS.supports('field-sizing', 'content')) {
1070110697 $(this).closest('.inline-drawer').find('.inline-drawer-content textarea.autoSetHeight').each(async function () {
1070210698 await resetScrollHeight($(this));
1070310699 return;
public/scripts/group-chats.js+8 -4
@@ -1491,9 +1491,11 @@ function select_group_chats(groupId, skipAnimation) {
14911491 }
14921492
14931493 // Toggle textbox sizes, as input events have not fired here
1494- $('#rm_group_chats_block .autoSetHeight').each(element => {
1494+ if (!CSS.supports('field-sizing', 'content')) {
1495- resetScrollHeight(element);
1495+ $('#rm_group_chats_block .autoSetHeight').each(element => {
1496- });
1496+ resetScrollHeight(element);
1497+ });
1498+ }
14971499
14981500 eventSource.emit('groupSelected', { detail: { id: openGroupId, group: group } });
14991501}
@@ -1965,7 +1967,9 @@ function doCurMemberListPopout() {
19651967
19661968jQuery(() => {
19671969 $(document).on('input', '#rm_group_chats_block .autoSetHeight', function () {
1968- resetScrollHeight($(this));
1970+ if (!CSS.supports('field-sizing', 'content')) {
1971+ resetScrollHeight($(this));
1972+ }
19691973 });
19701974
19711975 $(document).on('click', '.group_select', function () {
public/scripts/instruct-mode.js+1 -4
@@ -42,9 +42,6 @@ const controls = [
4242 { id: 'instruct_system_same_as_user', property: 'system_same_as_user', isCheckbox: true, trigger: true },
4343];
4444
45-const chromeUaIdx = navigator.userAgent.lastIndexOf('Chrome/');
46-const chromeVersion = navigator.userAgent.substring(chromeUaIdx + 7, navigator.userAgent.indexOf('.', chromeUaIdx));
47-
4845/**
4946 * Migrates instruct mode settings into the evergreen format.
5047 * @param {object} settings Instruct mode settings.
@@ -103,7 +100,7 @@ export async function loadInstructMode(data) {
103100
104101 $element.on('input', async function () {
105102 power_user.instruct[control.property] = control.isCheckbox ? !!$(this).prop('checked') : $(this).val;
106- if (chromeUaIdx == -1 || Number(chromeVersion) < 123) {
103+ if (!CSS.supports('field-sizing', 'content')) {
107104 await resetScrollHeight($(this));
108105 }
109106 saveSettingsDebounced();
public/scripts/openai.js+5 -3
@@ -5281,9 +5281,11 @@ $(document).ready(async function () {
52815281 saveSettingsDebounced();
52825282 });
52835283
52845284 $if (document)!CSS.onsupports('inputfield-sizing', '#openai_settings .autoSetHeightcontent', function ()) {
5285- resetScrollHeight($(this));
5285+ $(document).on('input', '#openai_settings .autoSetHeight', function () {
5286- });
5286+ resetScrollHeight($(this));
5287+ });
5288+ }
52875289
52885290 if (!isMobile()) {
52895291 $('#model_openrouter_select').select2({
public/scripts/power-user.js+1 -4
@@ -105,9 +105,6 @@ export const persona_description_positions = {
105105 NONE: 9,
106106};
107107
108-const chromeUaIdx = navigator.userAgent.lastIndexOf('Chrome/');
109-const chromeVersion = navigator.userAgent.substring(chromeUaIdx + 7, navigator.userAgent.indexOf('.', chromeUaIdx));
110-
111108let power_user = {
112109 tokenizer: tokenizers.BEST_MATCH,
113110 token_padding: 64,
@@ -1757,7 +1754,7 @@ async function loadContextSettings() {
17571754 power_user.context[control.property] = value;
17581755 }
17591756 console.log(`Setting ${$element.prop('id')} to ${value}`);
1760- if (chromeUaIdx == -1 || Number(chromeVersion) < 123) {
1757+ if (!CSS.supports('field-sizing', 'content')) {
17611758 await resetScrollHeight($(this));
17621759 }
17631760 saveSettingsDebounced();
public/scripts/utils.js+1 -4
@@ -2027,11 +2027,8 @@ export function toggleDrawer(drawer, expand = true) {
20272027 content.style.display = 'none';
20282028 }
20292029
2030- const chromeUaIdx = navigator.userAgent.lastIndexOf('Chrome/');
2031- const chromeVersion = navigator.userAgent.substring(chromeUaIdx + 7, navigator.userAgent.indexOf('.', chromeUaIdx));
2032-
20332030 // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height
2034- if (chromeUaIdx == -1 || Number(chromeVersion) < 123) {
2031+ if (!CSS.supports('field-sizing', 'content')) {
20352032 content.querySelectorAll('textarea.autoSetHeight').forEach(resetScrollHeight);
20362033 }
20372034}