amywu | 0c7262d | 2006-09-18 22:20:52 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2006 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 | *******************************************************************************/ |
| 11 | package org.eclipse.wst.sse.core.internal.text; |
| 12 | |
| 13 | import org.eclipse.jface.text.Position; |
| 14 | |
| 15 | class ReadOnlyPosition extends Position { |
| 16 | private boolean fIncludeStartOffset = false; |
| 17 | |
nitind | c8c1e28 | 2007-09-13 02:05:46 +0000 | [diff] [blame] | 18 | public ReadOnlyPosition(int newOffset, int newLength, boolean includeStart) { |
| 19 | super(newOffset, newLength); |
amywu | 0c7262d | 2006-09-18 22:20:52 +0000 | [diff] [blame] | 20 | fIncludeStartOffset = includeStart; |
| 21 | } |
| 22 | |
nitind | c8c1e28 | 2007-09-13 02:05:46 +0000 | [diff] [blame] | 23 | public boolean overlapsWith(int newOffset, int newLength) { |
| 24 | boolean overlapsWith = super.overlapsWith(newOffset, newLength); |
amywu | 0c7262d | 2006-09-18 22:20:52 +0000 | [diff] [blame] | 25 | if (overlapsWith) { |
| 26 | /* |
| 27 | * BUG157526 If at the start of the read only region and length = |
| 28 | * 0 most likely asking to insert and want to all inserting before |
| 29 | * read only region |
| 30 | */ |
nitind | c8c1e28 | 2007-09-13 02:05:46 +0000 | [diff] [blame] | 31 | if (fIncludeStartOffset && (newLength == 0) && (this.length != 0) && (newOffset == this.offset)) { |
amywu | 0c7262d | 2006-09-18 22:20:52 +0000 | [diff] [blame] | 32 | overlapsWith = false; |
| 33 | } |
| 34 | } |
| 35 | return overlapsWith; |
| 36 | } |
| 37 | } |