@@ -268,78 +268,76 @@ private void addQty(final int delta) {
268268
269269 @ Override
270270 protected void keyTyped (final char character , final int key ) throws IOException {
271- if (!this .checkHotbarKeys (key )) {
272- // Commas are virtual (auto-formatted), so we need to skip over them when
273- // pressing backspace or delete, otherwise the comma just gets re-added and
274- // the user's keypress appears to do nothing.
275- this .commaSkipped = false ;
276-
277- if (key == Keyboard .KEY_BACK ) {
278- String text = this .sizeField .getText ();
279- int cursor = this .sizeField .getCursorPosition ();
280-
281- if (cursor > 0 && text .charAt (cursor - 1 ) == ',' ) {
282- this .sizeField .setCursorPosition (cursor - 1 );
283- this .commaSkipped = true ;
284- }
285- } else if (key == Keyboard .KEY_DELETE ) {
286- String text = this .sizeField .getText ();
287- int cursor = this .sizeField .getCursorPosition ();
271+ // Commas are virtual (auto-formatted), so we need to skip over them when
272+ // pressing backspace or delete, otherwise the comma just gets re-added and
273+ // the user's keypress appears to do nothing.
274+ this .commaSkipped = false ;
275+
276+ if (key == Keyboard .KEY_BACK ) {
277+ String text = this .sizeField .getText ();
278+ int cursor = this .sizeField .getCursorPosition ();
279+
280+ if (cursor > 0 && text .charAt (cursor - 1 ) == ',' ) {
281+ this .sizeField .setCursorPosition (cursor - 1 );
282+ this .commaSkipped = true ;
283+ }
284+ } else if (key == Keyboard .KEY_DELETE ) {
285+ String text = this .sizeField .getText ();
286+ int cursor = this .sizeField .getCursorPosition ();
288287
289- if (cursor < text .length () && text .charAt (cursor ) == ',' ) {
290- this .sizeField .setCursorPosition (cursor + 1 );
291- this .commaSkipped = true ;
292- }
288+ if (cursor < text .length () && text .charAt (cursor ) == ',' ) {
289+ this .sizeField .setCursorPosition (cursor + 1 );
290+ this .commaSkipped = true ;
293291 }
292+ }
294293
295- if ((key == Keyboard .KEY_DELETE || key == Keyboard .KEY_RIGHT
296- || key == Keyboard .KEY_LEFT || key == Keyboard .KEY_BACK
297- || Character .isDigit (character )) && this .sizeField .textboxKeyTyped (character , key )) {
294+ if ((key == Keyboard .KEY_DELETE || key == Keyboard .KEY_RIGHT
295+ || key == Keyboard .KEY_LEFT || key == Keyboard .KEY_BACK
296+ || Character .isDigit (character )) && this .sizeField .textboxKeyTyped (character , key )) {
298297
299- String out = this .sizeField .getText ();
298+ String out = this .sizeField .getText ();
300299
301- // Remove commas from thousand separators
302- out = out .replaceAll ("," , "" );
300+ // Remove commas from thousand separators
301+ out = out .replaceAll ("," , "" );
303302
304- // Remove leading zeros
305- while (out .startsWith ("0" ) && out .length () > 1 ) {
306- out = out .substring (1 );
307- }
303+ // Remove leading zeros
304+ while (out .startsWith ("0" ) && out .length () > 1 ) {
305+ out = out .substring (1 );
306+ }
308307
309- if (out .isEmpty ()) {
310- if (isOverrideMode ()) {
311- // In per-slot mode, empty field clears the override
312- this .currentMaxSlotSize = 0 ;
313- CellsNetworkHandler .INSTANCE .sendToServer (new PacketSetMaxSlotSize (-1 ));
314- }
315- // In global mode, empty field is just unsaved (no packet sent)
316- } else {
317- try {
318- // Parse as long to handle large values
319- this .onQtyChanged (Long .parseLong (out ));
320- } catch (final NumberFormatException e ) {
321- // Parsing failed should mean we exceeded Long.MAX_VALUE, so clamp to max
322- this .onQtyChanged (Long .MAX_VALUE );
323- }
308+ if (out .isEmpty ()) {
309+ if (isOverrideMode ()) {
310+ // In per-slot mode, empty field clears the override
311+ this .currentMaxSlotSize = 0 ;
312+ CellsNetworkHandler .INSTANCE .sendToServer (new PacketSetMaxSlotSize (-1 ));
324313 }
314+ // In global mode, empty field is just unsaved (no packet sent)
315+ } else {
316+ try {
317+ // Parse as long to handle large values
318+ this .onQtyChanged (Long .parseLong (out ));
319+ } catch (final NumberFormatException e ) {
320+ // Parsing failed should mean we exceeded Long.MAX_VALUE, so clamp to max
321+ this .onQtyChanged (Long .MAX_VALUE );
322+ }
323+ }
325324
326- // After all processing (including potential reformat), if we
327- // pre-skipped a comma for backspace/delete, nudge the cursor past
328- // the comma so it lands on the correct side. This runs even when
329- // onQtyChanged didn't reformat (text unchanged).
330- if (this .commaSkipped ) {
331- String finalText = this .sizeField .getText ();
332- int cur = this .sizeField .getCursorPosition ();
333-
334- if (cur < finalText .length () && finalText .charAt (cur ) == ',' ) {
335- this .sizeField .setCursorPosition (cur + 1 );
336- }
325+ // After all processing (including potential reformat), if we
326+ // pre-skipped a comma for backspace/delete, nudge the cursor past
327+ // the comma so it lands on the correct side. This runs even when
328+ // onQtyChanged didn't reformat (text unchanged).
329+ if (this .commaSkipped ) {
330+ String finalText = this .sizeField .getText ();
331+ int cur = this .sizeField .getCursorPosition ();
337332
338- this .commaSkipped = false ;
333+ if (cur < finalText .length () && finalText .charAt (cur ) == ',' ) {
334+ this .sizeField .setCursorPosition (cur + 1 );
339335 }
340- } else {
341- super .keyTyped (character , key );
342- }
336+
337+ this .commaSkipped = false ;
338+ }
339+ } else {
340+ super .keyTyped (character , key );
343341 }
344342 }
345343}
0 commit comments