Issue #642 fix for finding double instances of words

Former-commit-id: 5d3001a8bdd5ab6b89efe54e7d3c6b3266e880ec
This commit is contained in:
Matt Nash 2012-05-21 08:43:30 -05:00
parent cb4b153cad
commit bed5ec6876

View file

@ -267,8 +267,9 @@ public abstract class AbstractSessionView extends ViewPart {
cal.setTimeInMillis(timestamp); cal.setTimeInMillis(timestamp);
String time = String.format("%1$tI:%1$tM:%1$tS %1$Tp", cal); String time = String.format("%1$tI:%1$tM:%1$tS %1$Tp", cal);
if (!CollaborationDataManager.getInstance() UserId myUser = CollaborationDataManager.getInstance()
.getCollaborationConnection(true).getUser().equals(userId) .getCollaborationConnection(true).getUser();
if (!myUser.equals(userId)
&& Activator.getDefault().getPreferenceStore() && Activator.getDefault().getPreferenceStore()
.getBoolean("notifications")) { .getBoolean("notifications")) {
createNotifier(userId, time, body); createNotifier(userId, time, body);
@ -297,50 +298,70 @@ public abstract class AbstractSessionView extends ViewPart {
List<StyleRange> ranges = new ArrayList<StyleRange>(); List<StyleRange> ranges = new ArrayList<StyleRange>();
if (alertWords != null) { if (alertWords != null) {
for (AlertWord keyword : alertWords) { for (AlertWord keyword : alertWords) {
if (sb.toString().toLowerCase() String text = keyword.getText().toLowerCase();
.contains(keyword.getText().toLowerCase())) { if (sb.toString().toLowerCase().contains(text)) {
Font font = null; String lowerCase = sb.toString().toLowerCase();
if (fonts.containsKey(keyword.getFont())) { // getting the current length of the text
font = fonts.get(keyword.getFont()); int currentLength = messagesText.getCharCount();
} else { int index = lowerCase.indexOf(text);
FontData fd = StringConverter.asFontData(keyword while (index >= 0) {
.getFont()); Font font = null;
font = new Font(Display.getCurrent(), fd); // storing off fonts so we don't leak
fonts.put(keyword.getFont(), font); if (fonts.containsKey(keyword.getFont())) {
} font = fonts.get(keyword.getFont());
RGB rgb = new RGB(keyword.getRed(), keyword.getGreen(), } else {
keyword.getBlue()); FontData fd = StringConverter.asFontData(keyword
Color color = null; .getFont());
if (colors.containsKey(rgb)) { font = new Font(Display.getCurrent(), fd);
color = colors.get(rgb); fonts.put(keyword.getFont(), font);
} else { }
color = new Color(Display.getCurrent(), rgb);
colors.put(rgb, color);
}
TextStyle style = new TextStyle(font, color, null);
StyleRange keywordRange = new StyleRange(style);
keywordRange.start = messagesText.getCharCount()
+ sb.toString().toLowerCase()
.indexOf(keyword.getText().toLowerCase());
keywordRange.length = keyword.getText().length();
// compare to see if this position is already styled RGB rgb = new RGB(keyword.getRed(), keyword.getGreen(),
// List<StyleRange> rnges = new ArrayList<StyleRange>(); keyword.getBlue());
// rnges.addAll(ranges); Color color = null;
// for (StyleRange range : rnges) { // using the stored colors so we don't leak
// if (range.start >= keywordRange.start if (colors.containsKey(rgb)) {
// && (range.start + range.length) >= (keywordRange.start)) color = colors.get(rgb);
// { } else {
// if (range.length < keywordRange.length) { color = new Color(Display.getCurrent(), rgb);
// ranges.remove(range); colors.put(rgb, color);
// ranges.add(keywordRange); }
// } else { TextStyle style = new TextStyle(font, color, null);
// ranges.add(keywordRange); StyleRange keywordRange = new StyleRange(style);
// } keywordRange.start = currentLength + index;
// } keywordRange.length = keyword.getText().length();
// }
ranges.add(keywordRange); // compare to see if this position is already styled
executeSightsSounds(keyword); // List<StyleRange> rnges = new ArrayList<StyleRange>();
// rnges.addAll(ranges);
// for (StyleRange range : rnges) {
// if (range.start >= keywordRange.start
// && (range.start + range.length) >=
// (keywordRange.start))
// {
// if (range.length < keywordRange.length) {
// ranges.remove(range);
// ranges.add(keywordRange);
// } else {
// ranges.add(keywordRange);
// }
// }
// }
ranges.add(keywordRange);
// only execute things if the same user didn't type it
if (!myUser.equals(userId)) {
executeSightsSounds(keyword);
}
System.out.println("index before : " + index);
// need to handle all instances of the keyword within
// the chat
index = lowerCase.indexOf(text, text.length() + index);
System.out.println("index after : " + index);
System.out.println("messagesText.getCharCount() : "
+ messagesText.getCharCount());
}
} }
} }
} }