MCPcopy Create free account
hub / github.com/bigcode-project/jupytercoder / getActiveContext

Function getActiveContext

src/utility.js:179–200  ·  view source on GitHub ↗
(currctJupyterModel)

Source from the content-addressed store, hash-verified

177
178*/
179const getActiveContext = (currctJupyterModel) => {
180 // Obtain the current input box (cell) from the Textarea of the current input box
181 const activeCell = document.activeElement.parentElement.parentElement;
182
183 const cellElements = Array.from(document.querySelectorAll(`.${currctJupyterModel.requiredClassName.cell}`));
184 const activeCellIndex = cellElements.findIndex(cell => cell.contains(activeCell));
185 let context = []
186
187 for (let i = 0; i < cellElements.length; i++) {
188 if (i == activeCellIndex) {
189 const [activeCellContent, cursorAtEndInLine] = getActiveCellPointerCode(activeCell, i, currctJupyterModel)
190 if (!cursorAtEndInLine) return []
191
192 context = [...context, ...activeCellContent]
193 } else if (i < activeCellIndex) {
194 const cellContent = getCellCode(cellElements[i], i, currctJupyterModel)
195 context = [...context, ...cellContent]
196 }
197 }
198
199 return context
200}
201
202
203

Calls 2

getActiveCellPointerCodeFunction · 0.85
getCellCodeFunction · 0.85

Tested by

no test coverage detected