mojira.dev
MC-260563

Text fields persistently highlight when you press shift

The bug

I've noticed this issue for a few years and, up until now, I never knew what the issue was. I would press shift to capitalise a character then go to click and the text starts to be highlighted. I found that you have to press either control, alt, or arrow keys to stop highlighting the text field but this isn't ideal as most players wouldn't know this.

To reproduce

  1. Type anything in a text field then press shift and let go

  2. Move your caret by clicking

  3. Text should be highlighted

  4. Press either the ctrl, alt, or arrow keys to deselect

I expected to only select text when I hold shift, not when I press it once.

Code analysis

Code analysis by @unknown can be found in this comment.

Related issues

Attachments

Comments

migrated
[media]
violine1101

Hard to show on video, but the steps to reproduce explain it pretty well. Effectively, the shift key still affects the cursor after being released. In the video I just attached, the shift key is never held when I'm clicking into the text field.

migrated

This issue is due to net.minecraft.client.gui.components.EditBox#moveCursorTo testing if the Shift key is down by reading the shiftPressed field, which is not updated properly before moveCursor is called in mouseClicked.

This shiftPressed field is useless because it is private and only used by moveCursorTo and keyPressed, which updates it with a call to net.minecraft.client.gui.screens.Screen#hasShiftDown. keyPressed sets shiftPressed to false before calling deleteText at two places, but this is useless because shiftPressed is only ever read by moveCursor.

Fixing this issue should be as easy as completely removing the shiftPressed field in EditBox, and replacing it in moveCursorTo with a call to Screen#hasShiftDown.

ChemistryIsCool

Affects 1.20.1

migrated

(Unassigned)

Confirmed

Platform

Low

UI

1.19.3, 1.19.4 Pre-release 1, 1.20, 1.20.1

Retrieved