private void deleteAndFireEvent(int startIndex, int length, String sessionId, String userId) {
int endIndex = startIndex + length;
assert length > 0 && endIndex <= length();
String toDelete = snapshot.substring(startIndex, endIndex);
TextDeletedEvent event =
new TextDeletedEventImpl(event(sessionId, userId).set("index", startIndex)
.set("text", toDelete));
snapshot.delete(startIndex, endIndex);
fireEvent(event);
model.bytesUsed -= length;