[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/actions PyAddBlockComment.java,1.3,1.4
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-04-20 14:42:14
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10367/src/org/python/pydev/editor/actions Modified Files: PyAddBlockComment.java Log Message: Comment block now goes to right position. Index: PyAddBlockComment.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyAddBlockComment.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyAddBlockComment.java 10 Apr 2004 01:48:14 -0000 1.3 --- PyAddBlockComment.java 20 Apr 2004 14:42:05 -0000 1.4 *************** *** 21,25 **** /** - * Hi. * Insert a comment block. * #===... --- 21,24 ---- *************** *** 40,65 **** .getSelection(); IRegion startLine = null; int startLineIndex = selection.getStartLine(); ! String endLineDelim = getDelimiter(doc, startLineIndex); startLine = doc.getLineInformation(startLineIndex); IRegion line = doc.getLineInformation(startLineIndex); int pos = line.getOffset(); StringBuffer strBuf = new StringBuffer(); strBuf.append(endLineDelim); ! strBuf.append( ! "#==============================================================================="); strBuf.append(endLineDelim); strBuf.append("# "); strBuf.append(endLineDelim); ! strBuf.append( ! "#==============================================================================="); ! strBuf.append(endLineDelim); strBuf.append(endLineDelim); ! ! doc.replace(pos, 0, strBuf.toString()); } catch (Exception e) { --- 39,77 ---- .getSelection(); + //strange things happen when we try to get the line information on the last line of the + //document (it doesn't return the end line delimiter correctly), so we always get on position + //0 and check to see if we are not in the last line. + if (doc.getNumberOfLines() <= 1) + return; + IRegion startLine = null; int startLineIndex = selection.getStartLine(); ! String endLineDelim = getDelimiter(doc, 0); startLine = doc.getLineInformation(startLineIndex); IRegion line = doc.getLineInformation(startLineIndex); + int lineLenght = line.getLength(); int pos = line.getOffset(); + + String content = doc.get(pos, lineLenght); + String comment = getFullCommentLine(); + StringBuffer strBuf = new StringBuffer(); + strBuf.append(endLineDelim); ! strBuf.append(comment); //#=========... strBuf.append(endLineDelim); + strBuf.append("# "); + strBuf.append(content); + strBuf.append(endLineDelim); ! strBuf.append(comment); //#=========... strBuf.append(endLineDelim); ! ! doc.replace(pos, lineLenght, strBuf.toString()); ! textEditor.selectAndReveal(pos+strBuf.length()-comment.length()-4,0); } catch (Exception e) { *************** *** 67,69 **** --- 79,85 ---- } } + + private String getFullCommentLine(){ + return "#==============================================================================="; + } } |