This commit is contained in:
Andrew Dupont 2023-12-25 18:04:44 -06:00
parent 0b51a77cd6
commit aef7c845b5
2 changed files with 21 additions and 10 deletions

View File

@ -162,9 +162,9 @@
; onClick={onClick}
; >
(jsx_opening_element ["<"] @indent
(#is-not? test.startsOnSameRowAs parent.lastChild))
(#is-not? test.startsOnSameRowAs parent.lastChild.startPosition))
((jsx_opening_element [">"] @dedent)
(#is-not? test.startsOnSameRowAs parent.firstChild))
(#is-not? test.startsOnSameRowAs parent.firstChild.startPosition))
; We match on the whole node here because
; (a) we need to please the dedent-while-typing heuristic, so the line text
@ -180,13 +180,13 @@
; alt={'foo'}
; />
(jsx_self_closing_element "<" @indent
(#is-not? test.startsOnSameRowAs parent.lastChild))
(#is-not? test.startsOnSameRowAs parent.lastChild.startPosition))
; There isn't a single node whose exact text will match the line content at any
; point, so the usual heuristic won't work. Instead we set `indent.force` and
; use `test.lastTextOnRow` to ensure that the dedent fires exactly once while
; typing.
((jsx_self_closing_element ">" @dedent)
(#is-not? test.startsOnSameRowAs parent.firstChild)
(#is-not? test.startsOnSameRowAs parent.firstChild.startPosition)
(#is? test.lastTextOnRow)
(#set! indent.force true))

View File

@ -3,11 +3,22 @@
; ===
(jsx_opening_element [">"] @indent)
(jsx_opening_element ["<"] @indent
(#is-not? test.startsOnSameRowAs parent.lastChild))
((jsx_opening_element [">"] @dedent)
(#is-not? test.startsOnSameRowAs parent.firstChild))
; Support things like…
; <div
; className={'foo'}
; onClick={onClick}
; >
(jsx_opening_element ["<"] @indent
(#is-not? test.startsOnSameRowAs parent.lastChild.startPosition))
((jsx_opening_element [">"] @dedent)
(#is-not? test.startsOnSameRowAs parent.firstChild.startPosition))
; We match on the whole node here because
; (a) we need to please the dedent-while-typing heuristic, so the line text
; must match the capture node's text; and
; (b) we don't want the dedent to trigger until the very last `>` has been
; typed.
(jsx_closing_element ">") @dedent
; Support things like…
@ -17,13 +28,13 @@
; alt={'foo'}
; />
(jsx_self_closing_element "<" @indent
(#is-not? test.startsOnSameRowAs parent.lastChild))
(#is-not? test.startsOnSameRowAs parent.lastChild.startPosition))
; There isn't a single node whose exact text will match the line content at any
; point, so the usual heuristic won't work. Instead we set `indent.force` and
; use `test.lastTextOnRow` to ensure that the dedent fires exactly once while
; typing.
((jsx_self_closing_element ">" @dedent)
(#is-not? test.startsOnSameRowAs parent.firstChild)
(#is-not? test.startsOnSameRowAs parent.firstChild.startPosition)
(#is? test.lastTextOnRow)
(#set! indent.force true))