1 11 package org.eclipse.pde.internal.ui.editor; 12 13 import org.eclipse.jface.text.*; 14 15 public class XMLDoubleClickStrategy implements ITextDoubleClickStrategy { 16 protected ITextViewer fText; 17 18 public void doubleClicked(ITextViewer part) { 19 int pos = part.getSelectedRange().x; 20 if (pos > 0) { 21 fText = part; 22 selectWord(pos); 23 } 24 } 25 26 protected boolean selectWord(int caretPos) { 27 28 IDocument doc = fText.getDocument(); 29 int startPos, endPos; 30 31 try { 32 33 int pos = caretPos; 34 char c; 35 36 while (pos >= 0) { 37 c = doc.getChar(pos); 38 if (!Character.isJavaIdentifierPart(c) && c != '.') 39 break; 40 --pos; 41 } 42 43 startPos = pos; 44 45 pos = caretPos; 46 int length = doc.getLength(); 47 48 while (pos < length) { 49 c = doc.getChar(pos); 50 if (!Character.isJavaIdentifierPart(c) && c != '.') 51 break; 52 ++pos; 53 } 54 55 endPos = pos; 56 selectRange(startPos, endPos); 57 return true; 58 59 } catch (BadLocationException x) { 60 } 61 62 return false; 63 } 64 65 private void selectRange(int startPos, int stopPos) { 66 int offset = startPos+1; 67 int length = stopPos - offset; 68 fText.setSelectedRange(offset, length); 69 } 70 } 71 | Popular Tags |