1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 20:15:22 +02:00

bug 205879: [terminal] clicking into the terminal creates a selection of one character

https://bugs.eclipse.org/bugs/show_bug.cgi?id=205879
The user has to drag at least one character to make a selection
This commit is contained in:
Michael Scharf 2007-10-11 16:42:39 +00:00
parent 74215bde26
commit e48c0ba278
2 changed files with 55 additions and 33 deletions

View file

@ -66,6 +66,7 @@ public interface ITextCanvasModel {
void setSelectionAnchor(Point anchor); void setSelectionAnchor(Point anchor);
/** /**
* Sets the selection. A negative startLine clears the selection.
* @param startLine * @param startLine
* @param endLine * @param endLine
* @param startColumn * @param startColumn

View file

@ -37,6 +37,7 @@ public class TextCanvas extends GridCanvas {
private boolean fScrollLock; private boolean fScrollLock;
private Point fDraggingStart; private Point fDraggingStart;
private Point fDraggingEnd; private Point fDraggingEnd;
private boolean fHasSelection;
private ResizeListener fResizeListener; private ResizeListener fResizeListener;
private int fMinColumns=20; private int fMinColumns=20;
private int fMinLines=4; private int fMinLines=4;
@ -84,6 +85,7 @@ public class TextCanvas extends GridCanvas {
public void mouseDown(MouseEvent e) { public void mouseDown(MouseEvent e) {
if(e.button==1) { // left button if(e.button==1) { // left button
fDraggingStart=screenPointToCell(e.x, e.y); fDraggingStart=screenPointToCell(e.x, e.y);
fHasSelection=false;
if((e.stateMask&SWT.SHIFT)!=0) { if((e.stateMask&SWT.SHIFT)!=0) {
Point anchor=fCellCanvasModel.getSelectionAnchor(); Point anchor=fCellCanvasModel.getSelectionAnchor();
if(anchor!=null) if(anchor!=null)
@ -96,7 +98,11 @@ public class TextCanvas extends GridCanvas {
} }
public void mouseUp(MouseEvent e) { public void mouseUp(MouseEvent e) {
if(e.button==1) { // left button if(e.button==1) { // left button
setSelection(screenPointToCell(e.x, e.y)); updateHasSelection(e);
if(fHasSelection)
setSelection(screenPointToCell(e.x, e.y));
else
fCellCanvasModel.setSelection(-1,-1,-1,-1);
fDraggingStart=null; fDraggingStart=null;
} }
} }
@ -105,6 +111,7 @@ public class TextCanvas extends GridCanvas {
public void mouseMove(MouseEvent e) { public void mouseMove(MouseEvent e) {
if (fDraggingStart != null) { if (fDraggingStart != null) {
updateHasSelection(e);
setSelection(screenPointToCell(e.x, e.y)); setSelection(screenPointToCell(e.x, e.y));
} }
} }
@ -113,6 +120,20 @@ public class TextCanvas extends GridCanvas {
setHorizontalBarVisible(false); setHorizontalBarVisible(false);
} }
/**
* The user has to drag the mouse to at least one character to make a selection.
* Once this is done, even a one char selection is OK.
*
* @param e
*/
private void updateHasSelection(MouseEvent e) {
if(fDraggingStart!=null) {
Point p=screenPointToCell(e.x, e.y);
if(fDraggingStart.x!=p.x||fDraggingStart.y!=p.y)
fHasSelection=true;
}
}
void setSelection(Point p) { void setSelection(Point p) {
if (fDraggingStart !=null && !p.equals(fDraggingEnd)) { if (fDraggingStart !=null && !p.equals(fDraggingEnd)) {
fDraggingEnd = p; fDraggingEnd = p;