Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDEX: Remove some unnecessary calls from rename #4449

Merged
merged 1 commit into from May 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions java/src/processing/mode/java/pdex/PDEX.java
Expand Up @@ -93,12 +93,10 @@ public class PDEX {
private Rename rename;
private DebugTree debugTree;

private JavaEditor editor;
private PreprocessingService pps;


public PDEX(JavaEditor editor, PreprocessingService pps) {
this.editor = editor;
this.pps = pps;

this.enabled = !editor.hasJavaTabs();
Expand Down Expand Up @@ -803,8 +801,6 @@ void rename(PreprocessedSketch ps, IBinding binding, String newName) {

editor.startCompoundEdit();

int currentTabIndex = sketch.getCurrentCodeIndex();
final int currentOffset = editor.getCaretOffset();
mappedNodes.entrySet().forEach(entry -> {
int tabIndex = entry.getKey();
SketchCode sketchCode = sketch.getCode(tabIndex);
Expand Down Expand Up @@ -833,9 +829,15 @@ void rename(PreprocessedSketch ps, IBinding binding, String newName) {
sketchCode.setProgram(document.getText(0, document.getLength()));
} catch (BadLocationException e) { /* Whatever */ }
sketchCode.setModified(true);
editor.repaintHeader();
});

editor.stopCompoundEdit();

editor.repaintHeader();

int currentTabIndex = sketch.getCurrentCodeIndex();
final int currentOffset = editor.getCaretOffset();

int precedingIntervals =
(int) mappedNodes.getOrDefault(currentTabIndex, Collections.emptyList())
.stream()
Expand All @@ -844,10 +846,8 @@ void rename(PreprocessedSketch ps, IBinding binding, String newName) {
int intervalLengthDiff = newName.length() - binding.getName().length();
int offsetDiff = precedingIntervals * intervalLengthDiff;

sketch.setCurrentCode(currentTabIndex);
editor.getTextArea().setCaretPosition(currentOffset + offsetDiff);

editor.stopCompoundEdit();
}


Expand Down