// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../ui/kit/kit.js';
import * as i18n from '../../core/i18n/i18n.js';
import * as QuickOpen from '../../ui/legacy/components/quick_open/quick_open.js';
import * as UI from '../../ui/legacy/legacy.js';
import {html, type TemplateResult} from '../../ui/lit/lit.js';
import {SourcesView} from './SourcesView.js';
import type {UISourceCodeFrame} from './UISourceCodeFrame.js';
const UIStrings = {
/**
* @description Text in Go To Line Quick Open of the Sources panel
*/
noFileSelected: 'No file selected',
/**
* @description Text to show no results have been found
*/
noResultsFound: 'No results found',
/**
* @description Text in Go To Line Quick Open of the Sources panel
*/
typeANumberToGoToThatLine: 'Type a number to go to that line',
/**
* @description Text in Go To Line Quick Open of the Sources panel
* @example {000} PH1
* @example {bbb} PH2
*/
currentPositionXsTypeAnOffset: 'Type an offset between 0x{PH1} and 0x{PH2} to navigate to',
/**
* @description Text in the GoToLine dialog of the Sources pane that describes the current line number, file line number range, and use of the GoToLine dialog
* @example {100} PH1
*/
currentLineSTypeALineNumber: 'Type a line number between 1 and {PH1} to navigate to',
/**
* @description Text in Go To Line Quick Open of the Sources panel
* @example {abc} PH1
*/
goToOffsetXs: 'Go to offset 0x{PH1}',
/**
* @description Text in Go To Line Quick Open of the Sources panel
* @example {2} PH1
* @example {2} PH2
*/
goToLineSAndColumnS: 'Go to line {PH1} and column {PH2}',
/**
* @description Text in Go To Line Quick Open of the Sources panel
* @example {2} PH1
*/
goToLineS: 'Go to line {PH1}',
} as const;
const str_ = i18n.i18n.registerUIStrings('panels/sources/GoToLineQuickOpen.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
export class GoToLineQuickOpen extends QuickOpen.FilteredListWidget.Provider {
#goToLineStrings: string[] = [];
override selectItem(_itemIndex: number|null, promptValue: string): void {
const sourceFrame = this.currentSourceFrame();
if (!sourceFrame) {
return;
}
const position = this.parsePosition(promptValue);
if (!position) {
return;
}
sourceFrame.revealPosition({lineNumber: position.line - 1, columnNumber: position.column - 1});
}
override itemCount(): number {
return this.#goToLineStrings.length;
}
override renderItem(itemIndex: number, _query: string): TemplateResult {
// clang-format off
return html`