Skip to content
This repository

Fix incorrect cursor location in magit-key-mode #514

Merged
merged 1 commit into from about 1 year ago

2 participants

Steven Thomas Yann Hodique
Steven Thomas

After setting an argument value, point would be in the wrong spot. Fix
this by saving which option point is at before redrawing, then jumping
to that option after redrawing. Add a new function
magit-key-mode-build-exec-point-alist to help with this.

Steven Thomas Fix incorrect cursor location in magit-key-mode
After setting an argument value, point would be in the wrong spot. Fix
this by saving which option point is at before redrawing, then jumping
to that option after redrawing. Add a new function
magit-key-mode-build-exec-point-alist to help with this.
92fdb63
Steven Thomas

Easiest way to repro the problem:

  1. Open magit on a repo.
  2. 'l' to bring up the log menu.
  3. Notice point is at the 'l', the first item in the actions section.
  4. '=g' and enter something for the grep value (e.g. "hello").
  5. Notice point is no longer at the 'l' in the actions section.
Yann Hodique
Owner

I do agree there's a problem there, but I'm not sure this fix goes into the right direction.
Actually all this derives from the fact that we're erasing the entire buffer and rebuilding it each time anything changes.
I think that's madness and that we should fix this instead.

Like, we could store a list of overlays for each option, and have them populated/altered whenever something changes.
That way the cursor would stay in place by itself, simply because it would never have to move !

Steven Thomas

I agree it'd be better to not redraw the buffer every time. Until that's done though, why not take my change? It at least fixes the bug with the cursor position. Once magit-key-mode is changed to not redraw the buffer every time, my code to fix the cursor pos would be obsolete and could be easily deleted.

Yann Hodique sigma merged commit 92fdb63 into from February 16, 2013
Yann Hodique sigma closed this February 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 28, 2012
Steven Thomas Fix incorrect cursor location in magit-key-mode
After setting an argument value, point would be in the wrong spot. Fix
this by saving which option point is at before redrawing, then jumping
to that option after redrawing. Add a new function
magit-key-mode-build-exec-point-alist to help with this.
92fdb63
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 20 additions and 1 deletion. Show diff stats Hide diff stats

  1. 21  magit-key-mode.el
21  magit-key-mode.el
@@ -251,6 +251,18 @@ FOR-GROUP."
251 251
                   (error "Nothing at point to do.")))
252 252
          (def (lookup-key (current-local-map) key)))
253 253
     (call-interactively def)))
  254
+
  255
+(defun magit-key-mode-build-exec-point-alist ()
  256
+  (save-excursion
  257
+    (goto-char (point-min))
  258
+    (let* ((exec (get-text-property (point) 'key-group-executor))
  259
+           (exec-alist (if exec `((,exec . ,(point))) nil)))
  260
+      (do nil ((eobp) (nreverse exec-alist))
  261
+        (when (not (eq exec (get-text-property (point) 'key-group-executor)))
  262
+          (setq exec (get-text-property (point) 'key-group-executor))
  263
+          (when exec (push (cons exec (point)) exec-alist)))
  264
+        (forward-char)))))
  265
+
254 266
 (defun magit-key-mode-jump-to-next-exec ()
255 267
   "Jump to the next action/args/option point."
256 268
   (interactive)
@@ -396,6 +408,8 @@ highlighted before the description."
396 408
 (defun magit-key-mode-redraw (for-group)
397 409
   "(re)draw the magit key buffer."
398 410
   (let ((buffer-read-only nil)
  411
+        (current-exec (get-text-property (point) 'key-group-executor))
  412
+        (new-exec-pos)
399 413
         (old-point (point))
400 414
         (is-first (zerop (buffer-size)))
401 415
         (actions-p nil))
@@ -405,10 +419,15 @@ highlighted before the description."
405 419
     (setq actions-p (magit-key-mode-draw for-group))
406 420
     (delete-trailing-whitespace)
407 421
     (setq mode-name "magit-key-mode" major-mode 'magit-key-mode)
  422
+    (when current-exec
  423
+      (setq new-exec-pos (cdr (assoc current-exec (magit-key-mode-build-exec-point-alist)))))
408 424
     (if (and is-first actions-p)
409 425
       (progn (goto-char actions-p)
410 426
              (magit-key-mode-jump-to-next-exec))
411  
-      (goto-char old-point)))
  427
+      (if new-exec-pos
  428
+          (progn (goto-char new-exec-pos)
  429
+                 (skip-chars-forward " "))
  430
+          (goto-char old-point))))
412 431
   (setq buffer-read-only t)
413 432
   (fit-window-to-buffer))
414 433
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.