Mercurial > projects > dwt-addons
comparison dwtx/jface/text/TreeLineTracker.d @ 158:25f1f92fa3df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 26 Aug 2008 02:46:34 +0200 |
parents | a9566845f1cb |
children | 7926b636c282 |
comparison
equal
deleted
inserted
replaced
157:7f75eaa8103a | 158:25f1f92fa3df |
---|---|
151 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | 151 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport |
152 import dwtx.jface.text.TextAttribute; // packageimport | 152 import dwtx.jface.text.TextAttribute; // packageimport |
153 import dwtx.jface.text.ITextViewerExtension4; // packageimport | 153 import dwtx.jface.text.ITextViewerExtension4; // packageimport |
154 import dwtx.jface.text.ITypedRegion; // packageimport | 154 import dwtx.jface.text.ITypedRegion; // packageimport |
155 | 155 |
156 | |
157 import dwt.dwthelper.utils; | 156 import dwt.dwthelper.utils; |
158 | |
159 import dwtx.dwtxhelper.Collection; | 157 import dwtx.dwtxhelper.Collection; |
160 | 158 |
161 | |
162 | |
163 | |
164 import dwtx.core.runtime.Assert; | 159 import dwtx.core.runtime.Assert; |
165 import dwtx.jface.text.AbstractLineTracker.DelimiterInfo; | 160 import dwtx.jface.text.AbstractLineTracker; |
166 | 161 |
167 /** | 162 /** |
168 * Abstract implementation of <code>ILineTracker</code>. It lets the definition of line | 163 * Abstract implementation of <code>ILineTracker</code>. It lets the definition of line |
169 * delimiters to subclasses. Assuming that '\n' is the only line delimiter, this abstract | 164 * delimiters to subclasses. Assuming that '\n' is the only line delimiter, this abstract |
170 * implementation defines the following line scheme: | 165 * implementation defines the following line scheme: |
801 * <code>node</code> > <code>length</code> | 796 * <code>node</code> > <code>length</code> |
802 */ | 797 */ |
803 private void replaceInternal(Node node, String text, int length, int firstLineDelta) { | 798 private void replaceInternal(Node node, String text, int length, int firstLineDelta) { |
804 // 1) modification on a single line | 799 // 1) modification on a single line |
805 | 800 |
806 DelimiterInfo info= text is null ? null : nextDelimiterInfo(text, 0); | 801 AbstractLineTracker.DelimiterInfo info= text is null ? null : nextDelimiterInfo(text, 0); |
807 | 802 |
808 if (info is null || info.delimiter is null) { | 803 if (info is null || info.delimiter is null) { |
809 // a) trivial case: insert into a single node, no line mangling | 804 // a) trivial case: insert into a single node, no line mangling |
810 int added= text is null ? 0 : text.length(); | 805 int added= text is null ? 0 : text.length(); |
811 updateLength(node, added - length); | 806 updateLength(node, added - length); |
858 Node toDelete= successor; | 853 Node toDelete= successor; |
859 successor= successor(successor); | 854 successor= successor(successor); |
860 updateLength(toDelete, -toDelete.length); | 855 updateLength(toDelete, -toDelete.length); |
861 } | 856 } |
862 | 857 |
863 DelimiterInfo info= text is null ? null : nextDelimiterInfo(text, 0); | 858 AbstractLineTracker.DelimiterInfo info= text is null ? null : nextDelimiterInfo(text, 0); |
864 | 859 |
865 if (info is null || info.delimiter is null) { | 860 if (info is null || info.delimiter is null) { |
866 int added= text is null ? 0 : text.length(); | 861 int added= text is null ? 0 : text.length(); |
867 | 862 |
868 // join the two lines if there are no lines added | 863 // join the two lines if there are no lines added |
1213 * | 1208 * |
1214 * @param text the text to be searched | 1209 * @param text the text to be searched |
1215 * @param offset the offset in the given text | 1210 * @param offset the offset in the given text |
1216 * @return the information of the first found delimiter or <code>null</code> | 1211 * @return the information of the first found delimiter or <code>null</code> |
1217 */ | 1212 */ |
1218 protected abstract DelimiterInfo nextDelimiterInfo(String text, int offset); | 1213 protected abstract AbstractLineTracker.DelimiterInfo nextDelimiterInfo(String text, int offset); |
1219 | 1214 |
1220 /* | 1215 /* |
1221 * @see dwtx.jface.text.ILineTracker#getLineDelimiter(int) | 1216 * @see dwtx.jface.text.ILineTracker#getLineDelimiter(int) |
1222 */ | 1217 */ |
1223 public final String getLineDelimiter(int line) { | 1218 public final String getLineDelimiter(int line) { |
1229 * @see dwtx.jface.text.ILineTracker#computeNumberOfLines(java.lang.String) | 1224 * @see dwtx.jface.text.ILineTracker#computeNumberOfLines(java.lang.String) |
1230 */ | 1225 */ |
1231 public final int computeNumberOfLines(String text) { | 1226 public final int computeNumberOfLines(String text) { |
1232 int count= 0; | 1227 int count= 0; |
1233 int start= 0; | 1228 int start= 0; |
1234 DelimiterInfo delimiterInfo= nextDelimiterInfo(text, start); | 1229 AbstractLineTracker.DelimiterInfo delimiterInfo= nextDelimiterInfo(text, start); |
1235 while (delimiterInfo !is null && delimiterInfo.delimiterIndex > -1) { | 1230 while (delimiterInfo !is null && delimiterInfo.delimiterIndex > -1) { |
1236 ++count; | 1231 ++count; |
1237 start= delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; | 1232 start= delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; |
1238 delimiterInfo= nextDelimiterInfo(text, start); | 1233 delimiterInfo= nextDelimiterInfo(text, start); |
1239 } | 1234 } |