mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-04 01:25:38 -05:00
* Fix #5238 Notebooks should support relative links - Added detection of relative #links inside notebooks - Added handling of these, at least for current notebook Not handled: open other notebook & scroll to position.
This commit is contained in:
@@ -24,7 +24,7 @@ import { AngularDisposable } from 'sql/base/node/lifecycle';
|
||||
import { CellTypes, CellType } from 'sql/workbench/parts/notebook/models/contracts';
|
||||
import { ICellModel, IModelFactory, INotebookModel, NotebookContentChange } from 'sql/workbench/parts/notebook/models/modelInterfaces';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService';
|
||||
import { INotebookService, INotebookParams, INotebookManager, INotebookEditor, INotebookSection, DEFAULT_NOTEBOOK_PROVIDER, SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService';
|
||||
import { IBootstrapParams } from 'sql/platform/bootstrap/node/bootstrapService';
|
||||
import { NotebookModel } from 'sql/workbench/parts/notebook/models/notebookModel';
|
||||
import { ModelFactory } from 'sql/workbench/parts/notebook/models/modelFactory';
|
||||
@@ -582,4 +582,48 @@ export class NotebookComponent extends AngularDisposable implements OnInit, OnDe
|
||||
}
|
||||
}
|
||||
|
||||
getSections(): INotebookSection[] {
|
||||
return this.getSectionElements();
|
||||
}
|
||||
|
||||
private getSectionElements(): NotebookSection[] {
|
||||
let headers: NotebookSection[] = [];
|
||||
let el: HTMLElement = this.container.nativeElement;
|
||||
let headerElements = el.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||
for (let i = 0; i < headerElements.length; i++) {
|
||||
let headerEl = headerElements[i] as HTMLElement;
|
||||
if (headerEl['id']) {
|
||||
headers.push(new NotebookSection(headerEl));
|
||||
}
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
navigateToSection(id: string): void {
|
||||
id = id.toLowerCase();
|
||||
let section = this.getSectionElements().find(s => s.relativeUri && s.relativeUri.toLowerCase() === id);
|
||||
if (section) {
|
||||
// Scroll this section to the top of the header instead of just bringing header into view.
|
||||
let scrollTop = jQuery(section.headerEl).offset().top;
|
||||
(<HTMLElement>this.container.nativeElement).scrollTo({
|
||||
top: scrollTop,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
section.headerEl.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NotebookSection implements INotebookSection {
|
||||
|
||||
constructor(public headerEl: HTMLElement) {
|
||||
}
|
||||
|
||||
get relativeUri(): string {
|
||||
return this.headerEl['id'];
|
||||
}
|
||||
|
||||
get header(): string {
|
||||
return this.headerEl.textContent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user