Skip to content

Commit

Permalink
Cycling "LSP4E Linked Editing" job when selecting attribute value #838
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny committed Jul 1, 2022
1 parent a8f1994 commit 9d3f114
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ private void updateLinkedEditing(ISelection selection) {
private void updateLinkedEditing(int offset) {
if (sourceViewer != null && fDocument != null && fEnabled && linkedModel == null || !linkedModel.anyPositionContains(offset)) {
collectLinkedEditingRanges(fDocument, offset)
.thenAcceptAsync(this::applyLinkedEdit);
.thenAcceptAsync(r -> {
if (rangesContainOffset(r, offset)) {
applyLinkedEdit(r);
}
});
}
}

Expand Down Expand Up @@ -232,9 +236,9 @@ public IStatus runInUIThread(IProgressMonitor monitor) {
String getValueInRange(LinkedEditingRanges ranges, VerifyEvent event, int offset, int length) {
try {
for (Range range : ranges.getRanges()) {
int start = LSPEclipseUtils.toOffset(range.getStart(), fDocument);
int end = LSPEclipseUtils.toOffset(range.getEnd(), fDocument);
if (start <= offset && offset <= end) {
if (LSPEclipseUtils.isOffsetInRange(offset, range, fDocument)) {
int start = LSPEclipseUtils.toOffset(range.getStart(), fDocument);
int end = LSPEclipseUtils.toOffset(range.getEnd(), fDocument);
StringBuilder sb = new StringBuilder();
sb.append(fDocument.get(start, end - start)); // The range text before the insertion
String newChars = event.character == 0 ? "" : Character.toString(event.character); //$NON-NLS-1$
Expand All @@ -248,6 +252,15 @@ String getValueInRange(LinkedEditingRanges ranges, VerifyEvent event, int offset
return null;
}

private boolean rangesContainOffset(LinkedEditingRanges ranges, int offset) {
for (Range range : ranges.getRanges()) {
if (LSPEclipseUtils.isOffsetInRange(offset, range, fDocument)) {
return true;
}
}
return false;
}

private LinkedPositionGroup toJFaceGroup(LinkedEditingRanges ranges) throws BadLocationException {
LinkedPositionGroup res = new LinkedPositionGroup();
for (Range range : ranges.getRanges()) {
Expand All @@ -257,5 +270,4 @@ private LinkedPositionGroup toJFaceGroup(LinkedEditingRanges ranges) throws BadL
}
return res;
}

}

0 comments on commit 9d3f114

Please sign in to comment.