File tree Expand file tree Collapse file tree
packages/ui/src/components/editor/common/prompts/shared/symbols Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import cn from 'classnames'
22import styles from './prompt-symbols.module.scss'
33import pfStyles from '../../PromptField/PromptField.module.scss'
44import { SelectionState } from '../../PromptField'
5+ import { display_token_count } from '@shared/utils/display-token-count'
56
67const escape_html = ( str : string ) : string => {
78 if ( ! str ) return ''
@@ -256,12 +257,13 @@ export const get_highlighted_text = (params: {
256257 )
257258 if ( part && pasted_text_match ) {
258259 const hash = pasted_text_match [ 1 ]
259- const token_count = pasted_text_match [ 2 ]
260- const label = `Pasted ${ token_count } tokens`
260+ const token_count_str = pasted_text_match [ 2 ]
261+ const token_count = parseInt ( token_count_str )
262+ const label = `Pasted ${ display_token_count ( token_count ) } tokens`
261263 return `<span class="${ cn (
262264 styles [ 'symbol' ] ,
263265 styles [ 'symbol--pasted-text' ]
264- ) } " data-type="pasted-text-symbol" data-hash="${ hash } " data-token-count="${ token_count } "><span class="${
266+ ) } " data-type="pasted-text-symbol" data-hash="${ hash } " data-token-count="${ token_count_str } "><span class="${
265267 styles [ 'symbol__icon' ]
266268 } " data-role="symbol-icon"></span><span class="${
267269 styles [ 'symbol__text' ]
Original file line number Diff line number Diff line change 1+ import { display_token_count } from '@shared/utils/display-token-count'
2+
13export const map_display_pos_to_raw_pos = ( params : {
24 display_pos : number
35 raw_text : string
@@ -70,9 +72,9 @@ export const map_display_pos_to_raw_pos = (params: {
7072 const match = pasted_text_symbol . match (
7173 / ^ # P a s t e d T e x t \( ( [ a - f A - F 0 - 9 ] + ) : ( \d + ) \) $ /
7274 )
73- const token_count = match ? match [ 2 ] : null
75+ const token_count = match ? parseInt ( match [ 2 ] ) : null
7476 display_match_length = token_count
75- ? `Pasted ${ token_count } tokens` . length
77+ ? `Pasted ${ display_token_count ( token_count ) } tokens` . length
7678 : 0
7779 is_replacement_match = true
7880 } else if ( website_symbol ) {
@@ -194,9 +196,9 @@ export const map_raw_pos_to_display_pos = (params: {
194196 const match = pasted_text_symbol . match (
195197 / ^ # P a s t e d T e x t \( ( [ a - f A - F 0 - 9 ] + ) : ( \d + ) \) $ /
196198 )
197- const token_count = match ? match [ 2 ] : null
199+ const token_count = match ? parseInt ( match [ 2 ] ) : null
198200 display_match_length = token_count
199- ? `Pasted ${ token_count } tokens` . length
201+ ? `Pasted ${ display_token_count ( token_count ) } tokens` . length
200202 : 0
201203 is_replacement_match = true
202204 } else if ( website_symbol ) {
Original file line number Diff line number Diff line change 1+ import { display_token_count } from '@shared/utils/display-token-count'
2+
13export const reconstruct_raw_value_from_node = ( node : Node ) : string => {
24 if ( node . nodeType == Node . TEXT_NODE ) {
35 return node . textContent || ''
@@ -126,15 +128,16 @@ export const reconstruct_raw_value_from_node = (node: Node): string => {
126128 }
127129 } else if ( el . dataset . type == 'pasted-text-symbol' ) {
128130 const hash = el . dataset . hash
129- const token_count = el . dataset . tokenCount
130- if ( ! hash || ! token_count ) return ''
131+ const token_count_str = el . dataset . tokenCount
132+ if ( ! hash || ! token_count_str ) return ''
131133
132- const expected_text = `Pasted ${ token_count } tokens`
134+ const token_count = parseInt ( token_count_str )
135+ const expected_text = `Pasted ${ display_token_count ( token_count ) } tokens`
133136 const index = inner_content . indexOf ( expected_text )
134137 if ( index != - 1 ) {
135138 const prefix = inner_content . substring ( 0 , index )
136139 const suffix = inner_content . substring ( index + expected_text . length )
137- return `${ prefix } #PastedText(${ hash } :${ token_count } )${ suffix } `
140+ return `${ prefix } #PastedText(${ hash } :${ token_count_str } )${ suffix } `
138141 }
139142 } else if ( el . dataset . type == 'website-symbol' ) {
140143 const url = el . dataset . url
You can’t perform that action at this time.
0 commit comments