Skip to content

Commit 49c12f3

Browse files
committed
Localize workspace selection status and show partially checked directories as checked
- parent folders in 'workspace' pane having some selection, should be visually 'checked', while in 'selected files' pane keep as is - on folders selected fully append 'selected fully', e.g. `12K · selected fully` - translate 'selected fully' - simplify: `310K · 16K selected` to `16K of 310K` and `310K · selected fully` to `310K` └── apps └── editor └── src ├── context │ ├── context-initialization.ts │ ├── helpers │ │ ├── get-all-workspace-files.ts │ │ └── get-selected-files.ts │ ├── providers │ │ ├── open-editors │ │ │ └── open-editors-provider.ts │ │ ├── selected-files │ │ │ └── selected-files-provider.ts │ │ └── workspace │ │ ├── modules │ │ │ ├── index.ts │ │ │ └── token-calculator.ts │ │ └── workspace-provider.ts │ ├── shared-context-state.ts │ └── utils │ └── shrink-file │ ├── index.ts │ ├── languages │ │ ├── c-style.ts │ │ ├── css.ts │ │ ├── html.ts │ │ ├── jsx.ts │ │ ├── python.ts │ │ ├── ruby.ts │ │ └── sql.ts │ ├── shrink-file.spec.ts │ ├── shrink-file.ts │ └── test-cases │ ├── c-style │ │ ├── input.txt │ │ └── output.txt │ ├── css │ │ ├── input.txt │ │ └── output.txt │ ├── html │ │ ├── input.txt │ │ └── output.txt │ ├── jsx │ │ ├── input.txt │ │ └── output.txt │ ├── python │ │ ├── input.txt │ │ └── output.txt │ ├── ruby │ │ ├── input.txt │ │ └── output.txt │ ├── scss │ │ ├── input.txt │ │ └── output.txt │ └── sql │ ├── input.txt │ └── output.txt └── i18n └── translations └── context.ts
1 parent 1e8bddf commit 49c12f3

2 files changed

Lines changed: 101 additions & 10 deletions

File tree

‎apps/editor/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Logger } from '@shared/utils/logger'
1313
import { display_token_count } from '@shared/utils/display-token-count'
1414
import { TokenCalculator } from './modules/token-calculator'
1515
import { normalize_path } from '@/utils/normalize-path'
16+
import { t } from '@/i18n'
1617

