blob: 3cdfd54fc2bc3fa35cbf80a172fa0a7afe637a19 [file] [log] [blame]
david_williamscfdb2cd2004-11-11 08:37:49 +00001/*******************************************************************************
2 * Copyright (c) 2001, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Jens Lukowski/Innoopract - initial renaming/restructuring
11 *
12 *******************************************************************************/
david_williams68bf9b32005-03-26 04:29:10 +000013package org.eclipse.wst.sse.core.internal.text;
david_williamscfdb2cd2004-11-11 08:37:49 +000014
15import org.eclipse.jface.text.BadPositionCategoryException;
16import org.eclipse.jface.text.DefaultPositionUpdater;
17
18/**
19 * Follows the behavior of DefaultPositionUpdater except in addition to
20 * deleting/overwriting text which completely contains the position deletes
21 * the position, deleting text that equals the text in position also deletes
22 * the position.
23 *
24 * @see org.eclipse.jface.text.DefaultPositionUpdater
25 */
26public class DeleteEqualPositionUpdater extends DefaultPositionUpdater {
27
28 /**
29 * @param category
30 */
31 public DeleteEqualPositionUpdater(String category) {
32 super(category);
33 }
34
35 /**
36 * Determines whether the currently investigated position has been deleted
37 * by the replace operation specified in the current event. If so, it
38 * deletes the position and removes it from the document's position
39 * category.
40 *
41 * NOTE: position is deleted if current event completely overwrites
42 * position OR if current event deletes the area surrounding/including the
43 * position
44 *
45 * @return <code>true</code> if position has been deleted
46 */
47 protected boolean notDeleted() {
48 // position is deleted if current event completely overwrites position
49 // OR if
50 // current event deletes the area surrounding/including the position
51 if ((fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) || (fOffset <= fPosition.offset && (fPosition.offset + fPosition.length <= fOffset + fLength) && fReplaceLength == 0)) {
52
53 fPosition.delete();
54
55 try {
56 fDocument.removePosition(getCategory(), fPosition);
57 } catch (BadPositionCategoryException x) {
58 }
59
60 return false;
61 }
62
63 return true;
64 }
65
66}