| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,6 +92,14 @@ public abstract class InputHandler extends KeyAdapter | |||
| 92 | 92 | ||
| 93 | 93 | private static Map<String, ActionListener> actions; | |
| 94 | 94 | ||
| 95 | + private static final Map<String, String> bracketsAndQuotesMap = new HashMap<String, String>(){ | ||
| 96 | + {put("(", ")");} | ||
| 97 | + {put("{", "}");} | ||
| 98 | + {put("[", "]");} | ||
| 99 | + {put("\"", "\"");} | ||
| 100 | + {put("\'", "\'");} | ||
| 101 | + }; | ||
| 102 | + | ||
| 95 | 103 | static | |
| 96 | 104 | { | |
| 97 | 105 | actions = new HashMap<String, ActionListener>(); | |
@@ -1157,13 +1165,34 @@ public void actionPerformed(ActionEvent evt) | |||
| 1157 | 1165 | StringBuilder sb = new StringBuilder(); | |
| 1158 | 1166 | for(int i = 0; i < repeatCount; i++) | |
| 1159 | 1167 | sb.append(str); | |
| 1160 | - textArea.overwriteSetSelectedText(sb.toString()); | ||
| 1168 | + if (hasBracketsAndQuotes(str)) { | ||
| 1169 | + matchBracketsAndQuotes(str, evt, textArea, sb); | ||
| 1170 | + } else { | ||
| 1171 | + textArea.overwriteSetSelectedText(sb.toString()); | ||
| 1172 | + } | ||
| 1161 | 1173 | } | |
| 1162 | 1174 | else | |
| 1163 | 1175 | { | |
| 1164 | 1176 | textArea.getToolkit().beep(); | |
| 1165 | 1177 | } | |
| 1166 | 1178 | } | |
| 1179 | + | ||
| 1180 | + public void matchBracketsAndQuotes(String str, ActionEvent evt, | ||
| 1181 | + JEditTextArea textArea, StringBuilder sb) | ||
| 1182 | + { | ||
| 1183 | + sb.append(bracketsAndQuotesMap.get(str)); | ||
| 1184 | + textArea.overwriteSetSelectedText(sb.toString()); | ||
| 1185 | + InputHandler.PREV_CHAR.actionPerformed(evt); | ||
| 1186 | + } | ||
| 1187 | + | ||
| 1188 | + public boolean hasBracketsAndQuotes(String str){ | ||
| 1189 | + for (String bracketsAndQuotes : bracketsAndQuotesMap.keySet()) | ||
| 1190 | + { | ||
| 1191 | + if (str.equals(bracketsAndQuotes)) | ||
| 1192 | + return true; | ||
| 1193 | + } | ||
| 1194 | + return false; | ||
| 1195 | + } | ||
| 1167 | 1196 | } | |
| 1168 | 1197 | ||
| 1169 | 1198 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments