1 11 package org.eclipse.jdt.internal.ui.text.template.contentassist; 12 13 import org.eclipse.jface.text.BadPositionCategoryException; 14 import org.eclipse.jface.text.DocumentEvent; 15 import org.eclipse.jface.text.IPositionUpdater; 16 import org.eclipse.jface.text.Position; 17 18 24 class InclusivePositionUpdater implements IPositionUpdater { 25 26 27 private final String fCategory; 28 29 34 public InclusivePositionUpdater(String category) { 35 fCategory= category; 36 } 37 38 41 public void update(DocumentEvent event) { 42 43 int eventOffset= event.getOffset(); 44 int eventOldLength= event.getLength(); 45 int eventNewLength= event.getText() == null ? 0 : event.getText().length(); 46 int deltaLength= eventNewLength - eventOldLength; 47 48 try { 49 Position[] positions= event.getDocument().getPositions(fCategory); 50 51 for (int i= 0; i != positions.length; i++) { 52 53 Position position= positions[i]; 54 55 if (position.isDeleted()) 56 continue; 57 58 int offset= position.getOffset(); 59 int length= position.getLength(); 60 int end= offset + length; 61 62 if (offset > eventOffset + eventOldLength) 63 position.setOffset(offset + deltaLength); 66 else if (end < eventOffset) { 67 } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { 70 position.setLength(length + deltaLength); 72 } else if (offset < eventOffset) { 73 int newEnd= eventOffset + eventNewLength; 75 position.setLength(newEnd - offset); 76 } else if (end > eventOffset + eventOldLength) { 77 position.setOffset(eventOffset); 82 int deleted= eventOffset + eventOldLength - offset; 83 position.setLength(length - deleted + eventNewLength); 84 } else { 85 position.delete(); 87 } 88 } 89 } catch (BadPositionCategoryException e) { 90 } 92 } 93 94 99 public String getCategory() { 100 return fCategory; 101 } 102 103 } 104 | Popular Tags |