[204703] Drag and Drop into SSE inserts @ one less than where dropped.
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ExtendedEditorDropTargetAdapter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ExtendedEditorDropTargetAdapter.java
index 02b9c12..7cec484 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ExtendedEditorDropTargetAdapter.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ExtendedEditorDropTargetAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * Copyright (c) 2001, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,8 +13,6 @@
package org.eclipse.wst.sse.ui.internal;
import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetAdapter;
@@ -22,8 +20,6 @@
import org.eclipse.swt.dnd.FileTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.dnd.TransferData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.ui.IEditorPart;
import org.eclipse.wst.sse.ui.internal.TransferBuilder.TransferProxyForDelayLoading;
@@ -153,44 +149,7 @@
public void dragOver(DropTargetEvent event) {
event.operations &= ~DND.DROP_MOVE;
event.detail = DND.DROP_COPY;
-
- if (textViewer != null) {
- Point pt = toControl(new Point(event.x, event.y));
- StyledText st = textViewer.getTextWidget();
-
- // auto scroll
- Rectangle ca = st.getClientArea();
- int margin = st.getLineHeight();
-
- if (pt.y < margin) { // up
- st.invokeAction(ST.LINE_UP);
- }
- else if (pt.y > ca.height - margin) { // down
- st.invokeAction(ST.LINE_DOWN);
- }
-
- int offsetUnder = getDropOffset(event);
- if (offsetUnder > 0 && offsetUnder < st.getCharCount()) {
- int currentLine = st.getLineAtOffset(offsetUnder);
- Rectangle rect = st.getTextBounds(offsetUnder, offsetUnder);
- if (pt.x < rect.width && st.getHorizontalPixel() > 0) {
- st.invokeAction(ST.COLUMN_PREVIOUS); // left
- if (offsetUnder != st.getCaretOffset()) {
- st.setCaretOffset(offsetUnder);
- st.setSelection(offsetUnder);
- }
- st.redraw();
- }
- else if (pt.x > st.getClientArea().x && offsetUnder + 2 < st.getCharCount() && currentLine == st.getLineAtOffset(offsetUnder + 2)) { // right
- st.invokeAction(ST.COLUMN_NEXT); // right
- if (offsetUnder != st.getCaretOffset()) {
- st.setCaretOffset(offsetUnder);
- st.setSelection(offsetUnder);
- }
- st.redraw();
- }
- }
- }
+ event.feedback |= DND.FEEDBACK_SCROLL;
}
/**
@@ -199,25 +158,6 @@
if (event.operations == DND.DROP_NONE)
return;
- if (textViewer != null) {
- Point pt = toControl(new Point(event.x, event.y));
- StyledText st = textViewer.getTextWidget();
-
- int offset = getDropOffset(st, pt);
- if (offset != st.getCaretOffset()) {
- st.setCaretOffset(offset);
- }
-
- // ISelectionProvider sp = textViewer.getSelectionProvider();
- // ISelection sel = new TextSelection(offset, 0);
- // sp.setSelection(sel);
- // BUG145392 - need to account for folded regions
- if (textViewer instanceof ITextViewerExtension5) {
- offset = ((ITextViewerExtension5) textViewer).widgetOffset2ModelOffset(offset);
- }
- textViewer.setSelectedRange(offset, 0);
- }
-
Transfer[] ts = getTransfers();
for (int i = 0; i < ts.length; i++) {
if (ts[i].isSupportedType(event.currentDataType)) {
@@ -227,65 +167,9 @@
}
}
}
-
+
protected int getDropOffset(DropTargetEvent event) {
- Point pt = getTextViewer().getTextWidget().toControl(new Point(event.x, event.y));
- StyledText st = textViewer.getTextWidget();
- return getDropOffset(st, pt);
- }
-
- private int getDropOffset(StyledText st, Point pt) {
- int offset = st.getCaretOffset();
- try {
- offset = st.getOffsetAtLocation(pt);
- }
- catch (IllegalArgumentException e) {
- // This is normal case if mouse cursor is on outside of valid
- // text.
- boolean found = false;
- Point p = new Point((pt.x > 0 ? pt.x : 0), pt.y);
- // search nearest character
- for (; p.x > -1; p.x--) {
- try {
- offset = st.getOffsetAtLocation(p);
-
- /*
- * Now that a valid offset has been found, try to place at
- * the end of the line
- */
- /*
- * partial line folding invalidates any "move to EOL"
- * action we might take
- */
- // if (textViewer != null && textViewer.getDocument() !=
- // null) {
- // IRegion lineInfo = null;
- // try {
- // if (textViewer instanceof ITextViewerExtension5) {
- // lineInfo =
- // textViewer.getDocument().getLineInformationOfOffset(((ITextViewerExtension5)textViewer).widgetOffset2ModelOffset(offset));
- // }
- // else {
- // lineInfo =
- // textViewer.getDocument().getLineInformationOfOffset(offset);
- // }
- // } catch (BadLocationException e1) {
- // }
- // if (lineInfo != null)
- // offset = lineInfo.getOffset() + lineInfo.getLength();
- // }
- found = true;
- break;
- }
- catch (IllegalArgumentException ex) {
- }
- }
-
- if (!found) {
- offset = st.getCharCount();
- }
- }
- return offset;
+ return getTextViewer().getSelectedRange().x;
}
public IEditorPart getTargetEditor() {
@@ -323,8 +207,4 @@
public void setTextViewer(ITextViewer textViewer) {
this.textViewer = textViewer;
}
-
- private Point toControl(Point point) {
- return (textViewer != null ? textViewer.getTextWidget().toControl(point) : point);
- }
}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ReadOnlyAwareDropTargetAdapter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ReadOnlyAwareDropTargetAdapter.java
index 4fc23f9..f2945c7 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ReadOnlyAwareDropTargetAdapter.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ReadOnlyAwareDropTargetAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2005 IBM Corporation and others.
+ * Copyright (c) 2001, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -16,6 +16,7 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.graphics.Point;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
@@ -36,7 +37,8 @@
public void drop(DropTargetEvent event) {
IDocument document = getTextViewer().getDocument();
if (document instanceof IStructuredDocument) {
- if (((IStructuredDocument) document).containsReadOnly(getDropOffset(event), 0)) {
+ Point selectedRange = getTextViewer().getSelectedRange();
+ if (((IStructuredDocument) document).containsReadOnly(selectedRange.x, selectedRange.y)) {
event.operations = DND.DROP_NONE;
event.detail = DND.DROP_NONE;
getTextViewer().getTextWidget().redraw();
@@ -46,5 +48,4 @@
}
super.drop(event);
}
-
}