1718
export interface IWorkspaceProvider {
1819
get_workspace_roots(): string[]
@@ -515,6 +516,11 @@ export class WorkspaceProvider
515516
let checkbox_state: vscode.TreeItemCheckboxState | undefined =
516517
this._checked_items.get(key) ?? vscode.TreeItemCheckboxState.Unchecked
517518

519+
const is_selected_files_view = element.contextValue?.startsWith('context') ?? false
520+
if (!is_selected_files_view && element.isDirectory && this._partially_checked_dirs.has(key)) {
521+
checkbox_state = vscode.TreeItemCheckboxState.Checked
522+
}
523+
518524
if (element.isDirectory) {
519525
const tokens = await this._token_calculator.calculate_directory_tokens(key)
520526
if (tokens.file_count === 0) {
@@ -542,7 +548,7 @@ export class WorkspaceProvider
542548
if (element.isDirectory) {
543549
if (formatted_total) {
544550
if (formatted_selected && selected_token_count! < total_token_count!) {
545-
display_description = `${formatted_total} · ${formatted_selected} selected`
551+
display_description = `${formatted_selected} ${t('context.of')} ${formatted_total}`
546552
} else {
547553
display_description = formatted_total
548554
}
@@ -564,14 +570,14 @@ export class WorkspaceProvider
564570
if (formatted_total) {
565571
tooltip_parts.push(`· About ${formatted_total} tokens`)
566572
}
567-
if (element.isDirectory && formatted_selected) {
573+
if (element.isDirectory) {
568574
if (
569-
total_token_count !== undefined &&
570-
selected_token_count == total_token_count
575+
element.checkboxState === vscode.TreeItemCheckboxState.Checked ||
576+
(formatted_selected && selected_token_count === total_token_count)
571577
) {
572-
tooltip_parts.push('· Fully selected')
573-
} else {
574-
tooltip_parts.push(`· ${formatted_selected} selected`)
578+
tooltip_parts.push(`· ${t('context.Selected-fully')}`)
579+
} else if (formatted_selected) {
580+
tooltip_parts.push(`· ${formatted_selected} ${t('context.selected')}`)
575581
}
576582
}
577583

@@ -581,8 +587,13 @@ export class WorkspaceProvider
581587
let root_tooltip = `${element.label} (Workspace Root)`
582588
if (formatted_total) {
583589
root_tooltip += ` • About ${formatted_total} tokens`
584-
if (formatted_selected) {
585-
root_tooltip += ` (${formatted_selected} selected)`
590+
if (
591+
element.checkboxState === vscode.TreeItemCheckboxState.Checked ||
592+
(formatted_selected && selected_token_count === total_token_count)
593+
) {
594+
root_tooltip += ` (${t('context.Selected-fully')})`
595+
} else if (formatted_selected) {
596+
root_tooltip += ` (${formatted_selected} ${t('context.selected')})`
586597
}
587598
}
588599
element.tooltip = root_tooltip
@@ -715,6 +726,10 @@ export class WorkspaceProvider
715726
let checkbox_state: vscode.TreeItemCheckboxState | undefined =
716727
this._checked_items.get(root) ?? vscode.TreeItemCheckboxState.Unchecked
717728

729+
if (!is_selected_files_view && this._partially_checked_dirs.has(root)) {
730+
checkbox_state = vscode.TreeItemCheckboxState.Checked
731+
}
732+
718733
if (total_tokens.file_count === 0) {
719734
checkbox_state = undefined
720735
}
@@ -960,6 +975,10 @@ export class WorkspaceProvider
960975
let final_checkbox_state: vscode.TreeItemCheckboxState | undefined =
961976
checkbox_state
962977

978+
if (is_directory && !is_selected_files_view && this._partially_checked_dirs.has(full_path)) {
979+
final_checkbox_state = vscode.TreeItemCheckboxState.Checked
980+
}
981+
963982
if (is_directory && (tokens as any).file_count === 0) {
964983
final_checkbox_state = undefined
965984
}
@@ -1662,4 +1681,4 @@ export class FileItem extends vscode.TreeItem {
16621681
this.contextValue = 'openEditor'
16631682
}
16641683
}
1665-
}
1684+
}

‎apps/editor/src/i18n/translations/context.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,77 @@ export const translations = {
1616
cs: 'Čekejte prosím, počítám tokeny...',
1717
hu: 'Kérem várjon, a tokenek számolása folyamatban...',
1818
bg: 'Моля, изчакайте, изчисляване на броя токени...'
19+
},
20+
'context.selected-fully': {
21+
en: 'selected fully',
22+
pl: 'w pełni zaznaczone',
23+
'zh-cn': '已全选',
24+
ja: 'すべて選択済み',
25+
'zh-tw': '已全選',
26+
de: 'vollständig ausgewählt',
27+
es: 'completamente seleccionado',
28+
fr: 'entièrement sélectionné',
29+
'pt-br': 'totalmente selecionado',
30+
ru: 'выбрано полностью',
31+
ko: '전체 선택됨',
32+
it: 'completamente selezionato',
33+
tr: 'tamamen seçildi',
34+
cs: 'zcela vybráno',
35+
hu: 'teljesen kiválasztva',
36+
bg: 'напълно избрано'
37+
},
38+
'context.Selected-fully': {
39+
en: 'Selected fully',
40+
pl: 'W pełni zaznaczone',
41+
'zh-cn': '已全选',
42+
ja: 'すべて選択済み',
43+
'zh-tw': '已全選',
44+
de: 'Vollständig ausgewählt',
45+
es: 'Completamente seleccionado',
46+
fr: 'Entièrement sélectionné',
47+
'pt-br': 'Totalmente selecionado',
48+
ru: 'Выбрано полностью',
49+
ko: '전체 선택됨',
50+
it: 'Completamente selezionato',
51+
tr: 'Tamamen seçildi',
52+
cs: 'Zcela vybráno',
53+
hu: 'Teljesen kiválasztva',
54+
bg: 'Напълно избрано'
55+
},
56+
'context.selected': {
57+
en: 'selected',
58+
pl: 'zaznaczone',
59+
'zh-cn': '已选',
60+
ja: '選択済み',
61+
'zh-tw': '已選',
62+
de: 'ausgewählt',
63+
es: 'seleccionado',
64+
fr: 'sélectionné',
65+
'pt-br': 'selecionado',
66+
ru: 'выбрано',
67+
ko: '선택됨',
68+
it: 'selezionato',
69+
tr: 'seçildi',
70+
cs: 'vybráno',
71+
hu: 'kiválasztva',
72+
bg: 'избрано'
73+
},
74+
'context.of': {
75+
en: 'of',
76+
pl: 'z',
77+
'zh-cn': '/',
78+
ja: '/',
79+
'zh-tw': '/',
80+
de: 'von',
81+
es: 'de',
82+
fr: 'sur',
83+
'pt-br': 'de',
84+
ru: 'из',
85+
ko: '/',
86+
it: 'di',
87+
tr: '/',
88+
cs: 'z',
89+
hu: '/',
90+
bg: 'от'
1991
}
2092
} as const

0 commit comments

Comments
 (0)