1 11 12 package org.eclipse.jdt.internal.ui.text.java; 13 14 import org.eclipse.jface.text.BadLocationException; 15 import org.eclipse.jface.text.IDocument; 16 import org.eclipse.jface.text.IRegion; 17 import org.eclipse.jface.text.ITextViewer; 18 import org.eclipse.jface.text.TextUtilities; 19 20 23 public class JavaStringDoubleClickSelector extends JavaDoubleClickSelector { 24 25 private String fPartitioning; 26 27 32 public JavaStringDoubleClickSelector(String partitioning) { 33 super(); 34 fPartitioning= partitioning; 35 } 36 37 40 public void doubleClicked(ITextViewer textViewer) { 41 42 int offset= textViewer.getSelectedRange().x; 43 44 if (offset < 0) 45 return; 46 47 IDocument document= textViewer.getDocument(); 48 49 IRegion region= match(document, offset); 50 if (region != null && region.getLength() >= 2) { 51 textViewer.setSelectedRange(region.getOffset() + 1, region.getLength() - 2); 52 } else { 53 region= selectWord(document, offset); 54 textViewer.setSelectedRange(region.getOffset(), region.getLength()); 55 } 56 } 57 58 private IRegion match(IDocument document, int offset) { 59 try { 60 if ((document.getChar(offset) == '"') || (document.getChar(offset) == '\'') || 61 (document.getChar(offset - 1) == '"') || (document.getChar(offset - 1) == '\'')) 62 { 63 return TextUtilities.getPartition(document, fPartitioning, offset, true); 64 } 65 } catch (BadLocationException e) { 66 } 67 68 return null; 69 } 70 } 71 | Popular Tags |