@@ -8,7 +8,7 @@ export const map_display_pos_to_raw_pos = (params: {
88 let last_raw_index = 0
99
1010 const regex =
11- / ` ( [ ^ ` ] + ) ` | ( # C h a n g e s \( [ ^ ) ] + \) ) | ( # S e l e c t i o n ) | ( # S a v e d C o n t e x t \( (?: W o r k s p a c e S t a t e | J S O N ) " ( (?: \\ .| [ ^ " \\ ] ) * ) " \) ) | ( # (?: C o m m i t | C o m m i t M e s s a g e ) \( [ ^ : ] + : ( [ ^ \s " ] + ) " (?: \\ .| [ ^ " \\ ] ) * " \) ) | ( < f r a g m e n t p a t h = " [ ^ " ] + " (?: [ ^ > ] + ) ? > ( [ \s \S ] * ? ) < \/ f r a g m e n t > ) | ( # S k i l l \( [ ^ ) ] + \) ) | ( # I m a g e \( [ a - f A - F 0 - 9 ] + \) ) | ( # P a s t e d T e x t \( [ a - f A - F 0 - 9 ] + : \d + \) ) | ( # W e b s i t e \( [ ^ ) ] + \) ) | ( # C l i p b o a r d P a t h s ) / g
11+ / ` ( [ ^ ` ] + ) ` | ( # C h a n g e s \( [ ^ ) ] + \) ) | ( # S e l e c t i o n ) | ( # S a v e d C o n t e x t \( (?: W o r k s p a c e S t a t e | J S O N ) " ( (?: \\ .| [ ^ " \\ ] ) * ) " \) ) | ( # (?: C o m m i t | C o m m i t M e s s a g e ) \( [ ^ : ] + : ( [ ^ \s " ] + ) " (?: \\ .| [ ^ " \\ ] ) * " \) ) | ( # F r a g m e n t \( ( . + ? ) : ( \d + ) : ( \d + ) - ( \d + ) : ( \d + ) \) ) | ( # S k i l l \( [ ^ ) ] + \) ) | ( # I m a g e \( [ a - f A - F 0 - 9 ] + \) ) | ( # P a s t e d T e x t \( [ a - f A - F 0 - 9 ] + : \d + \) ) | ( # W e b s i t e \( [ ^ ) ] + \) ) | ( # C l i p b o a r d P a t h s ) / g
1212 let match
1313
1414 while ( ( match = regex . exec ( params . raw_text ) ) !== null ) {
@@ -20,12 +20,13 @@ export const map_display_pos_to_raw_pos = (params: {
2020 const commit_symbol = match [ 6 ]
2121 const commit_hash = match [ 7 ]
2222 const fragment_symbol = match [ 8 ]
23- let fragment_content = match [ 9 ]
24- const skill_symbol = match [ 10 ]
25- const image_symbol = match [ 11 ]
26- const pasted_text_symbol = match [ 12 ]
27- const website_symbol = match [ 13 ]
28- const clipboard_paths_symbol = match [ 14 ]
23+ const fragment_start_line = match [ 10 ] ? parseInt ( match [ 10 ] , 10 ) : 0
24+ const fragment_end_line = match [ 12 ] ? parseInt ( match [ 12 ] , 10 ) : 0
25+ const skill_symbol = match [ 14 ]
26+ const image_symbol = match [ 15 ]
27+ const pasted_text_symbol = match [ 16 ]
28+ const website_symbol = match [ 17 ]
29+ const clipboard_paths_symbol = match [ 18 ]
2930
3031 let is_replacement_match = false
3132 let display_match_length = 0
@@ -52,28 +53,7 @@ export const map_display_pos_to_raw_pos = (params: {
5253 display_match_length = short_hash . length
5354 is_replacement_match = true
5455 } else if ( fragment_symbol ) {
55- if (
56- fragment_content . startsWith ( '\n```\n' ) &&
57- fragment_content . endsWith ( '\n```\n' )
58- ) {
59- fragment_content = fragment_content . slice ( 5 , - 5 )
60- } else if (
61- fragment_content . startsWith ( '```\n' ) &&
62- fragment_content . endsWith ( '\n```' )
63- ) {
64- fragment_content = fragment_content . slice ( 4 , - 4 )
65- } else if (
66- fragment_content . startsWith ( '```' ) &&
67- fragment_content . endsWith ( '```' )
68- ) {
69- fragment_content = fragment_content . slice ( 3 , - 3 )
70- } else if (
71- fragment_content . startsWith ( '\n' ) &&
72- fragment_content . endsWith ( '\n' )
73- ) {
74- fragment_content = fragment_content . slice ( 1 , - 1 )
75- }
76- const line_count = fragment_content . split ( '\n' ) . length
56+ const line_count = Math . max ( 1 , fragment_end_line - fragment_start_line + 1 )
7757 const lines_text = line_count === 1 ? 'line' : 'lines'
7858 display_match_length = `Pasted ${ line_count } ${ lines_text } ` . length
7959 is_replacement_match = true
@@ -152,7 +132,7 @@ export const map_raw_pos_to_display_pos = (params: {
152132 let last_raw_index = 0
153133
154134 const regex =
155- / ` ( [ ^ ` ] + ) ` | ( # C h a n g e s \( [ ^ ) ] + \) ) | ( # S e l e c t i o n ) | ( # S a v e d C o n t e x t \( (?: W o r k s p a c e S t a t e | J S O N ) " ( (?: \\ .| [ ^ " \\ ] ) * ) " \) ) | ( # (?: C o m m i t | C o m m i t M e s s a g e ) \( [ ^ : ] + : ( [ ^ \s " ] + ) " (?: \\ .| [ ^ " \\ ] ) * " \) ) | ( < f r a g m e n t p a t h = " [ ^ " ] + " (?: [ ^ > ] + ) ? > ( [ \s \S ] * ? ) < \/ f r a g m e n t > ) | ( # S k i l l \( [ ^ ) ] + \) ) | ( # I m a g e \( [ a - f A - F 0 - 9 ] + \) ) | ( # P a s t e d T e x t \( [ a - f A - F 0 - 9 ] + : \d + \) ) | ( # W e b s i t e \( [ ^ ) ] + \) ) | ( # C l i p b o a r d P a t h s ) / g
135+ / ` ( [ ^ ` ] + ) ` | ( # C h a n g e s \( [ ^ ) ] + \) ) | ( # S e l e c t i o n ) | ( # S a v e d C o n t e x t \( (?: W o r k s p a c e S t a t e | J S O N ) " ( (?: \\ .| [ ^ " \\ ] ) * ) " \) ) | ( # (?: C o m m i t | C o m m i t M e s s a g e ) \( [ ^ : ] + : ( [ ^ \s " ] + ) " (?: \\ .| [ ^ " \\ ] ) * " \) ) | ( # F r a g m e n t \( ( . + ? ) : ( \d + ) : ( \d + ) - ( \d + ) : ( \d + ) \) ) | ( # S k i l l \( [ ^ ) ] + \) ) | ( # I m a g e \( [ a - f A - F 0 - 9 ] + \) ) | ( # P a s t e d T e x t \( [ a - f A - F 0 - 9 ] + : \d + \) ) | ( # W e b s i t e \( [ ^ ) ] + \) ) | ( # C l i p b o a r d P a t h s ) / g
156136 let match
157137
158138 while ( ( match = regex . exec ( params . raw_text ) ) !== null ) {
@@ -164,12 +144,13 @@ export const map_raw_pos_to_display_pos = (params: {
164144 const commit_symbol = match [ 6 ]
165145 const commit_hash = match [ 7 ]
166146 const fragment_symbol = match [ 8 ]
167- let fragment_content = match [ 9 ]
168- const skill_symbol = match [ 10 ]
169- const image_symbol = match [ 11 ]
170- const pasted_text_symbol = match [ 12 ]
171- const website_symbol = match [ 13 ]
172- const clipboard_paths_symbol = match [ 14 ]
147+ const fragment_start_line = match [ 10 ] ? parseInt ( match [ 10 ] , 10 ) : 0
148+ const fragment_end_line = match [ 12 ] ? parseInt ( match [ 12 ] , 10 ) : 0
149+ const skill_symbol = match [ 14 ]
150+ const image_symbol = match [ 15 ]
151+ const pasted_text_symbol = match [ 16 ]
152+ const website_symbol = match [ 17 ]
153+ const clipboard_paths_symbol = match [ 18 ]
173154
174155 let is_replacement_match = false
175156 let display_match_length = 0
@@ -196,29 +177,8 @@ export const map_raw_pos_to_display_pos = (params: {
196177 display_match_length = short_hash . length
197178 is_replacement_match = true
198179 } else if ( fragment_symbol ) {
199- if (
200- fragment_content . startsWith ( '\n```\n' ) &&
201- fragment_content . endsWith ( '\n```\n' )
202- ) {
203- fragment_content = fragment_content . slice ( 5 , - 5 )
204- } else if (
205- fragment_content . startsWith ( '```\n' ) &&
206- fragment_content . endsWith ( '\n```' )
207- ) {
208- fragment_content = fragment_content . slice ( 4 , - 4 )
209- } else if (
210- fragment_content . startsWith ( '```' ) &&
211- fragment_content . endsWith ( '```' )
212- ) {
213- fragment_content = fragment_content . slice ( 3 , - 3 )
214- } else if (
215- fragment_content . startsWith ( '\n' ) &&
216- fragment_content . endsWith ( '\n' )
217- ) {
218- fragment_content = fragment_content . slice ( 1 , - 1 )
219- }
220- const line_count = fragment_content . split ( '\n' ) . length
221- const lines_text = line_count == 1 ? 'line' : 'lines'
180+ const line_count = Math . max ( 1 , fragment_end_line - fragment_start_line + 1 )
181+ const lines_text = line_count === 1 ? 'line' : 'lines'
222182 display_match_length = `Pasted ${ line_count } ${ lines_text } ` . length
223183 is_replacement_match = true
224184 } else if ( skill_symbol ) {
0 commit comments