Jan Scheffler | 1fc99c5 | 2021-04-07 21:12:40 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jack Franklin | a75ae7c | 2021-05-11 13:22:54 | [diff] [blame] | 5 | import type * as Common from '../../core/common/common.js'; |
Tim van der Lippe | 877f04a | 2021-07-23 11:02:54 | [diff] [blame] | 6 | import type * as TextUtils from '../../models/text_utils/text_utils.js'; |
Jan Scheffler | 1fc99c5 | 2021-04-07 21:12:40 | [diff] [blame] | 7 | |
Jack Franklin | a75ae7c | 2021-05-11 13:22:54 | [diff] [blame] | 8 | import type {AnchorBehavior} from './GlassPane.js'; |
Tim van der Lippe | 877f04a | 2021-07-23 11:02:54 | [diff] [blame] | 9 | import type {Suggestion} from './SuggestBox.js'; |
| 10 | import type {Widget} from './Widget.js'; |
Jan Scheffler | 1fc99c5 | 2021-04-07 21:12:40 | [diff] [blame] | 11 | |
| 12 | export interface TextEditorFactory { |
| 13 | createEditor(options: Options): TextEditor; |
| 14 | } |
| 15 | |
| 16 | export interface TextEditor extends Common.EventTarget.EventTarget { |
| 17 | widget(): Widget; |
| 18 | fullRange(): TextUtils.TextRange.TextRange; |
| 19 | selection(): TextUtils.TextRange.TextRange; |
| 20 | setSelection(selection: TextUtils.TextRange.TextRange): void; |
| 21 | text(textRange?: TextUtils.TextRange.TextRange): string; |
| 22 | textWithCurrentSuggestion(): string; |
| 23 | setText(text: string): void; |
| 24 | line(lineNumber: number): string; |
| 25 | newlineAndIndent(): void; |
| 26 | addKeyDownHandler(handler: (arg0: KeyboardEvent) => void): void; |
| 27 | configureAutocomplete(config: AutocompleteConfig|null): void; |
| 28 | clearAutocomplete(): void; |
| 29 | visualCoordinates(lineNumber: number, columnNumber: number): { |
| 30 | x: number, |
| 31 | y: number, |
| 32 | }; |
| 33 | tokenAtTextPosition(lineNumber: number, columnNumber: number): { |
| 34 | startColumn: number, |
| 35 | endColumn: number, |
| 36 | type: string, |
| 37 | }|null; |
| 38 | setPlaceholder(placeholder: string): void; |
| 39 | } |
| 40 | |
| 41 | // TODO(crbug.com/1167717): Make this a const enum again |
| 42 | // eslint-disable-next-line rulesdir/const_enum |
| 43 | export enum Events { |
| 44 | CursorChanged = 'CursorChanged', |
| 45 | TextChanged = 'TextChanged', |
| 46 | SuggestionChanged = 'SuggestionChanged', |
| 47 | } |
| 48 | |
| 49 | export interface Options { |
| 50 | bracketMatchingSetting?: Common.Settings.Setting<boolean>; |
| 51 | devtoolsAccessibleName?: string; |
| 52 | lineNumbers: boolean; |
| 53 | lineWrapping: boolean; |
| 54 | mimeType?: string; |
| 55 | autoHeight?: boolean; |
| 56 | padBottom?: boolean; |
| 57 | maxHighlightLength?: number; |
| 58 | placeholder?: string; |
| 59 | lineWiseCopyCut?: boolean; |
| 60 | inputStyle?: string; |
| 61 | } |
| 62 | |
| 63 | export interface AutocompleteConfig { |
| 64 | substituteRangeCallback?: ((arg0: number, arg1: number) => TextUtils.TextRange.TextRange | null); |
| 65 | tooltipCallback?: ((arg0: number, arg1: number) => Promise<Element|null>); |
| 66 | suggestionsCallback?: |
| 67 | ((arg0: TextUtils.TextRange.TextRange, arg1: TextUtils.TextRange.TextRange, |
| 68 | arg2?: boolean|undefined) => Promise<Suggestion[]>| null); |
| 69 | isWordChar?: ((arg0: string) => boolean); |
| 70 | anchorBehavior?: AnchorBehavior; |
| 71 | } |