-
- int offset = caretEndRange;
- int length = currentText.length();
- while (--offset >= 0 && (Character.isJavaIdentifierPart(currentText.charAt(offset)) && !Character.isWhitespace(currentText.charAt(offset))))
- length--;
-
- int nameSpaceBeginRange = currentText.lastIndexOf(".", caretEndRange - 1); //$NON-NLS-1$
- if (nameSpaceBeginRange > length)
- length = nameSpaceBeginRange;
- int endRange = currentText.length();
- if (caretEndRange < endRange)
- endRange = caretEndRange;
- text.setSelection(length, endRange);
+ int replacementOffset = findPrefixMatchOffset(currentText, caretOffset, contents);
+
+// System.out.println("text: " + currentText);
+// System.out.println("proposal to fill: " + contents);
+// System.out.format("longest match of proposed contents found from text @ offset %d: \"%s[%s]%s\"%n",
+// replacementOffset,
+// currentText.substring(0, replacementOffset),
+// currentText.substring(replacementOffset, caretOffset),
+// currentText.substring(caretOffset));
+
+ // The text between [replaceOffset, caretOffset) will be replaced with `contents`
+ text.setSelection(replacementOffset, caretOffset);