提交 4f38898b 编写于 作者: J Johannes Rieken

notebook - show first non-empty line for code cells, select and focus cells on select

上级 6c39ddae
......@@ -16,16 +16,21 @@ TableOfContentsProviderRegistry.register(NotebookEditor.ID, new class implements
// return an entry per markdown header
const result: ITableOfContentsEntry[] = [];
for (let cell of editor.viewModel.viewCells) {
if (cell.cellKind === CellKind.Code) {
continue;
}
const content = cell.getText();
const matches = content.match(/^[ \t]*(\#+)(.+)$/gm);
const regexp = cell.cellKind === CellKind.Markdown
? /^[ \t]*(\#+)(.+)$/gm // md: header
: /^.*\w+.*\w*$/m; // code: none empty line
const matches = content.match(regexp);
if (matches && matches.length) {
for (let j = 0; j < matches.length; j++) {
result.push({
label: matches[j].replace(/^[ \t]*(\#+)/, ''),
reveal: () => editor.revealInCenterIfOutsideViewport(cell)
reveal: () => {
editor.revealInCenterIfOutsideViewport(cell);
editor.selectElement(cell);
editor.focusNotebookCell(cell, 'container');
}
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册