提交 c6c03851 编写于 作者: R rebornix

reveal search result in center in markdown cell

上级 d4385d7f
...@@ -106,7 +106,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> { ...@@ -106,7 +106,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> {
} }
if (revealType === CellRevealType.Range) { if (revealType === CellRevealType.Range) {
element.revealRange(range); element.revealRangeInCenter(range);
} }
} }
...@@ -162,7 +162,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> { ...@@ -162,7 +162,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> {
this.view.setScrollTop(lineOffsetInView - this.view.renderHeight / 2); this.view.setScrollTop(lineOffsetInView - this.view.renderHeight / 2);
if (revealType === CellRevealType.Range) { if (revealType === CellRevealType.Range) {
element.revealRange(range); element.revealRangeInCenter(range);
} }
}; };
...@@ -194,7 +194,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> { ...@@ -194,7 +194,7 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> {
this.view.setScrollTop(lineOffsetInView - this.view.renderHeight / 2); this.view.setScrollTop(lineOffsetInView - this.view.renderHeight / 2);
if (revealType === CellRevealType.Range) { if (revealType === CellRevealType.Range) {
element.revealRange(range); element.revealRangeInCenter(range);
} }
}; };
...@@ -202,15 +202,17 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> { ...@@ -202,15 +202,17 @@ export class NotebookCellList extends WorkbenchList<CellViewModel> {
const wrapperBottom = scrollTop + this.view.renderHeight; const wrapperBottom = scrollTop + this.view.renderHeight;
const elementTop = this.view.elementTop(index); const elementTop = this.view.elementTop(index);
const viewItemOffset = elementTop; const viewItemOffset = elementTop;
const element = this.view.element(index);
if (viewItemOffset < scrollTop || viewItemOffset > wrapperBottom) { if (viewItemOffset < scrollTop || viewItemOffset > wrapperBottom) {
this.view.setScrollTop(viewItemOffset - this.view.renderHeight / 2); this.view.setScrollTop(viewItemOffset - this.view.renderHeight / 2);
const element = this.view.element(index);
if (!element.editorAttached) { if (!element.editorAttached) {
getEditorAttachedPromise(element).then(() => reveal(index, range, revealType)); getEditorAttachedPromise(element).then(() => reveal(index, range, revealType));
} else { } else {
// should not happen // should not happen
} }
} else {
element.revealRangeInCenter(range);
} }
} }
......
...@@ -68,6 +68,7 @@ export class StatefullMarkdownCell extends Disposable { ...@@ -68,6 +68,7 @@ export class StatefullMarkdownCell extends Disposable {
} }
}, {}); }, {});
viewCell.attachTextEditor(this.editor);
const cts = new CancellationTokenSource(); const cts = new CancellationTokenSource();
this._register({ dispose() { cts.dispose(true); } }); this._register({ dispose() { cts.dispose(true); } });
......
...@@ -291,8 +291,8 @@ export class CellViewModel extends Disposable { ...@@ -291,8 +291,8 @@ export class CellViewModel extends Disposable {
this._onDidChangeEditorAttachState.fire(false); this._onDidChangeEditorAttachState.fire(false);
} }
revealRange(range: Range) { revealRangeInCenter(range: Range) {
this._textEditor?.revealRange(range); this._textEditor?.revealRangeInCenter(range);
} }
getLineScrollTopOffset(line: number): number { getLineScrollTopOffset(line: number): number {
......
...@@ -190,7 +190,9 @@ export class NotebookViewModel extends Disposable { ...@@ -190,7 +190,9 @@ export class NotebookViewModel extends Disposable {
if (!mapping.has(ownerId)) { if (!mapping.has(ownerId)) {
const cell = this.viewCells.find(cell => cell.handle === ownerId); const cell = this.viewCells.find(cell => cell.handle === ownerId);
mapping.set(ownerId, { cell: cell!, oldDecorations: [], newDecorations: [] }); if (cell) {
mapping.set(ownerId, { cell: cell, oldDecorations: [], newDecorations: [] });
}
} }
const data = mapping.get(ownerId)!; const data = mapping.get(ownerId)!;
...@@ -202,7 +204,10 @@ export class NotebookViewModel extends Disposable { ...@@ -202,7 +204,10 @@ export class NotebookViewModel extends Disposable {
if (!mapping.has(ownerId)) { if (!mapping.has(ownerId)) {
const cell = this.viewCells.find(cell => cell.handle === ownerId); const cell = this.viewCells.find(cell => cell.handle === ownerId);
mapping.set(ownerId, { cell: cell!, oldDecorations: [], newDecorations: [] });
if (cell) {
mapping.set(ownerId, { cell: cell, oldDecorations: [], newDecorations: [] });
}
} }
const data = mapping.get(ownerId)!; const data = mapping.get(ownerId)!;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册