Skip to content
Browse files

Allow end-of-paragraph links on BLIP_SUBMITTED

Once the blip has been submitted, we can turn off our kludge that helps
avoid annotating the current insertion point.  This was on my to-do
list, and it was also suggested by Helge Jensen.
  • Loading branch information...
1 parent 632e35f commit 2893f3aa8b9a08aeca0d57f4f9a371eeced0fb71 @emk committed Sep 1, 2009
Showing with 31 additions and 19 deletions.
  1. +2 −5 src/buglinky/AdminView.java
  2. +29 −14 src/buglinky/BlipProcessor.java
View
7 src/buglinky/AdminView.java
@@ -37,11 +37,8 @@
/** The instructions to display when we join a wave. */
private static final String INSTRUCTIONS =
"buglinky will attempt to link \"issue #NNN\" to the Wave issue " +
- "tracker.\n\n" +
- "Note that the issue number must not be at the very end of " +
- "a paragraph. This is temporary kludge to discourage buglinky from " +
- "annotating your insertion point as you type.\n\n" +
- "Once you've set your preferences, you can delete this blip.";
+ "tracker (Once you've set your preferences, you can delete this " +
+ "blip.)";
/** Get the URL prefix we'll use to link to bugs. */
static String getBugUrl(Wavelet wavelet) {
View
43 src/buglinky/BlipProcessor.java
@@ -16,7 +16,8 @@
package buglinky;
import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Map.Entry;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -55,13 +56,20 @@ static void applyProcessorsToChangedBlips(
ArrayList<BlipProcessor> processors,
RobotMessageBundle bundle, String myAddress) {
// Find all affected blips.
- HashSet<Blip> changedBlips = new HashSet<Blip>();
+ HashMap<Blip, Boolean> changedBlips = new HashMap<Blip, Boolean>();
for (Event e : bundle.getEvents()) {
if (!e.getModifiedBy().equals(myAddress)) {
switch (e.getType()) {
- case BLIP_SUBMITTED: // The user has clicked "Done".
- case BLIP_VERSION_CHANGED: // The blip has been updated.
- changedBlips.add(e.getBlip());
+ // The blip has been updated. Assume that the user is not yet
+ // done editing.
+ case BLIP_VERSION_CHANGED:
+ changedBlips.put(e.getBlip(), true);
+ break;
+
+ // The user has clicked "Done". Assume that the user has
+ // finished editing.
+ case BLIP_SUBMITTED:
+ changedBlips.put(e.getBlip(), false);
break;
default:
@@ -71,9 +79,9 @@ static void applyProcessorsToChangedBlips(
}
// Process all affected blips.
- for (Blip blip : changedBlips) {
+ for (Entry<Blip, Boolean> entry : changedBlips.entrySet()) {
for (BlipProcessor processor : processors)
- processor.processBlip(blip);
+ processor.processBlip(entry.getKey(), entry.getValue());
}
}
@@ -82,15 +90,17 @@ static void applyProcessorsToChangedBlips(
* is not re-entrant.
*
* @param blip The blip to process.
+ * @param userIsCurrentlyEditing Is user still editing?
*/
- public void processBlip(Blip blip) {
+ public void processBlip(Blip blip, Boolean userIsCurrentlyEditing) {
LOG.fine("Processing blip " + blip.getBlipId() + " with " +
this.getClass().getName());
// Adapted from http://senikk.com/min-f%C3%B8rste-google-wave-robot,
// a robot which links to @names on Twitter.
TextView doc = blip.getDocument();
totalCorrection = 0; // Reset.
- Matcher matcher = getCompiledPattern().matcher(doc.getText());
+ Pattern pattern = getCompiledPattern(userIsCurrentlyEditing);
+ Matcher matcher = pattern.matcher(doc.getText());
while (matcher.find()) {
LOG.fine("Found match to process: " + matcher.group());
int start = matcher.start() + totalCorrection;
@@ -106,11 +116,13 @@ public void processBlip(Blip blip) {
/**
* Take our simple pattern, add some kludges, and compile it.
+ *
+ * @param userIsCurrentlyEditing Is user still editing?
*/
- private Pattern getCompiledPattern() {
- // KLUDGE - Try to avoid annotating text while the user's caret is
- // still inside the annotation. For example, imagine that the user
- // types:
+ private Pattern getCompiledPattern(Boolean userIsCurrentlyEditing) {
+ // KLUDGE - If the user is currently editing, try to avoid annotating
+ // text while the user's caret is still inside the annotation. For
+ // example, imagine that the user types:
//
// bug #12|
//
@@ -133,7 +145,10 @@ private Pattern getCompiledPattern() {
// don't want to use the last character that would normally be matched
// by getPattern as our negative lookahead, so we use a possessive
// qualifier to avoid backtracking.
- return Pattern.compile("(?:" + getPattern() + "){1}+(?!\\r|\\n)");
+ if (userIsCurrentlyEditing)
+ return Pattern.compile("(?:" + getPattern() + "){1}+(?!\\r|\\n)");
+ else
+ return Pattern.compile(getPattern());
}
/**

0 comments on commit 2893f3a

Please sign in to comment.
Something went wrong with that request. Please try again.