Lines 71-76
Link Here
|
71 |
public int tabLength; |
71 |
public int tabLength; |
72 |
public int indentationSize; |
72 |
public int indentationSize; |
73 |
private IRegion[] regions; |
73 |
private IRegion[] regions; |
|
|
74 |
private IRegion[] adaptedRegions; |
74 |
public int tabChar; |
75 |
public int tabChar; |
75 |
public int numberOfIndentations; |
76 |
public int numberOfIndentations; |
76 |
private boolean useTabsOnlyForLeadingIndents; |
77 |
private boolean useTabsOnlyForLeadingIndents; |
Lines 116-122
Link Here
|
116 |
* If a region should be adapted (see isAdaptableRegion(IRegion)) |
117 |
* If a region should be adapted (see isAdaptableRegion(IRegion)) |
117 |
* retrieve correct upper and lower bounds and replace the region. |
118 |
* retrieve correct upper and lower bounds and replace the region. |
118 |
*/ |
119 |
*/ |
119 |
private void adaptSelectedRegions() { |
120 |
private void adaptRegions() { |
|
|
121 |
this.adaptedRegions = new Region[this.regions.length]; |
120 |
for (int i = 0, max = this.regions.length; i < max; i++) { |
122 |
for (int i = 0, max = this.regions.length; i < max; i++) { |
121 |
IRegion aRegion = this.regions[i]; |
123 |
IRegion aRegion = this.regions[i]; |
122 |
int offset = aRegion.getOffset(); |
124 |
int offset = aRegion.getOffset(); |
Lines 131-147
Link Here
|
131 |
for (int j = 0, max2 = this.editsIndex; j < max2; j++) { |
133 |
for (int j = 0, max2 = this.editsIndex; j < max2; j++) { |
132 |
// search for lower bound |
134 |
// search for lower bound |
133 |
int editOffset = this.edits[j].offset; |
135 |
int editOffset = this.edits[j].offset; |
134 |
if (upperFound) { |
136 |
if (upperFound && lowerBound == 0) { |
135 |
int editLength = this.edits[j].length; |
137 |
int editLength = this.edits[j].length; |
136 |
if (lowerBound == 0 && editOffset + editLength < regionEnd) { |
138 |
if (editOffset == regionEnd) { // matching edit found |
|
|
139 |
lowerBound = regionEnd; |
140 |
break; |
141 |
} else if (editOffset + editLength < regionEnd) { |
137 |
continue; |
142 |
continue; |
138 |
} else { |
143 |
} else { |
139 |
lowerBound = editOffset + editLength; |
144 |
lowerBound = editOffset + editLength; // upper and lower bounds found |
140 |
break; // found both bonds - leave the loop |
145 |
break; |
141 |
} |
146 |
} |
142 |
// search for upper bound |
147 |
// search for upper bound |
143 |
} else { |
148 |
} else { |
144 |
if (this.edits[j+1].offset < offset) { |
149 |
if (this.edits[j + 1].offset < offset) { |
145 |
continue; |
150 |
continue; |
146 |
} else { |
151 |
} else { |
147 |
upperBound = editOffset; |
152 |
upperBound = editOffset; |
Lines 150-159
Link Here
|
150 |
} |
155 |
} |
151 |
} |
156 |
} |
152 |
if (lowerBound != 0) { |
157 |
if (lowerBound != 0) { |
153 |
// store result if any |
158 |
if (offset != upperBound || regionEnd != lowerBound) { // ensure we found a different region |
154 |
this.regions[i] = new Region(upperBound , lowerBound - upperBound); |
159 |
this.adaptedRegions[i] = new Region(upperBound, |
|
|
160 |
lowerBound - upperBound); |
161 |
} |
162 |
// keep other unadaptable region |
163 |
} else { |
164 |
this.adaptedRegions[i] = this.regions[i]; |
155 |
} |
165 |
} |
|
|
166 |
} else { |
167 |
this.adaptedRegions[i] = this.regions[i]; |
156 |
} |
168 |
} |
|
|
169 |
} else { |
170 |
this.adaptedRegions[i] = this.regions[i]; |
157 |
} |
171 |
} |
158 |
} |
172 |
} |
159 |
} |
173 |
} |
Lines 606-624
Link Here
|
606 |
|
620 |
|
607 |
public TextEdit getRootEdit() { |
621 |
public TextEdit getRootEdit() { |
608 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541 |
622 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208541 |
609 |
adaptSelectedRegions(); |
623 |
adaptRegions(); |
610 |
|
624 |
|
611 |
MultiTextEdit edit = null; |
625 |
MultiTextEdit edit = null; |
612 |
int regionsLength = this.regions.length; |
626 |
int regionsLength = this.adaptedRegions.length; |
613 |
int textRegionStart; |
627 |
int textRegionStart; |
614 |
int textRegionEnd; |
628 |
int textRegionEnd; |
615 |
if (regionsLength == 1) { |
629 |
if (regionsLength == 1) { |
616 |
IRegion lastRegion = this.regions[0]; |
630 |
IRegion lastRegion = this.adaptedRegions[0]; |
617 |
textRegionStart = lastRegion.getOffset(); |
631 |
textRegionStart = lastRegion.getOffset(); |
618 |
textRegionEnd = textRegionStart + lastRegion.getLength(); |
632 |
textRegionEnd = textRegionStart + lastRegion.getLength(); |
619 |
} else { |
633 |
} else { |
620 |
textRegionStart = this.regions[0].getOffset(); |
634 |
textRegionStart = this.adaptedRegions[0].getOffset(); |
621 |
IRegion lastRegion = this.regions[regionsLength - 1]; |
635 |
IRegion lastRegion = this.adaptedRegions[regionsLength - 1]; |
622 |
textRegionEnd = lastRegion.getOffset() + lastRegion.getLength(); |
636 |
textRegionEnd = lastRegion.getOffset() + lastRegion.getLength(); |
623 |
} |
637 |
} |
624 |
|
638 |
|
Lines 723-739
Link Here
|
723 |
* @return boolean true if line should be adapted, false otherwhise |
737 |
* @return boolean true if line should be adapted, false otherwhise |
724 |
*/ |
738 |
*/ |
725 |
private boolean isAdaptableRegion(int offset, int length) { |
739 |
private boolean isAdaptableRegion(int offset, int length) { |
726 |
int span = offset + length; |
740 |
int regionEnd = offset + length + this.lineSeparator.length() - 1; |
727 |
// first check region width |
741 |
// first check region width |
728 |
if (span > this.pageWidth) { |
742 |
if (regionEnd > this.pageWidth) { |
729 |
return false; |
743 |
return false; |
730 |
} |
744 |
} |
731 |
// more than one line selected |
745 |
int numberOfLineEnds = this.lineEnds != null && this.lineEnds.length > 0 ? this.lineEnds.length : 0; |
732 |
if (span > this.getLineEnd(this.scanner.getLineNumber(offset) + 1)) { |
746 |
if (this.line > 1 && numberOfLineEnds > 0) { // CU has more than one line |
733 |
return false; |
747 |
int lineNumber = Util.getLineNumber(offset, this.lineEnds, 0, this.line); |
734 |
// region is on a single line and CU has more than one line |
748 |
int lineEnd = this.getLineEnd(lineNumber); |
735 |
} else if (this.lineEnds != null && this.lineEnds.length > 1) { |
749 |
if (regionEnd > lineEnd) { |
736 |
return true; |
750 |
// if more than one line selected, check whether selection is at line end |
|
|
751 |
for (int i = lineNumber + 1 ; i <= numberOfLineEnds ; i++) { |
752 |
if (regionEnd == this.getLineEnd(i)) { |
753 |
return true; |
754 |
} |
755 |
} |
756 |
return false; // more than one line selected, no need to adapt region |
757 |
} else { |
758 |
if (this.scannerEndPosition - 1 == lineEnd) { // EOF reached? |
759 |
return false; |
760 |
} |
761 |
return true; // a single line was selected |
762 |
} |
737 |
} |
763 |
} |
738 |
return false; |
764 |
return false; |
739 |
} |
765 |
} |
Lines 792-798
Link Here
|
792 |
|
818 |
|
793 |
if (editOffset == this.scannerEndPosition) { |
819 |
if (editOffset == this.scannerEndPosition) { |
794 |
int index = Arrays.binarySearch( |
820 |
int index = Arrays.binarySearch( |
795 |
this.regions, |
821 |
this.adaptedRegions, |
796 |
new Region(editOffset, 0), |
822 |
new Region(editOffset, 0), |
797 |
new Comparator() { |
823 |
new Comparator() { |
798 |
public int compare(Object o1, Object o2) { |
824 |
public int compare(Object o1, Object o2) { |
Lines 833-839
Link Here
|
833 |
} |
859 |
} |
834 |
} |
860 |
} |
835 |
|
861 |
|
836 |
IRegion region = this.regions[index]; |
862 |
IRegion region = this.adaptedRegions[index]; |
837 |
if ((region.getOffset() <= offset) && (end <= region.getOffset() + region.getLength() - 1)) { |
863 |
if ((region.getOffset() <= offset) && (end <= region.getOffset() + region.getLength() - 1)) { |
838 |
return region; |
864 |
return region; |
839 |
} |
865 |
} |
Lines 841-854
Link Here
|
841 |
} |
867 |
} |
842 |
|
868 |
|
843 |
private int getIndexOfRegionAt(int offset) { |
869 |
private int getIndexOfRegionAt(int offset) { |
844 |
if (this.regions.length == 1) { |
870 |
if (this.adaptedRegions.length == 1) { |
845 |
int offset2 = this.regions[0].getOffset(); |
871 |
int offset2 = this.adaptedRegions[0].getOffset(); |
846 |
if (offset2 == offset) { |
872 |
if (offset2 == offset) { |
847 |
return 0; |
873 |
return 0; |
848 |
} |
874 |
} |
849 |
return offset2 < offset ? -2 : -1; |
875 |
return offset2 < offset ? -2 : -1; |
850 |
} |
876 |
} |
851 |
return Arrays.binarySearch(this.regions, new Region(offset, 0), new Comparator() { |
877 |
return Arrays.binarySearch(this.adaptedRegions, new Region(offset, 0), new Comparator() { |
852 |
public int compare(Object o1, Object o2) { |
878 |
public int compare(Object o1, Object o2) { |
853 |
int r1Offset = ((IRegion)o1).getOffset(); |
879 |
int r1Offset = ((IRegion)o1).getOffset(); |
854 |
int r2Offset = ((IRegion)o2).getOffset(); |
880 |
int r2Offset = ((IRegion)o2).getOffset(); |