Skip to content

Commit

Permalink
Fix a case of non-mnemonics
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Mar 15, 2024
1 parent c8c20aa commit 9c1c434
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/org/openide/awt/AbstractMnemonicsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public void setText(String text, Locale locale) {
int i = Mnemonics.findMnemonicAmpersand(text);
if (i < 0) {
putValue(Action.NAME, text);
putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, -1);
} else {
putValue(Action.NAME, text.substring(0, i) + text.substring(i + 1));
Mnemonics.setMnemonicAndIndex(this, text.charAt(i + 1), i, locale);
Expand Down
4 changes: 2 additions & 2 deletions test/src/org/openide/awt/MnemonicsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ public void testSetLocalizedTextAction() {
AbstractMnemonicsAction item = new MyAbstractMnemonicsAction();

Assert.assertEquals("Simple Text", item.getValue(Action.NAME));
Assert.assertEquals(0, item.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY));
Assert.assertEquals(isMacOS()? -1: 0, item.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY));
//
item.setText("Rock & Roll", new Locale("en"));
Assert.assertEquals("Rock & Roll", item.getValue(Action.NAME));
Assert.assertEquals(0, item.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY)); // default: 0
Assert.assertEquals(-1, item.getValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY));
//
item.setText("&\u041F\u043E\u0438\u0441\u043A", new Locale("ru"));
Assert.assertEquals("\u041F\u043E\u0438\u0441\u043A", item.getValue(Action.NAME));
Expand Down

0 comments on commit 9c1c434

Please sign in to comment.