public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); if(!textArea.isEditable()) { textArea.getToolkit().beep(); return; } if(textArea.getSelectionStart() != textArea.getSelectionEnd()) { textArea.setSelectedText(""); } else { int caret = textArea.getCaretPosition(); if(caret == textArea.getDocumentLength()) { textArea.getToolkit().beep(); return; } try { textArea.getDocument().remove(caret,1); } catch(BadLocationException bl) { bl.printStackTrace(); } } }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); int caret = textArea.getCaretPosition(); int line = textArea.getCaretLine(); int lineStart = textArea.getLineStartOffset(line); caret -= lineStart; String lineText = textArea.getLineText(textArea .getCaretLine()); if(caret == 0) { if(lineStart == 0) { textArea.getToolkit().beep(); return; } caret--; } else { String noWordSep = (String)textArea.getDocument().getProperty("noWordSep"); caret = TextUtilities.findWordStart(lineText,caret,noWordSep); } if(select) textArea.select(textArea.getMarkPosition(), lineStart + caret); else textArea.setCaretPosition(lineStart + caret); }
public void actionPerformed(ActionEvent evt) { JEditTextArea textArea = getTextArea(evt); int start = textArea.getSelectionStart(); if(start != textArea.getSelectionEnd()) { textArea.setSelectedText(""); } int line = textArea.getCaretLine(); int lineStart = textArea.getLineStartOffset(line); int caret = start - lineStart; String lineText = textArea.getLineText(textArea .getCaretLine()); if(caret == 0) { if(lineStart == 0) { textArea.getToolkit().beep(); return; } caret--; } else { String noWordSep = (String)textArea.getDocument().getProperty("noWordSep"); caret = TextUtilities.findWordStart(lineText,caret,noWordSep); } try { textArea.getDocument().remove( caret + lineStart, start - (caret + lineStart)); } catch(BadLocationException bl) { bl.printStackTrace(); } }
private void doComment(String commentChar, boolean addComment) { int startline = editor.getSelectionStartLine(); int endline = getLastRelevantSelectionLine(); if (commentChar == null) commentChar = "--"; int cLength = commentChar.length(); int pos = editor.getSelectionEnd(endline) - editor.getLineStartOffset(endline); SyntaxDocument document = editor.getDocument(); if (addComment && commentChar.equals("--")) { // workaround for an Oracle bug, where a comment like // // --commit; // // would not be treated correctly when sent to the database. // Apparently Oracle requires a blank after the two dashes. // // Adding the blank shouldn't do any harm for other databases commentChar = "-- "; } boolean ansiComment = "--".equals(commentChar); try { document.beginCompoundEdit(); for (int line = startline; line <= endline; line++) { String text = editor.getLineText(line); int lineStart = editor.getLineStartOffset(line); if (addComment) { document.insertString(lineStart, commentChar, null); } else { pos = text.indexOf(commentChar); if (pos > -1) { int commentLength = cLength; // remove the blank following the comment character to cater // for the blank that was inserted by commenting the lines (see above) if (ansiComment && text.length() > pos + cLength && Character.isWhitespace(text.charAt(pos + cLength))) { commentLength++; } document.remove(lineStart, pos + commentLength); } } } } catch (BadLocationException e) { LogMgr.logError("TextManipulator.doComment()", "Error when processing comment", e); } finally { document.endCompoundEdit(); } }