Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual cursor jumps to end of completion while real position stays put #28

Closed
jimeh opened this issue Jun 16, 2022 · 8 comments · Fixed by #351
Closed

Visual cursor jumps to end of completion while real position stays put #28

jimeh opened this issue Jun 16, 2022 · 8 comments · Fixed by #351

Comments

@jimeh
Copy link

jimeh commented Jun 16, 2022

Ever since commit dfa803e I'm afraid I've had issues with the cursor position.

Physically, the position does not change, and any cursor movement/editing actions briefly show the cursor in the correct position again, until a copilot suggestion appears. However it only happens for single-line suggestions from copilot. If it's suggesting multiple lines, the visual cursor position stays in the right place.

Here's a couple of gifs:

On commit 56b7d1b (latest):

copilot-current

On commit 3dcf2a7 with copilot-overlay-safe set to nil:

copilot-old

@zerolfx
Copy link
Collaborator

zerolfx commented Jun 17, 2022

The cursor property of the completion text does not work in your case.

The overlay thing is super easy to conflict with other plugins. I gave up the old approach (copilot-overlay-safe = nil) because of its compatibility.

Now the newer method seems not a perfect solution. Can you try to reproduce it with a minimal setup? So I can try to fix the compatibility issue. If I fail to fix it, I will provide an option to for these two approaches.

@jimeh
Copy link
Author

jimeh commented Jun 17, 2022

Sure thing, I'll narrow it down to a minimal setup this weekend :)

@jimeh
Copy link
Author

jimeh commented Jun 17, 2022

That didn't take long to find. First thing I tried was disabling whitespace-mode, and that was culprit.

jimeh added a commit to jimeh/.emacs.d that referenced this issue Jun 17, 2022
…ent issue

When whitespace-mode is enabled, single-line copilot completions makes
the cursor look like it's at the end of the completion rather than in
it's real position.

Issue with gifs showing the behavior is here:
copilot-emacs/copilot.el#28

For the most part I should be able to live without whitespace-mode in
day to day use, and improvements to the highlight-indent-guides setup
should help.

And worst case, whitespace-mode can always be toggled easily enough.
@zerolfx
Copy link
Collaborator

zerolfx commented Jun 19, 2022

I guess removing newline-mark in your whitespace-style will solve the problem.

@jimeh
Copy link
Author

jimeh commented Jun 20, 2022

Removing newline-mark did indeed solve the issue for me.

Not sure if you'd consider that a solution or a workaround though, so I'll let you choose if you want to close this issue or not.

Thanks again for your help, and continued support for copilot.el :)

zerolfx added a commit that referenced this issue Jun 21, 2022
@zerolfx
Copy link
Collaborator

zerolfx commented Jun 21, 2022

I decided to leave it unsolved for now. Figuring out the logic behind overlay and cursor is a pain for me.

The overlay part now is essentially the same as https://github.com/auto-complete/auto-complete/blob/master/auto-complete.el#L927, and I assume it is good enough for general use cases.

@asmeurer
Copy link

I'm also having this issue, particularly when the completion involves a newline. I am not using whitespace-mode, and in fact I can reproduce it with a minimal configuration only enabling copilot-mode in emacs -Q.

Here's a minimal reproducer:

;; 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 "~/Documents/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)

Then running:

emacs -Q -l test.el test.py

and typing

def test():

The completion looks like:

Screen Shot 2023-04-20 at 1 31 54 PM

Note that it shows the cursor at the end of the completion but it isn't really there. If I start typing more stuff the cursor is still at the : in the def test(): line. Needless to say, I find this behavior to be very disorienting.

@JiaweiChenC
Copy link

I also found the issue is still there with whitespace-mode disabled, does anyone have a temp solution for that?

aasseman pushed a commit to aasseman/copilot.el that referenced this issue Dec 21, 2024
Correct for indentation after accepting a completion rather than during
typing. This is less confusing than being impeded while typing spaces or
tabs on a new line while there is completion preview, and behaves more
like VSCode.

Fixes copilot-emacs#28 and copilot-emacs#200.
jcs090218 pushed a commit that referenced this issue Dec 22, 2024
Correct for indentation after accepting a completion rather than during
typing. This is less confusing than being impeded while typing spaces or
tabs on a new line while there is completion preview, and behaves more
like VSCode.

Fixes #28 and #200.

Co-authored-by: Alexis Asseman <[email protected]>
wangyuehong pushed a commit to wangyuehong/copilot.el that referenced this issue Dec 23, 2024
Correct for indentation after accepting a completion rather than during
typing. This is less confusing than being impeded while typing spaces or
tabs on a new line while there is completion preview, and behaves more
like VSCode.

Fixes copilot-emacs#28 and copilot-emacs#200.

Co-authored-by: Alexis Asseman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants