Skip to content

Commit 2ec00be

Browse files
authored
fix - Update the cursor position from event (microsoft#49)
* fix - Update the cursor position from event and rename variable
1 parent 1e266a0 commit 2ec00be

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

com.microsoft.copilot.eclipse.core/src/com/microsoft/copilot/eclipse/core/completion/CompletionProvider.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import org.eclipse.core.runtime.jobs.IJobChangeListener;
1010
import org.eclipse.lsp4j.Position;
1111

12-
import com.microsoft.copilot.eclipse.core.CopilotCore;
1312
import com.microsoft.copilot.eclipse.core.CopilotStatusManager;
14-
import com.microsoft.copilot.eclipse.core.logger.LogLevel;
1513
import com.microsoft.copilot.eclipse.core.lsp.CopilotLanguageServerConnection;
1614
import com.microsoft.copilot.eclipse.core.lsp.protocol.CompletionDocument;
1715
import com.microsoft.copilot.eclipse.core.lsp.protocol.CompletionParams;

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/completion/CompletionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public CompletionCollection getCompletions() {
139139

140140
@Override
141141
public void caretMoved(CaretEvent event) {
142-
int caretOffset = UiUtils.getCaretOffset(this.textViewer);
143-
this.triggerPosition = new org.eclipse.jface.text.Position(caretOffset);
142+
int modelOffset = UiUtils.widgetOffset2ModelOffset(textViewer, event.caretOffset);
143+
this.triggerPosition = new org.eclipse.jface.text.Position(modelOffset);
144144

145145
// it's guaranteed that the document change event comes earlier than caret
146146
// change event. See org.eclipse.swt.custom.StyledText#modifyContent()

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/UiUtils.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,19 @@ public static ImageDescriptor resizeIcon(String path, int width, int height) {
7777
}
7878

7979
/**
80-
* Gets the caret offset of the given text viewer.
80+
* Returns the widget offset that corresponds to the given offset in the viewer's input document or <code>-1</code> if
81+
* there is no such offset.
8182
*/
82-
public static int getCaretOffset(ITextViewer textViewer) {
83-
if (textViewer == null) {
84-
return 0;
85-
}
86-
return textViewer.getSelectedRange().x;
83+
public static int modelOffset2WidgetOffset(ITextViewer textViewer, int offset) {
84+
return textViewer instanceof ITextViewerExtension5 extension ? extension.modelOffset2WidgetOffset(offset) : offset;
8785
}
8886

8987
/**
90-
* Returns the widget offset that corresponds to the given offset in the viewer's input document or <code>-1</code> if
88+
* Returns the offset of the viewer's input document that corresponds to the given widget offset or <code>-1</code> if
9189
* there is no such offset.
9290
*/
93-
public static int modelOffset2WidgetOffset(ITextViewer textViewer, int offset) {
94-
return textViewer instanceof ITextViewerExtension5 extension ? extension.modelOffset2WidgetOffset(offset) : offset;
91+
public static int widgetOffset2ModelOffset(ITextViewer textViewer, int offset) {
92+
return textViewer instanceof ITextViewerExtension5 extension ? extension.widgetOffset2ModelOffset(offset) : offset;
9593
}
9694

9795
/**

0 commit comments

Comments
 (0)