@@ -18,13 +18,9 @@ export interface LLMCellContextSelectorProps {
18
18
cellTypes : "all" | "code" ;
19
19
onCellTypesChange : ( types : "all" | "code" ) => void ;
20
20
21
- // Current cell ID and frame actions for counting available cells
21
+ // Current cell ID and frame actions for enumerating available cells
22
22
currentCellId : string ;
23
23
frameActions : NotebookFrameActions | undefined ;
24
-
25
- // For ai-cell-generator, the context is relative to where the new cell will be inserted
26
- // For cell-tool, the context is relative to the current cell
27
- mode : "current-cell" | "insert-position" ;
28
24
}
29
25
30
26
export function LLMCellContextSelector ( {
@@ -34,68 +30,37 @@ export function LLMCellContextSelector({
34
30
onCellTypesChange,
35
31
currentCellId,
36
32
frameActions,
37
- mode,
38
33
} : LLMCellContextSelectorProps ) {
39
34
const { minValue, maxValue, marks } = useMemo ( ( ) => {
40
35
const jupyterActionsStore = frameActions ?. jupyter_actions . store ;
41
36
if ( ! jupyterActionsStore ) {
42
37
return { minValue : 0 , maxValue : 0 , marks : { 0 : "0" } } ;
43
38
}
44
39
45
- let minVal : number , maxVal : number ;
46
-
47
- if ( mode === "insert-position" ) {
48
- // For insert position, we need to count cells differently
49
- // Count all cells before the insertion point (include current cell and all above it)
50
- let cellsBefore = 0 ;
51
- let delta = 0 ; // Start from current cell (which will be "before" after insertion)
52
- while ( jupyterActionsStore . get_cell_id ( delta , currentCellId ) ) {
53
- cellsBefore ++ ;
54
- delta -- ;
55
- }
56
-
57
- // Count cells after
58
- let cellsAfter = 0 ;
59
- delta = 1 ;
60
- while ( jupyterActionsStore . get_cell_id ( delta , currentCellId ) ) {
61
- cellsAfter ++ ;
62
- delta ++ ;
63
- }
64
-
65
- minVal = - cellsBefore ;
66
- maxVal = cellsAfter ;
67
- } else {
68
- // For current-cell mode, count cells above and below as before
69
- let cellsAbove = 0 ;
70
- let delta = - 1 ;
71
- while ( jupyterActionsStore . get_cell_id ( delta , currentCellId ) ) {
72
- cellsAbove ++ ;
73
- delta -- ;
74
- }
75
-
76
- // Count cells below
77
- let cellsBelow = 0 ;
78
- delta = 1 ;
79
- while ( jupyterActionsStore . get_cell_id ( delta , currentCellId ) ) {
80
- cellsBelow ++ ;
81
- delta ++ ;
82
- }
83
-
84
- minVal = - cellsAbove ;
85
- maxVal = cellsBelow ;
40
+ // Count all cells before the insertion point (include current cell and all above it)
41
+ let cellsBefore = 0 ;
42
+ while ( jupyterActionsStore . get_cell_id ( cellsBefore , currentCellId ) ) {
43
+ cellsBefore ++ ;
44
+ }
45
+
46
+ // start with the first cell after the current cell (+1 offset)
47
+ let cellsAfter = 0 ;
48
+ while ( jupyterActionsStore . get_cell_id ( cellsAfter + 1 , currentCellId ) ) {
49
+ cellsAfter ++ ;
86
50
}
87
51
52
+ const minVal = - cellsBefore ;
53
+ const maxVal = cellsAfter ;
54
+
88
55
// Create marks dynamically
89
- const marks : SliderSingleProps [ "marks" ] = {
90
- 0 : mode === "current-cell" ? "0" : "insert" ,
91
- } ;
56
+ const marks : SliderSingleProps [ "marks" ] = { 0 : "0" } ;
92
57
93
58
// Only add boundary marks if they don't conflict with -2/+2
94
- if ( minVal < 0 ) {
95
- marks [ minVal ] = minVal === - 2 ? "-2" : "first" ;
59
+ if ( minVal < - 3 ) {
60
+ marks [ minVal ] = "first" ;
96
61
}
97
- if ( maxVal > 0 ) {
98
- marks [ maxVal ] = maxVal === 2 ? "+2" : "last" ;
62
+ if ( maxVal > 3 ) {
63
+ marks [ maxVal ] = "last" ;
99
64
}
100
65
101
66
// Add -2 and +2 marks only if they're not at the boundaries
@@ -107,26 +72,19 @@ export function LLMCellContextSelector({
107
72
}
108
73
109
74
return { minValue : minVal , maxValue : maxVal , marks } ;
110
- } , [ currentCellId , frameActions , mode ] ) ;
75
+ } , [ currentCellId , frameActions ] ) ;
111
76
112
- // Adjust range to be within bounds
77
+ // clip range to be within bounds, just to be safe
113
78
const adjustedRange : [ number , number ] = [
114
79
Math . max ( contextRange [ 0 ] , minValue ) ,
115
80
Math . min ( contextRange [ 1 ] , maxValue ) ,
116
81
] ;
117
82
118
- const getDescription = ( ) => {
119
- if ( mode === "current-cell" ) {
120
- return `Selected: ${ Math . abs (
121
- adjustedRange [ 0 ] ,
122
- ) } cells above + current cell + ${ adjustedRange [ 1 ] } cells below`;
123
- } else {
124
- // For insert position mode
125
- const beforeCount = Math . abs ( adjustedRange [ 0 ] ) ;
126
- const afterCount = adjustedRange [ 1 ] ;
127
- return `Selected: ${ beforeCount } cells before insertion + ${ afterCount } cells after insertion` ;
128
- }
129
- } ;
83
+ function getDescription ( ) {
84
+ return `Selected: ${ Math . abs (
85
+ adjustedRange [ 0 ] ,
86
+ ) } cells above including current cell + ${ adjustedRange [ 1 ] } cells below`;
87
+ }
130
88
131
89
return (
132
90
< >
0 commit comments