} else { // no selection, get current word try { searchWord = Utilities.getIdentifier((BaseDocument)target.getDocument(), dotPos); revert = !Boolean.TRUE.equals(props.put(SettingsNames.FIND_WHOLE_WORDS, Boolean.TRUE));
/** * Helper method to get the identifier under the mouse cursor. * * @return string containing identifier under mouse cursor. */ public String getIdentifierUnderCursor() { String word = null; try { JTextComponent component = extEditorUI.getComponent(); BaseTextUI ui = (BaseTextUI) component.getUI(); int pos = ui.viewToModel(component, lastMouseEvent.getPoint()); if (pos >= 0) { BaseDocument doc = (BaseDocument) component.getDocument(); int eolPos = Utilities.getRowEnd(doc, pos); Rectangle eolRect = ui.modelToView(component, eolPos); int lineHeight = extEditorUI.getLineHeight(); if (lastMouseEvent.getX() <= eolRect.x && lastMouseEvent.getY() <= eolRect.y + lineHeight) { word = Utilities.getIdentifier(doc, pos); } } } catch (BadLocationException e) { // word will be null } return word; }
/** Get the selection if there's any or get the identifier around * the position if there's no selection. */ public static String getSelectionOrIdentifier(JTextComponent c, int offset) throws BadLocationException { Document doc = c.getDocument(); Caret caret = c.getCaret(); String ret; if (caret.isSelectionVisible()) { ret = c.getSelectedText(); if (ret != null) return ret; } if (doc instanceof BaseDocument){ ret = getIdentifier((BaseDocument) doc, caret.getDot()); } else { ret = getWord(c, offset); } return ret; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { FindSupport findSupport = FindSupport.getFindSupport(); Caret caret = target.getCaret(); int dotPos = caret.getDot(); HashMap props = new HashMap(findSupport.getFindProperties()); String searchWord = null; if (caret.isSelectionVisible()) { // valid selection searchWord = target.getSelectedText(); props.put(SettingsNames.FIND_WHOLE_WORDS, Boolean.FALSE); } else { // no selection, get current word try { searchWord = Utilities.getIdentifier((BaseDocument) target.getDocument(), dotPos); props.put(SettingsNames.FIND_WHOLE_WORDS, Boolean.TRUE); } catch (BadLocationException e) { e.printStackTrace(); } } if (searchWord != null) { int n = searchWord.indexOf('\n'); if (n >= 0) searchWord = searchWord.substring(0, n); props.put(SettingsNames.FIND_WHAT, searchWord); findSupport.putFindProperties(props); findSupport.find(null, false); } } } }
/** * Get the selection if there's any or get the identifier around the * position if there's no selection. */ public static String getSelectionOrIdentifier(JTextComponent c, int offset) throws BadLocationException { Document doc = c.getDocument(); Caret caret = c.getCaret(); String ret; if (caret.isSelectionVisible()) { ret = c.getSelectedText(); if (ret != null) return ret; } if (doc instanceof BaseDocument) { ret = getIdentifier((BaseDocument) doc, caret.getDot()); } else { ret = getWord(c, offset); } return ret; }
/** Helper method to get the identifier * under the mouse cursor. * @return string containing identifier under * mouse cursor. */ public String getIdentifierUnderCursor() { String word = null; if (!isGlyphGutterMouseEvent(lastMouseEvent)) { try { JTextComponent component = extEditorUI.getComponent(); BaseTextUI ui = (BaseTextUI)component.getUI(); Point lmePoint = getLastMouseEventPoint(); int pos = ui.viewToModel(component, lmePoint); if (pos >= 0) { BaseDocument doc = (BaseDocument)component.getDocument(); int eolPos = Utilities.getRowEnd(doc, pos); Rectangle eolRect = ui.modelToView(component, eolPos); int lineHeight = extEditorUI.getLineHeight(); if (lmePoint.x <= eolRect.x && lmePoint.y <= eolRect.y + lineHeight) { word = Utilities.getIdentifier(doc, pos); } } } catch (BadLocationException e) { // word will be null } } return word; }
if (lineBounds.containsInclusive(caretOffset) && fileObject != null) { try { String identifier = Utilities.getIdentifier(doc, caretOffset); if (identifier != null && identifier.startsWith("$")) { PHPParseResult parseResult = (PHPParseResult) context.parserResult;
try { ident = Utilities.getIdentifier( doc, caret); } catch (BadLocationException e) { ErrorManager.getDefault().notify(e);