Skip to content

Commit

Permalink
Merge pull request #64 from iTrace-Dev/58-error-thrown-when-opening-p…
Browse files Browse the repository at this point in the history
…laintext-files-when-tracking

Test if there are any errors thrown when opening text files while tracking
  • Loading branch information
KangilPark authored May 24, 2022
2 parents a7ba919 + c33f268 commit 73e4620
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/org/itrace/gaze/handlers/StyledTextGazeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public class StyledTextGazeHandler implements IGazeHandler {
public StyledTextGazeHandler(Object target, IEditorPart editor) {
this.targetStyledText = (StyledText) target;
this.editor = editor;
projectionViewer = (ProjectionViewer) editor.getAdapter(ITextOperationTarget.class);

ITextOperationTarget t = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
if(t instanceof ProjectionViewer) projectionViewer = (ProjectionViewer)t;
// projectionViewer = (ProjectionViewer) editor.getAdapter(ITextOperationTarget.class);
}

@Override
Expand All @@ -52,16 +55,21 @@ public IStyledTextGazeResponse handleGaze(int absoluteX, int absoluteY, int rela
try {
// Get the actual offset of the current line from the top
// Allows code folding to be taken into account
int foldedLineIndex = targetStyledText.getLineIndex(relativeY);
int lineOffset = targetStyledText.getOffsetAtLine(foldedLineIndex);

int offset = targetStyledText.getOffsetAtPoint(new Point(relativeX, relativeY));
if(offset == -1) {
return null;
}

col = offset - lineOffset + 1;
lineIndex = projectionViewer.widgetLine2ModelLine(foldedLineIndex);
int lineOffset;
// Only use ProjectionViewer if StyledTextGazeHandler.editor.getAdapter is an instance of ProjectionViewer
if (projectionViewer != null) {
int foldedLineIndex = targetStyledText.getLineIndex(relativeY);
lineOffset = targetStyledText.getOffsetAtLine(foldedLineIndex);
lineIndex = projectionViewer.widgetLine2ModelLine(foldedLineIndex);
} else {
lineIndex = targetStyledText.getLineIndex(relativeY);
lineOffset = targetStyledText.getOffsetAtLine(lineIndex);
}
col = offset - lineOffset + 1;

// (0, 0) relative to the control in absolute screen
// coordinates.
Expand Down Expand Up @@ -162,4 +170,4 @@ public String getPath() {

};
}
}
}

0 comments on commit 73e4620

Please sign in to comment.