Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 293474 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ui/editor/context/XMLInputContext.java (-2 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2008 IBM Corporation and others.
2
 * Copyright (c) 2003, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 108-113 Link Here
108
			if (node.getOffset() > -1) {
108
			if (node.getOffset() > -1) {
109
				// this is an element that was of the form <element/>
109
				// this is an element that was of the form <element/>
110
				// it now needs to be broken up into <element><new/></element>
110
				// it now needs to be broken up into <element><new/></element>
111
				// Note that the node here has the correct stored length (the previous value, not what will be written out during the write() call), see bug 293474
111
				op = new ReplaceEdit(node.getOffset(), node.getLength(), node.write(false));
112
				op = new ReplaceEdit(node.getOffset(), node.getLength(), node.write(false));
112
			} else {
113
			} else {
113
				// try to insert after last sibling that has an offset
114
				// try to insert after last sibling that has an offset
Lines 217-231 Link Here
217
		Object changedObject = attr;
218
		Object changedObject = attr;
218
		TextEdit op = null;
219
		TextEdit op = null;
219
		if (offset > -1) {
220
		if (offset > -1) {
221
			// Attribute exists, replace the old value with the new value
220
			if (newValue == null || newValue.toString().length() == 0) {
222
			if (newValue == null || newValue.toString().length() == 0) {
221
				int length = attr.getValueOffset() + attr.getValueLength() + 1 - attr.getNameOffset();
223
				int length = attr.getValueOffset() + attr.getValueLength() + 1 - attr.getNameOffset();
222
				op = getAttributeDeleteEditOperation(attr.getNameOffset(), length);
224
				op = getAttributeDeleteEditOperation(attr.getNameOffset(), length);
223
			} else {
225
			} else {
224
				op = new ReplaceEdit(offset, attr.getValueLength(), getWritableAttributeNodeValue(event.getNewValue().toString()));
226
				int oldLength = ((String) event.getOldValue()).length();
227
				op = new ReplaceEdit(offset, oldLength, getWritableAttributeNodeValue(event.getNewValue().toString()));
225
			}
228
			}
226
		}
229
		}
227
230
228
		if (op == null) {
231
		if (op == null) {
232
			// Attribute doesn't exist, check if the parent exists and add the attribute to it
229
			IDocumentElementNode node = attr.getEnclosingElement();
233
			IDocumentElementNode node = attr.getEnclosingElement();
230
			IDocument doc = getDocumentProvider().getDocument(getInput());
234
			IDocument doc = getDocumentProvider().getDocument(getInput());
231
			if (node.getOffset() > -1) {
235
			if (node.getOffset() > -1) {
Lines 233-238 Link Here
233
				int len = getNextPosition(doc, node.getOffset(), '>');
237
				int len = getNextPosition(doc, node.getOffset(), '>');
234
				op = new ReplaceEdit(node.getOffset(), len + 1, node.writeShallow(shouldTerminateElement(doc, node.getOffset() + len)));
238
				op = new ReplaceEdit(node.getOffset(), len + 1, node.writeShallow(shouldTerminateElement(doc, node.getOffset() + len)));
235
			} else {
239
			} else {
240
				// Parent doesn't exist in the doc, write out whole parent to the doc
236
				insertNode(node, ops);
241
				insertNode(node, ops);
237
				return;
242
				return;
238
			}
243
			}

Return to bug 293474