buffer.beginCompoundEdit();  try { buffer.remove(caret,str.length()); buffer.insertString(caret,str,null); } catch(BadLocationException bl) { bl.printStackTrace(); } finally { buffer.endCompoundEdit(); }
int caretLineEnd = getLineEndOffset(caretLine); if(caretLineEnd - caret > 1) buffer.remove(caret,1);
	public void userInput(String str)	{		if(!isEditable())		{			getToolkit().beep();			return;		}		int caretLine = getCaretLine();		char ch = str.charAt(0);		if(ch == ' ' && Abbrevs.getExpandOnInput()			&& Abbrevs.expandAbbrev(view,false))			return;		else if(ch == '\t')		{			if(buffer.getBooleanProperty("indentOnTab")				&& selectionStart == selectionEnd				&& buffer.indentLine(selectionStartLine,true,false))				return;			else if(buffer.getBooleanProperty("noTabs"))			{				String line = getLineText(selectionStartLine);				setSelectedText(createSoftTab(line,					buffer.getTabSize()));			}			else				setSelectedText("\t");			return;		}		else if(ch == '\n')		{			try			{				buffer.beginCompoundEdit();				setSelectedText("\n");				if(buffer.getBooleanProperty("indentOnEnter"))					buffer.indentLine(selectionStartLine,true,false);			}			finally			{				buffer.endCompoundEdit();			}			return;		}		else		{			try			{				doWordWrap(caretLine,str);			}			catch(BadLocationException bl)			{				Log.log(Log.ERROR,this,bl);			}			if(!overwrite || selectionStart != selectionEnd)				setSelectedText(str);			else			{				// Don't overstrike if we're on the end of				// the line				int caret = getCaretPosition();				int caretLineEnd = getLineEndOffset(caretLine);				if(caretLineEnd - caret <= str.length())					setSelectedText(str);				else				{					buffer.beginCompoundEdit();						try					{						buffer.remove(caret,str.length());						buffer.insertString(caret,str,null);					}					catch(BadLocationException bl)					{						bl.printStackTrace();					}					finally					{						buffer.endCompoundEdit();					}				}			}		}		String indentOpenBrackets = (String)buffer			.getProperty("indentOpenBrackets");		String indentCloseBrackets = (String)buffer			.getProperty("indentCloseBrackets");		if((indentCloseBrackets != null && indentCloseBrackets.indexOf(ch) != -1)			|| (indentOpenBrackets != null && indentOpenBrackets.indexOf(ch) != -1))		{			buffer.indentLine(caretLine,false,true);		}	}