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

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 16, 2013
Jump to file or symbol
Failed to load files and symbols.
+20 −1
Split
View
@@ -251,6 +251,18 @@ FOR-GROUP."
(error "Nothing at point to do.")))
(def (lookup-key (current-local-map) key)))
(call-interactively def)))
+
+(defun magit-key-mode-build-exec-point-alist ()
+ (save-excursion
+ (goto-char (point-min))
+ (let* ((exec (get-text-property (point) 'key-group-executor))
+ (exec-alist (if exec `((,exec . ,(point))) nil)))
+ (do nil ((eobp) (nreverse exec-alist))
+ (when (not (eq exec (get-text-property (point) 'key-group-executor)))
+ (setq exec (get-text-property (point) 'key-group-executor))
+ (when exec (push (cons exec (point)) exec-alist)))
+ (forward-char)))))
+
(defun magit-key-mode-jump-to-next-exec ()
"Jump to the next action/args/option point."
(interactive)
@@ -396,6 +408,8 @@ highlighted before the description."
(defun magit-key-mode-redraw (for-group)
"(re)draw the magit key buffer."
(let ((buffer-read-only nil)
+ (current-exec (get-text-property (point) 'key-group-executor))
+ (new-exec-pos)
(old-point (point))
(is-first (zerop (buffer-size)))
(actions-p nil))
@@ -405,10 +419,15 @@ highlighted before the description."
(setq actions-p (magit-key-mode-draw for-group))
(delete-trailing-whitespace)
(setq mode-name "magit-key-mode" major-mode 'magit-key-mode)
+ (when current-exec
+ (setq new-exec-pos (cdr (assoc current-exec (magit-key-mode-build-exec-point-alist)))))
(if (and is-first actions-p)
(progn (goto-char actions-p)
(magit-key-mode-jump-to-next-exec))
- (goto-char old-point)))
+ (if new-exec-pos
+ (progn (goto-char new-exec-pos)
+ (skip-chars-forward " "))
+ (goto-char old-point))))
(setq buffer-read-only t)
(fit-window-to-buffer))