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

Tab completion works incorrect when text is already selected

XMLWordPrintable

    • Community Consensus

      The bug

      When you try to tab complete a command or player name but you selected the command partwise, the completion will append to the not selected characters.

      How to reproduce

      1. Type the following in the chat (you need to have cheats enabled)
        /particle snow
        
      2. Now select a part of this text (by pressing SHIFT and using the left arrow key) (see "Chat selection.png")
        /particle s[SELECTION END]now[SELECTION START]
        
      3. Press TAB

      The reason

      The reason why this happens is because the autocompletePlayerNames() method of the net.minecraft.client.gui.GuiChat class calls the deleteFromCursor(int p_146175_1_) method of the net.minecraft.client.gui.GuiTextField class (MCP 1.8 names). The latter however ignores the parameter in case text is selected (this is intended) and only removes the selected text. One way to fix this could be to call this method with a deletion index of 0 before trying to remove the prefix. This way it would in case text is selected, first remove the selected text and then remove the prefix.

      public void autocompletePlayerNames()
      {
      	String var3;
      
      	if (this.playerNamesFound)
      	{
      		// Added the following line
      		this.inputField.deleteFromCursor(0);        	
      		this.inputField.deleteFromCursor(this.inputField.func_146197_a(-1, this.inputField.getCursorPosition(), false) - this.inputField.getCursorPosition());
      
      		if (this.autocompleteIndex >= this.foundPlayerNames.size())
      		{
      			this.autocompleteIndex = 0;
      		}
      	}
      	
      	//...
      	
      }
      

      As this method is also called when the prefixes do not match it would need to be changed in the onAutocompleteResponse(String[] p_146406_1_) method as well.

      public void onAutocompleteResponse(String[] p_146406_1_)
      {
      	if (this.waitingOnAutocomplete)
      	{
      		//...
      		
      		if (var7.length() > 0 && !var6.equalsIgnoreCase(var7))
      		{
      			// Added the following line
      			this.inputField.deleteFromCursor(0);
      			this.inputField.deleteFromCursor(this.inputField.func_146197_a(-1, this.inputField.getCursorPosition(), false) - this.inputField.getCursorPosition());
      			this.inputField.writeText(var7);
      		}
      		
      		//...
      	}
      }
      

            grum [Mojang] Grum (Erik Broes)
            marcono1234 [Mod] Marcono1234
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: