Skip to content

Commit

Permalink
adding more methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aiday-mar committed Jan 7, 2025
1 parent e75e7f1 commit c7ce4b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/vs/editor/browser/editorBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ export interface ICodeEditor extends editorCommon.IEditor {
*/
getTopForPosition(lineNumber: number, column: number): number;

getLineHeightForLineNumber(lineNumber: number): number;

/**
* Set the model ranges that will be hidden in the view.
* Hidden areas are stored per source.
Expand Down
7 changes: 7 additions & 0 deletions src/vs/editor/browser/widget/codeEditor/codeEditorWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,13 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
return CodeEditorWidget._getVerticalOffsetAfterPosition(this._modelData, lineNumber, maxCol, includeViewZones);
}

public getLineHeightForLineNumber(lineNumber: number): number {
if (!this._modelData) {
return -1;
}
return this._modelData.viewModel.viewLayout.getLineHeightForLineNumber(lineNumber);
}

public setHiddenAreas(ranges: IRange[], source?: unknown, forceUpdate?: boolean): void {
this._modelData?.viewModel.setHiddenAreas(ranges.map(r => Range.lift(r)), source, forceUpdate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,33 +617,15 @@ export class StickyScrollController extends Disposable implements IEditorContrib
const topOfElementAtDepth = range.topOfElement;
const bottomOfElementAtDepth = range.bottomOfElement;

const bottomOfStart = this._editor.getBottomForLineNumber(start);
const topForEnd = this._editor.getTopForLineNumber(end);
const bottomForEnd = this._editor.getBottomForLineNumber(end);
const bottomOfBeginningLine = bottomOfStart - scrollTop;
const topOfEndLine = topForEnd - scrollTop;
const bottomOfEndLine = bottomForEnd - scrollTop;

console.log('start', start);
console.log('end', end);
console.log('topOfElementAtDepth', topOfElementAtDepth);
console.log('bottomOfElementAtDepth', bottomOfElementAtDepth);
console.log('bottomOfStart', bottomOfStart);
console.log('topForEnd', topForEnd);
console.log('bottomForEnd', bottomForEnd);

console.log('bottomOfBeginningLine', bottomOfBeginningLine);
console.log('topOfEndLine', topOfEndLine);
console.log('bottomOfEndLine', bottomOfEndLine);

console.log('topOfElementAtDepth > topOfEndLine : ', topOfElementAtDepth > topOfEndLine);
console.log('topOfElementAtDepth <= bottomOfEndLine : ', topOfElementAtDepth <= bottomOfEndLine);
console.log('bottomOfElementAtDepth > bottomOfBeginningLine : ', bottomOfElementAtDepth > bottomOfBeginningLine);
console.log('bottomOfElementAtDepth <= bottomOfEndLine : ', bottomOfElementAtDepth <= bottomOfEndLine);

if (topOfElementAtDepth > topOfEndLine && topOfElementAtDepth <= bottomOfEndLine) {
const bottomOfBeginningLine = this._editor.getBottomForLineNumber(start) - scrollTop;
const topOfEndLine = this._editor.getTopForLineNumber(end) - scrollTop;
const bottomOfEndLine = this._editor.getBottomForLineNumber(end) - scrollTop;
const heightOfEndLine = this._editor.getLineHeightForLineNumber(end);
const heightOfStartLine = this._editor.getLineHeightForLineNumber(start);
const delta = heightOfEndLine - heightOfStartLine;

if (topOfElementAtDepth > topOfEndLine + delta && topOfElementAtDepth <= bottomOfEndLine - delta) {
startLineNumbers.push(start);
console.log('push start 1 : ', start);
endLineNumbers.push(end + 1);
if (topOfElementAtDepth > bottomOfEndLine - range.height) {
lastLineRelativePosition = bottomOfEndLine - bottomOfElementAtDepth;
Expand All @@ -652,7 +634,6 @@ export class StickyScrollController extends Disposable implements IEditorContrib
}
else if (bottomOfElementAtDepth > bottomOfBeginningLine && bottomOfElementAtDepth <= bottomOfEndLine) {
startLineNumbers.push(start);
console.log('push start 2 : ', start);
endLineNumbers.push(end + 1);
}
if (startLineNumbers.length === maxNumberStickyLines) {
Expand Down
1 change: 1 addition & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6101,6 +6101,7 @@ declare namespace monaco.editor {
* Get the vertical position (top offset) for the position w.r.t. to the first line.
*/
getTopForPosition(lineNumber: number, column: number): number;
getLineHeightForLineNumber(lineNumber: number): number;
/**
* Write the screen reader content to be the current selection
*/
Expand Down

0 comments on commit c7ce4b2

Please sign in to comment.