From 4d6ea401b570f998ce1988635274ba0e47841a1c Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Wed, 23 Jul 2025 03:36:18 +0530 Subject: [PATCH] (feat:chunks) line numbered editor --- frontend/src/components/DocumentChunks.tsx | 143 ++++++++++++++------- 1 file changed, 94 insertions(+), 49 deletions(-) diff --git a/frontend/src/components/DocumentChunks.tsx b/frontend/src/components/DocumentChunks.tsx index d2c402a9..9f3f639f 100644 --- a/frontend/src/components/DocumentChunks.tsx +++ b/frontend/src/components/DocumentChunks.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect } from 'react'; import { useSelector } from 'react-redux'; import { useTranslation } from 'react-i18next'; import { selectToken } from '../preferences/preferenceSlice'; @@ -15,6 +15,67 @@ import { ChunkType } from '../settings/types'; import EditIcon from '../assets/edit.svg'; import Pagination from './DocumentPagination'; +interface LineNumberedTextareaProps { + value: string; + onChange: (value: string) => void; + placeholder?: string; + ariaLabel?: string; + className?: string; +} + +const LineNumberedTextarea: React.FC = ({ + value, + onChange, + placeholder, + ariaLabel, + className = '' +}) => { + const handleChange = (e: React.ChangeEvent) => { + onChange(e.target.value); + }; + + const lineHeight = 19.93; + const contentLines = value.split('\n').length; + const minLinesForDisplay = Math.ceil((typeof window !== 'undefined' ? window.innerHeight - 300 : 600) / lineHeight); + const totalLines = Math.max(contentLines, minLinesForDisplay); + + return ( +
+
+ {Array.from({ length: totalLines }, (_, i) => ( +
+ {i + 1} +
+ ))} +
+ -
- - -
- - +
+
) : editingChunk && ( @@ -365,13 +411,12 @@ const DocumentChunks: React.FC = ({ {editingChunk.metadata.token_count ? editingChunk.metadata.token_count.toLocaleString() : '-'} tokens -
- + onChange={setEditingText} + ariaLabel={t('modals.chunk.promptText')} + />