Skip to content

Backward block navigation skips current block start #157

@ultronozm

Description

@ultronozm

Steps to reproduce:

  • Place point in the middle of a navigable block.
  • Press p (or S-<tab>).

This jumps to the previous block.

I would have expected Emacs-style behavior: first go to the start of the current block, and only on the next p go to the previous block, like with the following patch:

diff --git a/agent-shell-ui.el b/agent-shell-ui.el
index bafa099..2d8eb5b 100644
--- a/agent-shell-ui.el
+++ b/agent-shell-ui.el
@@ -518,17 +518,21 @@ INDENT-STRING defaults to two spaces."
   (interactive)
   (when-let* ((start-point (point))
               (found (save-mark-and-excursion
-                       ;; In navigatable block already
-                       ;; move to beginning.
-                       (when-let ((state (get-text-property (point) 'agent-shell-ui-state))
-                                  (block (agent-shell-ui--block-range :position (point))))
-                         (goto-char (map-elt block :start)))
-                       (when-let ((prev (text-property-search-backward
-                                         'agent-shell-ui-state nil
-                                         (lambda (_old-val new-val)
-                                           (and new-val (map-elt new-val :navigatable)))
-                                         t)))
-                         (prop-match-beginning prev)))))
+                       (let* ((state (get-text-property (point) 'agent-shell-ui-state))
+                              (block (agent-shell-ui--block-range :position (point)))
+                              (block-start (and block (map-elt block :start)))
+                              (navigatable (and state (map-elt state :navigatable))))
+                         (if (and navigatable block-start (> (point) block-start))
+                             ;; In navigatable block already: go to its start first.
+                             block-start
+                           (when block-start
+                             (goto-char (max (point-min) (1- block-start))))
+                           (when-let ((prev (text-property-search-backward
+                                             'agent-shell-ui-state nil
+                                             (lambda (_old-val new-val)
+                                               (and new-val (map-elt new-val :navigatable)))
+                                             t)))
+                             (prop-match-beginning prev)))))))
     (when found
       (deactivate-mark)
       (goto-char found)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions