1 22 23 package org.gjt.sp.jedit.buffer; 24 25 import javax.swing.text.Segment ; 26 27 33 public class IndentFoldHandler extends FoldHandler 34 { 35 public IndentFoldHandler() 36 { 37 super("indent"); 38 } 39 40 50 public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment seg) 51 { 52 int tabSize = buffer.getTabSize(); 53 54 buffer.getLineText(lineIndex,seg); 55 56 int offset = seg.offset; 57 int count = seg.count; 58 59 int whitespace = 0; 60 61 boolean seenNonWhiteSpace = false; 62 63 loop: for(int i = 0; i < count; i++) 64 { 65 switch(seg.array[offset + i]) 66 { 67 case ' ': 68 whitespace++; 69 break; 70 case '\t': 71 whitespace += (tabSize - whitespace % tabSize); 72 break; 73 default: 74 seenNonWhiteSpace = true; 75 break loop; 76 } 77 } 78 79 if(!seenNonWhiteSpace) 80 { 81 if(lineIndex != 0) 83 return buffer.getFoldLevel(lineIndex - 1); 84 else 85 return 0; 86 } 87 return whitespace; 88 } } 90 | Popular Tags |