Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes auto correct can destroy content. Closes #321

Auto correct on save processes the content from start to end using the
original string and a regexp matcher find approach. The returned offset
needed to be adjusted for already made replacements. This fix simply
keeps track of diff in offset up to the point of replacement and makes
use of that when making the next replacement.
  • Loading branch information...
commit 57facf2f914b6bbce1bbf52ee09e6246ab020721 1 parent b18897e
Henrik Lindberg hlindberg authored
11 org.cloudsmith.geppetto.pp.dsl.ui/src/org/cloudsmith/geppetto/pp/dsl/ui/editor/actions/SaveActions.java
View
@@ -83,34 +83,37 @@ public void perform(IResource r, IXtextDocument document) {
Matcher matcher = trimPattern.matcher(content);
boolean mustRefetch = false;
;
+ int lengthAdjustment = 0;
while(matcher.find()) {
int offset = matcher.start();
int length = matcher.end() - offset;
try {
- document.replace(offset, length, matcher.group(1));
+ String replacement = matcher.group(1);
+ document.replace(offset - lengthAdjustment, length, replacement);
+ lengthAdjustment += (length - replacement.length());
mustRefetch = true;
}
catch(BadLocationException e) {
// ignore
}
}
- // content = trimPattern.matcher(content).replaceAll("$1");
if(mustRefetch)
content = document.get();
}
if(replaceFunkySpace) {
Matcher matcher = funkySpacePattern.matcher(content);
+ int lengthAdjustment = 0;
while(matcher.find()) {
int offset = matcher.start();
int length = matcher.end() - offset;
try {
- document.replace(offset, length, " ");
+ document.replace(offset - lengthAdjustment, length, " ");
+ lengthAdjustment += length - 1;
}
catch(BadLocationException e) {
// ignore
}
}
- content = funkySpacePattern.matcher(content).replaceAll(" ");
}
}
// // USE THIS IF SEMANTIC CHANGES ARE NEEDED LATER
Please sign in to comment.
Something went wrong with that request. Please try again.