@@ -112,12 +112,41 @@ export class FlashcardPanel {
112112 vscode . commands . executeCommand ( 'workbench.action.openSettings' , 'wordslash.tts' ) ;
113113 break ;
114114
115- case 'refresh' :
116- // Clear recent cards cache and reload
115+ case 'refresh' : {
116+ console . log ( '[WordSlash] Refresh requested' ) ;
117+ // Clear all caches and reload from storage
117118 this . _recentCardIds = [ ] ;
119+ const currentCardId = this . _currentCard ?. id ;
118120 this . _currentCard = null ;
119- await this . _sendNextCard ( ) ;
121+
122+ // Try to reload the same card if it still exists, otherwise get next
123+ if ( currentCardId ) {
124+ console . log ( '[WordSlash] Reloading current card:' , currentCardId ) ;
125+ const cards = await this . _storage . readAllCards ( ) ;
126+ const events = await this . _storage . readAllEvents ( ) ;
127+ console . log ( '[WordSlash] Reloaded cards:' , cards . length , 'events:' , events . length ) ;
128+ const index = buildIndex ( cards , events ) ;
129+
130+ // Get the latest version of the card from the index
131+ const reloadedCard = index . cards . get ( currentCardId ) ;
132+
133+ if ( reloadedCard ) {
134+ console . log ( '[WordSlash] Card found, reloading:' , reloadedCard . front . term ) ;
135+ console . log ( '[WordSlash] Card morphemes:' , reloadedCard . front . morphemes ) ;
136+ this . _currentCard = reloadedCard ;
137+ const srs = index . srsStates . get ( reloadedCard . id ) ;
138+ this . _postMessage ( { type : 'card' , card : reloadedCard , srs } ) ;
139+ } else {
140+ console . log ( '[WordSlash] Card not found or deleted, getting next' ) ;
141+ // Card was deleted, get next one
142+ await this . _sendNextCard ( ) ;
143+ }
144+ } else {
145+ console . log ( '[WordSlash] No current card, getting next' ) ;
146+ await this . _sendNextCard ( ) ;
147+ }
120148 break ;
149+ }
121150 }
122151 }
123152
@@ -210,7 +239,8 @@ export class FlashcardPanel {
210239 // Get current SRS state and calculate next
211240 const currentSrs = index . srsStates . get ( cardId ) ;
212241 if ( currentSrs ) {
213- const nextSrs = calculateNextState ( currentSrs , rating , Date . now ( ) ) ;
242+ // Note: nextSrs calculation validates the SRS algorithm but index is already rebuilt
243+ calculateNextState ( currentSrs , rating , Date . now ( ) ) ;
214244 // Save updated index
215245 await this . _storage . atomicWriteJson ( 'index.json' , {
216246 version : 1 ,
@@ -273,19 +303,15 @@ export class FlashcardPanel {
273303 }
274304
275305 .term-container {
276- display: flex;
277- align-items: center;
278- justify-content: center;
279- gap: 16px;
280306 margin-bottom: 16px;
281307 }
282308
283309 .term {
284- font-size: 3.2em ;
285- font-weight: 700 ;
310+ font-size: 2.5em ;
311+ font-weight: 500 ;
286312 color: var(--vscode-textLink-foreground);
287- letter-spacing: 0.02em ;
288- font-family: var(--vscode-editor-font-family), 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
313+ letter-spacing: 0.04em ;
314+ font-family: var(--vscode-editor-font-family), Monaco, 'SF Mono', 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
289315 }
290316
291317 .btn-speak {
@@ -317,16 +343,23 @@ export class FlashcardPanel {
317343 border-width: 2px;
318344 }
319345
346+ .phonetic-container {
347+ display: flex;
348+ align-items: center;
349+ justify-content: center;
350+ gap: 12px;
351+ margin-bottom: 20px;
352+ }
353+
320354 .phonetic {
321355 font-size: 1.3em;
322356 color: var(--vscode-descriptionForeground);
323- margin-bottom: 20px;
324357 font-family: 'Lucida Sans Unicode', 'Arial Unicode MS', sans-serif;
325358 }
326359
327360 .morphemes {
328- font-size: 1 .1em;
329- color: var(--vscode-textLink-foreground) ;
361+ font-size: 2 .1em;
362+ color: #00d4ff ;
330363 font-family: var(--vscode-editor-font-family), 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
331364 margin-top: 8px;
332365 margin-bottom: 16px;
@@ -340,7 +373,7 @@ export class FlashcardPanel {
340373 }
341374
342375 .morphemes .morpheme {
343- font-weight: 600 ;
376+ font-weight: 500 ;
344377 }
345378
346379 .example-container {
@@ -375,11 +408,6 @@ export class FlashcardPanel {
375408 border-top: 2px solid var(--vscode-input-border);
376409 }
377410
378- .back-content .morphemes {
379- font-size: 1em;
380- margin-bottom: 12px;
381- }
382-
383411 .translation {
384412 font-size: 2.2em;
385413 margin-bottom: 16px;
@@ -523,9 +551,11 @@ export class FlashcardPanel {
523551 <div class="card" id="card-view">
524552 <div class="term-container">
525553 <div class="term" id="term"></div>
526- <button class="btn-speak" onclick="speakTerm()" title="Pronounce term">🔊</button>
527554 </div>
528- <div class="phonetic" id="phonetic"></div>
555+ <div class="phonetic-container" id="phonetic-container">
556+ <div class="phonetic" id="phonetic"></div>
557+ <button class="btn-speak btn-speak-small" onclick="speakTerm()" title="Pronounce term">🔊</button>
558+ </div>
529559 <div class="morphemes" id="morphemes"></div>
530560 <div class="example-container" id="example-container">
531561 <div class="example" id="example"></div>
@@ -537,7 +567,6 @@ export class FlashcardPanel {
537567 </div>
538568
539569 <div id="back-content" class="back-content hidden">
540- <div class="morphemes" id="morphemes-back"></div>
541570 <div class="translation" id="translation"></div>
542571 <div class="example-cn" id="example-cn"></div>
543572 <div class="explanation" id="explanation"></div>
@@ -577,13 +606,15 @@ export class FlashcardPanel {
577606 // Listen for messages from extension
578607 window.addEventListener('message', event => {
579608 const message = event.data;
609+ console.log('[WordSlash UI] Received message:', message.type);
580610
581611 switch (message.type) {
582612 case 'tts_settings':
583613 ttsSettings = message.settings;
584614 console.log('[WordSlash] TTS settings:', ttsSettings);
585615 break;
586616 case 'card':
617+ console.log('[WordSlash UI] Displaying card:', message.card.front.term);
587618 showCard(message.card, message.srs);
588619 break;
589620 case 'empty':
@@ -603,8 +634,16 @@ export class FlashcardPanel {
603634
604635 // Show front
605636 document.getElementById('term').textContent = card.front.term;
606- document.getElementById('phonetic').textContent = card.front.phonetic || '';
607- document.getElementById('phonetic').classList.toggle('hidden', !card.front.phonetic);
637+
638+ // Show phonetic with container
639+ const phoneticContainer = document.getElementById('phonetic-container');
640+ const phoneticEl = document.getElementById('phonetic');
641+ if (card.front.phonetic) {
642+ phoneticEl.textContent = card.front.phonetic;
643+ phoneticContainer.classList.remove('hidden');
644+ } else {
645+ phoneticContainer.classList.add('hidden');
646+ }
608647
609648 // Show morphemes on front
610649 const morphemesEl = document.getElementById('morphemes');
@@ -630,17 +669,6 @@ export class FlashcardPanel {
630669 // Prepare back (including example Chinese translation)
631670 const back = card.back || {};
632671
633- // Show morphemes on back
634- const morphemesBackEl = document.getElementById('morphemes-back');
635- if (card.front.morphemes && card.front.morphemes.length > 0) {
636- morphemesBackEl.innerHTML = card.front.morphemes
637- .map(m => '<span class="morpheme">' + m + '</span>')
638- .join('<span class="separator">+</span>');
639- morphemesBackEl.classList.remove('hidden');
640- } else {
641- morphemesBackEl.classList.add('hidden');
642- }
643-
644672 document.getElementById('translation').textContent = back.translation || '(no translation)';
645673
646674 // Example Chinese goes to back
@@ -846,6 +874,11 @@ export class FlashcardPanel {
846874 document.getElementById('back-content').classList.remove('hidden');
847875 document.getElementById('back-buttons').classList.remove('hidden');
848876
877+ // Auto-pronounce when revealing back (if enabled)
878+ if (ttsSettings.autoPlay) {
879+ speak();
880+ }
881+
849882 vscode.postMessage({ type: 'reveal_back', cardId: currentCard.id });
850883 }
851884
@@ -861,6 +894,7 @@ export class FlashcardPanel {
861894 }
862895
863896 function refresh() {
897+ console.log('[WordSlash UI] Refresh button clicked');
864898 vscode.postMessage({ type: 'refresh' });
865899 }
866900
0 commit comments