Update of /cvsroot/jreepad/jreepad/src/jreepad/editor
In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18867/src/jreepad/editor
Modified Files:
PlainTextEditor.java
Log Message:
moved selectWordUnderCursor() to PlainTextEditor;
code cleanup
Index: PlainTextEditor.java
===================================================================
RCS file: /cvsroot/jreepad/jreepad/src/jreepad/editor/PlainTextEditor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PlainTextEditor.java 5 Feb 2007 10:56:43 -0000 1.1
--- PlainTextEditor.java 7 Feb 2007 17:39:16 -0000 1.2
***************
*** 123,126 ****
--- 123,155 ----
}
+ public String selectWordUnderCursor()
+ {
+ try
+ {
+ String text = getText();
+ int startpos = getCaretPosition();
+ int endpos = startpos;
+ if (text.length() > 0)
+ {
+ // Select the character before/after the current position, and
+ // grow it until we hit whitespace...
+ while (startpos > 0 && !Character.isWhitespace(getText(startpos - 1, 1).charAt(0)))
+ startpos--;
+ while (endpos < (text.length()) && !Character.isWhitespace(getText(endpos, 1).charAt(0)))
+ endpos++;
+ if (endpos > startpos)
+ {
+ setSelectionStart(startpos);
+ setSelectionEnd(endpos);
+ return getSelectedText();
+ }
+ }
+ }
+ catch (BadLocationException e)
+ {
+ }
+ return "";
+ }
+
public void caretUpdate(CaretEvent e)
{
|