From 9d3f114e09689f3f2ea06892f28c3477f8ae409f Mon Sep 17 00:00:00 2001 From: Victor Rubezhny Date: Wed, 29 Jun 2022 19:40:41 +0200 Subject: [PATCH] Cycling "LSP4E Linked Editing" job when selecting attribute value #838 Signed-off-by: Victor Rubezhny --- .../LSPLinkedEditingReconcilingStrategy.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/linkedediting/LSPLinkedEditingReconcilingStrategy.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/linkedediting/LSPLinkedEditingReconcilingStrategy.java index b8d3aa4e9..39e93897b 100644 --- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/linkedediting/LSPLinkedEditingReconcilingStrategy.java +++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/linkedediting/LSPLinkedEditingReconcilingStrategy.java @@ -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); + } + }); } } @@ -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$ @@ -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()) { @@ -257,5 +270,4 @@ private LinkedPositionGroup toJFaceGroup(LinkedEditingRanges ranges) throws BadL } return res; } - } \ No newline at end of file