1 11 package org.eclipse.jface.text.link; 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 28 public class InclusivePositionUpdater implements IPositionUpdater { 29 30 31 private final String fCategory; 32 33 38 public InclusivePositionUpdater(String category) { 39 fCategory= category; 40 } 41 42 45 public void update(DocumentEvent event) { 46 47 int eventOffset= event.getOffset(); 48 int eventOldLength= event.getLength(); 49 int eventNewLength= event.getText() == null ? 0 : event.getText().length(); 50 int deltaLength= eventNewLength - eventOldLength; 51 52 try { 53 Position[] positions= event.getDocument().getPositions(fCategory); 54 55 for (int i= 0; i != positions.length; i++) { 56 57 Position position= positions[i]; 58 59 if (position.isDeleted()) 60 continue; 61 62 int offset= position.getOffset(); 63 int length= position.getLength(); 64 int end= offset + length; 65 66 if (offset > eventOffset + eventOldLength) 67 position.setOffset(offset + deltaLength); 70 else if (end < eventOffset) { 71 } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { 74 position.setLength(length + deltaLength); 76 } else if (offset < eventOffset) { 77 int newEnd= eventOffset + eventNewLength; 79 position.setLength(newEnd - offset); 80 } else if (end > eventOffset + eventOldLength) { 81 position.setOffset(eventOffset); 86 int deleted= eventOffset + eventOldLength - offset; 87 position.setLength(length - deleted + eventNewLength); 88 } else { 89 position.delete(); 91 } 92 } 93 } catch (BadPositionCategoryException e) { 94 } 96 } 97 98 103 public String getCategory() { 104 return fCategory; 105 } 106 107 } 108 | Popular Tags |