diff options
author | Duong Nguyen | 2007-08-30 21:45:04 +0000 |
---|---|---|
committer | Duong Nguyen | 2007-08-30 21:45:04 +0000 |
commit | f0e42825523d2b1027f60ed8177aefac28317a8c (patch) | |
tree | 729ff6e41831ef639e1a6c83830b046cb6095fcf | |
parent | f3e96f662738a7d9d8dfe9b3d0a107eb91c7a9f9 (diff) | |
download | eclipse.platform.swt-f0e42825523d2b1027f60ed8177aefac28317a8c.tar.gz eclipse.platform.swt-f0e42825523d2b1027f60ed8177aefac28317a8c.tar.xz eclipse.platform.swt-f0e42825523d2b1027f60ed8177aefac28317a8c.zip |
Bug 193515- [DND] Cannot drag a single character selection in StyledText
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java index 5620b4999e..7c5909c2b8 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java @@ -1839,8 +1839,8 @@ boolean checkDragDetect(Event event) { if (event.button != 1) return false; } if (selection.x == selection.y) return false; - int offset = getOffsetAtPoint(event.x, event.y); - if (offset > selection.x && offset < selection.y) { + int offset = getOffsetAtPoint(event.x, event.y, null); + if (selection.x <= offset && offset < selection.y) { return dragDetect(event); } return false; @@ -3860,6 +3860,28 @@ int getOffsetAtPoint(int x, int y, int lineIndex) { renderer.disposeTextLayout(layout); return offsetInLine + content.getOffsetAtLine(lineIndex); } +int getOffsetAtPoint(int x, int y, int[] trailing) { + if (y < topMargin || x < leftMargin || y > clientAreaHeight - bottomMargin || x > clientAreaWidth - rightMargin) { + return -1; + } + int bottomIndex = getPartialBottomIndex(); + int height = getLinePixel(bottomIndex + 1); + if (y > height) { + return -1; + } + int lineIndex = getLineIndex(y); + int lineOffset = content.getOffsetAtLine(lineIndex); + TextLayout layout = renderer.getTextLayout(lineIndex); + x = x + horizontalScrollOffset - leftMargin ; + y = y - getLinePixel(lineIndex); + int offset = layout.getOffset(x, y, trailing); + Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset)); + renderer.disposeTextLayout(layout); + if (rect.x <= x && x < rect.x + rect.width) { + return offset + lineOffset; + } + return -1; +} /** * Returns the orientation of the receiver. * |