Commit aaed6c9f authored by Johannes Roith's avatar Johannes Roith

fix the column bug.

parent e983a3c5
...@@ -35,9 +35,7 @@ class CTEDocumentListener implements IDocumentListener { ...@@ -35,9 +35,7 @@ class CTEDocumentListener implements IDocumentListener {
return; return;
} }
private void patchModel(DocumentEvent event) { private void patchModel(DocumentEvent event) {
// long timerBefore = System.currentTimeMillis(); // TODO: remove!
IDocument document = event.getDocument(); IDocument document = event.getDocument();
Model model = Model.getInstanceForDocument(document); Model model = Model.getInstanceForDocument(document);
...@@ -48,7 +46,9 @@ class CTEDocumentListener implements IDocumentListener { ...@@ -48,7 +46,9 @@ class CTEDocumentListener implements IDocumentListener {
return; return;
int offset = event.getOffset(); int offset = event.getOffset();
int textLength = event.getText().length();
int removedLength = event.getLength();
int offsetOfLineTwo = -1; int offsetOfLineTwo = -1;
int linesAdded = 0; int linesAdded = 0;
int addedLastLineColumns = 0; int addedLastLineColumns = 0;
...@@ -61,13 +61,13 @@ class CTEDocumentListener implements IDocumentListener { ...@@ -61,13 +61,13 @@ class CTEDocumentListener implements IDocumentListener {
e.printStackTrace(); e.printStackTrace();
} }
int endOffset = offset + event.getText().length(); int endOffset = offset + textLength;
int endLineNumber = document.getLineOfOffset(endOffset); int endLineNumber = document.getLineOfOffset(endOffset);
addedLastLineColumns = endOffset addedLastLineColumns = endOffset
- document.getLineOffset(endLineNumber); - document.getLineOffset(endLineNumber);
linesAdded = endLineNumber - startLineNumber; linesAdded = endLineNumber - startLineNumber;
/*
/* System.out.println("PROCESSING DocumentEvent: "); System.out.println("PROCESSING DocumentEvent: ");
System.out.println(" Offset: " + offset); System.out.println(" Offset: " + offset);
System.out.println(" Replaced: " + event.getLength()); System.out.println(" Replaced: " + event.getLength());
System.out.println(" New: " + event.getText().length()); System.out.println(" New: " + event.getText().length());
...@@ -81,27 +81,22 @@ class CTEDocumentListener implements IDocumentListener { ...@@ -81,27 +81,22 @@ class CTEDocumentListener implements IDocumentListener {
// NOTE: we do not try to fix the replaced part. // NOTE: we do not try to fix the replaced part.
int fixColumnUntilOffset = offsetOfLineTwo; int fixColumnUntilOffset = offsetOfLineTwo + removedLength;
int fixAfterOffset = offset + event.getLength(); int fixAfterOffset = offset + removedLength;
int diffOffset = event.getText().length() - event.getLength(); int diffOffset = textLength - removedLength;
int diffLines = linesAdded - linesRemoved; int diffLines = linesAdded - linesRemoved;
int diffColumns = addedLastLineColumns - removedLastLineColumns; int diffColumns = addedLastLineColumns - removedLastLineColumns;
/* System.out.println(" fixAfterOffset: " + fixAfterOffset); /*
System.out.println(" fixAfterOffset: " + fixAfterOffset);
System.out.println(" offsetOfLineTwo: " + offsetOfLineTwo);
System.out.println(" diffOffset: " + diffOffset); System.out.println(" diffOffset: " + diffOffset);
System.out.println(" diffLines: " + diffLines); System.out.println(" diffLines: " + diffLines);
System.out.println(" diffColumns: " + diffColumns); System.out.println(" diffColumns: " + diffColumns);
*/ */
System.out.println(" fixAfterOffset: " + fixAfterOffset);
System.out.println(" offsetOfLineTwo: " + offsetOfLineTwo);
LocationPatchVisitor visitor = new LocationPatchVisitor(fixAfterOffset, LocationPatchVisitor visitor = new LocationPatchVisitor(fixAfterOffset,
fixColumnUntilOffset, diffLines, diffColumns, diffOffset); fixColumnUntilOffset, diffLines, diffColumns, diffOffset);
ast.accept(visitor, null); ast.accept(visitor, null);
// long timerAfter = System.currentTimeMillis(); // TODO: remove!
// System.out.println("Location patch took: " + (timerAfter - timerBefore) + " millis.");
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment