Skip to content

Commit 12f8209

Browse files
CopilotKinneyzhang
andcommitted
Fix trailing spaces not being preserved
- Update css-parser-loop to attach remaining accumulated spaces to last node's :after field - Now correctly preserves trailing whitespace in selectors - Test: " div a " now correctly stringifies back to " div a " (was losing trailing space) Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
1 parent b6661d4 commit 12f8209

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

css-selector-parser.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,18 @@ TYPE是节点类型,PROPS是属性列表。"
643643
(while (< (css-parser-position parser)
644644
(length (css-parser-tokens parser)))
645645
(css-parser-parse parser))
646+
647+
;; 处理剩余的尾随空白 - 附加到最后一个节点的 :after
648+
(when (and (css-parser-spaces-before parser)
649+
(not (string= (css-parser-spaces-before parser) "")))
650+
(let* ((current-selector (css-parser-current parser))
651+
(nodes (plist-get current-selector :nodes)))
652+
(when nodes
653+
(let* ((last-node (car (last nodes)))
654+
(spaces (plist-get last-node :spaces)))
655+
(when spaces
656+
(plist-put spaces :after (css-parser-spaces-before parser)))))))
657+
646658
(css-parser-root parser))
647659

648660
;;; 公共API

0 commit comments

Comments
 (0)