Commit 4c75f0eea5
Copy SHA
4c75f0eea5342f7f5a56227654fb6f40d0ef56e6
parent: 1dda0291d2
Verified · cmc
cmc <hello@cleberg.net> · 2026-10-09 01:27 UTC
Fill at the cursor with M-q in visual block state
Evil turns transient-mark-mode off in block state, so org-fill-paragraph sees no region and fills the paragraph at the cursor; with no change the block stays. Block state now reads its cursor from the last motion as the other visual states do, so motions past the second line extend the block.
Changed files (2)
Sources/OrgEditorAppKit/Modal.swift
+14 −8 · view
@@ -34,7 +34,7 @@ extension OrgEditor {
34 34 if keys . count > 1 { onKeysPending ? ( nil , [ ] ) }
35 35 let context = editContext ( )
36 36 if let binding = candidates . first ( where : { modalRuns ( $0 , in : context ) } ) {
37 if binding . command = = " org.fill-paragraph " , vim . mode = = . visual || vim . mode = = . visualLine {
37 if binding . command = = " org.fill-paragraph " , vim . mode = = . visual || vim . mode = = . visualLine || vim . mode = = . visualBlock {
38 38 fillVisual ( )
39 39 } else {
40 40 run ( binding . command )
@@ -57,15 +57,21 @@ extension OrgEditor {
57 57 }
58 58 }
59 59
60 // / M - q i n v i s u a l s t a t e s : ` o r g - f i l l - p a r a g r a p h ` o n t h e r e g i o n , t h e c u r s o r k e p t . A c h a n g e
61 // / d e a c t i v a t e s t h e r e g i o n , w h i c h l e a v e s v i s u a l s t a t e .
60 // / M - q i n v i s u a l s t a t e s : ` o r g - f i l l - p a r a g r a p h ` o n t h e r e g i o n , t h e c u r s o r k e p t . E v i l t u r n s
61 // / ` t r a n s i e n t - m a r k - m o d e ` o f f i n b l o c k s t a t e , s o t h e r e i t f i l l s t h e p a r a g r a p h a t t h e c u r s o r .
62 // / A c h a n g e d e a c t i v a t e s t h e r e g i o n , w h i c h l e a v e s v i s u a l s t a t e .
62 63 private func fillVisual ( ) {
63 let selected = textView . selectedRange ( )
64 let cursor = visualCaret ? ? selected . location
64 let selected = textView . selectedRange s
65 let cursor = visualCaret ? ? textView . selectedRange ( ) . location
65 66 let text = document . text
66 perform ( FillParagraph ( point : cursor ) )
67 if vim . mode = = . visualBlock {
68 textView . setSelectedRange ( NSRange ( location : cursor , length : 0 ) )
69 perform ( FillParagraph ( ) )
70 } else {
71 perform ( FillParagraph ( point : cursor ) )
72 }
67 73 if document . text = = text {
68 textView . se tSelectedRange ( selected )
74 textView . se lectedRanges = selected
69 75 visualCaret = cursor
70 76 } else {
71 77 vim . reset ( )
@@ -91,7 +97,7 @@ extension OrgEditor {
91 97 }
92 98 }
93 99 let wasInsert = vim . mode = = . insert
94 let visual = vim . mode = = . visual || vim . mode = = . visualLine
100 let visual = vim . mode = = . visual || vim . mode = = . visualLine || vim . mode = = . visualBlock
95 101 let caret = visual ? ( visualCaret ? ? textView . selectedRange ( ) . location ) : textView . selectedRange ( ) . location
96 102 if jumpToFileMark ( key ) { continue }
97 103 let clipboard = NSPasteboard . general . string ( forType : . string )
Tests/OrgEditorAppKitTests/ModalTests.swift
+29 · view
@@ -161,6 +161,35 @@ struct ModalTests {
161 161 # expect ( lines . editor . vim . mode = = . normal )
162 162 }
163 163
164 // / E v i l t u r n s ` t r a n s i e n t - m a r k - m o d e ` o f f i n v i s u a l b l o c k s t a t e , s o M - q t h e r e f i l l s t h e
165 // / p a r a g r a p h a t t h e c u r s o r ( c h e c k e d a g a i n s t e v i l w i t h ` o r g - f i l l - p a r a g r a p h ` ) .
166 @ Test func fillParagraphInVisualBlockFillsAtTheCursor ( ) {
167 let h = doom ( " aaa \n bbb \n \n ccc \n ddd \n \n eee \n fff \n " )
168 h . caret ( at : 0 )
169 type ( h , " C-v j j j " )
170 # expect ( h . textView . selectedRanges . first ? . rangeValue = = NSRange ( location : 0 , length : 1 ) && h . textView . selectedRanges . last ? . rangeValue = = NSRange ( location : 9 , length : 1 ) )
171 KeyTests ( ) . press ( h , " q " , option : KeyEvents . leftOption , typed : " œ " )
172 # expect ( h . editor . document . text = = " aaa \n bbb \n \n ccc ddd \n \n eee \n fff \n " )
173 # expect ( h . textView . selectedRange ( ) = = NSRange ( location : 9 , length : 0 ) )
174 # expect ( h . editor . vim . mode = = . normal )
175 let up = doom ( " aaa \n bbb \n ccc \n \n x \n y \n " )
176 up . caret ( at : 8 )
177 type ( up , " C-v k " )
178 KeyTests ( ) . press ( up , " q " , option : KeyEvents . leftOption , typed : " œ " )
179 # expect ( up . editor . document . text = = " aaa bbb ccc \n \n x \n y \n " )
180 # expect ( up . textView . selectedRange ( ) = = NSRange ( location : 4 , length : 0 ) )
181 # expect ( up . editor . vim . mode = = . normal )
182 // N o t h i n g t o f i l l : t h e b l o c k s t a y s .
183 let filled = doom ( " aaa bbb \n \n ccc \n " )
184 filled . caret ( at : 0 )
185 type ( filled , " C-v l " )
186 let block = filled . textView . selectedRanges
187 KeyTests ( ) . press ( filled , " q " , option : KeyEvents . leftOption , typed : " œ " )
188 # expect ( filled . editor . document . text = = " aaa bbb \n \n ccc \n " )
189 # expect ( filled . textView . selectedRanges = = block )
190 # expect ( filled . editor . vim . mode = = . visualBlock )
191 }
192
164 193 @ Test func zzSavesAndClosesAsWq ( ) {
165 194 let h = doom ( " text \n " )
166 195 var app : [ String ] = [ ]