1 11 package org.eclipse.jface.text; 12 13 14 21 public class DefaultIndentLineAutoEditStrategy implements IAutoEditStrategy { 22 23 27 public DefaultIndentLineAutoEditStrategy() { 28 } 29 30 41 protected int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException { 42 while (offset < end) { 43 char c= document.getChar(offset); 44 if (c != ' ' && c != '\t') { 45 return offset; 46 } 47 offset++; 48 } 49 return end; 50 } 51 52 58 private void autoIndentAfterNewLine(IDocument d, DocumentCommand c) { 59 60 if (c.offset == -1 || d.getLength() == 0) 61 return; 62 63 try { 64 int p= (c.offset == d.getLength() ? c.offset - 1 : c.offset); 66 IRegion info= d.getLineInformationOfOffset(p); 67 int start= info.getOffset(); 68 69 int end= findEndOfWhiteSpace(d, start, c.offset); 71 72 StringBuffer buf= new StringBuffer (c.text); 73 if (end > start) { 74 buf.append(d.get(start, end - start)); 76 } 77 78 c.text= buf.toString(); 79 80 } catch (BadLocationException excp) { 81 } 83 } 84 85 88 public void customizeDocumentCommand(IDocument d, DocumentCommand c) { 89 if (c.length == 0 && c.text != null && TextUtilities.endsWith(d.getLegalLineDelimiters(), c.text) != -1) 90 autoIndentAfterNewLine(d, c); 91 } 92 } 93 | Popular Tags |