mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-14 12:35:22 +02:00
fixed selection (now shift works to expand the selection)
This commit is contained in:
parent
8ba78ead2d
commit
3dafd57026
3 changed files with 45 additions and 11 deletions
|
@ -33,6 +33,8 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
private int fSelectionStartCoumn;
|
private int fSelectionStartCoumn;
|
||||||
private int fSelectionEndColumn;
|
private int fSelectionEndColumn;
|
||||||
private ITerminalTextDataSnapshot fSelectionSnapshot;
|
private ITerminalTextDataSnapshot fSelectionSnapshot;
|
||||||
|
private String fCurrentSelection=""; //$NON-NLS-1$
|
||||||
|
private final Point fSelectionAnchor=new Point(0,0);
|
||||||
|
|
||||||
public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
|
public AbstractTextCanvasModel(ITerminalTextDataSnapshot snapshot) {
|
||||||
fSnapshot=snapshot;
|
fSnapshot=snapshot;
|
||||||
|
@ -182,8 +184,22 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
else
|
else
|
||||||
return new Point(fSelectionStartCoumn,fSelectionStartLine);
|
return new Point(fSelectionStartCoumn,fSelectionStartLine);
|
||||||
}
|
}
|
||||||
|
public Point getSelectionAnchor() {
|
||||||
|
if(fSelectionStartLine<0)
|
||||||
|
return null;
|
||||||
|
return new Point(fSelectionAnchor.x,fSelectionAnchor.y);
|
||||||
|
}
|
||||||
|
public void setSelectionAnchor(Point anchor) {
|
||||||
|
fSelectionAnchor.x=anchor.x;
|
||||||
|
fSelectionAnchor.y=anchor.y;
|
||||||
|
}
|
||||||
|
|
||||||
public void setSelection(int startLine, int endLine, int startColumn, int endColumn) {
|
public void setSelection(int startLine, int endLine, int startColumn, int endColumn) {
|
||||||
|
// System.err.println(startLine+","+endLine+","+startColumn+","+endColumn);
|
||||||
|
doSetSelection(startLine, endLine, startColumn, endColumn);
|
||||||
|
fCurrentSelection=extractSelectedText();
|
||||||
|
}
|
||||||
|
private void doSetSelection(int startLine, int endLine, int startColumn, int endColumn) {
|
||||||
assert(startLine<0 || startLine<=endLine);
|
assert(startLine<0 || startLine<=endLine);
|
||||||
if(startLine>=0) {
|
if(startLine>=0) {
|
||||||
if(fSelectionSnapshot==null) {
|
if(fSelectionSnapshot==null) {
|
||||||
|
@ -201,7 +217,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
fSelectionStartCoumn = startColumn;
|
fSelectionStartCoumn = startColumn;
|
||||||
fSelectionEndColumn = endColumn;
|
fSelectionEndColumn = endColumn;
|
||||||
if(fSelectionSnapshot!=null) {
|
if(fSelectionSnapshot!=null) {
|
||||||
fSelectionSnapshot.setInterestWindow(0, fSeletionEndLine+1);
|
fSelectionSnapshot.setInterestWindow(0, fSelectionSnapshot.getHeight());
|
||||||
}
|
}
|
||||||
int changedStart;
|
int changedStart;
|
||||||
int changedEnd;
|
int changedEnd;
|
||||||
|
@ -228,6 +244,13 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSelectedText() {
|
public String getSelectedText() {
|
||||||
|
return fCurrentSelection;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Calculates the currently selected text
|
||||||
|
* @return the currently selected text
|
||||||
|
*/
|
||||||
|
private String extractSelectedText() {
|
||||||
if(fSelectionStartLine<0 || fSelectionStartCoumn<0|| fSelectionSnapshot==null)
|
if(fSelectionStartLine<0 || fSelectionStartCoumn<0|| fSelectionSnapshot==null)
|
||||||
return ""; //$NON-NLS-1$
|
return ""; //$NON-NLS-1$
|
||||||
StringBuffer buffer=new StringBuffer();
|
StringBuffer buffer=new StringBuffer();
|
||||||
|
@ -255,8 +278,6 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
}
|
}
|
||||||
private void updateSelection() {
|
private void updateSelection() {
|
||||||
if (fSelectionSnapshot != null && fSelectionSnapshot.isOutOfDate()) {
|
if (fSelectionSnapshot != null && fSelectionSnapshot.isOutOfDate()) {
|
||||||
// let's see if the selection text has changed since the last snapshot
|
|
||||||
String oldSelection = getSelectedText();
|
|
||||||
fSelectionSnapshot.updateSnapshot(true);
|
fSelectionSnapshot.updateSnapshot(true);
|
||||||
// has the selection moved?
|
// has the selection moved?
|
||||||
if (fSelectionSnapshot != null && fSelectionStartLine >= 0 && fSelectionSnapshot.getScrollWindowSize() > 0) {
|
if (fSelectionSnapshot != null && fSelectionStartLine >= 0 && fSelectionSnapshot.getScrollWindowSize() > 0) {
|
||||||
|
@ -267,20 +288,22 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel {
|
||||||
start = 0;
|
start = 0;
|
||||||
else
|
else
|
||||||
start = -1;
|
start = -1;
|
||||||
setSelection(start, end, fSelectionStartCoumn, fSelectionEndColumn);
|
doSetSelection(start, end, fSelectionStartCoumn, fSelectionEndColumn);
|
||||||
}
|
}
|
||||||
// have lines inside the selection changed?
|
// check if the content of the selection has changed. If the content has
|
||||||
if (fSelectionSnapshot != null && fSelectionSnapshot.getFirstChangedLine() <= fSeletionEndLine &&
|
// changed, clear the selection
|
||||||
fSelectionSnapshot.getLastChangedLine() >= fSelectionStartLine) {
|
if (fCurrentSelection.length()>0 && fSelectionSnapshot != null
|
||||||
|
&& fSelectionSnapshot.getFirstChangedLine() <= fSeletionEndLine
|
||||||
|
&& fSelectionSnapshot.getLastChangedLine() >= fSelectionStartLine) {
|
||||||
// has the selected text changed?
|
// has the selected text changed?
|
||||||
String newSelection = getSelectedText();
|
if (!fCurrentSelection.equals(extractSelectedText())) {
|
||||||
if (!oldSelection.equals(newSelection))
|
|
||||||
setSelection(-1, -1, -1, -1);
|
setSelection(-1, -1, -1, -1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// update the observed window...
|
// update the observed window...
|
||||||
if (fSelectionSnapshot != null)
|
if (fSelectionSnapshot != null)
|
||||||
// todo make -1 to work!
|
// todo make -1 to work!
|
||||||
fSelectionSnapshot.setInterestWindow(0, fSeletionEndLine+1);
|
fSelectionSnapshot.setInterestWindow(0, fSelectionSnapshot.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,10 @@ public interface ITextCanvasModel {
|
||||||
* {@link Point#x} is the column and {@link Point#y} is the line.
|
* {@link Point#x} is the column and {@link Point#y} is the line.
|
||||||
*/
|
*/
|
||||||
Point getSelectionEnd();
|
Point getSelectionEnd();
|
||||||
|
|
||||||
|
Point getSelectionAnchor();
|
||||||
|
|
||||||
|
void setSelectionAnchor(Point anchor);
|
||||||
/**
|
/**
|
||||||
* @param startLine
|
* @param startLine
|
||||||
* @param endLine
|
* @param endLine
|
||||||
|
|
|
@ -84,6 +84,13 @@ 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);
|
||||||
|
if((e.stateMask&SWT.SHIFT)!=0) {
|
||||||
|
Point anchor=fCellCanvasModel.getSelectionAnchor();
|
||||||
|
if(anchor!=null)
|
||||||
|
fDraggingStart=anchor;
|
||||||
|
} else {
|
||||||
|
fCellCanvasModel.setSelectionAnchor(fDraggingStart);
|
||||||
|
}
|
||||||
fDraggingEnd=null;
|
fDraggingEnd=null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +211,7 @@ public class TextCanvas extends GridCanvas {
|
||||||
}
|
}
|
||||||
public void selectAll() {
|
public void selectAll() {
|
||||||
fCellCanvasModel.setSelection(0, fCellCanvasModel.getTerminalText().getHeight(), 0, fCellCanvasModel.getTerminalText().getWidth());
|
fCellCanvasModel.setSelection(0, fCellCanvasModel.getTerminalText().getHeight(), 0, fCellCanvasModel.getTerminalText().getWidth());
|
||||||
|
fCellCanvasModel.setSelectionAnchor(new Point(0,0));
|
||||||
}
|
}
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue