Skip to content

Commit 47323bc

Browse files
Preserve number padding in increment/decrement actions (#3136)
## Overview Preserve leading zeros when incrementing or decrementing a number. Before: ```py # increment this 01 -> 2 ``` After: ```py # increment this 01 -> 02 ``` - Add `hasLeadingZeros()` helper to detect numbers with leading zeros - Add `formatNumber()` function to preserve original number formatting (leading zeros and decimal places) - Update `updateInteger()` and `updateFloat()` to return formatted strings instead of raw numbers - Preserve formatting for numbers like `007` → `008`, `3.0` → `4.0`, and `004.60` → `005.60` - Add new fixtures files for increment/decrement --------- Co-authored-by: Andreas Arvidsson <andreas.arvidsson87@gmail.com>
1 parent c5f66a7 commit 47323bc

10 files changed

Lines changed: 647 additions & 6 deletions

File tree

data/fixtures/recorded/actions/decrementFile.yml renamed to data/fixtures/recorded/actions/incrementDecrement/decrementFile.yml

File renamed without changes.
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: decrement file
5+
action:
6+
name: decrement
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: containingScope
11+
scopeType: {type: document}
12+
usePrePhraseSnapshot: true
13+
initialState:
14+
documentContents: |-
15+
4.0
16+
11.0
17+
0.1
18+
19+
008
20+
002
21+
001
22+
0008
23+
24+
100
25+
010
26+
27+
00101
28+
011
29+
30+
005.60
31+
002.5
32+
100.99
33+
34+
004.0
35+
100.0
36+
000.2
37+
38+
-006
39+
000
40+
-002.0
41+
-98
42+
43+
000.6
44+
000.2
45+
46+
002.234
47+
004.00
48+
008.999
49+
selections:
50+
- anchor: {line: 18, character: 0}
51+
active: {line: 18, character: 0}
52+
marks: {}
53+
finalState:
54+
documentContents: |-
55+
3.0
56+
10.0
57+
0.0
58+
59+
007
60+
001
61+
000
62+
0007
63+
64+
99
65+
009
66+
67+
00100
68+
010
69+
70+
004.60
71+
001.5
72+
99.99
73+
74+
003.0
75+
99.0
76+
000.1
77+
78+
-007
79+
-001
80+
-003.0
81+
-99
82+
83+
000.5
84+
000.1
85+
86+
001.234
87+
003.00
88+
007.999
89+
selections:
90+
- anchor: {line: 18, character: 0}
91+
active: {line: 18, character: 0}
92+
thatMark:
93+
- type: UntypedTarget
94+
contentRange:
95+
start: {line: 0, character: 0}
96+
end: {line: 0, character: 3}
97+
isReversed: false
98+
hasExplicitRange: true
99+
- type: UntypedTarget
100+
contentRange:
101+
start: {line: 1, character: 0}
102+
end: {line: 1, character: 4}
103+
isReversed: false
104+
hasExplicitRange: true
105+
- type: UntypedTarget
106+
contentRange:
107+
start: {line: 2, character: 0}
108+
end: {line: 2, character: 3}
109+
isReversed: false
110+
hasExplicitRange: true
111+
- type: UntypedTarget
112+
contentRange:
113+
start: {line: 4, character: 0}
114+
end: {line: 4, character: 3}
115+
isReversed: false
116+
hasExplicitRange: true
117+
- type: UntypedTarget
118+
contentRange:
119+
start: {line: 5, character: 0}
120+
end: {line: 5, character: 3}
121+
isReversed: false
122+
hasExplicitRange: true
123+
- type: UntypedTarget
124+
contentRange:
125+
start: {line: 6, character: 0}
126+
end: {line: 6, character: 3}
127+
isReversed: false
128+
hasExplicitRange: true
129+
- type: UntypedTarget
130+
contentRange:
131+
start: {line: 7, character: 0}
132+
end: {line: 7, character: 4}
133+
isReversed: false
134+
hasExplicitRange: true
135+
- type: UntypedTarget
136+
contentRange:
137+
start: {line: 9, character: 0}
138+
end: {line: 9, character: 2}
139+
isReversed: false
140+
hasExplicitRange: true
141+
- type: UntypedTarget
142+
contentRange:
143+
start: {line: 10, character: 0}
144+
end: {line: 10, character: 3}
145+
isReversed: false
146+
hasExplicitRange: true
147+
- type: UntypedTarget
148+
contentRange:
149+
start: {line: 12, character: 0}
150+
end: {line: 12, character: 5}
151+
isReversed: false
152+
hasExplicitRange: true
153+
- type: UntypedTarget
154+
contentRange:
155+
start: {line: 13, character: 0}
156+
end: {line: 13, character: 3}
157+
isReversed: false
158+
hasExplicitRange: true
159+
- type: UntypedTarget
160+
contentRange:
161+
start: {line: 15, character: 0}
162+
end: {line: 15, character: 6}
163+
isReversed: false
164+
hasExplicitRange: true
165+
- type: UntypedTarget
166+
contentRange:
167+
start: {line: 16, character: 0}
168+
end: {line: 16, character: 5}
169+
isReversed: false
170+
hasExplicitRange: true
171+
- type: UntypedTarget
172+
contentRange:
173+
start: {line: 17, character: 0}
174+
end: {line: 17, character: 5}
175+
isReversed: false
176+
hasExplicitRange: true
177+
- type: UntypedTarget
178+
contentRange:
179+
start: {line: 19, character: 0}
180+
end: {line: 19, character: 5}
181+
isReversed: false
182+
hasExplicitRange: true
183+
- type: UntypedTarget
184+
contentRange:
185+
start: {line: 20, character: 0}
186+
end: {line: 20, character: 4}
187+
isReversed: false
188+
hasExplicitRange: true
189+
- type: UntypedTarget
190+
contentRange:
191+
start: {line: 21, character: 0}
192+
end: {line: 21, character: 5}
193+
isReversed: false
194+
hasExplicitRange: true
195+
- type: UntypedTarget
196+
contentRange:
197+
start: {line: 23, character: 0}
198+
end: {line: 23, character: 4}
199+
isReversed: false
200+
hasExplicitRange: true
201+
- type: UntypedTarget
202+
contentRange:
203+
start: {line: 24, character: 0}
204+
end: {line: 24, character: 4}
205+
isReversed: false
206+
hasExplicitRange: true
207+
- type: UntypedTarget
208+
contentRange:
209+
start: {line: 25, character: 0}
210+
end: {line: 25, character: 6}
211+
isReversed: false
212+
hasExplicitRange: true
213+
- type: UntypedTarget
214+
contentRange:
215+
start: {line: 26, character: 0}
216+
end: {line: 26, character: 3}
217+
isReversed: false
218+
hasExplicitRange: true
219+
- type: UntypedTarget
220+
contentRange:
221+
start: {line: 28, character: 0}
222+
end: {line: 28, character: 5}
223+
isReversed: false
224+
hasExplicitRange: true
225+
- type: UntypedTarget
226+
contentRange:
227+
start: {line: 29, character: 0}
228+
end: {line: 29, character: 5}
229+
isReversed: false
230+
hasExplicitRange: true
231+
- type: UntypedTarget
232+
contentRange:
233+
start: {line: 31, character: 0}
234+
end: {line: 31, character: 7}
235+
isReversed: false
236+
hasExplicitRange: true
237+
- type: UntypedTarget
238+
contentRange:
239+
start: {line: 32, character: 0}
240+
end: {line: 32, character: 6}
241+
isReversed: false
242+
hasExplicitRange: true
243+
- type: UntypedTarget
244+
contentRange:
245+
start: {line: 33, character: 0}
246+
end: {line: 33, character: 7}
247+
isReversed: false
248+
hasExplicitRange: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
languageId: plaintext
2+
command:
3+
version: 7
4+
spokenForm: decrement first sub
5+
action:
6+
name: decrement
7+
target:
8+
type: primitive
9+
modifiers:
10+
- type: ordinalScope
11+
scopeType: {type: word}
12+
start: 0
13+
length: 1
14+
usePrePhraseSnapshot: true
15+
initialState:
16+
documentContents: "2026_015"
17+
selections:
18+
- anchor: {line: 0, character: 8}
19+
active: {line: 0, character: 8}
20+
marks: {}
21+
finalState:
22+
documentContents: "2025_015"
23+
selections:
24+
- anchor: {line: 0, character: 8}
25+
active: {line: 0, character: 8}
26+
thatMark:
27+
- type: UntypedTarget
28+
contentRange:
29+
start: {line: 0, character: 0}
30+
end: {line: 0, character: 4}
31+
isReversed: false
32+
hasExplicitRange: true

data/fixtures/recorded/actions/incrementFile.yml renamed to data/fixtures/recorded/actions/incrementDecrement/incrementFile.yml

File renamed without changes.

0 commit comments

Comments
 (0)