Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions agent-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -7143,8 +7143,7 @@ Uses AGENT-CWD to shorten file paths where necessary."
(let ((char-start (map-elt region :char-start))
(char-end (map-elt region :char-end))
(max-preview-lines 5))
(if (equal (line-number-at-pos char-start)
(line-number-at-pos char-end))
(if (= (count-lines char-start char-end) 1)
;; Same line region? Avoid numbering.
(buffer-substring char-start char-end)
(agent-shell--get-numbered-region
Expand All @@ -7170,7 +7169,11 @@ If CAP is non-nil, truncate at CAP."
(save-excursion
(goto-char from)
(let* ((start-line (line-number-at-pos from))
(end-line (line-number-at-pos to))
(end-line (save-excursion
(goto-char to)
(when (and (bolp) (not (bobp)))
(backward-char))
(line-number-at-pos)))
(lines '())
(current-line start-line))
(goto-char (point-min))
Expand Down Expand Up @@ -7394,8 +7397,12 @@ Available values:
(:language . ,language)
(:char-start . ,start)
(:char-end . ,end)
(:line-start . ,(save-excursion (goto-char start) (line-number-at-pos)))
(:line-end . ,(save-excursion (goto-char end) (line-number-at-pos)))
(:line-start . ,(line-number-at-pos start))
(:line-end . ,(save-excursion
(goto-char end)
(when (and (bolp) (not (bobp)))
(backward-char))
(line-number-at-pos)))
(:content . ,content)))))

(cl-defun agent-shell--align-alist (&key data columns (separator " ") joiner)
Expand Down
23 changes: 21 additions & 2 deletions tests/agent-shell-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,12 @@
(ert-deftest agent-shell--get-numbered-region-test ()
"Test `agent-shell--get-numbered-region' preserves selection and respects TRIM."
(with-temp-buffer
;; Lines: 1="", 2="foo", 3="", 4="bar", 5="" (trailing newline).
;; Lines: 1="", 2="foo", 3="", 4="bar", 5="" (including trailing newline).
(insert "
foo

bar

")
;; Without TRIM: empty boundary lines (1 and 5) are preserved.
(should (equal (agent-shell--get-numbered-region
Expand All @@ -449,7 +450,25 @@ bar
:trim t)
" 2: foo
3:
4: bar"))))
4: bar")))
(with-temp-buffer
(insert "foo
bar
baz
")
(let (from to)
(goto-char (point-min))
(forward-line 1)
(setq from (point))
(forward-line 1)
(setq to (point))
;; When selecting whole lines including trailing newline, adjust
;; region-end
(should (equal (agent-shell--get-numbered-region
:buffer (current-buffer)
:from from
:to to)
" 2: bar")))))

(ert-deftest agent-shell--expand-truncated-regions-test ()
"Test `agent-shell--expand-truncated-regions' substitutes marked spans for their full text."
Expand Down
Loading