<commit_before>// code adapted from https://stackoverflow.com/questions/17731083/how-to-autogrow-text-area-with-css3
import angular from 'angular';
import {
  clamp,
} from '../utils.js';

function genDirectiveConf() {
    return {
      restrict: 'A',
      link: (scope, element, attributes) => {

        const minRows = parseInt(attributes.minRows) || 1;
        const maxRows = parseInt(attributes.maxRows) || 999;
        const area = element[0];


        /* 
         * necessary styling 
         */

        //Height math depends on content box sizing
        area.style.boxSizing = 'content-box';
        // no reason to allow manual resizing, as it will automatically be resized on first input
        area.style.resize = 'none'; 



        /*
         * calculate line-height
         */
        let lineHeight, offsets;
        function updateLineHeightAndOffsets() {
          const originalContent = area.value;
          const originalPlaceholder = area.placeholder;

          // reduce to one line in height, so lineHeight can be calculated correctly
          area.value = '';
          area.placeholder = '';
          area.style.height = '0px';
          
          const style = window.getComputedStyle(area, null);
          offsets = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);

          lineHeight = area.scrollHeight - offsets;
          
          area.value = originalContent;
          area.placeholder = originalPlaceholder;
          return { lineHeight, offsets };
        }
        updateLineHeightAndOffsets();



        /*
         * update height
         */

        function updateHeight() {
          stopObservingStyleChange(); // we don't want the style listener to trigger due to the height-change


          area.style.height = '0px';
          const height = area.scrollHeight - offsets;
          
          const lines = clamp(Math.floor(height/lineHeight), minRows, maxRows);
          if(height > lineHeight*maxRows) {
            area.style.overflowY = 'scroll';
          } else {
            area.style.overflowY = 'hidden';
          }
          area.style.height = lines * lineHeight + 'px';
<commit_msg>Fixed issue where scroll-bar was shown to early in autogrowing textarea.<commit_after>// code adapted from https://stackoverflow.com/questions/17731083/how-to-autogrow-text-area-with-css3
import angular from 'angular';
import {
  clamp,
} from '../utils.js';

function genDirectiveConf() {
    return {
      restrict: 'A',
      link: (scope, element, attributes) => {

        const minRows = parseInt(attributes.minRows) || 1;
        const maxRows = parseInt(attributes.maxRows) || 999;
        const area = element[0];


        /* 
         * necessary styling 
         */

        //Height math depends on content box sizing
        area.style.boxSizing = 'content-box';
        // no reason to allow manual resizing, as it will automatically be resized on first input
        area.style.resize = 'none'; 



        /*
         * calculate line-height
         */
        let lineHeight, offsets;
        function updateLineHeightAndOffsets() {
          const originalContent = area.value;
          const originalPlaceholder = area.placeholder;

          // reduce to one line in height, so lineHeight can be calculated correctly
          area.value = '';
          area.placeholder = '';
          area.style.height = '0px';
          
          const style = window.getComputedStyle(area, null);
          offsets = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);

          lineHeight = area.scrollHeight - offsets;
          
          area.value = originalContent;
          area.placeholder = originalPlaceholder;
          return { lineHeight, offsets };
        }
        updateLineHeightAndOffsets();



        /*
         * update height
         */

        function updateHeight() {
          stopObservingStyleChange(); // we don't want the style listener to trigger due to the height-change


          area.style.height = '0px';
          const height = area.scrollHeight - offsets;
          
          const lines = clamp(Math.floor(height/lineHeight), minRows, maxRows);
          if(height < lineHeight * (maxRows + 1)) {
            area.style.overflowY = 'hidden';
          } else {
            area.style.overflowY = 'scroll';
          }
          area.style.height = lines * lineHeight + 'px';

{'fraction_non_alphanumeric': 0.10042879711126157, 'fraction_numerical': 0.007447528774542992, 'mean_word_length': 1.9645484949832777, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '985742', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1126, 'n_words': 306}