File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,13 +90,18 @@ export async function addWordsToNotepad(notepadId: string, words: string[]) {
9090 targetLineIndex = 0 ;
9191 }
9292
93- // 去重:从 words 中移除已存在于 lines 中的单词
94- const linesSet = new Set ( lines . map ( line => line . trim ( ) . toLowerCase ( ) ) ) ;
93+ // Deduplicate: filter out words that already exist in lines
94+ // Only check actual word entries, exclude headers (lines starting with #) and empty lines
95+ const existingWords = new Set (
96+ lines
97+ . filter ( line => line && ! line . startsWith ( '#' ) )
98+ . map ( line => line . trim ( ) . toLowerCase ( ) )
99+ ) ;
95100 const uniqueWords = [ ] ;
96101 const duplicateWords = [ ] ;
97102 for ( const word of words ) {
98103 const trimmedWord = word . trim ( ) . toLowerCase ( ) ;
99- if ( linesSet . has ( trimmedWord ) ) {
104+ if ( existingWords . has ( trimmedWord ) ) {
100105 duplicateWords . push ( word ) ;
101106 } else {
102107 uniqueWords . push ( word ) ;
@@ -131,7 +136,6 @@ export async function addWordsToNotepad(notepadId: string, words: string[]) {
131136 } ) . then ( ( _resp ) => {
132137 const resp = _resp . data ;
133138 if ( resp ?. success ) {
134- // 构建返回消息
135139 const messages = [ ] ;
136140 if ( result . uniqueWords . length > 0 ) {
137141 messages . push ( `单词 ${ result . uniqueWords . join ( ", " ) } 已添加到云词本` ) ;
You can’t perform that action at this time.
0 commit comments