|
87 | 87 | import java.io.IOException; |
88 | 88 | import java.lang.ref.WeakReference; |
89 | 89 | import java.util.ArrayList; |
| 90 | +import java.util.Comparator; |
90 | 91 | import java.util.HashSet; |
91 | 92 | import java.util.List; |
92 | 93 | import java.util.Map; |
@@ -737,14 +738,23 @@ public void actionPerformed(ActionEvent ae) { |
737 | 738 | String question = questionPane.getText(); |
738 | 739 | Map<String, String> prompts = PreferencesManager.getInstance().getPrompts(); |
739 | 740 |
|
740 | | - for (Map.Entry<String, String> entry : prompts.entrySet()) { |
741 | | - String promptKey = entry.getKey(); |
742 | | - String promptValue = entry.getValue(); |
| 741 | + // |
| 742 | + // To make sure the longest matching shortcut matches (i.e. |
| 743 | + // 'shortcutlong' is 'shortcut' is defined as well) let's |
| 744 | + // sort the shurtcuts in descending order; this guarantees |
| 745 | + // 'shortcut2' is matched before "shortcut" in the for loop |
| 746 | + // |
| 747 | + ArrayList<String> promptKeys = new ArrayList(); |
| 748 | + promptKeys.addAll(prompts.keySet()); |
| 749 | + promptKeys.sort(Comparator.reverseOrder()); |
743 | 750 |
|
744 | | - String toReplace = "/" + promptKey; |
| 751 | + for (String key: promptKeys) { |
| 752 | + String prompt = prompts.get(key); |
| 753 | + |
| 754 | + String toReplace = "/" + key; |
745 | 755 |
|
746 | 756 | if (question.contains(toReplace)) { |
747 | | - question = question.replace(toReplace, promptValue); |
| 757 | + question = question.replace(toReplace, prompt); |
748 | 758 | } |
749 | 759 | } |
750 | 760 | if (!question.isEmpty()) { |
|
0 commit comments