Skip to content

Commit

Permalink
Adapt line number to be 1-based from a 0-based position.
Browse files Browse the repository at this point in the history
  • Loading branch information
rschnekenbu committed Jun 22, 2023
1 parent b6294fd commit 4a2b423
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/editor/src/browser/editor-linenumber-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// *****************************************************************************

import { EditorManager } from './editor-manager';
import { EditorMouseEvent, MouseTargetType, TextEditor } from './editor';
import { EditorMouseEvent, MouseTargetType, Position, TextEditor } from './editor';
import { injectable, inject, optional } from '@theia/core/shared/inversify';
import { FrontendApplicationContribution, QuickInputService, ApplicationShell, ContextMenuRenderer } from '@theia/core/lib/browser';
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
Expand Down Expand Up @@ -62,10 +62,11 @@ export class EditorLineNumberContribution implements FrontendApplicationContribu
if (event.target && event.target.type === MouseTargetType.GUTTER_LINE_NUMBERS) {
if (event.event.button === 2) {
editor.focus();
const contextKeyService = this.contextKeyService.createOverlay([['editorLineNumber', event.target.position?.line]]);
const lineNumber = lineNumberFromPosition(event.target.position);
const contextKeyService = this.contextKeyService.createOverlay([['editorLineNumber', lineNumber]]);
const uri = editor.getResourceUri()!;
const args = [{
lineNumber: event.target.position?.line!,
lineNumber: lineNumber,
uri: uri['codeUri']
}];

Expand All @@ -83,3 +84,12 @@ export class EditorLineNumberContribution implements FrontendApplicationContribu
}

}

function lineNumberFromPosition(position: Position | undefined): number | undefined {
// position.line is 0-based line position, where the expected editor line number is 1-based.
if (position) {
return position.line + 1;
}
return undefined;
}

0 comments on commit 4a2b423

Please sign in to comment.