From fbafd8e07ce8f1f2051f9ddfa9f7badadc82db5d Mon Sep 17 00:00:00 2001 From: Manindra Moharana Date: Tue, 18 Jun 2013 17:40:04 +0530 Subject: [PATCH] Selection thingy works like a charm --- .../mode/experimental/ASTGenerator.java | 10 ++++--- .../mode/experimental/ASTNodeWrapper.java | 8 +++--- .../experimental/ErrorCheckerService.java | 26 +++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/pdex/src/processing/mode/experimental/ASTGenerator.java b/pdex/src/processing/mode/experimental/ASTGenerator.java index 6afc450d4..7c512ae14 100644 --- a/pdex/src/processing/mode/experimental/ASTGenerator.java +++ b/pdex/src/processing/mode/experimental/ASTGenerator.java @@ -1124,9 +1124,13 @@ public class ASTGenerator { if (tnode.getUserObject() instanceof ASTNodeWrapper) { // 3 friggin casts. Javaaargh. ASTNodeWrapper awrap = (ASTNodeWrapper) tnode.getUserObject(); - int offsets[] = awrap.getPDECodeOffsets(errorCheckerService); - ErrorCheckerService.scrollToErrorLine(editor, offsets[0], - offsets[1]); + int pdeoffsets[] = awrap.getPDECodeOffsets(errorCheckerService); + int javaoffsets[] = awrap.getJavaCodeOffsets(); + ErrorCheckerService.scrollToErrorLine(editor, pdeoffsets[0], + pdeoffsets[1], + javaoffsets[2] + - javaoffsets[1], + javaoffsets[3]); } } }; diff --git a/pdex/src/processing/mode/experimental/ASTNodeWrapper.java b/pdex/src/processing/mode/experimental/ASTNodeWrapper.java index 26bfaeaca..313f27400 100644 --- a/pdex/src/processing/mode/experimental/ASTNodeWrapper.java +++ b/pdex/src/processing/mode/experimental/ASTNodeWrapper.java @@ -43,7 +43,7 @@ public class ASTNodeWrapper { /** * For this node, finds various offsets (java code). - * + * Note that line start offset for this node is int[2] - int[1] * @return int[]{line number, line number start offset, node start offset, * node length} */ @@ -52,14 +52,14 @@ public class ASTNodeWrapper { .getLength(); ASTNode thisNode = node; while (thisNode.getParent() != null) { - if (getLineNumber(node.getParent()) == lineNumber) { - node = node.getParent(); + if (getLineNumber(thisNode.getParent()) == lineNumber) { + thisNode = thisNode.getParent(); } else { break; } } return new int[] { - lineNumber, node.getStartPosition(), nodeOffset, nodeLength }; + lineNumber, thisNode.getStartPosition(), nodeOffset, nodeLength }; } /** diff --git a/pdex/src/processing/mode/experimental/ErrorCheckerService.java b/pdex/src/processing/mode/experimental/ErrorCheckerService.java index 6e0f8d494..5b931eb70 100644 --- a/pdex/src/processing/mode/experimental/ErrorCheckerService.java +++ b/pdex/src/processing/mode/experimental/ErrorCheckerService.java @@ -1081,31 +1081,35 @@ public class ErrorCheckerService implements Runnable{ } /** - * Static method for scroll to a particular line in the PDE. Requires - * the editor instance as arguement. About time this went static. + * /** Static method for scroll to a particular line in the PDE. Requires the + * editor instance as arguement. + * * @param edt * @param tabIndex - * @param lineNoInTab - line number in the corresponding tab + * @param lineNoInTab + * - line number in the corresponding tab + * @param lineStartOffset + * - selection start offset(from line start non-whitespace offset) + * @param length + * - length of selection * @return - true, if scroll was successful */ - public static boolean scrollToErrorLine(Editor edt, int tabIndex, int lineNoInTab) { + public static boolean scrollToErrorLine(Editor edt, int tabIndex, int lineNoInTab, int lineStartOffset, int length) { if (edt == null) { return false; } try { edt.toFront(); edt.getSketch().setCurrentCode(tabIndex); - - edt.setSelection(edt.getTextArea() - .getLineStartNonWhiteSpaceOffset(lineNoInTab - 1) - + edt.getTextArea().getLineText(lineNoInTab - 1) - .trim().length(), edt.getTextArea() - .getLineStartNonWhiteSpaceOffset(lineNoInTab - 1)); + int lsno = edt.getTextArea() + .getLineStartNonWhiteSpaceOffset(lineNoInTab - 1) + lineStartOffset; + edt.setSelection(lsno, lsno + length); edt.getTextArea().scrollTo(lineNoInTab - 1, 0); edt.repaint(); + System.out.println(lineStartOffset + " LSO,len " + length); } catch (Exception e) { System.err.println(e - + " : Error while selecting text in scrollToErrorLine()"); + + " : Error while selecting text in static scrollToErrorLine()"); e.printStackTrace(); return false; }