This repository was archived by the owner on Jan 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { truncate } from './stringOperations' ;
2
+
3
+ describe ( 'truncate' , ( ) => {
4
+ test ( 'should return strings with at most max length unchanged' , ( ) => {
5
+ expect ( truncate ( 'Lorem ipsum' , 11 ) ) . toBe ( 'Lorem ipsum' ) ;
6
+ } ) ;
7
+
8
+ test ( 'should truncate strings longer than max length and append ...' , ( ) => {
9
+ expect ( truncate ( 'Lorem ipsum' , 10 ) ) . toBe ( 'Lorem ips\u2026' ) ;
10
+ } ) ;
11
+ } ) ;
Original file line number Diff line number Diff line change
1
+ export const truncate = function ( text : string , maxLength : number ) : string {
2
+ return text . length > maxLength ? text . substring ( 0 , maxLength - 1 ) + '\u2026' : text ;
3
+ } ;
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ import {
64
64
showRenameAnnotationForm ,
65
65
showTodoAnnotationForm ,
66
66
} from '../ui/uiSlice' ;
67
+ import { truncate } from '../../common/util/stringOperations' ;
67
68
68
69
interface AnnotationViewProps {
69
70
target : string ;
@@ -252,6 +253,7 @@ export const AnnotationView: React.FC<AnnotationViewProps> = function ({ target
252
253
{ todoAnnotation && (
253
254
< AnnotationTag
254
255
type = "todo"
256
+ name = { truncate ( todoAnnotation . newTodo , 50 ) }
255
257
annotation = { todoAnnotation }
256
258
onEdit = { ( ) => dispatch ( showTodoAnnotationForm ( target ) ) }
257
259
onDelete = { ( ) => dispatch ( removeTodo ( target ) ) }
You can’t perform that action at this time.
0 commit comments