Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-30217

All text fields can cut off the last few characters / Phantom selection highlighting appears at the end of text fields with some texts

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 13w36b, Minecraft 13w37a, Minecraft 13w38a, Minecraft 13w38b, Minecraft 13w38c, Minecraft 13w39b, Minecraft 13w41a, Minecraft 1.7.1, Minecraft 1.7.2, Minecraft 1.7.3, Minecraft 1.7.4, Minecraft 14w03b, Minecraft 14w04b, Minecraft 1.7.5, Minecraft 14w10c, Minecraft 14w11b, Minecraft 1.7.6-pre2, Minecraft 14w26c, Minecraft 1.7.10, Minecraft 1.8, Minecraft 1.8.1-pre3, Minecraft 1.8.1, Minecraft 1.8.2-pre1, Minecraft 1.8.8, Minecraft 15w32c, Minecraft 1.8.9, Minecraft 16w02a, Minecraft 1.9, Minecraft 1.9.1 Pre-Release 3, Minecraft 1.10.2, Minecraft 16w42a, Minecraft 1.12.1, Minecraft 1.12.2, Minecraft 18w02a, Minecraft 18w20c, Minecraft 1.13.1, Minecraft 1.13.2-pre2, Minecraft 1.13.2, Minecraft 18w44a, Minecraft 19w12b, Minecraft 19w13b, Minecraft 1.14.4 Pre-Release 4, 20w11a, 20w12a, 1.16.1, 1.16.2 Pre-release 1, 1.16.4, 20w51a, 21w03a, 21w05b, 21w06a, 1.17, 1.19, 1.19.2, 1.19.3, 1.20.3 Release Candidate 1
    • Confirmed
    • UI
    • Low
    • Platform

      The bug

      All text fields can cut off the last few characters and display them incorrectly, see for example command_block.png.

      How to reproduce

      1. Paste (or write) the following text in chat or in a command block
        iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii_
        
      2. Look at the end of the text field
        The last characters are cut off and are displayed incorrectly

      Code analysis

      The following is based on decompiled version of Minecraft 1.9 using MCP 9.24 beta. All method and class names are the names used in the decompiled version.

      The reason why this happens is very likely that the method net.minecraft.client.gui.GuiTextField.setSelectionPos(int) calls the method net.minecraft.client.gui.FontRenderer.trimStringToWidth(String, int) without reversing the text of the text field. This is a problem because the text of the textfield should not be trimmed at the end, but instead at the beginning. To prevent the underscore from overflowing over the text field, the width could be reduced by the width of the underscore.

      /**
       * Sets the position of the selection anchor (i.e. position the selection was started at)
       */
      public void setSelectionPos(int p_146199_1_)
      {
          int i = this.text.length();
      
          if (p_146199_1_ > i)
          {
              p_146199_1_ = i;
          }
      
          if (p_146199_1_ < 0)
          {
              p_146199_1_ = 0;
          }
      
          this.selectionEnd = p_146199_1_;
      
          if (this.fontRendererInstance != null)
          {
              if (this.lineScrollOffset > i)
              {
                  this.lineScrollOffset = i;
              }
      
              // Replaced this
              //int j = this.getWidth();
              //String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), j);
              int j = this.getWidth() - this.fontRendererInstance.getCharWidth('_');
              String s = this.fontRendererInstance.trimStringToWidth(this.text.substring(this.lineScrollOffset), j, true);
              
              
              int k = s.length() + this.lineScrollOffset;
      
              if (p_146199_1_ == this.lineScrollOffset)
              {
                  this.lineScrollOffset -= this.fontRendererInstance.trimStringToWidth(this.text, j, true).length();
              }
      
              if (p_146199_1_ > k)
              {
                  this.lineScrollOffset += p_146199_1_ - k;
              }
              else if (p_146199_1_ <= this.lineScrollOffset)
              {
                  this.lineScrollOffset -= this.lineScrollOffset - p_146199_1_;
              }
      
              this.lineScrollOffset = MathHelper.clamp_int(this.lineScrollOffset, 0, i);
          }
      }
      

        1. MC-30217.png
          MC-30217.png
          283 kB
        2. command_block.png
          command_block.png
          258 kB
        3. 2018-01-13_18.36.06.png
          2018-01-13_18.36.06.png
          45 kB

            Unassigned Unassigned
            kumasasa [Mod] Kumasasa
            Votes:
            14 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              CHK: