copilot.el icon indicating copy to clipboard operation
copilot.el copied to clipboard

Cursor position error

Open JiaweiChenC opened this issue 1 year ago • 8 comments

When the real cursor position is not at the start of the overlay preview. The cursor will jump to the end of the overlay.

For example: copilot_bug the cursor will keep jumping to the end of the overlay.

Another similar situation: another_bug the cursor's real position is after :, but it will jump to the end of the completion.

To reproduce:

emacs -Q -l test.el test.py
;; test.el
(package-initialize)

;; straight.el initialization
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/"))

;; Location of my use-package git clone
(add-to-list 'load-path "~/.emacs.d/.local/straight/repos/use-package/")
(require 'use-package)

(use-package copilot
  :straight (:host github :repo "zerolfx/copilot.el" :files ("dist" "*.el"))
  :ensure t)

(add-hook 'prog-mode-hook 'copilot-mode)

JiaweiChenC avatar Nov 11 '23 22:11 JiaweiChenC

It seems that this happens when the first character of the completion is a newline and the code is attempting to set the cursor property on the newline character. :thinking:

emil-vdw avatar Dec 26 '23 13:12 emil-vdw

Is this the same issue reported with Typescript? https://github.com/copilot-emacs/copilot.el/issues/165

I often have issues with the cursor jumping in TS files, but that issue was closed as stale a while back.

johnnywalker avatar Jan 17 '24 18:01 johnnywalker

I still have the same problem on latest master so upvoted this issue.

baongoc124 avatar Apr 17 '24 01:04 baongoc124

I'll look into this!

jcs090218 avatar Apr 17 '24 02:04 jcs090218

If it helps, here’s another reproduction of the issue that happens for me all the time. Here after if I type ( instead of hitting tab because I want to write something other than the suggestion. The ( does not show behind the suggestion, but it’s there and later appears after what I type. This is typescript-mode with lsp-mode. Everything should be latest version, I suppose.

https://github.com/copilot-emacs/copilot.el/assets/531910/b4bb41fa-834b-4586-8055-ca2e38f2cb63

mostafah avatar Jun 06 '24 05:06 mostafah

Same here, with typescript-mode (happens without lsp-mode / eglot). Colons, parentheses, braces are all affected.

julian-hoch avatar Jun 11 '24 20:06 julian-hoch

It happens in python model as well, that sometimes the cursor is placed at the end of the suggestion instead of the beginning. E.g. in the following image the last character input by my was ":", the rest was filled in by copilot and the cursor is shown at the end of the suggestion, instead of the beginning:

wrong-cursor

dov avatar Jun 26 '24 07:06 dov

I'm also experiencing this in Python.

AndreaOrru avatar Jul 31 '24 12:07 AndreaOrru