8000 Fix lineOffset for R · scijava/script-editor@928d96d · GitHub
[go: up one dir, main page]

Skip to content

Commit 928d96d

Browse files
committed
Fix lineOffset for R
While at it allow selected text in stack traces to be searched in the main script
1 parent d76013b commit 928d96d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/org/scijava/ui/swing/script/ErrorParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ private void parse(final String errorLog) {
194194
// HACK scala code seems to always be pre-pended by some 10 lines of code(!?).
195195
if ("Scala".equals(lang.getLanguageName()))
196196
lineOffset += 10;
197+
// HACK and R by one (!?)
198+
else if ("R".equals(lang.getLanguageName()))
199+
lineOffset += 1;
197200

198201
errorLines = new TreeSet<>();
199202
final StringTokenizer tokenizer = new StringTokenizer(errorLog, "\n");

src/main/java/org/scijava/ui/swing/script/TextEditor.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3766,6 +3766,19 @@ protected void applyConsolePopupMenu(final JTextArea textArea) {
37663766
if (text != null) findDialog.setSearchPattern(text);
37673767
findDialog.show(false);
37683768
});
3769+
jmi = new JMenuItem("Search Script for Selected Text");
3770+
popup.add(jmi);
3771+
jmi.addActionListener(e -> {
3772+
final String text = textArea.getSelectedText();
3773+
if (text == null) {
3774+
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
3775+
} else {
3776+
findDialog.setLocationRelativeTo(this);
3777+
findDialog.setRestrictToConsole(false);
3778+
if (text != null) findDialog.setSearchPattern(text);
3779+
findDialog.show(false);
3780+
}
3781+
});
37693782
popup.addSeparator();
37703783

37713784
jmi = new JMenuItem("Clear Selected Text...");
@@ -3776,6 +3789,8 @@ protected void applyConsolePopupMenu(final JTextArea textArea) {
37763789
else
37773790
textArea.replaceSelection("");
37783791
});
3792+
final DefaultHighlighter highlighter = (DefaultHighlighter)textArea.getHighlighter();
3793+
highlighter.setDrawsLayeredHighlights(false);
37793794
jmi = new JMenuItem("Highlight Selected Text...");
37803795
popup.add(jmi);
37813796
jmi.addActionListener(e -> {
@@ -3784,7 +3799,8 @@ protected void applyConsolePopupMenu(final JTextArea textArea) {
37843799
final DefaultHighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter(color);
37853800
textArea.getHighlighter().addHighlight(textArea.getSelectionStart(), textArea.getSelectionEnd(), painter);
37863801
textArea.setCaretPosition(textArea.getSelectionEnd());
3787-
} catch (BadLocationException ignored) {
3802+
textArea.getHighlighter();
3803+
} catch (final BadLocationException ignored) {
37883804
UIManager.getLookAndFeel().provideErrorFeedback(textArea);
37893805
}
37903806
});

0 commit comments

Comments
 (0)
0