From 7e7f3298da7f7e0a6b3fdc80b30408614f41687b Mon Sep 17 00:00:00 2001 From: mkslanc Date: Fri, 25 Aug 2023 18:02:22 +0400 Subject: [PATCH 01/36] correct many descriptions; automatic type declarations generation with tsc --- ace.d.ts | 600 +++++++----------------------- demo/webpack/demo.js | 28 +- package.json | 7 +- src/ace.js | 30 +- src/anchor.js | 19 +- src/autocomplete.js | 4 +- src/autocomplete/popup.js | 2 +- src/clipboard.js | 4 + src/document.js | 118 +++--- src/edit_session.js | 319 +++++++++++----- src/edit_session/bracket_match.js | 3 +- src/editor.js | 312 +++++++++++----- src/keyboard/textinput.js | 6 + src/lib/app_config.js | 5 + src/lib/event_emitter.js | 5 +- src/lib/oop.js | 14 + src/range.js | 31 +- src/search.js | 6 +- src/selection.js | 13 +- src/virtual_renderer.js | 233 +++++++++--- tsconfig.json | 28 ++ 21 files changed, 1001 insertions(+), 786 deletions(-) create mode 100644 tsconfig.json diff --git a/ace.d.ts b/ace.d.ts index 81ab5adb784..598afafaf4c 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,53 +1,42 @@ /// -export namespace Ace { - export type NewLineMode = 'auto' | 'unix' | 'windows'; - export interface Anchor extends EventEmitter { - getPosition(): Position; - getDocument(): Document; - setPosition(row: number, column: number, noClip?: boolean): void; - detach(): void; - attach(doc: Document): void; - } - - export interface Document extends EventEmitter { - setValue(text: string): void; - getValue(): string; - createAnchor(row: number, column: number): Anchor; - getNewLineCharacter(): string; - setNewLineMode(newLineMode: NewLineMode): void; - getNewLineMode(): NewLineMode; - isNewLine(text: string): boolean; - getLine(row: number): string; - getLines(firstRow: number, lastRow: number): string[]; - getAllLines(): string[]; - getLength(): number; - getTextRange(range: Range): string; - getLinesForRange(range: Range): string[]; - insert(position: Position, text: string): Position; - insert(position: {row: number, column: number}, text: string): Position; - insertInLine(position: Position, text: string): Position; - insertNewLine(position: Point): Point; - clippedPos(row: number, column: number): Point; - clonePos(pos: Point): Point; - pos(row: number, column: number): Point; - insertFullLines(row: number, lines: string[]): void; - insertMergedLines(position: Position, lines: string[]): Point; - remove(range: Range): Position; - removeInLine(row: number, startColumn: number, endColumn: number): Position; - removeFullLines(firstRow: number, lastRow: number): string[]; - removeNewLine(row: number): void; - replace(range: Range, text: string): Position; - applyDeltas(deltas: Delta[]): void; - revertDeltas(deltas: Delta[]): void; - applyDelta(delta: Delta, doNotValidate?: boolean): void; - revertDelta(delta: Delta): void; - indexToPosition(index: number, startRow: number): Position; - positionToIndex(pos: Position, startRow?: number): number; - } - - export interface FoldLine { +declare namespace Ace { + interface EditorProperties { + $mergeUndoDeltas?: any, + $highlightSelectedWord?: boolean, + $updatePlaceholder?: Function, + $cursorStyle?: string, + $readOnly?: any, + searchBox?: any, + $highlightActiveLine?: any, + $enableAutoIndent?: any, + $copyWithEmptySelection?: any + $selectionStyle?: string, + env?: any; + } + + interface EditSessionProperties { + $highlightLineMarker?: Range + $useSoftTabs?: boolean, + $tabSize?: number, + $useWorker?: boolean, + $wrapAsCode?: boolean, + $indentedSoftWrap?: boolean, + widgetManager?: any, + $bracketHighlight?: any, + $selectionMarker?: number + } + + interface EditorMultiSelectProperties { + inMultiSelectMode?: boolean, + forEachSelection?: Function, + exitMultiSelectMode?: Function + } + + type NewLineMode = 'auto' | 'unix' | 'windows'; + + interface FoldLine { folds: Fold[]; range: Range; start: Point; @@ -64,7 +53,7 @@ export namespace Ace { idxToPosition(idx: number): Point; } - export interface Fold { + interface Fold { range: Range; start: Point; end: Point; @@ -78,7 +67,7 @@ export namespace Ace { restoreRange(range: Range): void; } - interface Folding { + class Folding { getFoldAt(row: number, column: number, side: number): Fold; getFoldsInRange(range: Range): Fold[]; getFoldsInRangeList(ranges: Range[]): Fold[]; @@ -99,8 +88,8 @@ export namespace Ace { unfold(location: null | number | Point | Range, expandInner?: boolean): Fold[] | undefined; isRowFolded(docRow: number, startFoldRow?: FoldLine): boolean; - getFoldRowEnd(docRow: number, startFoldRow?: FoldLine): number; - getFoldRowStart(docRow: number, startFoldRow?: FoldLine): number; + getRowFoldEnd(docRow: number, startFoldRow?: FoldLine): number; + getRowFoldStart(docRow: number, startFoldRow?: FoldLine): number; getFoldDisplayLine(foldLine: FoldLine, endRow: number | null, endColumn: number | null, @@ -124,39 +113,7 @@ export namespace Ace { updateFoldWidgets(delta: Delta): void; } - export interface Range { - start: Point; - end: Point; - - isEqual(range: Range): boolean; - toString(): string; - contains(row: number, column: number): boolean; - compareRange(range: Range): number; - comparePoint(p: Point): number; - containsRange(range: Range): boolean; - intersects(range: Range): boolean; - isEnd(row: number, column: number): boolean; - isStart(row: number, column: number): boolean; - setStart(row: number, column: number): void; - setEnd(row: number, column: number): void; - inside(row: number, column: number): boolean; - insideStart(row: number, column: number): boolean; - insideEnd(row: number, column: number): boolean; - compare(row: number, column: number): number; - compareStart(row: number, column: number): number; - compareEnd(row: number, column: number): number; - compareInside(row: number, column: number): number; - clipRows(firstRow: number, lastRow: number): Range; - extend(row: number, column: number): Range; - isEmpty(): boolean; - isMultiLine(): boolean; - clone(): Range; - collapseRows(): Range; - toScreenRange(session: EditSession): Range; - moveBy(row: number, column: number): void; - } - - export interface EditSessionOptions { + interface EditSessionOptions { wrap: "off" | "free" | "printmargin" | boolean | number; wrapMethod: 'code' | 'text' | 'auto'; indentedSoftWrap: boolean; @@ -171,7 +128,7 @@ export namespace Ace { mode: string; } - export interface VirtualRendererOptions { + interface VirtualRendererOptions { animatedScroll: boolean; showInvisibles: boolean; showPrintMargin: boolean; @@ -200,7 +157,7 @@ export namespace Ace { showFoldedAnnotations: boolean; } - export interface MouseHandlerOptions { + interface MouseHandlerOptions { scrollSpeed: number; dragDelay: number; dragEnabled: boolean; @@ -208,7 +165,7 @@ export namespace Ace { tooltipFollowsMouse: boolean; } - export interface EditorOptions extends EditSessionOptions, + interface EditorOptions extends EditSessionOptions, MouseHandlerOptions, VirtualRendererOptions { selectionStyle: string; @@ -236,7 +193,21 @@ export namespace Ace { enableKeyboardAccessibility: boolean; } - export interface SearchOptions { + class EventEmitter { + once?(name: string, callback: Function): void; + setDefaultHandler?(name: string, callback: Function): void; + removeDefaultHandler?(name: string, callback: Function): void; + on?(name: string, callback: Function, capturing?: boolean): Function; + addEventListener?(name: string, callback: Function, capturing?: boolean): Function; + off?(name: string, callback: Function): void; + removeListener?(name: string, callback: Function): void; + removeEventListener?(name: string, callback: Function): void; + removeAllListeners?(name?: string): void; + _signal?(eventName: string, e: any): void; + _emit?(eventName: string, e: any): void; + } + + interface SearchOptions { needle: string | RegExp; preventScroll: boolean; backwards: boolean; @@ -250,63 +221,53 @@ export namespace Ace { wrap: boolean; } - export interface EventEmitter { - once(name: string, callback: Function): void; - setDefaultHandler(name: string, callback: Function): void; - removeDefaultHandler(name: string, callback: Function): void; - on(name: string, callback: Function, capturing?: boolean): void; - addEventListener(name: string, callback: Function, capturing?: boolean): void; - off(name: string, callback: Function): void; - removeListener(name: string, callback: Function): void; - removeEventListener(name: string, callback: Function): void; - removeAllListeners(name?: string): void; - } - - export interface Point { + interface Point { row: number; column: number; } + + type Position = Point; - export interface Delta { + interface Delta { action: 'insert' | 'remove'; start: Point; end: Point; lines: string[]; } - export interface Annotation { + interface Annotation { row?: number; column?: number; text: string; type: string; } - export interface MarkerGroupItem { + interface MarkerGroupItem { range: Range; className: string; } - export class MarkerGroup { + class MarkerGroup { constructor(session: EditSession); setMarkers(markers: MarkerGroupItem[]): void; getMarkerAtPosition(pos: Position): MarkerGroupItem; } - export interface Command { + interface Command { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; exec: (editor: Editor, args?: any) => void; } - export type CommandLike = Command | ((editor: Editor) => void); + type CommandLike = Command | ((editor: Editor) => void); - export interface KeyboardHandler { + interface KeyboardHandler { handleKeyboard: Function; } - export interface MarkerLike { + interface MarkerLike { range?: Range; type: string; renderer?: MarkerRenderer; @@ -320,13 +281,13 @@ export namespace Ace { config: any) => void; } - export type MarkerRenderer = (html: string[], + type MarkerRenderer = (html: string[], range: Range, left: number, top: number, config: any) => void; - export interface Token { + interface Token { type: string; value: string; index?: number; @@ -342,17 +303,17 @@ export namespace Ace { completerId?: string; } - export interface SnippetCompletion extends BaseCompletion { + interface SnippetCompletion extends BaseCompletion { snippet: string; } - export interface ValueCompletion extends BaseCompletion { + interface ValueCompletion extends BaseCompletion { value: string; } - export type Completion = SnippetCompletion | ValueCompletion + type Completion = SnippetCompletion | ValueCompletion - export interface Tokenizer { + interface Tokenizer { removeCapturingGroups(src: string): string; createSplitterRegexp(src: string, flag?: string): RegExp; getLineTokens(line: string, startState: string | string[]): Token[]; @@ -368,7 +329,7 @@ export namespace Ace { stepForward(): Token; } - export type HighlightRule = {defaultToken: string} | {include: string} | {todo: string} | { + type HighlightRule = {defaultToken: string} | {include: string} | {todo: string} | { token: string | string[] | ((value: string) => string); regex: string | RegExp; next?: string; @@ -377,11 +338,11 @@ export namespace Ace { caseInsensitive?: boolean; } - export type HighlightRulesMap = Record; + type HighlightRulesMap = Record; - export type KeywordMapper = (keyword: string) => string; + type KeywordMapper = (keyword: string) => string; - export interface HighlightRules { + interface HighlightRules { addRules(rules: HighlightRulesMap, prefix?: string): void; getRules(): HighlightRulesMap; embedRules(rules: (new () => HighlightRules) | HighlightRulesMap, prefix: string, escapeRules?: boolean, append?: boolean): void; @@ -390,7 +351,7 @@ export namespace Ace { createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; } - export interface FoldMode { + interface FoldMode { foldingStartMarker: RegExp; foldingStopMarker?: RegExp; getFoldWidget(session: EditSession, foldStyle: string, row: number): string; @@ -403,7 +364,7 @@ export namespace Ace { type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => {text: string, selection: number[]} | Range | undefined; type BehaviorMap = Record>; - export interface Behaviour { + interface Behaviour { add(name: string, action: string, callback: BehaviorAction): void; addBehaviours(behaviours: BehaviorMap): void; remove(name: string): void; @@ -411,13 +372,13 @@ export namespace Ace { getBehaviours(filter: string[]): BehaviorMap; } - export interface Outdent { + interface Outdent { checkOutdent(line: string, input: string): boolean; autoOutdent(doc: Document, row: number): number | undefined; } - export interface SyntaxMode { - HighlightRules: new () => HighlightRules; + interface SyntaxMode { + HighlightRules: HighlightRules; foldingRules?: FoldMode; $behaviour?: Behaviour; $defaultBehaviour?: Behaviour; @@ -448,31 +409,33 @@ export namespace Ace { type AfterLoadCallback = (err: Error | null, module: unknown) => void; type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; - export interface Config { - get(key: string): any; - set(key: string, value: any): void; - all(): { [key: string]: any }; - moduleUrl(name: string, component?: string): string; - setModuleUrl(name: string, subst: string): string; - setLoader(cb: LoaderFunction): void; - setModuleLoader(name: string, onLoad: Function): void; - loadModule(moduleName: string | [string, string], + interface Config { + get?(key: string): any; + set?(key: string, value: any): void; + all?(): { [key: string]: any }; + moduleUrl?(name: string, component?: string): string; + setModuleUrl?(name: string, subst: string): string; + setLoader?(cb: LoaderFunction): void; + setModuleLoader?(name: string, onLoad: Function): void; + loadModule?(moduleName: string | [string, string], onLoad?: (module: any) => void): void; - init(packaged: any): any; - defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; - resetOptions(obj: any): void; - setDefaultValue(path: string, name: string, value: any): void; - setDefaultValues(path: string, optionHash: { [key: string]: any }): void; + init?(packaged: any): any; + defineOptions?(obj: any, path: string, options: { [key: string]: any }): Config; + resetOptions?(obj: any): void; + setDefaultValue?(path: string, name: string, value: any): void; + setDefaultValues?(path: string, optionHash: { [key: string]: any }): void; } - export interface OptionsProvider { - setOptions(optList: { [key: string]: any }): void; - getOptions(optionNames?: string[] | { [key: string]: any }): { [key: string]: any }; - setOption(name: string, value: any): void; - getOption(name: string): any; + interface OptionsBase { [key: string]: any; } + + class OptionsProvider { + setOptions?(optList: Partial): void; + getOptions?(optionNames?: Array | Partial): Partial; + setOption?(name: K, value: K[T]): void; + getOption?(name: K): T[K]; } - export interface UndoManager { + interface UndoManager { addSession(session: EditSession): void; add(delta: Delta, allowMerge: boolean, session: EditSession): void; addSelection(selection: string, rev?: number): void; @@ -493,136 +456,8 @@ export namespace Ace { isClean(): boolean; markClean(rev?: number): void; } - - export interface Position { - row: number, - column: number - } - - export interface EditSession extends EventEmitter, OptionsProvider, Folding { - selection: Selection; - - // TODO: define BackgroundTokenizer - - on(name: 'changeFold', - callback: (obj: { data: Fold, action: string }) => void): Function; - on(name: 'changeScrollLeft', callback: (scrollLeft: number) => void): Function; - on(name: 'changeScrollTop', callback: (scrollTop: number) => void): Function; - on(name: 'tokenizerUpdate', - callback: (obj: { data: { first: number, last: number } }) => void): Function; - on(name: 'change', callback: () => void): Function; - on(name: 'changeTabSize', callback: () => void): Function; - - - setOption(name: T, value: EditSessionOptions[T]): void; - getOption(name: T): EditSessionOptions[T]; - - readonly doc: Document; - - setDocument(doc: Document): void; - getDocument(): Document; - resetCaches(): void; - setValue(text: string): void; - getValue(): string; - getSelection(): Selection; - getState(row: number): string; - getTokens(row: number): Token[]; - getTokenAt(row: number, column: number): Token | null; - setUndoManager(undoManager: UndoManager): void; - markUndoGroup(): void; - getUndoManager(): UndoManager; - getTabString(): string; - setUseSoftTabs(val: boolean): void; - getUseSoftTabs(): boolean; - setTabSize(tabSize: number): void; - getTabSize(): number; - isTabStop(position: Position): boolean; - setNavigateWithinSoftTabs(navigateWithinSoftTabs: boolean): void; - getNavigateWithinSoftTabs(): boolean; - setOverwrite(overwrite: boolean): void; - getOverwrite(): boolean; - toggleOverwrite(): void; - addGutterDecoration(row: number, className: string): void; - removeGutterDecoration(row: number, className: string): void; - getBreakpoints(): string[]; - setBreakpoints(rows: number[]): void; - clearBreakpoints(): void; - setBreakpoint(row: number, className: string): void; - clearBreakpoint(row: number): void; - addMarker(range: Range, - className: string, - type: "fullLine" | "screenLine" | "text" | MarkerRenderer, - inFront?: boolean): number; - addDynamicMarker(marker: MarkerLike, inFront: boolean): MarkerLike; - removeMarker(markerId: number): void; - getMarkers(inFront?: boolean): {[id: number]: MarkerLike}; - highlight(re: RegExp): void; - highlightLines(startRow: number, - endRow: number, - className: string, - inFront?: boolean): Range; - setAnnotations(annotations: Annotation[]): void; - getAnnotations(): Annotation[]; - clearAnnotations(): void; - getWordRange(row: number, column: number): Range; - getAWordRange(row: number, column: number): Range; - setNewLineMode(newLineMode: NewLineMode): void; - getNewLineMode(): NewLineMode; - setUseWorker(useWorker: boolean): void; - getUseWorker(): boolean; - setMode(mode: string | SyntaxMode, callback?: () => void): void; - getMode(): SyntaxMode; - setScrollTop(scrollTop: number): void; - getScrollTop(): number; - setScrollLeft(scrollLeft: number): void; - getScrollLeft(): number; - getScreenWidth(): number; - getLineWidgetMaxWidth(): number; - getLine(row: number): string; - getLines(firstRow: number, lastRow: number): string[]; - getLength(): number; - getTextRange(range: Range): string; - insert(position: Position, text: string): void; - remove(range: Range): void; - removeFullLines(firstRow: number, lastRow: number): void; - undoChanges(deltas: Delta[], dontSelect?: boolean): void; - redoChanges(deltas: Delta[], dontSelect?: boolean): void; - setUndoSelect(enable: boolean): void; - replace(range: Range, text: string): void; - moveText(fromRange: Range, toPosition: Position, copy?: boolean): void; - indentRows(startRow: number, endRow: number, indentString: string): void; - outdentRows(range: Range): void; - moveLinesUp(firstRow: number, lastRow: number): void; - moveLinesDown(firstRow: number, lastRow: number): void; - duplicateLines(firstRow: number, lastRow: number): void; - setUseWrapMode(useWrapMode: boolean): void; - getUseWrapMode(): boolean; - setWrapLimitRange(min: number, max: number): void; - adjustWrapLimit(desiredLimit: number): boolean; - getWrapLimit(): number; - setWrapLimit(limit: number): void; - getWrapLimitRange(): { min: number, max: number }; - getRowLineCount(row: number): number; - getRowWrapIndent(screenRow: number): number; - getScreenLastRowColumn(screenRow: number): number; - getDocumentLastRowColumn(docRow: number, docColumn: number): number; - getdocumentLastRowColumnPosition(docRow: number, docColumn: number): Position; - getRowSplitData(row: number): string | undefined; - getScreenTabSize(screenColumn: number): number; - screenToDocumentRow(screenRow: number, screenColumn: number): number; - screenToDocumentColumn(screenRow: number, screenColumn: number): number; - screenToDocumentPosition(screenRow: number, - screenColumn: number, - offsetX?: number): Position; - documentToScreenPosition(docRow: number, docColumn: number): Position; - documentToScreenPosition(position: Position): Position; - documentToScreenColumn(row: number, docColumn: number): number; - documentToScreenRow(docRow: number, docColumn: number): number; - getScreenLength(): number; - destroy(): void; - } - - export interface KeyBinding { + + interface KeyBinding { setDefaultHandler(handler: KeyboardHandler): void; setKeyboardHandler(handler: KeyboardHandler): void; addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; @@ -643,7 +478,7 @@ export namespace Ace { args: any[] }) => void; - export interface CommandManager extends EventEmitter { + interface CommandManager extends EventEmitter { byName: CommandMap, commands: CommandMap, on(name: 'exec', callback: execEventHandler): Function; @@ -674,7 +509,7 @@ export namespace Ace { getStatusText(editor: Editor, data: {}): string; } - export interface VirtualRenderer extends OptionsProvider, EventEmitter { + interface VirtualRenderer extends OptionsProvider, EventEmitter { readonly container: HTMLElement; readonly scroller: HTMLElement; readonly content: HTMLElement; @@ -774,7 +609,7 @@ export namespace Ace { } - export interface Selection extends EventEmitter { + interface Selection extends EventEmitter { moveCursorWordLeft(): void; moveCursorWordRight(): void; fromOrientedRange(range: Range): void; @@ -836,168 +671,23 @@ export namespace Ace { new(session: EditSession): Selection; } - export interface TextInput { + interface TextInput { resetSelection(): void; setAriaOption(activeDescendant: string, role: string): void; } + - export interface Editor extends OptionsProvider, EventEmitter { - container: HTMLElement; - renderer: VirtualRenderer; - id: string; - commands: CommandManager; - keyBinding: KeyBinding; - session: EditSession; - selection: Selection; - textInput: TextInput; - - on(name: 'blur', callback: (e: Event) => void): void; - on(name: 'input', callback: () => void): void; - on(name: 'change', callback: (delta: Delta) => void): void; - on(name: 'changeSelectionStyle', callback: (obj: { data: string }) => void): void; - on(name: 'changeSession', - callback: (obj: { session: EditSession, oldSession: EditSession }) => void): void; - on(name: 'copy', callback: (obj: { text: string }) => void): void; - on(name: 'focus', callback: (e: Event) => void): void; - on(name: 'paste', callback: (obj: { text: string }) => void): void; - on(name: 'mousemove', callback: (e: any) => void): void; - on(name: 'mouseup', callback: (e: any) => void): void; - on(name: 'mousewheel', callback: (e: any) => void): void; - on(name: 'click', callback: (e: any) => void): void; - on(name: 'guttermousedown', callback: (e: any) => void): void; - on(name: 'gutterkeydown', callback: (e: any) => void): void; - - onPaste(text: string, event: any): void; - - setOption(name: T, value: EditorOptions[T]): void; - getOption(name: T): EditorOptions[T]; - - setKeyboardHandler(keyboardHandler: string, callback?: () => void): void; - setKeyboardHandler(keyboardHandler: KeyboardHandler|null): void; - getKeyboardHandler(): string; - setSession(session: EditSession | undefined): void; - getSession(): EditSession; - setValue(val: string, cursorPos?: number): string; - getValue(): string; - getSelection(): Selection; - resize(force?: boolean): void; - setTheme(theme: string, callback?: () => void): void; - getTheme(): string; - setStyle(style: string): void; - unsetStyle(style: string): void; - getFontSize(): string; - setFontSize(size: number|string): void; - focus(): void; - isFocused(): boolean; - blur(): void; - getSelectedText(): string; - getCopyText(): string; - execCommand(command: string | string[], args?: any): boolean; - insert(text: string, pasted?: boolean): void; - setOverwrite(overwrite: boolean): void; - getOverwrite(): boolean; - toggleOverwrite(): void; - setScrollSpeed(speed: number): void; - getScrollSpeed(): number; - setDragDelay(dragDelay: number): void; - getDragDelay(): number; - setSelectionStyle(val: string): void; - getSelectionStyle(): string; - setHighlightActiveLine(shouldHighlight: boolean): void; - getHighlightActiveLine(): boolean; - setHighlightGutterLine(shouldHighlight: boolean): void; - getHighlightGutterLine(): boolean; - setHighlightSelectedWord(shouldHighlight: boolean): void; - getHighlightSelectedWord(): boolean; - setAnimatedScroll(shouldAnimate: boolean): void; - getAnimatedScroll(): boolean; - setShowInvisibles(showInvisibles: boolean): void; - getShowInvisibles(): boolean; - setDisplayIndentGuides(display: boolean): void; - getDisplayIndentGuides(): boolean; - setShowPrintMargin(showPrintMargin: boolean): void; - getShowPrintMargin(): boolean; - setPrintMarginColumn(showPrintMargin: number): void; - getPrintMarginColumn(): number; - setReadOnly(readOnly: boolean): void; - getReadOnly(): boolean; - setBehavioursEnabled(enabled: boolean): void; - getBehavioursEnabled(): boolean; - setWrapBehavioursEnabled(enabled: boolean): void; - getWrapBehavioursEnabled(): boolean; - setShowFoldWidgets(show: boolean): void; - getShowFoldWidgets(): boolean; - setFadeFoldWidgets(fade: boolean): void; - getFadeFoldWidgets(): boolean; - remove(dir?: 'left' | 'right'): void; - removeWordRight(): void; - removeWordLeft(): void; - removeLineToEnd(): void; - splitLine(): void; - setGhostText(text: string, position: Point): void; - removeGhostText(): void; - transposeLetters(): void; - toLowerCase(): void; - toUpperCase(): void; - indent(): void; - blockIndent(): void; - blockOutdent(): void; - sortLines(): void; - toggleCommentLines(): void; - toggleBlockComment(): void; - modifyNumber(amount: number): void; - removeLines(): void; - duplicateSelection(): void; - moveLinesDown(): void; - moveLinesUp(): void; - moveText(range: Range, toPosition: Point, copy?: boolean): Range; - copyLinesUp(): void; - copyLinesDown(): void; - getFirstVisibleRow(): number; - getLastVisibleRow(): number; - isRowVisible(row: number): boolean; - isRowFullyVisible(row: number): boolean; - selectPageDown(): void; - selectPageUp(): void; - gotoPageDown(): void; - gotoPageUp(): void; - scrollPageDown(): void; - scrollPageUp(): void; - scrollToRow(row: number): void; - scrollToLine(line: number, center: boolean, animate: boolean, callback: () => void): void; - centerSelection(): void; - getCursorPosition(): Point; - getCursorPositionScreen(): Point; - getSelectionRange(): Range; - selectAll(): void; - clearSelection(): void; - moveCursorTo(row: number, column: number): void; - moveCursorToPosition(pos: Point): void; - jumpToMatching(select: boolean, expand: boolean): void; - gotoLine(lineNumber: number, column: number, animate: boolean): void; - navigateTo(row: number, column: number): void; - navigateUp(times?: number): void; - navigateDown(times?: number): void; - navigateLeft(times?: number): void; - navigateRight(times?: number): void; - navigateLineStart(): void; - navigateLineEnd(): void; - navigateFileEnd(): void; - navigateFileStart(): void; - navigateWordRight(): void; - navigateWordLeft(): void; - replace(replacement: string, options?: Partial): number; - replaceAll(replacement: string, options?: Partial): number; - getLastSearchOptions(): Partial; - find(needle: string | RegExp, options?: Partial, animate?: boolean): Ace.Range | undefined; - findNext(options?: Partial, animate?: boolean): void; - findPrevious(options?: Partial, animate?: boolean): void; - findAll(needle: string | RegExp, options?: Partial, additive?: boolean): number; - undo(): void; - redo(): void; - destroy(): void; - setAutoScrollEditorIntoView(enable: boolean): void; - completers: Completer[]; + class Editor { + once?(name: string, callback: Function): void; + setDefaultHandler?(name: string, callback: Function): void; + removeDefaultHandler?(name: string, callback: Function): void; + on(name: string, callback: Function, capturing?: boolean): void; + addEventListener?(name: string, callback: Function, capturing?: boolean): void; + off?(name: string, callback: Function): void; + removeListener?(name: string, callback: Function): void; + removeEventListener?(name: string, callback: Function): void; + removeAllListeners?(name?: string): void; + _signal?(eventName: string, e: any): void; } type CompleterCallback = (error: any, completions: Completion[]) => void; @@ -1015,7 +705,7 @@ export namespace Ace { triggerCharacters?: string[] } - export class AceInline { + class AceInline { show(editor: Editor, completion: Completion, prefix: string): void; isOpen(): void; hide(): void; @@ -1046,7 +736,7 @@ export namespace Ace { type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; - export class CompletionProvider { + class CompletionProvider { insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; completions: CompletionRecord; @@ -1055,7 +745,7 @@ export namespace Ace { detach(): void; } - export class Autocomplete { + class Autocomplete { constructor(); autoInsert?: boolean; autoSelect?: boolean; @@ -1072,7 +762,7 @@ export namespace Ace { type AcePopupNavigation = "up" | "down" | "start" | "end"; - export class AcePopup { + class AcePopup { constructor(parentNode: HTMLElement); setData(list: Completion[], filterText: string): void; getData(row: number): Completion; @@ -1086,29 +776,11 @@ export namespace Ace { } -export const version: string; -export const config: Ace.Config; -export function require(name: string): any; -export function edit(el: Element | string, options?: Partial): Ace.Editor; -export function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; -export const VirtualRenderer: { - new(container: HTMLElement, theme?: string): Ace.VirtualRenderer; -}; -export const EditSession: { - new(text: string | Ace.Document, mode?: Ace.SyntaxMode): Ace.EditSession; -}; -export const UndoManager: { - new(): Ace.UndoManager; -}; -export const Editor: { - new(): Ace.Editor; -}; -export const Range: { - new(startRow: number, startColumn: number, endRow: number, endColumn: number): Ace.Range; - fromPoints(start: Ace.Point, end: Ace.Point): Ace.Range; - comparePoints(p1: Ace.Point, p2: Ace.Point): number; -}; - +declare const version: string; +declare const config: Ace.Config; +declare function require(name: string): any; +declare function edit(el: Element | string, options?: Partial): Ace.Editor; +declare function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; @@ -1122,7 +794,7 @@ interface TooltipCommand extends Ace.Command { cssClass: string } -export class InlineAutocomplete { +declare class InlineAutocomplete { constructor(); getInlineRenderer(): Ace.AceInline; getInlineTooltip(): CommandBarTooltip; @@ -1141,7 +813,7 @@ export class InlineAutocomplete { updateCompletions(options: Ace.CompletionOptions): void; } -export class CommandBarTooltip { +declare class CommandBarTooltip { constructor(parentElement: HTMLElement); registerCommand(id: string, command: TooltipCommand): void; attach(editor: Ace.Editor): void; diff --git a/demo/webpack/demo.js b/demo/webpack/demo.js index 6ff273d254d..a6a044047ff 100644 --- a/demo/webpack/demo.js +++ b/demo/webpack/demo.js @@ -1,34 +1,24 @@ "use strict"; - +Object.defineProperty(exports, "__esModule", { value: true }); // import ace -import ace from '../../build' +var build_1 = require("../../build"); // import Range from ace (it is also available as ace.Range) -import {Range, EditSession} from '../../build/' - +var build_2 = require("../../build/"); // import modes that you want to include into your main bundle -import "../../build/src-noconflict/mode-javascript"; - +require("../../build/src-noconflict/mode-javascript"); // import webpack resolver to dynamically load modes, you need to install file-loader for this to work! -import "../../build/webpack-resolver"; +require("../../build/webpack-resolver"); // if you want to allow dynamic loading of only a few modules use setModuleUrl for each of them manually /* import jsWorkerUrl from "file-loader!../../build/src-noconflict/worker-javascript"; ace.config.setModuleUrl("ace/mode/javascript_worker", jsWorkerUrl) */ - -var editor = ace.edit(null, { +var editor = build_1.default.edit(null, { maxLines: 50, minLines: 10, value: "var hello = 'world'" + "\n", mode: "ace/mode/javascript", bug: 1 -}) - -editor.selection.setRange(new Range(0,0,0,3)) - -document.body.appendChild(editor.container) - -/* -import {Mode as JSMode} from "../../build/src-noconflict/mode-javascript" -editor.setMode( new JSMode()) -*/ +}); +editor.selection.setRange(new build_2.Range(0, 0, 0, 3)); +document.body.appendChild(editor.container); diff --git a/package.json b/package.json index 2c460954e04..927dae497b9 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "author": "Fabian Jakobs ", "main": "src/ace.js", - "typings": "ace.d.ts", + "typings": "types/ace.d.ts", "repository": { "type": "git", "url": "http://github.com/ajaxorg/ace.git" @@ -21,7 +21,7 @@ "eslint": "^8.20.0", "istanbul": "^0.4.5", "standard-version": "^9.3.2", - "typescript": "^4.7.4" + "typescript": "^5.3.0-dev.20230817" }, "mappings": { "ace": "." @@ -44,7 +44,8 @@ "lint": "eslint \"src/**/*.js\"", "fix": "eslint --fix \"src/**/*.js\"", "changelog": "standard-version", - "prepack": "node tool/esm_resolver_generator.js && node Makefile.dryice.js css --target build-styles && mv build-styles/css styles" + "prepack": "node tool/esm_resolver_generator.js && node Makefile.dryice.js css --target build-styles && mv build-styles/css styles", + "tsc": "rimraf types && tsc --project tsconfig.json" }, "standard-version": { "skip": { diff --git a/src/ace.js b/src/ace.js index 5198e4cf6cb..6e1a0246db9 100644 --- a/src/ace.js +++ b/src/ace.js @@ -3,15 +3,24 @@ * * @class Ace **/ - +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ +/** + * + * @typedef IEditor + * @type {import("./editor").IEditor} + */ "use strict"; "include loader_build"; var dom = require("./lib/dom"); var Range = require("./range").Range; -var Editor = require("./editor").Editor; var EditSession = require("./edit_session").EditSession; +var Editor = require("./editor").Editor; var UndoManager = require("./undomanager").UndoManager; var Renderer = require("./virtual_renderer").VirtualRenderer; @@ -29,9 +38,9 @@ exports.config = require("./config"); /** * Embeds the Ace editor into the DOM, at the element provided by `el`. - * @param {String | Element} el Either the id of an element, or the element itself - * @param {Object } options Options for the editor - * + * @param {String | Element & {env?, value?}} el Either the id of an element, or the element itself + * @param {Object } [options] Options for the editor + * @returns {IEditor} **/ exports.edit = function(el, options) { if (typeof el == "string") { @@ -56,7 +65,9 @@ exports.edit = function(el, options) { } var doc = exports.createEditSession(value); - + /** + * @type {IEditor} + */ var editor = new Editor(new Renderer(el), doc, options); var env = { @@ -74,11 +85,14 @@ exports.edit = function(el, options) { /** * Creates a new [[EditSession]], and returns the associated [[Document]]. - * @param {Document | String} text {:textParam} - * @param {TextMode} mode {:modeParam} + * @param {import('./document').Document | String} text {:textParam} + * @param {import("./edit_session").TextMode} [mode] {:modeParam} * **/ exports.createEditSession = function(text, mode) { + /** + * @type {IEditSession} + */ var doc = new EditSession(text, mode); doc.setUndoManager(new UndoManager()); return doc; diff --git a/src/anchor.js b/src/anchor.js index 06884e56bd6..ff94384ec44 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -1,5 +1,8 @@ "use strict"; - +/** + * @typedef IDocument + * @type {import("./document").Document} + */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -10,15 +13,15 @@ class Anchor { /** * Creates a new `Anchor` and associates it with a document. * - * @param {Document} doc The document to associate with the anchor - * @param {Number} row The starting row position - * @param {Number} column The starting column position + * @param {IDocument} doc The document to associate with the anchor + * @param {Number|Ace.Point} row The starting row position + * @param {Number} [column] The starting column position **/ constructor(doc, row, column) { this.$onChange = this.onChange.bind(this); this.attach(doc); - if (typeof column == "undefined") + if (typeof row != "number") this.setPosition(row.row, row.column); else this.setPosition(row, column); @@ -35,7 +38,7 @@ class Anchor { /** * * Returns the current document. - * @returns {Document} + * @returns {IDocument} **/ getDocument() { return this.document; @@ -73,7 +76,7 @@ class Anchor { * Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped. * @param {Number} row The row index to move the anchor to * @param {Number} column The column index to move the anchor to - * @param {Boolean} noClip Identifies if you want the position to be clipped + * @param {Boolean} [noClip] Identifies if you want the position to be clipped * **/ setPosition(row, column, noClip) { @@ -113,7 +116,7 @@ class Anchor { /** * When called, the `"change"` event listener is appended. - * @param {Document} doc The document to associate with + * @param {IDocument} doc The document to associate with * **/ attach(doc) { diff --git a/src/autocomplete.js b/src/autocomplete.js index 3fbd71dbbfd..6dc38213797 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -26,14 +26,14 @@ var config = require("./config"); */ /** - * @typedef SnippetCompletion * @extends BaseCompletion + * @typedef SnippetCompletion * @property {string} snippet - a text snippet that would be inserted when the completion is selected */ /** - * @typedef ValueCompletion * @extends BaseCompletion + * @typedef ValueCompletion * @property {string} value - The text that would be inserted when selecting this completion. */ diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 5fd15bc7221..2749fd2009e 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -40,7 +40,7 @@ class AcePopup { */ constructor(parentNode) { var el = dom.createElement("div"); - var popup = new $singleLineEditor(el); + var popup = $singleLineEditor(el); if (parentNode) { parentNode.appendChild(el); diff --git a/src/clipboard.js b/src/clipboard.js index 57c6466c1a8..4f83a07b04d 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -1,6 +1,10 @@ "use strict"; var $cancelT; +/** + * + * @type {{cancel: Function, lineMode: boolean|string, pasteCancelled: ((function(): (boolean))|*)}} + */ module.exports = { lineMode: false, pasteCancelled: function() { diff --git a/src/document.js b/src/document.js index 10ddbc5ca0d..b2535c22abc 100644 --- a/src/document.js +++ b/src/document.js @@ -1,5 +1,9 @@ "use strict"; - +/** + * @typedef IDocument + * @type {Document & Ace.EventEmitter} + * @export + */ var oop = require("./lib/oop"); var applyDelta = require("./apply_delta").applyDelta; var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -17,6 +21,9 @@ class Document { * @param {String | String[]} textOrLines text The starting text **/ constructor(textOrLines) { + /** + * @type {string[]} + */ this.$lines = [""]; // There has to be one line at least in the document. If you pass an empty @@ -43,6 +50,7 @@ class Document { /** * Returns all the lines in the document as a single string, joined by the new line character. + * @returns {String} **/ getValue() { return this.getAllLines().join(this.getNewLineCharacter()); @@ -52,12 +60,16 @@ class Document { * Creates a new `Anchor` to define a floating point in the document. * @param {Number} row The row number to use * @param {Number} column The column number to use - * + * @returns {Anchor} **/ createAnchor(row, column) { return new Anchor(this, row, column); } + /** + * @param {string} text + * @this {IDocument} + */ $detectNewLine(text) { var match = text.match(/^.*?(\r\n|\r|\n)/m); this.$autoNewLine = match ? match[1] : "\n"; @@ -84,8 +96,8 @@ class Document { /** * [Sets the new line mode.]{: #Document.setNewLineMode.desc} - * @param {String} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} - * + * @param {Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} + * @this {IDocument} **/ setNewLineMode(newLineMode) { if (this.$newLineMode === newLineMode) @@ -97,7 +109,7 @@ class Document { /** * [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode} - * @returns {String} + * @returns {Ace.NewLineMode} **/ getNewLineMode() { return this.$newLineMode; @@ -106,7 +118,7 @@ class Document { /** * Returns `true` if `text` is a newline character (either `\r\n`, `\r`, or `\n`). * @param {String} text The text to check - * + * @returns {boolean} **/ isNewLine(text) { return (text == "\r\n" || text == "\r" || text == "\n"); @@ -115,7 +127,7 @@ class Document { /** * Returns a verbatim copy of the given line as it is in the document * @param {Number} row The row index to retrieve - * + * @returns {string} **/ getLine(row) { return this.$lines[row] || ""; @@ -125,7 +137,7 @@ class Document { * Returns an array of strings of the rows between `firstRow` and `lastRow`. This function is inclusive of `lastRow`. * @param {Number} firstRow The first row index to retrieve * @param {Number} lastRow The final row index to retrieve - * + * @returns {string[]} **/ getLines(firstRow, lastRow) { return this.$lines.slice(firstRow, lastRow + 1); @@ -133,6 +145,7 @@ class Document { /** * Returns all lines in the document as string array. + * @returns {string[]} **/ getAllLines() { return this.getLines(0, this.getLength()); @@ -140,6 +153,7 @@ class Document { /** * Returns the number of rows in the document. + * @returns {Number} **/ getLength() { return this.$lines.length; @@ -193,9 +207,9 @@ class Document { /** * Inserts a block of `text` at the indicated `position`. - * @param {Position} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` + * @param {Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text to insert - * @returns {Object} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @returns {Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. * **/ insert(position, text) { @@ -213,9 +227,9 @@ class Document { * 1. This does NOT handle newline characters (single-line text only). * 2. This is faster than the `insert` method for single-line text insertions. * - * @param {Object} position The position to insert at; it's an object that looks like `{ row: row, column: column}` + * @param {Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text - * @returns {Object} Returns an object containing the final row and column, like this: + * @returns {Ace.Point} Returns an object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -233,7 +247,13 @@ class Document { return this.clonePos(end); } - + + /** + * + * @param {number} row + * @param {number} column + * @return {Ace.Point} + */ clippedPos(row, column) { var length = this.getLength(); if (row === undefined) { @@ -250,15 +270,29 @@ class Document { column = Math.min(Math.max(column, 0), line.length); return {row: row, column: column}; } - + + /** + * @param {Ace.Point} pos + * @return {Ace.Point} + */ clonePos(pos) { return {row: pos.row, column: pos.column}; } - + + /** + * @param {number} row + * @param {number} column + * @return {Ace.Point} + */ pos(row, column) { return {row: row, column: column}; } - + + /** + * @param {Ace.Point} position + * @return {Ace.Point} + * @private + */ $clipPosition(position) { var length = this.getLength(); if (position.row >= length) { @@ -292,15 +326,6 @@ class Document { * Inserts the elements in `lines` into the document as full lines (does not merge with existing line), starting at the row index given by `row`. This method also triggers the `"change"` event. * @param {Number} row The index of the row to insert at * @param {string[]} lines An array of strings - * @returns {Object} Contains the final row and column, like this: - * ``` - * {row: endRow, column: 0} - * ``` - * If `lines` is empty, this function returns an object containing the current row, and column, like this: - * ``` - * {row: row, column: 0} - * ``` - * **/ insertFullLines(row, lines) { // Clip to document. @@ -326,9 +351,9 @@ class Document { /** * Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event. - * @param {Position} position + * @param {Ace.Position} position * @param {string[]} lines An array of strings - * @returns {Object} Contains the final row and column, like this: + * @returns {Ace.Point} Contains the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -358,8 +383,7 @@ class Document { /** * Removes the `range` from the document. * @param {Range} range A specified Range to remove - * @returns {Object} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. - * + * @returns {Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { var start = this.clippedPos(range.start.row, range.start.column); @@ -378,7 +402,7 @@ class Document { * @param {Number} row The row to remove from * @param {Number} startColumn The column to start removing at * @param {Number} endColumn The column to stop removing at - * @returns {Object} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. + * @returns {Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. * **/ removeInLine(row, startColumn, endColumn) { @@ -399,7 +423,7 @@ class Document { * Removes a range of full lines. This method also triggers the `"change"` event. * @param {Number} firstRow The first row to be removed * @param {Number} lastRow The last row to be removed - * @returns {[String]} Returns all the removed lines. + * @returns {String[]} Returns all the removed lines. * **/ removeFullLines(firstRow, lastRow) { @@ -450,9 +474,9 @@ class Document { /** * Replaces a range in the document with the new `text`. - * @param {Range} range A specified Range to replace + * @param {Range | {start: Ace.Point, end: Ace.Point}} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {Object} Returns an object containing the final row and column, like this: + * @returns {Ace.Point} Returns an object containing the final row and column, like this: * {row: endRow, column: 0} * If the text and range are empty, this function returns an object containing the current `range.start` value. * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value. @@ -483,7 +507,7 @@ class Document { /** * Applies all changes in `deltas` to the document. - * @param {Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @param {Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) **/ applyDeltas(deltas) { for (var i=0; i=0; i--) { @@ -503,8 +527,9 @@ class Document { /** * Applies `delta` to the document. - * @param {Object} delta A delta object (can include "insert" and "remove" actions) + * @param {Ace.Delta} delta A delta object (can include "insert" and "remove" actions) * @param [doNotValidate] + * @this {IDocument} **/ applyDelta(delta, doNotValidate) { var isInsert = delta.action == "insert"; @@ -522,7 +547,11 @@ class Document { this._signal("change", delta); } } - + + /** + * + * @param {Ace.Delta} delta + */ $safeApplyDelta(delta) { var docLength = this.$lines.length; // verify that delta is in the document to prevent applyDelta from corrupting lines array @@ -533,7 +562,12 @@ class Document { this.applyDelta(delta); } } - + + /** + * + * @param {Ace.Delta} delta + * @param {number} MAX + */ $splitAndapplyLargeDelta(delta, MAX) { // Split large insert deltas. This is necessary because: // 1. We need to support splicing delta lines into the document via $lines.splice.apply(...) @@ -568,7 +602,7 @@ class Document { /** * Reverts `delta` from the document. - * @param {Object} delta A delta object (can include "insert" and "remove" actions) + * @param {Ace.Delta} delta A delta object (can include "insert" and "remove" actions) **/ revertDelta(delta) { this.$safeApplyDelta({ @@ -593,7 +627,7 @@ class Document { * * @param {Number} index An index to convert * @param {Number} startRow=0 The row from which to start the conversion - * @returns {Object} A `{row, column}` object of the `index` position + * @returns {Ace.Point} A `{row, column}` object of the `index` position */ indexToPosition(index, startRow) { var lines = this.$lines || this.getAllLines(); @@ -618,7 +652,7 @@ class Document { * * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second. * - * @param {Object} pos The `{row, column}` to convert + * @param {Ace.Point} pos The `{row, column}` to convert * @param {Number} startRow=0 The row from which to start the conversion * @returns {Number} The index position in the document */ @@ -638,7 +672,7 @@ class Document { * * @method $split * @param {String} text The text to work with - * @returns {String} A String array, with each index containing a piece of the original `text` string. + * @returns {String[]} A String array, with each index containing a piece of the original `text` string. * **/ $split(text) { diff --git a/src/edit_session.js b/src/edit_session.js index 43bbcf5692d..654908a4ade 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,8 +1,23 @@ +/// + "use strict"; +/** + * @typedef IEditSession + * @type {EditSession & Ace.OptionsProvider & Ace.Folding & Ace.EventEmitter & Ace.EditSessionProperties & import("./edit_session/bracket_match").BracketMatch} + * @export + */ +/** + * @typedef IDocument + * @type {import("./document").IDocument} + */ var oop = require("./lib/oop"); var lang = require("./lib/lang"); var BidiHandler = require("./bidihandler").BidiHandler; +/** + * + * @type {import("./lib/app_config").AppConfigWithAllOptions} + */ var config = require("./config"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Selection = require("./selection").Selection; @@ -100,11 +115,25 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; * `EditSession` can be attached to only one [[Document `Document`]]. Same `Document` can be attached to several `EditSession`s. **/ +/** + * @typedef TextMode + * @type {Ace.SyntaxMode} + */ + +/** + * @type {IEditSession} + */ class EditSession { + /** + * @type {Document} + */ + doc; + /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. - * @param {Document | String} text [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} - * @param {Mode} mode [The initial language mode to use for the document]{: #modeParam} + * @param {IDocument | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} + * @param {Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} + * @this {IEditSession} **/ constructor(text, mode) { this.$breakpoints = []; @@ -123,6 +152,7 @@ class EditSession { // Set default background tokenizer with Text mode until editor session mode is set this.bgTokenizer = new BackgroundTokenizer((new TextMode()).getTokenizer(), this); + var _self = this; this.bgTokenizer.on("update", function(e) { _self._signal("tokenizerUpdate", e); @@ -148,13 +178,13 @@ class EditSession { /** * Sets the `EditSession` to point to a new `Document`. If a `BackgroundTokenizer` exists, it also points to `doc`. * - * @param {Document} doc The new `Document` to use + * @param {IDocument} doc The new `Document` to use * **/ setDocument(doc) { if (this.doc) this.doc.off("change", this.$onChange); - + this.doc = doc; doc.on("change", this.$onChange, true); @@ -165,7 +195,7 @@ class EditSession { /** * Returns the `Document` associated with this session. - * @return {Document} + * @return {IDocument} **/ getDocument() { return this.doc; @@ -222,6 +252,11 @@ class EditSession { this.$resetRowCache(fold.start.row); } + /** + * + * @param {Ace.Delta} delta + * @this {IEditSession} + */ onChange(delta) { this.$modified = true; this.$bidiHandler.onChange(delta); @@ -273,6 +308,7 @@ class EditSession { /** * Returns selection object. + * @returns {Selection} **/ getSelection() { return this.selection; @@ -281,7 +317,7 @@ class EditSession { /** * {:BackgroundTokenizer.getState} * @param {Number} row The row to start at - * + * @returns {string} * @related BackgroundTokenizer.getState **/ getState(row) { @@ -291,7 +327,7 @@ class EditSession { /** * Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows. * @param {Number} row The row to start at - * @returns {Token[]} + * @returns {Ace.Token[]} **/ getTokens(row) { return this.bgTokenizer.getTokens(row); @@ -301,7 +337,7 @@ class EditSession { * Returns an object indicating the token at the current row. The object has two properties: `index` and `start`. * @param {Number} row The row number to retrieve from * @param {Number} column The column number to retrieve from - * @returns {Token} + * @returns {Ace.Token} * **/ getTokenAt(row, column) { @@ -360,6 +396,7 @@ class EditSession { /** * Returns the current undo manager. + * @returns {UndoManager} **/ getUndoManager() { return this.$undoManager || this.$defaultUndoManager; @@ -367,6 +404,7 @@ class EditSession { /** * Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by [[EditSession.getTabSize `getTabSize()`]]); otherwise it's simply `'\t'`. + * @returns {String} **/ getTabString() { if (this.getUseSoftTabs()) { @@ -379,6 +417,7 @@ class EditSession { /** * Pass `true` to enable the use of soft tabs. Soft tabs means you're using spaces instead of the tab character (`'\t'`). * @param {Boolean} val Value indicating whether or not to use soft tabs + * @this {IEditSession} **/ setUseSoftTabs(val) { this.setOption("useSoftTabs", val); @@ -387,6 +426,7 @@ class EditSession { /** * Returns `true` if soft tabs are being used, `false` otherwise. * @returns {Boolean} + * @this {IEditSession} **/ getUseSoftTabs() { // todo might need more general way for changing settings from mode, but this is ok for now @@ -395,12 +435,14 @@ class EditSession { /** * Set the number of spaces that define a soft tab; for example, passing in `4` transforms the soft tabs to be equivalent to four spaces. This function also emits the `changeTabSize` event. * @param {Number} tabSize The new tab size + * @this {IEditSession} **/ setTabSize(tabSize) { this.setOption("tabSize", tabSize); } /** * Returns the current tab size. + * @this {IEditSession} **/ getTabSize() { return this.$tabSize; @@ -408,8 +450,8 @@ class EditSession { /** * Returns `true` if the character at the position is a soft tab. - * @param {Object} position The position to check - * + * @param {Ace.Point} position The position to check + * @this {IEditSession} **/ isTabStop(position) { return this.$useSoftTabs && (position.column % this.$tabSize === 0); @@ -418,6 +460,7 @@ class EditSession { /** * Set whether keyboard navigation of soft tabs moves the cursor within the soft tab, rather than over * @param {Boolean} navigateWithinSoftTabs Value indicating whether or not to navigate within soft tabs + * @this {IEditSession} **/ setNavigateWithinSoftTabs(navigateWithinSoftTabs) { this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs); @@ -437,7 +480,7 @@ class EditSession { * * @param {Boolean} overwrite Defines whether or not to set overwrites * - * + * @this {IEditSession} **/ setOverwrite(overwrite) { this.setOption("overwrite", overwrite); @@ -461,7 +504,7 @@ class EditSession { * Adds `className` to the `row`, to be used for CSS stylings and whatnot. * @param {Number} row The row number * @param {String} className The class to add - * + * @this {IEditSession} **/ addGutterDecoration(row, className) { if (!this.$decorations[row]) @@ -474,7 +517,7 @@ class EditSession { * Removes `className` from the `row`. * @param {Number} row The row number * @param {String} className The class to add - * + * @this {IEditSession} **/ removeGutterDecoration(row, className) { this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, ""); @@ -483,7 +526,7 @@ class EditSession { /** * Returns an array of strings, indicating the breakpoint class (if any) applied to each row. - * @returns {[String]} + * @returns {String[]} **/ getBreakpoints() { return this.$breakpoints; @@ -491,8 +534,8 @@ class EditSession { /** * Sets a breakpoint on every row number given by `rows`. This function also emites the `'changeBreakpoint'` event. - * @param {Array} rows An array of row indices - * + * @param {number[]} rows An array of row indices + * @this {IEditSession} **/ setBreakpoints(rows) { this.$breakpoints = []; @@ -504,6 +547,7 @@ class EditSession { /** * Removes all breakpoints on the rows. This function also emits the `'changeBreakpoint'` event. + * @this {IEditSession} **/ clearBreakpoints() { this.$breakpoints = []; @@ -514,7 +558,7 @@ class EditSession { * Sets a breakpoint on the row number given by `row`. This function also emits the `'changeBreakpoint'` event. * @param {Number} row A row index * @param {String} className Class of the breakpoint - * + * @this {IEditSession} **/ setBreakpoint(row, className) { if (className === undefined) @@ -529,7 +573,7 @@ class EditSession { /** * Removes a breakpoint on the row number given by `row`. This function also emits the `'changeBreakpoint'` event. * @param {Number} row A row index - * + * @this {IEditSession} **/ clearBreakpoint(row) { delete this.$breakpoints[row]; @@ -540,10 +584,11 @@ class EditSession { * Adds a new marker to the given `Range`. If `inFront` is `true`, a front marker is defined, and the `'changeFrontMarker'` event fires; otherwise, the `'changeBackMarker'` event fires. * @param {Range} range Define the range of the marker * @param {String} clazz Set the CSS class for the marker - * @param {Function | String} type Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. - * @param {Boolean} inFront Set to `true` to establish a front marker + * @param {Ace.MarkerRenderer | "fullLine" | "screenLine" | "text"} type Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. + * @param {Boolean} [inFront] Set to `true` to establish a front marker * * @return {Number} The new marker id + * @this {IEditSession} **/ addMarker(range, clazz, type, inFront) { var id = this.$markerId++; @@ -570,10 +615,11 @@ class EditSession { /** * Adds a dynamic marker to the session. - * @param {Object} marker object with update method - * @param {Boolean} inFront Set to `true` to establish a front marker + * @param {Ace.MarkerLike} marker object with update method + * @param {Boolean} [inFront] Set to `true` to establish a front marker * - * @return {Object} The added marker + * @return {Ace.MarkerLike} The added marker + * @this {IEditSession} **/ addDynamicMarker(marker, inFront) { if (!marker.update) @@ -596,7 +642,7 @@ class EditSession { /** * Removes the marker with the specified ID. If this marker was in front, the `'changeFrontMarker'` event is emitted. If the marker was in the back, the `'changeBackMarker'` event is emitted. * @param {Number} markerId A number representing a marker - * + * @this {IEditSession} **/ removeMarker(markerId) { var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId]; @@ -610,14 +656,18 @@ class EditSession { /** * Returns an object containing all of the markers, either front or back. - * @param {Boolean} inFront If `true`, indicates you only want front markers; `false` indicates only back markers + * @param {Boolean} [inFront] If `true`, indicates you only want front markers; `false` indicates only back markers * - * @returns {Object} + * @returns {{[id: number]: Ace.MarkerLike}} **/ getMarkers(inFront) { return inFront ? this.$frontMarkers : this.$backMarkers; } + /** + * + * @param {RegExp} re + */ highlight(re) { if (!this.$searchHighlight) { var highlight = new SearchHighlight(null, "ace_selected-word", "text"); @@ -626,7 +676,14 @@ class EditSession { this.$searchHighlight.setRegexp(re); } - // experimental + /** + * experimental + * @param {number} startRow + * @param {number} endRow + * @param {string} clazz + * @param {boolean} [inFront] + * @return {Range} + */ highlightLines(startRow, endRow, clazz, inFront) { if (typeof endRow != "number") { clazz = endRow; @@ -651,8 +708,8 @@ class EditSession { */ /** * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event. - * @param {Annotation[]} annotations A list of annotations - * + * @param {Ace.Annotation[]} annotations A list of annotations + * @this {IEditSession} **/ setAnnotations(annotations) { this.$annotations = annotations; @@ -661,7 +718,7 @@ class EditSession { /** * Returns the annotations for the `EditSession`. - * @returns {Annotation[]} + * @returns {Ace.Annotation[]} **/ getAnnotations() { return this.$annotations || []; @@ -748,7 +805,7 @@ class EditSession { /** * {:Document.setNewLineMode.desc} - * @param {String} newLineMode {:Document.setNewLineMode.param} + * @param {Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} * * * @related Document.setNewLineMode @@ -760,7 +817,7 @@ class EditSession { /** * * Returns the current new line mode. - * @returns {String} + * @returns {Ace.NewLineMode} * @related Document.getNewLineMode **/ getNewLineMode() { @@ -770,17 +827,19 @@ class EditSession { /** * Identifies if you want to use a worker for the `EditSession`. * @param {Boolean} useWorker Set to `true` to use a worker - * + * @this {IEditSession} **/ setUseWorker(useWorker) { this.setOption("useWorker", useWorker); } /** * Returns `true` if workers are being used. + * @this {IEditSession} **/ getUseWorker() { return this.$useWorker; } /** * Reloads all the tokens on the current session. This function calls [[BackgroundTokenizer.start `BackgroundTokenizer.start ()`]] to all the rows; it also emits the `'tokenizerUpdate'` event. + * @this {IEditSession} **/ onReloadTokenizer(e) { var rows = e.data; @@ -790,8 +849,8 @@ class EditSession { /** * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. - * @param {TextMode} mode Set a new text mode - * @param {Function} cb optional callback + * @param {Ace.SyntaxMode} mode Set a new text mode + * @param {() => void} [cb] optional callback * **/ setMode(mode, cb) { @@ -836,6 +895,12 @@ class EditSession { this.$onChangeMode(this.$modes["ace/mode/text"], true); } + /** + * + * @param mode + * @param [$isPlaceholder] + * @this {IEditSession} + */ $onChangeMode(mode, $isPlaceholder) { if (!$isPlaceholder) this.$modeId = mode.$id; @@ -860,6 +925,9 @@ class EditSession { this.bgTokenizer.setTokenizer(tokenizer); this.bgTokenizer.setDocument(this.getDocument()); + /** + * @type {RegExp} + */ this.tokenRe = mode.tokenRe; this.nonTokenRe = mode.nonTokenRe; @@ -902,7 +970,7 @@ class EditSession { /** * This function sets the scroll top value. It also emits the `'changeScrollTop'` event. * @param {Number} scrollTop The new scroll top value - * + * @this {IEditSession} **/ setScrollTop(scrollTop) { // TODO: should we force integer lineheight instead? scrollTop = Math.round(scrollTop); @@ -923,7 +991,9 @@ class EditSession { /** * [Sets the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.setScrollLeft} - **/ + * @this {IEditSession} + * @param {number} scrollLeft + */ setScrollLeft(scrollLeft) { // scrollLeft = Math.round(scrollLeft); if (this.$scrollLeft === scrollLeft || isNaN(scrollLeft)) @@ -999,7 +1069,6 @@ class EditSession { /** * Returns a verbatim copy of the given line as it is in the document * @param {Number} row The row to retrieve from - * * @returns {String} **/ getLine(row) { @@ -1011,7 +1080,7 @@ class EditSession { * @param {Number} firstRow The first row index to retrieve * @param {Number} lastRow The final row index to retrieve * - * @returns {[String]} + * @returns {String[]} * **/ getLines(firstRow, lastRow) { @@ -1038,11 +1107,9 @@ class EditSession { /** * Inserts a block of `text` and the indicated `position`. - * @param {Object} position The position {row, column} to start inserting at + * @param {Ace.Point} position The position {row, column} to start inserting at * @param {String} text A chunk of text to insert - * @returns {Object} The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. - * - * + * @returns {Ace.Point} The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. **/ insert(position, text) { return this.doc.insert(position, text); @@ -1051,10 +1118,7 @@ class EditSession { /** * Removes the `range` from the document. * @param {Range} range A specified Range to remove - * @returns {Object} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. - * - * @related Document.remove - * + * @returns {Ace.Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { return this.doc.remove(range); @@ -1064,7 +1128,7 @@ class EditSession { * Removes a range of full lines. This method also triggers the `'change'` event. * @param {Number} firstRow The first row to be removed * @param {Number} lastRow The last row to be removed - * @returns {[String]} Returns all the removed lines. + * @returns {String[]} Returns all the removed lines. * * @related Document.removeFullLines * @@ -1075,8 +1139,9 @@ class EditSession { /** * Reverts previous changes to your document. - * @param {Delta[]} deltas An array of previous changes - * @param {Boolean} dontSelect [If `true`, doesn't select the range of where the change occured]{: #dontSelect} + * @param {Ace.Delta[]} deltas An array of previous changes + * @param {Boolean} [dontSelect] [If `true`, doesn't select the range of where the change occured]{: #dontSelect} + * @this {IEditSession} **/ undoChanges(deltas, dontSelect) { if (!deltas.length) @@ -1102,8 +1167,8 @@ class EditSession { /** * Re-implements a previously undone change to your document. - * @param {Delta[]} deltas An array of previous changes - * @param {Boolean} dontSelect {:dontSelect} + * @param {Ace.Delta[]} deltas An array of previous changes + * @param {Boolean} [dontSelect] {:dontSelect} **/ redoChanges(deltas, dontSelect) { if (!deltas.length) @@ -1135,6 +1200,12 @@ class EditSession { this.$undoSelect = enable; } + /** + * + * @param {Ace.Delta[]} deltas + * @param {boolean} [isUndo] + * @return {Range} + */ $getUndoSelection(deltas, isUndo) { function isInsert(delta) { return isUndo ? delta.action !== "insert" : delta.action === "insert"; @@ -1178,7 +1249,7 @@ class EditSession { * * @param {Range} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {Object} An object containing the final row and column, like this: + * @returns {Ace.Point} An object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -1197,9 +1268,10 @@ class EditSession { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} fromRange The range of text you want moved within the document - * @param {Object} toPosition The location (row and column) where you want to move the text to - * @param {boolean} copy + * @param {Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {boolean} [copy] * @returns {Range} The new range where the text was moved to. + * @this {IEditSession} **/ moveText(fromRange, toPosition, copy) { var text = this.getTextRange(fromRange); @@ -1286,6 +1358,14 @@ class EditSession { } } + /** + * + * @param {number} firstRow + * @param {number} lastRow + * @param [dir] + * @returns {number} + * @this {IEditSession} + */ $moveLines(firstRow, lastRow, dir) { firstRow = this.getRowFoldStart(firstRow); lastRow = this.getRowFoldEnd(lastRow); @@ -1349,16 +1429,29 @@ class EditSession { return this.$moveLines(firstRow, lastRow, 0); } - + /** + * @param {number} row + * @returns {number} + */ $clipRowToDocument(row) { return Math.max(0, Math.min(row, this.doc.getLength()-1)); } + /** + * @param {number} row + * @param {number} column + * @returns {number} + */ $clipColumnToRow(row, column) { if (column < 0) return 0; return Math.min(this.doc.getLine(row).length, column); } - + + /** + * @param {number} row + * @param {number} column + * @returns {Ace.Point} + */ $clipPositionToDocument(row, column) { column = Math.max(0, column); @@ -1381,6 +1474,11 @@ class EditSession { }; } + /** + * + * @param {Range} range + * @returns {Range} + */ $clipRangeToDocument(range) { if (range.start.row < 0) { range.start.row = 0; @@ -1408,7 +1506,7 @@ class EditSession { /** * Sets whether or not line wrapping is enabled. If `useWrapMode` is different than the current value, the `'changeWrapMode'` event is emitted. * @param {Boolean} useWrapMode Enable (or disable) wrap mode - * + * @this {IEditSession} **/ setUseWrapMode(useWrapMode) { if (useWrapMode != this.$useWrapMode) { @@ -1443,7 +1541,7 @@ class EditSession { * Sets the boundaries of wrap. Either value can be `null` to have an unconstrained wrap, or, they can be the same number to pin the limit. If the wrap limits for `min` or `max` are different, this method also emits the `'changeWrapMode'` event. * @param {Number} min The minimum wrap value (the left side wrap) * @param {Number} max The maximum wrap value (the right side wrap) - * + * @this {IEditSession} **/ setWrapLimitRange(min, max) { if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) { @@ -1460,8 +1558,9 @@ class EditSession { /** * This should generally only be called by the renderer when a resize is detected. * @param {Number} desiredLimit The new wrap limit + * @param [$printMargin] * @returns {Boolean} - * + * @this {IEditSession} * @private **/ adjustWrapLimit(desiredLimit, $printMargin) { @@ -1482,6 +1581,13 @@ class EditSession { return false; } + /** + * + * @param {number} wrapLimit + * @param {number} [min] + * @param {number} [max] + * @returns {number} + */ $constrainWrapLimit(wrapLimit, min, max) { if (min) wrapLimit = Math.max(min, wrapLimit); @@ -1515,7 +1621,7 @@ class EditSession { * * { min: wrapLimitRange_min, max: wrapLimitRange_max } * - * @returns {Object} + * @returns {{ min: number, max: number }} **/ getWrapLimitRange() { // Avoid unexpected mutation by returning a copy @@ -1525,6 +1631,11 @@ class EditSession { }; } + /** + * + * @param {Ace.Delta} delta + * @this {IEditSession} + */ $updateInternalDataOnChange(delta) { var useWrapMode = this.$useWrapMode; var action = delta.action; @@ -1633,11 +1744,21 @@ class EditSession { return removedFolds; } - $updateRowLengthCache(firstRow, lastRow, b) { + /** + * + * @param {number} firstRow + * @param {number} lastRow + */ + $updateRowLengthCache(firstRow, lastRow) { this.$rowLengthCache[firstRow] = null; this.$rowLengthCache[lastRow] = null; } + /** + * + * @param {number} firstRow + * @param {number} lastRow + */ $updateWrapData(firstRow, lastRow) { var lines = this.doc.getAllLines(); var tabSize = this.getTabSize(); @@ -1681,7 +1802,15 @@ class EditSession { } } } - + + /** + * + * @param {number[]}tokens + * @param {number} wrapLimit + * @param {number} tabSize + * @returns {*[]} + * @this {IEditSession} + */ $computeWrapSplits(tokens, wrapLimit, tabSize) { if (tokens.length == 0) { return []; @@ -1834,7 +1963,8 @@ class EditSession { /** * Given a string, returns an array of the display characters, including tabs and spaces. * @param {String} str The string to check - * @param {Number} offset The value to start at + * @param {Number} [offset] The value to start at + * @returns {number[]} **/ $getDisplayTokens(str, offset) { var arr = []; @@ -1870,9 +2000,9 @@ class EditSession { /** * Calculates the width of the string `str` on the screen while assuming that the string starts at the first column on the screen. * @param {String} str The string to calculate the screen width of - * @param {Number} maxScreenColumn - * @param {Number} screenColumn - * @returns {[Number]} Returns an `int[]` array with two elements:
+ * @param {Number} [maxScreenColumn] + * @param {Number} [screenColumn] + * @returns {Number[]} Returns an `int[]` array with two elements:
* The first position indicates the number of columns for `str` on screen.
* The second value contains the position of the document column that this function read until. **/ @@ -1907,7 +2037,6 @@ class EditSession { /** * Returns number of screenrows in a wrapped line. * @param {Number} row The row number to check - * * @returns {Number} **/ getRowLength(row) { @@ -1920,6 +2049,11 @@ class EditSession { else return this.$wrapData[row].length + h; } + + /** + * @param {Number} row + * @returns {Number} + **/ getRowLineCount(row) { if (!this.$useWrapMode || !this.$wrapData[row]) { return 1; @@ -1928,6 +2062,10 @@ class EditSession { } } + /** + * @param {Number} screenRow + * @returns {Number} + **/ getRowWrapIndent(screenRow) { if (this.$useWrapMode) { var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE); @@ -1953,8 +2091,8 @@ class EditSession { /** * For the given document row and column, this returns the column position of the last screen row. * @param {Number} docRow - * * @param {Number} docColumn + * @returns {number} **/ getDocumentLastRowColumn(docRow, docColumn) { var screenRow = this.documentToScreenRow(docRow, docColumn); @@ -1965,7 +2103,7 @@ class EditSession { * For the given document row and column, this returns the document position of the last row. * @param {Number} docRow * @param {Number} docColumn - * + * @returns {Ace.Point} **/ getDocumentLastRowColumnPosition(docRow, docColumn) { var screenRow = this.documentToScreenRow(docRow, docColumn); @@ -1974,8 +2112,9 @@ class EditSession { /** * For the given row, this returns the split data. - * @returns {String} - **/ + * @param {number} row + * @returns {String | undefined} + */ getRowSplitData(row) { if (!this.$useWrapMode) { return undefined; @@ -1989,17 +2128,26 @@ class EditSession { * @param {Number} screenColumn The screen column to check * * @returns {Number} + * @this {IEditSession} **/ getScreenTabSize(screenColumn) { return this.$tabSize - (screenColumn % this.$tabSize | 0); } - + /** + * @param {number} screenRow + * @param {number} screenColumn + * @returns {number} + */ screenToDocumentRow(screenRow, screenColumn) { return this.screenToDocumentPosition(screenRow, screenColumn).row; } - + /** + * @param {number} screenRow + * @param {number} screenColumn + * @returns {number} + */ screenToDocumentColumn(screenRow, screenColumn) { return this.screenToDocumentPosition(screenRow, screenColumn).column; } @@ -2008,11 +2156,12 @@ class EditSession { * Converts characters coordinates on the screen to characters coordinates within the document. [This takes into account code folding, word wrap, tab size, and any other visual modifications.]{: #conversionConsiderations} * @param {Number} screenRow The screen row to check * @param {Number} screenColumn The screen column to check - * @param {Number} offsetX screen character x-offset [optional] + * @param {Number} [offsetX] screen character x-offset [optional] * - * @returns {Object} The object returned has two properties: `row` and `column`. + * @returns {Ace.Point} The object returned has two properties: `row` and `column`. * * @related EditSession.documentToScreenPosition + * @this {IEditSession} **/ screenToDocumentPosition(screenRow, screenColumn, offsetX) { if (screenRow < 0) @@ -2104,11 +2253,12 @@ class EditSession { /** * Converts document coordinates to screen coordinates. {:conversionConsiderations} - * @param {Number|Position} docRow The document row to check + * @param {Number|Ace.Point} docRow The document row to check * @param {Number|undefined} [docColumn] The document column to check - * @returns {Position} The object returned by this method has two properties: `row` and `column`. + * @returns {Ace.Point} The object returned by this method has two properties: `row` and `column`. * * @related EditSession.screenToDocumentPosition + * @this {IEditSession} **/ documentToScreenPosition(docRow, docColumn) { // Normalize the passed in arguments. @@ -2220,7 +2370,7 @@ class EditSession { * For the given document row and column, returns the screen row. * @param {Number} docRow * @param {Number} docColumn - * + * @returns {number} **/ documentToScreenRow(docRow, docColumn) { return this.documentToScreenPosition(docRow, docColumn).row; @@ -2229,6 +2379,7 @@ class EditSession { /** * Returns the length of the screen. * @returns {Number} + * @this {IEditSession} **/ getScreenLength() { var screenRows = 0; @@ -2335,10 +2486,7 @@ EditSession.prototype.$defaultUndoManager = { addSession: function() {} }; EditSession.prototype.$overwrite = false; -/** - * - * @type {TextMode|null} - */ + EditSession.prototype.$mode = null; EditSession.prototype.$modeId = null; EditSession.prototype.$scrollTop = 0; @@ -2482,6 +2630,10 @@ config.defineOptions(EditSession.prototype, "session", { }, useSoftTabs: {initialValue: true}, tabSize: { + /** + * @this {IEditSession} + * @param tabSize + */ set: function(tabSize) { tabSize = parseInt(tabSize); if (tabSize > 0 && this.$tabSize !== tabSize) { @@ -2516,3 +2668,4 @@ config.defineOptions(EditSession.prototype, "session", { }); exports.EditSession = EditSession; + diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index 17d39b4390c..d2ec1ce19d2 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -68,7 +68,8 @@ function BracketMatch() { * * two Ranges if there is opening and closing brackets; * * one Range if there is only one bracket * - * @param {Point} pos + * @memberOf EditSession + * @param {Ace.Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} */ diff --git a/src/editor.js b/src/editor.js index fbed78eb579..227375d6631 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,4 +1,18 @@ "use strict"; +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ +/** + * @typedef IVirtualRenderer + * @type {import("./virtual_renderer").IVirtualRenderer} + */ +/** + * @typedef IEditor + * @type {Editor & Ace.EventEmitter & Ace.OptionsProvider & Ace.EditorProperties & Ace.EditorMultiSelectProperties} + * @export + */ var oop = require("./lib/oop"); var dom = require("./lib/dom"); @@ -14,6 +28,9 @@ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var CommandManager = require("./commands/command_manager").CommandManager; var defaultCommands = require("./commands/default_commands").commands; +/** + * @type {import("./lib/app_config").AppConfigWithAllOptions} + */ var config = require("./config"); var TokenIterator = require("./token_iterator").TokenIterator; var LineWidgets = require("./line_widgets").LineWidgets; @@ -23,38 +40,66 @@ var nls = require("./config").nls; var clipboard = require("./clipboard"); var keys = require('./lib/keys'); + /** * The main entry point into the Ace functionality. * * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen. * * Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them. + * @type {IEditor} **/ class Editor { + /** + * @type {IEditSession} + */ + session; + /** * Creates a new `Editor` object. * - * @param {VirtualRenderer} renderer Associated `VirtualRenderer` that draws everything - * @param {EditSession} session The `EditSession` to refer to + * @param {IVirtualRenderer} renderer Associated `VirtualRenderer` that draws everything + * @param {IEditSession} [session] The `EditSession` to refer to + * @param {Object} [options] The default options + * @this {IEditor} **/ constructor(renderer, session, options) { this.$toDestroy = []; + var container = renderer.getContainerElement(); + /** + * @type {HTMLElement & {env?, value?}} + */ this.container = container; + /** + * @type {IVirtualRenderer} + */ this.renderer = renderer; + /** + * @type {string} + */ this.id = "editor" + (++Editor.$uid); - + /** + * @type {CommandManager} + */ this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands); if (typeof document == "object") { this.textInput = new TextInput(renderer.getTextAreaContainer(), this); this.renderer.textarea = this.textInput.getElement(); // TODO detect touch event support + /** + * @type {MouseHandler} + */ this.$mouseHandler = new MouseHandler(this); new FoldHandler(this); } - + /** + * @type {KeyBinding} + */ this.keyBinding = new KeyBinding(this); - + /** + * @type {Search} + */ this.$search = new Search().set({ wrap: true }); @@ -81,6 +126,9 @@ class Editor { config._signal("editor", this); } + /** + * @this {IEditor} + */ $initOperationListeners() { this.commands.on("exec", this.startOperation.bind(this), true); this.commands.on("afterExec", this.endOperation.bind(this), true); @@ -125,6 +173,11 @@ class Editor { this.curOp.selectionBefore = this.selection.toJSON(); } + /** + * + * @param e + * @this {IEditor} + */ endOperation(e) { if (this.curOp && this.session) { if (e && e.returnValue === false || !this.session) @@ -170,7 +223,12 @@ class Editor { this.curOp = null; } } - + + /** + * + * @param e + * @this {IEditor} + */ $historyTracker(e) { if (!this.$mergeUndoDeltas) return; @@ -209,8 +267,8 @@ class Editor { /** * Sets a new key handler, such as "vim" or "windows". - * @param {String} keyboardHandler The new key handler - * + * @param {String | Ace.KeyboardHandler | null} keyboardHandler The new key handler + * @param {() => void} [cb] **/ setKeyboardHandler(keyboardHandler, cb) { if (keyboardHandler && typeof keyboardHandler === "string" && keyboardHandler != "ace") { @@ -230,9 +288,7 @@ class Editor { /** * Returns the keyboard handler, such as "vim" or "windows". - * - * @returns {String} - * + * @returns {string} **/ getKeyboardHandler() { return this.keyBinding.getKeyboardHandler(); @@ -247,8 +303,8 @@ class Editor { **/ /** * Sets a new editsession to use. This method also emits the `'changeSession'` event. - * @param {EditSession} session The new session to use - * + * @param {IEditSession} [session] The new session to use + * @this {IEditor} **/ setSession(session) { if (this.session == session) @@ -365,7 +421,7 @@ class Editor { /** * Returns the current session being used. - * @returns {EditSession} + * @returns {IEditSession} **/ getSession() { return this.session; @@ -374,7 +430,7 @@ class Editor { /** * Sets the current document to `val`. * @param {String} val The new value to set for the document - * @param {Number} cursorPos Where to set the new value. `undefined` or 0 is selectAll, -1 is at the document start, and 1 is at the end + * @param {Number} [cursorPos] Where to set the new value. `undefined` or 0 is selectAll, -1 is at the document start, and 1 is at the end * * @returns {String} The current document value * @related Document.setValue @@ -413,9 +469,7 @@ class Editor { /** * {:VirtualRenderer.onResize} - * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed - * - * + * @param {Boolean} [force] If `true`, recomputes the size, even if the height and width haven't changed * @related VirtualRenderer.onResize **/ resize(force) { @@ -425,7 +479,7 @@ class Editor { /** * {:VirtualRenderer.setTheme} * @param {String} theme The path to a theme - * @param {Function} cb optional callback called when theme is loaded + * @param {() => void} [cb] optional callback called when theme is loaded **/ setTheme(theme, cb) { this.renderer.setTheme(theme, cb); @@ -444,8 +498,6 @@ class Editor { /** * {:VirtualRenderer.setStyle} * @param {String} style A class name - * - * * @related VirtualRenderer.setStyle **/ setStyle(style) { @@ -455,13 +507,16 @@ class Editor { /** * {:VirtualRenderer.unsetStyle} * @related VirtualRenderer.unsetStyle - **/ + * @param {string} style + */ unsetStyle(style) { this.renderer.unsetStyle(style); } /** * Gets the current font size of the editor text. + * @this {IEditor} + * @return {string} */ getFontSize() { return this.getOption("fontSize") || @@ -471,8 +526,7 @@ class Editor { /** * Set a new font size (in pixels) for the editor text. * @param {String} size A font size ( _e.g._ "12px") - * - * + * @this {IEditor} **/ setFontSize(size) { this.setOption("fontSize", size); @@ -569,8 +623,7 @@ class Editor { /** * Emitted once the editor comes into focus. * @event focus - * - * + * @this {IEditor} **/ onFocus(e) { if (this.$isFocused) @@ -584,8 +637,7 @@ class Editor { /** * Emitted once the editor has been blurred. * @event blur - * - * + * @this {IEditor} **/ onBlur(e) { if (!this.$isFocused) @@ -605,10 +657,8 @@ class Editor { /** * Emitted whenever the document is changed. * @event change - * @param {Object} delta Contains a single property, `data`, which has the delta of changes - * - * - * + * @param {Ace.Delta} delta Contains a single property, `data`, which has the delta of changes + * @this {IEditor} **/ onDocumentChange(delta) { // Rerender and emit "change" event. @@ -638,13 +688,16 @@ class Editor { /** * Emitted when the selection changes. - * + * @this {IEditor} **/ onCursorChange() { this.$cursorChange(); this._signal("changeSelection"); } + /** + * @this {IEditor} + */ $updateHighlightActiveLine() { var session = this.getSession(); @@ -673,6 +726,11 @@ class Editor { } } + /** + * + * @param e + * @this {IEditor} + */ onSelectionChange(e) { var session = this.session; @@ -743,7 +801,10 @@ class Editor { this.renderer.setAnnotations(this.session.getAnnotations()); } - + /** + * @this {IEditor} + * @param e + */ onChangeMode (e) { this.renderer.updateText(); this._emit("changeMode", e); @@ -784,6 +845,7 @@ class Editor { **/ /** * Returns the string of text currently highlighted. + * @this {IEditor} * @returns {String} **/ getCopyText () { @@ -830,14 +892,20 @@ class Editor { /** * Called whenever a text "paste" happens. * @param {String} text The pasted text - * + * @param {any} event * **/ onPaste(text, event) { var e = {text: text, event: event}; this.commands.exec("paste", this, e); } - + + /** + * + * @param e + * @this {IEditor} + * @returns {boolean} + */ $handlePaste(e) { if (typeof e == "string") e = {text: e}; @@ -873,6 +941,12 @@ class Editor { } } + /** + * + * @param {string | string[]}command + * @param [args] + * @return {boolean} + */ execCommand(command, args) { return this.commands.exec(command, this, args); } @@ -880,7 +954,8 @@ class Editor { /** * Inserts `text` into wherever the cursor is pointing. * @param {String} text The new text to add - * + * @param {boolean} [pasted] + * @this {IEditor} **/ insert(text, pasted) { var session = this.session; @@ -913,7 +988,7 @@ class Editor { this.clearSelection(); } else if (this.session.getOverwrite() && text.indexOf("\n") == -1) { - var range = new Range.fromPoints(cursor, cursor); + var range = Range.fromPoints(cursor, cursor); range.end.column += text.length; this.session.remove(range); } @@ -1001,7 +1076,13 @@ class Editor { } } - + /** + * + * @param text + * @param composition + * @this {IEditor} + * @returns {*} + */ onTextInput(text, composition) { if (!composition) return this.keyBinding.onTextInput(text); @@ -1045,8 +1126,6 @@ class Editor { /** * Pass in `true` to enable overwrites in your session, or `false` to disable. If overwrites is enabled, any text you enter will type over any text after it. If the value of `overwrite` changes, this function also emits the `changeOverwrite` event. * @param {Boolean} overwrite Defines whether or not to set overwrites - * - * * @related EditSession.setOverwrite **/ setOverwrite(overwrite) { @@ -1073,6 +1152,7 @@ class Editor { /** * Sets how fast the mouse scrolling should do. * @param {Number} speed A value indicating the new speed (in milliseconds) + * @this {IEditor} **/ setScrollSpeed(speed) { this.setOption("scrollSpeed", speed); @@ -1080,6 +1160,7 @@ class Editor { /** * Returns the value indicating how fast the mouse scroll speed is (in milliseconds). + * @this {IEditor} * @returns {Number} **/ getScrollSpeed() { @@ -1088,6 +1169,7 @@ class Editor { /** * Sets the delay (in milliseconds) of the mouse drag. + * @this {IEditor} * @param {Number} dragDelay A value indicating the new delay **/ setDragDelay(dragDelay) { @@ -1096,6 +1178,7 @@ class Editor { /** * Returns the current mouse drag delay. + * @this {IEditor} * @returns {Number} **/ getDragDelay() { @@ -1110,7 +1193,7 @@ class Editor { /** * Draw selection markers spanning whole line, or only over selected text. Default value is "line" * @param {String} val The new selection style "line"|"text" - * + * @this {IEditor} **/ setSelectionStyle(val) { this.setOption("selectionStyle", val); @@ -1118,6 +1201,7 @@ class Editor { /** * Returns the current selection style. + * @this {IEditor} * @returns {String} **/ getSelectionStyle() { @@ -1127,21 +1211,32 @@ class Editor { /** * Determines whether or not the current line should be highlighted. * @param {Boolean} shouldHighlight Set to `true` to highlight the current line + * @this {IEditor} **/ setHighlightActiveLine(shouldHighlight) { this.setOption("highlightActiveLine", shouldHighlight); } /** * Returns `true` if current lines are always highlighted. + * @this {IEditor} * @return {Boolean} **/ getHighlightActiveLine() { return this.getOption("highlightActiveLine"); } + + /** + * @this {IEditor} + * @param {boolean} shouldHighlight + */ setHighlightGutterLine(shouldHighlight) { this.setOption("highlightGutterLine", shouldHighlight); } + /** + * @this {IEditor} + * @returns {Boolean} + */ getHighlightGutterLine() { return this.getOption("highlightGutterLine"); } @@ -1149,7 +1244,7 @@ class Editor { /** * Determines if the currently selected word should be highlighted. * @param {Boolean} shouldHighlight Set to `true` to highlight the currently selected word - * + * @this {IEditor} **/ setHighlightSelectedWord(shouldHighlight) { this.setOption("highlightSelectedWord", shouldHighlight); @@ -1157,16 +1252,23 @@ class Editor { /** * Returns `true` if currently highlighted words are to be highlighted. + * @this {IEditor} * @returns {Boolean} **/ getHighlightSelectedWord() { return this.$highlightSelectedWord; } + /** + * @param {boolean} shouldAnimate + */ setAnimatedScroll(shouldAnimate){ this.renderer.setAnimatedScroll(shouldAnimate); } + /** + * @return {boolean} + */ getAnimatedScroll(){ return this.renderer.getAnimatedScroll(); } @@ -1174,7 +1276,6 @@ class Editor { /** * If `showInvisibles` is set to `true`, invisible characters—like spaces or new lines—are show in the editor. * @param {Boolean} showInvisibles Specifies whether or not to show invisible characters - * **/ setShowInvisibles(showInvisibles) { this.renderer.setShowInvisibles(showInvisibles); @@ -1188,18 +1289,30 @@ class Editor { return this.renderer.getShowInvisibles(); } + /** + * @param {boolean} display + */ setDisplayIndentGuides(display) { this.renderer.setDisplayIndentGuides(display); } + /** + * @return {boolean} + */ getDisplayIndentGuides() { return this.renderer.getDisplayIndentGuides(); } + /** + * @param {boolean} highlight + */ setHighlightIndentGuides(highlight) { this.renderer.setHighlightIndentGuides(highlight); } + /** + * @return {boolean} + */ getHighlightIndentGuides() { return this.renderer.getHighlightIndentGuides(); } @@ -1241,7 +1354,7 @@ class Editor { /** * If `readOnly` is true, then the editor is set to read-only mode, and none of the content can change. * @param {Boolean} readOnly Specifies whether the editor can be modified or not - * + * @this {IEditor} **/ setReadOnly(readOnly) { this.setOption("readOnly", readOnly); @@ -1249,6 +1362,7 @@ class Editor { /** * Returns `true` if the editor is set to read-only mode. + * @this {IEditor} * @returns {Boolean} **/ getReadOnly() { @@ -1258,7 +1372,7 @@ class Editor { /** * Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef} * @param {Boolean} enabled Enables or disables behaviors - * + * @this {IEditor} **/ setBehavioursEnabled(enabled) { this.setOption("behavioursEnabled", enabled); @@ -1266,7 +1380,7 @@ class Editor { /** * Returns `true` if the behaviors are currently enabled. {:BehaviorsDef} - * + * @this {IEditor} * @returns {Boolean} **/ getBehavioursEnabled() { @@ -1277,7 +1391,7 @@ class Editor { * Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets * when such a character is typed in. * @param {Boolean} enabled Enables or disables wrapping behaviors - * + * @this {IEditor} **/ setWrapBehavioursEnabled(enabled) { this.setOption("wrapBehavioursEnabled", enabled); @@ -1285,6 +1399,8 @@ class Editor { /** * Returns `true` if the wrapping behaviors are currently enabled. + * @this {IEditor} + * @returns {boolean} **/ getWrapBehavioursEnabled() { return this.getOption("wrapBehavioursEnabled"); @@ -1293,6 +1409,7 @@ class Editor { /** * Indicates whether the fold widgets should be shown or not. * @param {Boolean} show Specifies whether the fold widgets are shown + * @this {IEditor} **/ setShowFoldWidgets(show) { this.setOption("showFoldWidgets", show); @@ -1300,23 +1417,32 @@ class Editor { } /** * Returns `true` if the fold widgets are shown. + * @this {IEditor} * @return {Boolean} **/ getShowFoldWidgets() { return this.getOption("showFoldWidgets"); } + /** + * @this {IEditor} + * @param {boolean} fade + */ setFadeFoldWidgets(fade) { this.setOption("fadeFoldWidgets", fade); } + /** + * @this {IEditor} + * @returns {boolean} + */ getFadeFoldWidgets() { return this.getOption("fadeFoldWidgets"); } /** * Removes the current selection or one character. - * @param {String} dir The direction of the deletion to occur, either "left" or "right" + * @param {'left' | 'right'} [dir] The direction of the deletion to occur, either "left" or "right" * **/ remove(dir) { @@ -1421,7 +1547,7 @@ class Editor { * inline in the editor such as, for example, code completions. * * @param {String} text Text to be inserted as "ghost" text - * @param {object} position Position to insert text to + * @param {Ace.Point} position Position to insert text to */ setGhostText(text, position) { if (!this.session.widgetManager) { @@ -1600,7 +1726,7 @@ class Editor { /** * Works like [[EditSession.getTokenAt]], except it returns a number. - * @returns {Number} + * @returns {any} **/ getNumberAt(row, column) { var _numberRx = /[\-]?[0-9]+(?:\.[0-9]+)?/g; @@ -1776,7 +1902,7 @@ class Editor { doc.duplicateLines(row, row); } else { var point = reverse ? range.start : range.end; - var endPoint = doc.insert(point, doc.getTextRange(range), false); + var endPoint = doc.insert(point, doc.getTextRange(range)); range.start = point; range.end = endPoint; @@ -1787,7 +1913,6 @@ class Editor { /** * Shifts all the selected lines down one row. * - * @returns {Number} On success, it returns -1. * @related EditSession.moveLinesUp **/ moveLinesDown() { @@ -1796,7 +1921,6 @@ class Editor { /** * Shifts all the selected lines up one row. - * @returns {Number} On success, it returns -1. * @related EditSession.moveLinesDown **/ moveLinesUp() { @@ -1809,8 +1933,9 @@ class Editor { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} range The range of text you want moved within the document - * @param {Object} toPosition The location (row and column) where you want to move the text to - * + * @param {Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {boolean} [copy] + * * @returns {Range} The new range where the text was moved to. * @related EditSession.moveText **/ @@ -1820,7 +1945,6 @@ class Editor { /** * Copies all the selected lines up one row. - * @returns {Number} On success, returns 0. * **/ copyLinesUp() { @@ -1829,7 +1953,6 @@ class Editor { /** * Copies all the selected lines down one row. - * @returns {Number} On success, returns the number of new rows added; in other words, `lastRow - firstRow + 1`. * @related EditSession.duplicateLines * **/ @@ -2039,7 +2162,8 @@ class Editor { /** * Moves the editor to the specified row. * @related VirtualRenderer.scrollToRow - **/ + * @param {number} row + */ scrollToRow(row) { this.renderer.scrollToRow(row); } @@ -2049,8 +2173,7 @@ class Editor { * @param {Number} line The line to scroll to * @param {Boolean} center If `true` * @param {Boolean} animate If `true` animates scrolling - * @param {Function} callback Function to be called when the animation has finished - * + * @param {() => void} [callback] Function to be called when the animation has finished * * @related VirtualRenderer.scrollToLine **/ @@ -2072,7 +2195,7 @@ class Editor { /** * Gets the current position of the cursor. - * @returns {Object} An object that looks something like this: + * @returns {Ace.Point} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -2086,7 +2209,7 @@ class Editor { /** * Returns the screen position of the cursor. - * @returns {Position} + * @returns {Ace.Point} * @related EditSession.documentToScreenPosition **/ getCursorPositionScreen() { @@ -2130,7 +2253,7 @@ class Editor { /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. - * @param {Position} pos An object with two properties, row and column + * @param {Ace.Point} pos An object with two properties, row and column * @related Selection.moveCursorToPosition **/ moveCursorToPosition(pos) { @@ -2139,8 +2262,9 @@ class Editor { /** * Moves the cursor's row and column to the next matching bracket or HTML tag. - * - **/ + * @param {boolean} select + * @param {boolean} expand + */ jumpToMatching(select, expand) { var cursor = this.getCursorPosition(); var iterator = new TokenIterator(this.session, cursor.row, cursor.column); @@ -2291,7 +2415,7 @@ class Editor { * @param {Number} lineNumber The line number to go to * @param {Number} column A column number to go to * @param {Boolean} animate If `true` animates scolling - * + * @this {IEditor} **/ gotoLine(lineNumber, column, animate) { this.selection.clearSelection(); @@ -2310,7 +2434,6 @@ class Editor { * @param {Number} row The new row number * @param {Number} column The new column number * - * * @related Editor.moveCursorTo **/ navigateTo(row, column) { @@ -2319,8 +2442,7 @@ class Editor { /** * Moves the cursor up in the document the specified number of times. Note that this does de-select the current selection. - * @param {Number} times The number of times to change navigation - * + * @param {Number} [times] The number of times to change navigation * **/ navigateUp(times) { @@ -2334,8 +2456,7 @@ class Editor { /** * Moves the cursor down in the document the specified number of times. Note that this does de-select the current selection. - * @param {Number} times The number of times to change navigation - * + * @param {Number} [times] The number of times to change navigation * **/ navigateDown(times) { @@ -2349,8 +2470,7 @@ class Editor { /** * Moves the cursor left in the document the specified number of times. Note that this does de-select the current selection. - * @param {Number} times The number of times to change navigation - * + * @param {Number} [times] The number of times to change navigation * **/ navigateLeft(times) { @@ -2369,8 +2489,7 @@ class Editor { /** * Moves the cursor right in the document the specified number of times. Note that this does de-select the current selection. - * @param {Number} times The number of times to change navigation - * + * @param {Number} [times] The number of times to change navigation * **/ navigateRight(times) { @@ -2444,9 +2563,8 @@ class Editor { /** * Replaces the first occurrence of `options.needle` with the value in `replacement`. * @param {String} replacement The text to replace with - * @param {Object} options The [[Search `Search`]] options to use - * - * + * @param {Partial} [options] The [[Search `Search`]] options to use + * @return {number} **/ replace(replacement, options) { if (options) @@ -2470,9 +2588,8 @@ class Editor { /** * Replaces all occurrences of `options.needle` with the value in `replacement`. * @param {String} replacement The text to replace with - * @param {Object} options The [[Search `Search`]] options to use - * - * + * @param {Partial} [options] The [[Search `Search`]] options to use + * @return {number} **/ replaceAll(replacement, options) { if (options) { @@ -2512,7 +2629,7 @@ class Editor { /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions - * @returns {Object} + * @returns {Partial} **/ getLastSearchOptions() { return this.$search.getOptions(); @@ -2521,8 +2638,8 @@ class Editor { /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String|RegExp|Object} needle The text to search for (optional) - * @param {Object} options An object defining various search properties - * @param {Boolean} animate If `true` animate scrolling + * @param {Partial} [options] An object defining various search properties + * @param {Boolean} [animate] If `true` animate scrolling * @related Search.find **/ find(needle, options, animate) { @@ -2566,9 +2683,8 @@ class Editor { /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. - * @param {Object} options search options - * @param {Boolean} animate If `true` animate scrolling - * + * @param {Partial} [options] search options + * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find **/ @@ -2578,9 +2694,8 @@ class Editor { /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. - * @param {Object} options search options - * @param {Boolean} animate If `true` animate scrolling - * + * @param {Partial} [options] search options + * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find **/ @@ -2588,6 +2703,11 @@ class Editor { this.find(options, {skipCurrent: true, backwards: true}, animate); } + /** + * + * @param {Range} range + * @param {boolean} [animate] + */ revealRange(range, animate) { this.session.unfold(range); this.selection.setSelectionRange(range); @@ -2619,6 +2739,7 @@ class Editor { /** * * Cleans up the entire editor. + * @this {IEditor} **/ destroy() { if (this.$toDestroy) { @@ -2641,6 +2762,7 @@ class Editor { /** * Enables automatic scrolling of the cursor into view when editor itself is inside scrollable element * @param {Boolean} enable default true + * @this {IEditor} **/ setAutoScrollEditorIntoView(enable) { if (!enable) @@ -2696,7 +2818,9 @@ class Editor { }; } - + /** + * @this {IEditor} + */ $resetCursorStyle() { var style = this.$cursorStyle || "ace"; var cursorLayer = this.renderer.$cursorLayer; @@ -2835,6 +2959,10 @@ config.defineOptions(Editor.prototype, "editor", { } }, placeholder: { + /** + * @this {IEditor} + * @param message + */ set: function(message) { if (!this.$updatePlaceholder) { this.$updatePlaceholder = function() { diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index 0dfe81dc654..8ee1f919992 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -17,6 +17,12 @@ var isIOS = useragent.isIOS; var valueResetRegex = isIOS ? /\s/ : /\n/; var isMobile = useragent.isMobile; +/** + * @type Class + * @param parentNode + * @param host + * @constructor + */ var TextInput = function(parentNode, host) { var text = dom.createElement("textarea"); text.className = "ace_text-input"; diff --git a/src/lib/app_config.js b/src/lib/app_config.js index 6ad96377fee..874441e4dc3 100644 --- a/src/lib/app_config.js +++ b/src/lib/app_config.js @@ -66,6 +66,11 @@ function reportError(msg, data) { var messages; +/** + * @typedef AppConfigWithAllOptions + * @type {AppConfig & Ace.OptionsProvider & Ace.EventEmitter & Ace.Config} + * @export + */ class AppConfig { constructor() { this.$defaultOptions = {}; diff --git a/src/lib/event_emitter.js b/src/lib/event_emitter.js index 5d1372bc947..f5b65e13f21 100644 --- a/src/lib/event_emitter.js +++ b/src/lib/event_emitter.js @@ -1,5 +1,8 @@ "use strict"; - +/** + * @class EventEmitter + * @type {{_eventRegistry?: {}, _defaultHandlers, _emit?, _dispatchEvent?, _signal?, once?, setDefaultHandler?, removeDefaultHandler?, on?, addEventListener?, off?, removeListener?, removeEventListener?, removeAllListeners?, listeners?, getListeners?, listenerCount?, emit?, dispatchEvent?, signal?, setDefaultMaxListeners?, getMaxListeners?, defaultMaxListeners?, eventNames?, init?}} + */ var EventEmitter = {}; var stopPropagation = function() { this.propagationStopped = true; }; var preventDefault = function() { this.defaultPrevented = true; }; diff --git a/src/lib/oop.js b/src/lib/oop.js index 01289fe4eb4..e0489f46eb2 100644 --- a/src/lib/oop.js +++ b/src/lib/oop.js @@ -12,6 +12,13 @@ exports.inherits = function(ctor, superCtor) { }); }; +/** + * Implements mixin properties into the prototype of an object. + * @template T + * @param {T} obj - The prototype of the target object. + * @param {Object} mixin - The source object. + * @returns {T & Object} The merged prototype. + */ exports.mixin = function(obj, mixin) { for (var key in mixin) { obj[key] = mixin[key]; @@ -19,6 +26,13 @@ exports.mixin = function(obj, mixin) { return obj; }; +/** + * Implements mixin properties into the prototype of an object. + * @template T + * @param {T} proto - The prototype of the target object. + * @param {Object} mixin - The source object. + * @returns {T & Object} The merged prototype. + */ exports.implement = function(proto, mixin) { exports.mixin(proto, mixin); }; diff --git a/src/range.js b/src/range.js index afa70a6c410..6d42f724daa 100644 --- a/src/range.js +++ b/src/range.js @@ -1,13 +1,20 @@ "use strict"; -var comparePoints = function(p1, p2) { - return p1.row - p2.row || p1.column - p2.column; -}; /** * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. * @class Range + * @export **/ +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ class Range { + /** + * @type {Number| undefined} + */ + id; /** * Creates a new `Range` object with the given starting and ending rows and columns. * @param {Number} startRow The starting row @@ -17,11 +24,16 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { + /** + * @type {Ace.Point} + */ this.start = { row: startRow, column: startColumn }; - + /** + * @type {Ace.Point} + */ this.end = { row: endRow, column: endColumn @@ -162,7 +174,7 @@ class Range { /** * Sets the starting row and column for the range. * @param {Number|Ace.Point} row A row to set - * @param {Number} column A column to set + * @param {Number} [column] A column to set * **/ setStart(row, column) { @@ -178,7 +190,7 @@ class Range { /** * Sets the starting row and column for the range. * @param {Number|Ace.Point} row A row to set - * @param {Number} column A column to set + * @param {Number} [column] A column to set * **/ setEnd(row, column) { @@ -412,7 +424,7 @@ class Range { /** * Given the current `Range`, this function converts those starting and ending [[Point]]'s into screen positions, and then returns a new `Range` object. - * @param {EditSession} session The `EditSession` to retrieve coordinates from + * @param {IEditSession} session The `EditSession` to retrieve coordinates from * @returns {Range} **/ toScreenRange(session) { @@ -442,14 +454,13 @@ class Range { /** * Creates and returns a new `Range` based on the `start` [[Point]] and `end` [[Point]] of the given parameters. - * @param {Point} start A starting point to use - * @param {Point} end An ending point to use + * @param {Ace.Point} start A starting point to use + * @param {Ace.Point} end An ending point to use * @returns {Range} **/ Range.fromPoints = function(start, end) { return new Range(start.row, start.column, end.row, end.column); }; -Range.comparePoints = comparePoints; /** * Compares `p1` and `p2` [[Point]]'s, useful for sorting diff --git a/src/search.js b/src/search.js index 5a0bd239b1b..cff236102d3 100644 --- a/src/search.js +++ b/src/search.js @@ -37,7 +37,7 @@ class Search { /** * Sets the search options via the `options` parameter. - * @param {SearchOptions} options An object containing all the new search properties + * @param {Partial} options An object containing all the new search properties * @returns {Search} * @chainable **/ @@ -48,7 +48,7 @@ class Search { /** * [Returns an object containing all the search options.]{: #Search.getOptions} - * @returns {SearchOptions} + * @returns {Partial} **/ getOptions() { return lang.copyObject(this.$options); @@ -66,7 +66,7 @@ class Search { /** * Searches for `options.needle`. If found, this method returns the [[Range `Range`]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session. * @param {EditSession} session The session to search with - * @returns {Range|boolean} + * @returns {Range|false} **/ find(session) { var options = this.$options; diff --git a/src/selection.js b/src/selection.js index 12cb18ca525..31efa17b272 100644 --- a/src/selection.js +++ b/src/selection.js @@ -5,12 +5,7 @@ var lang = require("./lib/lang"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; -/** - * Contains the cursor position and the text selection of an edit session. - * - * The row/columns used in the selection are in document coordinates representing the coordinates as they appear in the document before applying soft wrap and folding. - * @class Selection - **/ + /** @@ -29,6 +24,12 @@ var Range = require("./range").Range; * * @constructor **/ +/** + * Contains the cursor position and the text selection of an edit session. + * + * The row/columns used in the selection are in document coordinates representing the coordinates as they appear in the document before applying soft wrap and folding. + * @type Class + **/ var Selection = function(session) { this.session = session; this.doc = session.getDocument(); diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 3947f44f24f..5ca6d97f6e6 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1,5 +1,13 @@ "use strict"; - +/** + * @typedef IVirtualRenderer + * @type {VirtualRenderer & Ace.EventEmitter & Ace.OptionsProvider} + */ +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ var oop = require("./lib/oop"); var dom = require("./lib/dom"); var lang = require("./lib/lang"); @@ -25,16 +33,20 @@ dom.importCssString(editorCss, "ace_editor.css", false); /** * The class that is responsible for drawing everything you see on the screen! * @related editor.renderer + * @type {IVirtualRenderer} **/ class VirtualRenderer { /** * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`. * @param {Element} container The root element of the editor * @param {String} [theme] The starting theme + * @this {IVirtualRenderer} **/ constructor(container, theme) { var _self = this; - + /** + * @type {HTMLElement} + */ this.container = container || dom.createElement("div"); dom.addCssClass(this.container, "ace_editor"); @@ -48,12 +60,16 @@ class VirtualRenderer { this.$gutter.className = "ace_gutter"; this.container.appendChild(this.$gutter); this.$gutter.setAttribute("aria-hidden", true); - + /** + * @type {HTMLElement} + */ this.scroller = dom.createElement("div"); this.scroller.className = "ace_scroller"; this.container.appendChild(this.scroller); - + /** + * @type {HTMLElement} + */ this.content = dom.createElement("div"); this.content.className = "ace_content"; this.scroller.appendChild(this.content); @@ -193,6 +209,7 @@ class VirtualRenderer { /** * * Associates the renderer with an [[EditSession `EditSession`]]. + * @param {IEditSession} session The session to associate with **/ setSession(session) { if (this.session) @@ -223,7 +240,7 @@ class VirtualRenderer { * Triggers a partial update of the text, from the range given by the two parameters. * @param {Number} firstRow The first row to update * @param {Number} lastRow The last row to update - * + * @param {boolean} [force] **/ updateLines(firstRow, lastRow, force) { if (lastRow === undefined) @@ -278,7 +295,7 @@ class VirtualRenderer { /** * Triggers a full update of all the layers, for all the rows. - * @param {Boolean} force If `true`, forces the changes through + * @param {Boolean} [force] If `true`, forces the changes through **/ updateFull(force) { if (force) @@ -302,10 +319,10 @@ class VirtualRenderer { } /** * [Triggers a resize of the editor.]{: #VirtualRenderer.onResize} - * @param {Boolean} force If `true`, recomputes the size, even if the height and width haven't changed - * @param {Number} gutterWidth The width of the gutter in pixels - * @param {Number} width The width of the editor in pixels - * @param {Number} height The hiehgt of the editor, in pixels + * @param {Boolean} [force] If `true`, recomputes the size, even if the height and width haven't changed + * @param {Number} [gutterWidth] The width of the gutter in pixels + * @param {Number} [width] The width of the editor in pixels + * @param {Number} [height] The hiehgt of the editor, in pixels * **/ onResize(force, gutterWidth, width, height) { @@ -346,7 +363,15 @@ class VirtualRenderer { this.$updateCustomScrollbar(true); } } - + + /** + * @param [force] + * @param [gutterWidth] + * @param [width] + * @param [height] + * @return {number} + * @this {IVirtualRenderer} + */ $updateCachedSize(force, gutterWidth, width, height) { height -= (this.$extraHeight || 0); var changes = 0; @@ -405,6 +430,10 @@ class VirtualRenderer { return changes; } + /** + * + * @param {number} width + */ onGutterResize(width) { var gutterWidth = this.$showGutter ? width : 0; if (gutterWidth != this.gutterWidth) @@ -431,7 +460,7 @@ class VirtualRenderer { /** * Identifies whether you want to have an animated scroll or not. * @param {Boolean} shouldAnimate Set to `true` to show animated scrolls - * + * @this {IVirtualRenderer} **/ setAnimatedScroll(shouldAnimate){ this.setOption("animatedScroll", shouldAnimate); @@ -448,7 +477,7 @@ class VirtualRenderer { /** * Identifies whether you want to show invisible characters or not. * @param {Boolean} showInvisibles Set to `true` to show invisibles - * + * @this {IVirtualRenderer} **/ setShowInvisibles(showInvisibles) { this.setOption("showInvisibles", showInvisibles); @@ -458,22 +487,40 @@ class VirtualRenderer { /** * Returns whether invisible characters are being shown or not. * @returns {Boolean} + * @this {IVirtualRenderer} **/ getShowInvisibles() { return this.getOption("showInvisibles"); } + + /** + * @return {boolean} + * @this {IVirtualRenderer} + */ getDisplayIndentGuides() { return this.getOption("displayIndentGuides"); } + /** + * @param {boolean} display + * @this {IVirtualRenderer} + */ setDisplayIndentGuides(display) { this.setOption("displayIndentGuides", display); } + /** + * @this {IVirtualRenderer} + * @return {boolean} + */ getHighlightIndentGuides() { return this.getOption("highlightIndentGuides"); } + /** + * @this {IVirtualRenderer} + * @param {boolean} highlight + */ setHighlightIndentGuides(highlight) { this.setOption("highlightIndentGuides", highlight); } @@ -481,7 +528,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the print margin or not. * @param {Boolean} showPrintMargin Set to `true` to show the print margin - * + * @this {IVirtualRenderer} **/ setShowPrintMargin(showPrintMargin) { this.setOption("showPrintMargin", showPrintMargin); @@ -490,6 +537,7 @@ class VirtualRenderer { /** * Returns whether the print margin is being shown or not. * @returns {Boolean} + * @this {IVirtualRenderer} **/ getShowPrintMargin() { return this.getOption("showPrintMargin"); @@ -497,7 +545,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the print margin column or not. * @param {Boolean} showPrintMargin Set to `true` to show the print margin column - * + * @this {IVirtualRenderer} **/ setPrintMarginColumn(showPrintMargin) { this.setOption("printMarginColumn", showPrintMargin); @@ -505,7 +553,8 @@ class VirtualRenderer { /** * Returns whether the print margin column is being shown or not. - * @returns {Boolean} + * @returns {number} + * @this {IVirtualRenderer} **/ getPrintMarginColumn() { return this.getOption("printMarginColumn"); @@ -514,6 +563,7 @@ class VirtualRenderer { /** * Returns `true` if the gutter is being shown. * @returns {Boolean} + * @this {IVirtualRenderer} **/ getShowGutter(){ return this.getOption("showGutter"); @@ -522,24 +572,40 @@ class VirtualRenderer { /** * Identifies whether you want to show the gutter or not. * @param {Boolean} show Set to `true` to show the gutter - * + * @this {IVirtualRenderer} **/ setShowGutter(show){ return this.setOption("showGutter", show); } + /** + * @this {IVirtualRenderer} + * @returns {boolean} + */ getFadeFoldWidgets(){ return this.getOption("fadeFoldWidgets"); } + /** + * @this {IVirtualRenderer} + * @param {boolean} show + */ setFadeFoldWidgets(show) { this.setOption("fadeFoldWidgets", show); } + /** + * @this {IVirtualRenderer} * + * @param {boolean} shouldHighlight + */ setHighlightGutterLine(shouldHighlight) { this.setOption("highlightGutterLine", shouldHighlight); } + /** + * @this {IVirtualRenderer} + * @returns {boolean} + */ getHighlightGutterLine() { return this.getOption("highlightGutterLine"); } @@ -568,7 +634,7 @@ class VirtualRenderer { /** * * Returns the root element containing this renderer. - * @returns {Element} + * @returns {HTMLElement} **/ getContainerElement() { return this.container; @@ -577,7 +643,7 @@ class VirtualRenderer { /** * * Returns the element that the mouse events are attached to - * @returns {Element} + * @returns {HTMLElement} **/ getMouseEventTarget() { return this.scroller; @@ -586,7 +652,7 @@ class VirtualRenderer { /** * * Returns the element to which the hidden text area is added. - * @returns {Element} + * @returns {HTMLElement} **/ getTextAreaContainer() { return this.container; @@ -699,7 +765,14 @@ class VirtualRenderer { this.$loop.schedule(this.CHANGE_FULL); this.$updatePrintMargin(); } - + + /** + * + * @param {number} [top] + * @param {number} [bottom] + * @param {number} [left] + * @param {number} [right] + */ setScrollMargin(top, bottom, left, right) { var sm = this.scrollMargin; sm.top = top|0; @@ -712,7 +785,14 @@ class VirtualRenderer { this.session.setScrollTop(-sm.top); this.updateFull(); } - + + /** + * + * @param {number} [top] + * @param {number} [bottom] + * @param {number} [left] + * @param {number} [right] + */ setMargin(top, bottom, left, right) { var sm = this.margin; sm.top = top|0; @@ -736,6 +816,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the horizontal scrollbar or not. * @param {Boolean} alwaysVisible Set to `true` to make the horizontal scroll bar visible + * @this {IVirtualRenderer} **/ setHScrollBarAlwaysVisible(alwaysVisible) { this.setOption("hScrollBarAlwaysVisible", alwaysVisible); @@ -751,6 +832,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the horizontal scrollbar or not. * @param {Boolean} alwaysVisible Set to `true` to make the horizontal scroll bar visible + @this {IVirtualRenderer} **/ setVScrollBarAlwaysVisible(alwaysVisible) { this.setOption("vScrollBarAlwaysVisible", alwaysVisible); @@ -782,6 +864,13 @@ class VirtualRenderer { this.$frozen = false; } + /** + * + * @param {number} changes + * @param {boolean} [force] + * @returns {number} + * @this {IVirtualRenderer} + */ $renderChanges(changes, force) { if (this.$changes) { changes |= this.$changes; @@ -941,7 +1030,9 @@ class VirtualRenderer { this._signal("afterRender", changes); } - + /** + * @this {IVirtualRenderer} + */ $autosize() { var height = this.session.getScreenLength() * this.lineHeight; var maxHeight = this.$maxLines * this.lineHeight; @@ -972,7 +1063,11 @@ class VirtualRenderer { this._signal("autosize"); } } - + + /** + * @this {IVirtualRenderer} + * @returns {number} + */ $computeLayerConfig() { var session = this.session; var size = this.$size; @@ -1079,6 +1174,9 @@ class VirtualRenderer { return changes; } + /** + * @returns {boolean | undefined} + */ $updateLines() { if (!this.$changedLines) return; var firstRow = this.$changedLines.firstRow; @@ -1103,6 +1201,10 @@ class VirtualRenderer { return true; } + /** + * + * @returns {number} + */ $getLongestLine() { var charCount = this.session.getScreenWidth(); if (this.showInvisibles && !this.session.$useWrapMode) @@ -1149,16 +1251,18 @@ class VirtualRenderer { } /** - * + * * Redraw breakpoints. - **/ + * @param {any} [rows] + */ updateBreakpoints(rows) { + this._rows = rows; this.$loop.schedule(this.CHANGE_GUTTER); } /** * Sets annotations for the gutter. - * @param {Annotation[]} annotations An array containing annotations + * @param {Ace.Annotation[]} annotations An array containing annotations * **/ setAnnotations(annotations) { @@ -1190,6 +1294,12 @@ class VirtualRenderer { this.$cursorLayer.showCursor(); } + /** + * + * @param {Ace.Point} anchor + * @param {Ace.Point} lead + * @param {number} [offset] + */ scrollSelectionIntoView(anchor, lead, offset) { // first scroll anchor into view then scroll lead into view this.scrollCursorIntoView(anchor, offset); @@ -1197,9 +1307,12 @@ class VirtualRenderer { } /** - * + * * Scrolls the cursor into the first visibile area of the editor - **/ + * @param {Ace.Point} [cursor] + * @param {number} [offset] + * @param {{ top: any; bottom: any; }} [$viewMargin] + */ scrollCursorIntoView(cursor, offset, $viewMargin) { // the editor is not visible if (this.$size.scrollerHeight === 0) @@ -1295,6 +1408,12 @@ class VirtualRenderer { this.session.setScrollTop(row * this.lineHeight); } + /** + * + * @param {Ace.Point} cursor + * @param {number} [alignment] + * @returns {number} + */ alignCursor(cursor, alignment) { if (typeof cursor == "number") cursor = {row: cursor, column: 0}; @@ -1307,6 +1426,12 @@ class VirtualRenderer { return offset; } + /** + * + * @param {number} fromValue + * @param {number} toValue + * @returns {*[]} + */ $calcSteps(fromValue, toValue){ var i = 0; var l = this.STEPS; @@ -1327,7 +1452,7 @@ class VirtualRenderer { * @param {Number} line A line number * @param {Boolean} center If `true`, centers the editor the to indicated line * @param {Boolean} animate If `true` animates scrolling - * @param {Function} callback Function to be called after the animation has finished + * @param {() => void} [callback] Function to be called after the animation has finished * **/ scrollToLine(line, center, animate, callback) { @@ -1401,8 +1526,6 @@ class VirtualRenderer { /** * Scrolls the editor to the y pixel indicated. * @param {Number} scrollTop The position to scroll to - * - * @returns {Number} **/ scrollToY(scrollTop) { // after calling scrollBar.setScrollTop @@ -1416,8 +1539,6 @@ class VirtualRenderer { /** * Scrolls the editor across the x-axis to the pixel indicated. * @param {Number} scrollLeft The position to scroll to - * - * @returns {Number} **/ scrollToX(scrollLeft) { if (this.scrollLeft !== scrollLeft) @@ -1465,6 +1586,12 @@ class VirtualRenderer { return true; } + /** + * + * @param {number} x + * @param {number} y + * @returns {{row: number, column: number, side: 1|-1, offsetX: number}} + */ pixelToScreenCoordinates(x, y) { var canvasPos; if (this.$hasCssTransforms) { @@ -1484,6 +1611,12 @@ class VirtualRenderer { return {row: row, column: col, side: offset - col > 0 ? 1 : -1, offsetX: offsetX}; } + /** + * + * @param {number} x + * @param {number} y + * @returns {Ace.Point} + */ screenToTextCoordinates(x, y) { var canvasPos; if (this.$hasCssTransforms) { @@ -1509,7 +1642,7 @@ class VirtualRenderer { * @param {Number} row The document row position * @param {Number} column The document column position * - * @returns {Object} + * @returns {{ pageX: number, pageY: number}} **/ textToScreenCoordinates(row, column) { var canvasPos = this.scroller.getBoundingClientRect(); @@ -1545,8 +1678,6 @@ class VirtualRenderer { /** * @param {Object} composition - * - * @private **/ showComposition(composition) { this.$composition = composition; @@ -1597,6 +1728,10 @@ class VirtualRenderer { this.$cursorLayer.element.style.display = ""; } + /** + * @param {string} text + * @param {Ace.Point} position + */ setGhostText(text, position) { var cursor = this.session.selection.cursor; var insertPosition = position || { row: cursor.row, column: cursor.column }; @@ -1636,6 +1771,12 @@ class VirtualRenderer { this.$ghostText = null; } + /** + * @param {string} text + * @param {string} type + * @param {number} row + * @param {number} [column] + */ addToken(text, type, row, column) { var session = this.session; session.bgTokenizer.lines[row] = null; @@ -1669,8 +1810,8 @@ class VirtualRenderer { /** * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} * @param {String} [theme] The path to a theme - * @param {Function} [cb] optional callback - * + * @param {() => void} [cb] optional callback + * @this {IVirtualRenderer} **/ setTheme(theme, cb) { var _self = this; @@ -1696,7 +1837,6 @@ class VirtualRenderer { module.cssClass, _self.container ); - if (_self.theme) dom.removeCssClass(_self.container, _self.theme.cssClass); @@ -1738,7 +1878,7 @@ class VirtualRenderer { /** * [Adds a new class, `style`, to the editor.]{: #VirtualRenderer.setStyle} * @param {String} style A class name - * + * @param {boolean}[include] **/ setStyle(style, include) { dom.setCssClass(this.container, style, include !== false); @@ -1752,14 +1892,16 @@ class VirtualRenderer { unsetStyle(style) { dom.removeCssClass(this.container, style); } - + + /** + * @param {string} style + */ setCursorStyle(style) { dom.setStyle(this.scroller.style, "cursor", style); } /** * @param {String} cursorStyle A css cursor style - * **/ setMouseCursor(cursorStyle) { dom.setStyle(this.scroller.style, "cursor", cursorStyle); @@ -1771,6 +1913,7 @@ class VirtualRenderer { /** * Destroys the text and cursor layers for this renderer. + * @this {IVirtualRenderer} **/ destroy() { this.freeze(); @@ -1781,6 +1924,10 @@ class VirtualRenderer { this.setOption("useResizeObserver", false); } + /** + * + * @param {boolean} [val] + */ $updateCustomScrollbar(val) { var _self = this; this.$horizScroll = this.$vScroll = null; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000000..d92e0aeecd4 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "strict": false, + "noImplicitAny": false, + "skipLibCheck": true, + "module": "commonjs", + "target": "es2019", + "sourceMap": true, + "allowJs": true, + "checkJs": true, + "declaration": true, + "declarationDir": "./types", + "emitDeclarationOnly": true, + "outDir": "./out", + "declarationMap": true, + }, + "exclude": [ + "node_modules", + "src/test", + "src/**/*_test.js", + "./src/mode/**/*", + "./types/**/*", + ], + "include": [ + "./src/**/*", + "./ace.d.ts" + ] +} From 1d09f95fe626b4d694a1f1880c501b6b6fb0c682 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Fri, 25 Aug 2023 21:01:05 +0400 Subject: [PATCH 02/36] continue type casting --- ace.d.ts | 1862 ++++++++++++++++++------------- src/commands/command_manager.js | 32 +- src/edit_session.js | 50 +- src/edit_session/folding.js | 226 +++- src/editor.js | 22 +- src/undomanager.js | 85 +- src/virtual_renderer.js | 50 +- 7 files changed, 1469 insertions(+), 858 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 598afafaf4c..ed68d231ccd 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -2,784 +2,1021 @@ declare namespace Ace { - interface EditorProperties { - $mergeUndoDeltas?: any, - $highlightSelectedWord?: boolean, - $updatePlaceholder?: Function, - $cursorStyle?: string, - $readOnly?: any, - searchBox?: any, - $highlightActiveLine?: any, - $enableAutoIndent?: any, - $copyWithEmptySelection?: any - $selectionStyle?: string, - env?: any; - } - - interface EditSessionProperties { - $highlightLineMarker?: Range - $useSoftTabs?: boolean, - $tabSize?: number, - $useWorker?: boolean, - $wrapAsCode?: boolean, - $indentedSoftWrap?: boolean, - widgetManager?: any, - $bracketHighlight?: any, - $selectionMarker?: number - } - - interface EditorMultiSelectProperties { - inMultiSelectMode?: boolean, - forEachSelection?: Function, - exitMultiSelectMode?: Function - } - - type NewLineMode = 'auto' | 'unix' | 'windows'; - - interface FoldLine { - folds: Fold[]; - range: Range; - start: Point; - end: Point; - - shiftRow(shift: number): void; - addFold(fold: Fold): void; - containsRow(row: number): boolean; - walk(callback: Function, endRow?: number, endColumn?: number): void; - getNextFoldTo(row: number, column: number): null | { fold: Fold, kind: string }; - addRemoveChars(row: number, column: number, len: number): void; - split(row: number, column: number): FoldLine; - merge(foldLineNext: FoldLine): void; - idxToPosition(idx: number): Point; - } - - interface Fold { - range: Range; - start: Point; - end: Point; - foldLine?: FoldLine; - sameRow: boolean; - subFolds: Fold[]; - - setFoldLine(foldLine: FoldLine): void; - clone(): Fold; - addSubFold(fold: Fold): Fold; - restoreRange(range: Range): void; - } - - class Folding { - getFoldAt(row: number, column: number, side: number): Fold; - getFoldsInRange(range: Range): Fold[]; - getFoldsInRangeList(ranges: Range[]): Fold[]; - getAllFolds(): Fold[]; - getFoldStringAt(row: number, - column: number, - trim?: number, - foldLine?: FoldLine): string | null; - getFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; - getNextFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; - getFoldedRowCount(first: number, last: number): number; - addFold(placeholder: string | Fold, range?: Range): Fold; - addFolds(folds: Fold[]): void; - removeFold(fold: Fold): void; - removeFolds(folds: Fold[]): void; - expandFold(fold: Fold): void; - expandFolds(folds: Fold[]): void; - unfold(location: null | number | Point | Range, - expandInner?: boolean): Fold[] | undefined; - isRowFolded(docRow: number, startFoldRow?: FoldLine): boolean; - getRowFoldEnd(docRow: number, startFoldRow?: FoldLine): number; - getRowFoldStart(docRow: number, startFoldRow?: FoldLine): number; - getFoldDisplayLine(foldLine: FoldLine, - endRow: number | null, - endColumn: number | null, - startRow: number | null, - startColumn: number | null): string; - getDisplayLine(row: number, - endColumn: number | null, - startRow: number | null, - startColumn: number | null): string; - toggleFold(tryToUnfold?: boolean): void; - getCommentFoldRange(row: number, - column: number, - dir: number): Range | undefined; - foldAll(startRow?: number, endRow?: number, depth?: number): void; - setFoldStyle(style: string): void; - getParentFoldRangeData(row: number, ignoreCurrent?: boolean): { - range?: Range, - firstRange: Range - }; - toggleFoldWidget(toggleParent?: boolean): void; - updateFoldWidgets(delta: Delta): void; - } - - interface EditSessionOptions { - wrap: "off" | "free" | "printmargin" | boolean | number; - wrapMethod: 'code' | 'text' | 'auto'; - indentedSoftWrap: boolean; - firstLineNumber: number; - useWorker: boolean; - useSoftTabs: boolean; - tabSize: number; - navigateWithinSoftTabs: boolean; - foldStyle: 'markbegin' | 'markbeginend' | 'manual'; - overwrite: boolean; - newLineMode: NewLineMode; - mode: string; - } - - interface VirtualRendererOptions { - animatedScroll: boolean; - showInvisibles: boolean; - showPrintMargin: boolean; - printMarginColumn: number; - printMargin: boolean | number; - showGutter: boolean; - fadeFoldWidgets: boolean; - showFoldWidgets: boolean; - showLineNumbers: boolean; - displayIndentGuides: boolean; - highlightIndentGuides: boolean; - highlightGutterLine: boolean; - hScrollBarAlwaysVisible: boolean; - vScrollBarAlwaysVisible: boolean; - fontSize: number; - fontFamily: string; - maxLines: number; - minLines: number; - scrollPastEnd: boolean; - fixedWidthGutter: boolean; - customScrollbar: boolean; - theme: string; - hasCssTransforms: boolean; - maxPixelHeight: number; - useSvgGutterIcons: boolean; - showFoldedAnnotations: boolean; - } - - interface MouseHandlerOptions { - scrollSpeed: number; - dragDelay: number; - dragEnabled: boolean; - focusTimeout: number; - tooltipFollowsMouse: boolean; - } - - interface EditorOptions extends EditSessionOptions, - MouseHandlerOptions, - VirtualRendererOptions { - selectionStyle: string; - highlightActiveLine: boolean; - highlightSelectedWord: boolean; - readOnly: boolean; - copyWithEmptySelection: boolean; - cursorStyle: 'ace' | 'slim' | 'smooth' | 'wide'; - mergeUndoDeltas: true | false | 'always'; - behavioursEnabled: boolean; - wrapBehavioursEnabled: boolean; - enableAutoIndent: boolean; - enableBasicAutocompletion: boolean | Completer[]; - enableLiveAutocompletion: boolean | Completer[]; - liveAutocompletionDelay: number; - liveAutocompletionThreshold: number; - enableSnippets: boolean; - autoScrollEditorIntoView: boolean; - keyboardHandler: string | null; - placeholder: string; - value: string; - session: EditSession; - relativeLineNumbers: boolean; - enableMultiselect: boolean; - enableKeyboardAccessibility: boolean; - } - - class EventEmitter { - once?(name: string, callback: Function): void; - setDefaultHandler?(name: string, callback: Function): void; - removeDefaultHandler?(name: string, callback: Function): void; - on?(name: string, callback: Function, capturing?: boolean): Function; - addEventListener?(name: string, callback: Function, capturing?: boolean): Function; - off?(name: string, callback: Function): void; - removeListener?(name: string, callback: Function): void; - removeEventListener?(name: string, callback: Function): void; - removeAllListeners?(name?: string): void; - _signal?(eventName: string, e: any): void; - _emit?(eventName: string, e: any): void; - } - - interface SearchOptions { - needle: string | RegExp; - preventScroll: boolean; - backwards: boolean; - start: Range; - skipCurrent: boolean; - range: Range; - preserveCase: boolean; - regExp: boolean; - wholeWord: boolean; - caseSensitive: boolean; - wrap: boolean; - } - - interface Point { - row: number; - column: number; - } - - type Position = Point; - - interface Delta { - action: 'insert' | 'remove'; - start: Point; - end: Point; - lines: string[]; - } - - interface Annotation { - row?: number; - column?: number; - text: string; - type: string; - } - - interface MarkerGroupItem { - range: Range; - className: string; - } - - class MarkerGroup { - constructor(session: EditSession); - setMarkers(markers: MarkerGroupItem[]): void; - getMarkerAtPosition(pos: Position): MarkerGroupItem; - } - - - interface Command { - name?: string; - bindKey?: string | { mac?: string, win?: string }; - readOnly?: boolean; - exec: (editor: Editor, args?: any) => void; - } - - type CommandLike = Command | ((editor: Editor) => void); - - interface KeyboardHandler { - handleKeyboard: Function; - } - - interface MarkerLike { - range?: Range; - type: string; - renderer?: MarkerRenderer; - clazz: string; - inFront: boolean; - id: number; - update?: (html: string[], - // TODO maybe define Marker class - marker: any, - session: EditSession, - config: any) => void; - } - - type MarkerRenderer = (html: string[], - range: Range, - left: number, - top: number, - config: any) => void; - - interface Token { - type: string; - value: string; - index?: number; - start?: number; - } - - interface BaseCompletion { - score?: number; - meta?: string; - caption?: string; - docHTML?: string; - docText?: string; - completerId?: string; - } - - interface SnippetCompletion extends BaseCompletion { - snippet: string; - } - - interface ValueCompletion extends BaseCompletion { - value: string; - } - - type Completion = SnippetCompletion | ValueCompletion - - interface Tokenizer { - removeCapturingGroups(src: string): string; - createSplitterRegexp(src: string, flag?: string): RegExp; - getLineTokens(line: string, startState: string | string[]): Token[]; - } - - interface TokenIterator { - getCurrentToken(): Token; - getCurrentTokenColumn(): number; - getCurrentTokenRow(): number; - getCurrentTokenPosition(): Point; - getCurrentTokenRange(): Range; - stepBackward(): Token; - stepForward(): Token; - } - - type HighlightRule = {defaultToken: string} | {include: string} | {todo: string} | { - token: string | string[] | ((value: string) => string); - regex: string | RegExp; - next?: string; - push?: string; - comment?: string; - caseInsensitive?: boolean; - } - - type HighlightRulesMap = Record; - - type KeywordMapper = (keyword: string) => string; - - interface HighlightRules { - addRules(rules: HighlightRulesMap, prefix?: string): void; - getRules(): HighlightRulesMap; - embedRules(rules: (new () => HighlightRules) | HighlightRulesMap, prefix: string, escapeRules?: boolean, append?: boolean): void; - getEmbeds(): string[]; - normalizeRules(): void; - createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; - } - - interface FoldMode { - foldingStartMarker: RegExp; - foldingStopMarker?: RegExp; - getFoldWidget(session: EditSession, foldStyle: string, row: number): string; - getFoldWidgetRange(session: EditSession, foldStyle: string, row: number, forceMultiline?: boolean): Range | undefined; - indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; - openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; - closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; - } - - type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => {text: string, selection: number[]} | Range | undefined; - type BehaviorMap = Record>; - - interface Behaviour { - add(name: string, action: string, callback: BehaviorAction): void; - addBehaviours(behaviours: BehaviorMap): void; - remove(name: string): void; - inherit(mode: SyntaxMode | (new () => SyntaxMode), filter: string[]): void; - getBehaviours(filter: string[]): BehaviorMap; - } - - interface Outdent { - checkOutdent(line: string, input: string): boolean; - autoOutdent(doc: Document, row: number): number | undefined; - } - - interface SyntaxMode { - HighlightRules: HighlightRules; - foldingRules?: FoldMode; - $behaviour?: Behaviour; - $defaultBehaviour?: Behaviour; - lineCommentStart?: string; - getTokenizer(): Tokenizer; - toggleCommentLines(state: any, - session: EditSession, - startRow: number, - endRow: number): void; - toggleBlockComment(state: any, - session: EditSession, - range: Range, - cursor: Point): void; - getNextLineIndent(state: any, line: string, tab: string): string; - checkOutdent(state: any, line: string, input: string): boolean; - autoOutdent(state: any, doc: Document, row: number): void; - // TODO implement WorkerClient types - createWorker(session: EditSession): any; - createModeDelegates(mapping: { [key: string]: string }): void; - transformAction: BehaviorAction; - getKeywords(append?: boolean): Array; - getCompletions(state: string, - session: EditSession, - pos: Point, - prefix: string): Completion[]; - } - - type AfterLoadCallback = (err: Error | null, module: unknown) => void; - type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; - - interface Config { - get?(key: string): any; - set?(key: string, value: any): void; - all?(): { [key: string]: any }; - moduleUrl?(name: string, component?: string): string; - setModuleUrl?(name: string, subst: string): string; - setLoader?(cb: LoaderFunction): void; - setModuleLoader?(name: string, onLoad: Function): void; - loadModule?(moduleName: string | [string, string], - onLoad?: (module: any) => void): void; - init?(packaged: any): any; - defineOptions?(obj: any, path: string, options: { [key: string]: any }): Config; - resetOptions?(obj: any): void; - setDefaultValue?(path: string, name: string, value: any): void; - setDefaultValues?(path: string, optionHash: { [key: string]: any }): void; - } - - interface OptionsBase { [key: string]: any; } - - class OptionsProvider { - setOptions?(optList: Partial): void; - getOptions?(optionNames?: Array | Partial): Partial; - setOption?(name: K, value: K[T]): void; - getOption?(name: K): T[K]; - } - - interface UndoManager { - addSession(session: EditSession): void; - add(delta: Delta, allowMerge: boolean, session: EditSession): void; - addSelection(selection: string, rev?: number): void; - startNewGroup(): void; - markIgnored(from: number, to?: number): void; - getSelection(rev: number, after?: boolean): { value: string, rev: number }; - getRevision(): number; - getDeltas(from: number, to?: number): Delta[]; - undo(session: EditSession, dontSelect?: boolean): void; - redo(session: EditSession, dontSelect?: boolean): void; - reset(): void; - canUndo(): boolean; - canRedo(): boolean; - bookmark(rev?: number): void; - isAtBookmark(): boolean; - hasUndo(): boolean; - hasRedo(): boolean; - isClean(): boolean; - markClean(rev?: number): void; - } - - interface KeyBinding { - setDefaultHandler(handler: KeyboardHandler): void; - setKeyboardHandler(handler: KeyboardHandler): void; - addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; - removeKeyboardHandler(handler: KeyboardHandler): boolean; - getKeyboardHandler(): KeyboardHandler; - getStatusText(): string; - onCommandKey(e: any, hashId: number, keyCode: number): boolean; - onTextInput(text: string): boolean; - } - - interface CommandMap { - [name: string]: Command; - } - - type execEventHandler = (obj: { - editor: Editor, - command: Command, - args: any[] - }) => void; - - interface CommandManager extends EventEmitter { - byName: CommandMap, - commands: CommandMap, - on(name: 'exec', callback: execEventHandler): Function; - on(name: 'afterExec', callback: execEventHandler): Function; - once(name: string, callback: Function): void; - setDefaultHandler(name: string, callback: Function): void; - removeDefaultHandler(name: string, callback: Function): void; - on(name: string, callback: Function, capturing?: boolean): void; - addEventListener(name: string, callback: Function, capturing?: boolean): void; - off(name: string, callback: Function): void; - removeListener(name: string, callback: Function): void; - removeEventListener(name: string, callback: Function): void; - - exec(command: string, editor: Editor, args: any): boolean; - toggleRecording(editor: Editor): void; - replay(editor: Editor): void; - addCommand(command: Command): void; - addCommands(command: Command[]): void; - removeCommand(command: Command | string, keepCommand?: boolean): void; - removeCommands(command: Command[]): void; - bindKey(key: string | { mac?: string, win?: string}, - command: CommandLike, - position?: number): void; - bindKeys(keys: {[s: string]: Function}): void; - parseKeys(keyPart: string): {key: string, hashId: number}; - findKeyCommand(hashId: number, keyString: string): string | undefined; - handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | {command: string}; - getStatusText(editor: Editor, data: {}): string; - } - - interface VirtualRenderer extends OptionsProvider, EventEmitter { - readonly container: HTMLElement; - readonly scroller: HTMLElement; - readonly content: HTMLElement; - readonly characterWidth: number; - readonly lineHeight: number; - readonly scrollLeft: number; - readonly scrollTop: number; - readonly $padding: number; - - setOption(name: T, value: VirtualRendererOptions[T]): void; - getOption(name: T): VirtualRendererOptions[T]; - - setSession(session: EditSession): void; - updateLines(firstRow: number, lastRow: number, force?: boolean): void; - updateText(): void; - updateFull(force?: boolean): void; - updateFontSize(): void; - adjustWrapLimit(): boolean; - setAnimatedScroll(shouldAnimate: boolean): void; - getAnimatedScroll(): boolean; - setShowInvisibles(showInvisibles: boolean): void; - getShowInvisibles(): boolean; - setDisplayIndentGuides(display: boolean): void; - getDisplayIndentGuides(): boolean; - setShowPrintMargin(showPrintMargin: boolean): void; - getShowPrintMargin(): boolean; - setPrintMarginColumn(showPrintMargin: boolean): void; - getPrintMarginColumn(): boolean; - setShowGutter(show: boolean): void; - getShowGutter(): boolean; - setFadeFoldWidgets(show: boolean): void; - getFadeFoldWidgets(): boolean; - setHighlightGutterLine(shouldHighlight: boolean): void; - getHighlightGutterLine(): boolean; - getContainerElement(): HTMLElement; - getMouseEventTarget(): HTMLElement; - getTextAreaContainer(): HTMLElement; - getFirstVisibleRow(): number; - getFirstFullyVisibleRow(): number; - getLastFullyVisibleRow(): number; - getLastVisibleRow(): number; - setPadding(padding: number): void; - setScrollMargin(top: number, - bottom: number, - left: number, - right: number): void; - setHScrollBarAlwaysVisible(alwaysVisible: boolean): void; - getHScrollBarAlwaysVisible(): boolean; - setVScrollBarAlwaysVisible(alwaysVisible: boolean): void; - getVScrollBarAlwaysVisible(): boolean; - freeze(): void; - unfreeze(): void; - updateFrontMarkers(): void; - updateBackMarkers(): void; - updateBreakpoints(): void; - setAnnotations(annotations: Annotation[]): void; - updateCursor(): void; - hideCursor(): void; - showCursor(): void; - scrollSelectionIntoView(anchor: Position, - lead: Position, - offset?: number): void; - scrollCursorIntoView(cursor: Position, offset?: number): void; - getScrollTop(): number; - getScrollLeft(): number; - getScrollTopRow(): number; - getScrollBottomRow(): number; - scrollToRow(row: number): void; - alignCursor(cursor: Position | number, alignment: number): number; - scrollToLine(line: number, - center: boolean, - animate: boolean, - callback: () => void): void; - animateScrolling(fromValue: number, callback: () => void): void; - scrollToY(scrollTop: number): void; - scrollToX(scrollLeft: number): void; - scrollTo(x: number, y: number): void; - scrollBy(deltaX: number, deltaY: number): void; - isScrollableBy(deltaX: number, deltaY: number): boolean; - textToScreenCoordinates(row: number, column: number): { pageX: number, pageY: number}; - pixelToScreenCoordinates(x: number, y: number): {row: number, column: number, side: 1|-1, offsetX: number}; - visualizeFocus(): void; - visualizeBlur(): void; - showComposition(position: number): void; - setCompositionText(text: string): void; - hideComposition(): void; - setGhostText(text: string, position: Point): void; - removeGhostText(): void; - setTheme(theme: string, callback?: () => void): void; - getTheme(): string; - setStyle(style: string, include?: boolean): void; - unsetStyle(style: string): void; - setCursorStyle(style: string): void; - setMouseCursor(cursorStyle: string): void; - attachToShadowRoot(): void; - destroy(): void; - } - - - interface Selection extends EventEmitter { - moveCursorWordLeft(): void; - moveCursorWordRight(): void; - fromOrientedRange(range: Range): void; - setSelectionRange(match: any): void; - getAllRanges(): Range[]; - addRange(range: Range): void; - isEmpty(): boolean; - isMultiLine(): boolean; - setCursor(row: number, column: number): void; - setAnchor(row: number, column: number): void; - getAnchor(): Position; - getCursor(): Position; - isBackwards(): boolean; - getRange(): Range; - clearSelection(): void; - selectAll(): void; - setRange(range: Range, reverse?: boolean): void; - selectTo(row: number, column: number): void; - selectToPosition(pos: any): void; - selectUp(): void; - selectDown(): void; - selectRight(): void; - selectLeft(): void; - selectLineStart(): void; - selectLineEnd(): void; - selectFileEnd(): void; - selectFileStart(): void; - selectWordRight(): void; - selectWordLeft(): void; - getWordRange(): void; - selectWord(): void; - selectAWord(): void; - selectLine(): void; - moveCursorUp(): void; - moveCursorDown(): void; - moveCursorLeft(): void; - moveCursorRight(): void; - moveCursorLineStart(): void; - moveCursorLineEnd(): void; - moveCursorFileEnd(): void; - moveCursorFileStart(): void; - moveCursorLongWordRight(): void; - moveCursorLongWordLeft(): void; - moveCursorBy(rows: number, chars: number): void; - moveCursorToPosition(position: any): void; - moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void; - moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void; - - toJSON(): SavedSelection | SavedSelection[]; - fromJSON(selection: SavedSelection | SavedSelection[]): void; - } - interface SavedSelection { - start: Point; - end: Point; - isBackwards: boolean; - } - - var Selection: { - new(session: EditSession): Selection; - } - - interface TextInput { - resetSelection(): void; - setAriaOption(activeDescendant: string, role: string): void; - } - - - class Editor { - once?(name: string, callback: Function): void; - setDefaultHandler?(name: string, callback: Function): void; - removeDefaultHandler?(name: string, callback: Function): void; - on(name: string, callback: Function, capturing?: boolean): void; - addEventListener?(name: string, callback: Function, capturing?: boolean): void; - off?(name: string, callback: Function): void; - removeListener?(name: string, callback: Function): void; - removeEventListener?(name: string, callback: Function): void; - removeAllListeners?(name?: string): void; - _signal?(eventName: string, e: any): void; - } - - type CompleterCallback = (error: any, completions: Completion[]) => void; - - interface Completer { - identifierRegexps?: Array, - getCompletions(editor: Editor, - session: EditSession, - position: Point, - prefix: string, - callback: CompleterCallback): void; - getDocTooltip?(item: Completion): undefined | string | Completion; - cancel?(): void; - id?: string; - triggerCharacters?: string[] - } - - class AceInline { - show(editor: Editor, completion: Completion, prefix: string): void; - isOpen(): void; - hide(): void; - destroy(): void; - } - - interface CompletionOptions { - matches?: Completion[]; - } - - type CompletionProviderOptions = { - exactMatch?: boolean; - ignoreCaption?: boolean; - } - - type CompletionRecord = { - all: Completion[]; - filtered: Completion[]; - filterText: string; - } | CompletionProviderOptions - - type GatherCompletionRecord = { - prefix: string; - matches: Completion[]; - finished: boolean; - } - - type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; - type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; - - class CompletionProvider { - insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; - insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; - completions: CompletionRecord; - gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; - provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; - detach(): void; - } + interface EditorProperties { + $mergeUndoDeltas?: any, + $highlightSelectedWord?: boolean, + $updatePlaceholder?: Function, + $cursorStyle?: string, + $readOnly?: any, + searchBox?: any, + $highlightActiveLine?: any, + $enableAutoIndent?: any, + $copyWithEmptySelection?: any + $selectionStyle?: string, + env?: any; + } + + interface EditSessionProperties { + $highlightLineMarker?: { + start: Ace.Point, + end: Ace.Point, + id?: number + } + $useSoftTabs?: boolean, + $tabSize?: number, + $useWorker?: boolean, + $wrapAsCode?: boolean, + $indentedSoftWrap?: boolean, + widgetManager?: any, + $bracketHighlight?: any, + $selectionMarker?: number, + curOp?: { + command: {}, + args: string, + scrollTop: number + }, + lineWidgetsWidth?: number, + } + + interface EditorMultiSelectProperties { + inMultiSelectMode?: boolean, + forEachSelection?: Function, + exitMultiSelectMode?: Function + } + + interface VirtualRendererProperties { + $customScrollbar?: boolean, + $extraHeight?: number, + $showGutter?: boolean, + $showPrintMargin?: boolean, + $printMarginColumn?: number, + $animatedScroll?: boolean, + $isMousePressed?: boolean, + textarea?: HTMLTextAreaElement, + $hScrollBarAlwaysVisible?: boolean, + $vScrollBarAlwaysVisible?: boolean + $maxLines?: number, + $scrollPastEnd?: number, + enableKeyboardAccessibility?: boolean, + keyboardFocusClassName?: string, + $highlightGutterLine?: boolean, + $minLines?: number, + $maxPixelHeight?: number, + $gutterWidth?: number, + showInvisibles?: boolean, + $hasCssTransforms?: boolean, + $blockCursor?: boolean, + $useTextareaForIME?: boolean, + theme?: any, + $theme?: any, + } + + type NewLineMode = 'auto' | 'unix' | 'windows'; + + interface FoldLine { + folds: Fold[]; + range: Range; + start: Point; + end: Point; + + shiftRow(shift: number): void; + + addFold(fold: Fold): void; + + containsRow(row: number): boolean; + + walk(callback: Function, endRow?: number, endColumn?: number): void; + + getNextFoldTo(row: number, column: number): null | { fold: Fold, kind: string }; + + addRemoveChars(row: number, column: number, len: number): void; + + split(row: number, column: number): FoldLine; + + merge(foldLineNext: FoldLine): void; + + idxToPosition(idx: number): Point; + } + + interface Fold { + range: Range; + start: Point; + end: Point; + foldLine?: FoldLine; + sameRow: boolean; + subFolds: Fold[]; + + setFoldLine(foldLine: FoldLine): void; + + clone(): Fold; + + addSubFold(fold: Fold): Fold; + + restoreRange(range: Range): void; + } + + interface EditSessionOptions { + wrap: "off" | "free" | "printmargin" | boolean | number; + wrapMethod: 'code' | 'text' | 'auto'; + indentedSoftWrap: boolean; + firstLineNumber: number; + useWorker: boolean; + useSoftTabs: boolean; + tabSize: number; + navigateWithinSoftTabs: boolean; + foldStyle: 'markbegin' | 'markbeginend' | 'manual'; + overwrite: boolean; + newLineMode: NewLineMode; + mode: string; + } + + interface VirtualRendererOptions { + animatedScroll: boolean; + showInvisibles: boolean; + showPrintMargin: boolean; + printMarginColumn: number; + printMargin: boolean | number; + showGutter: boolean; + fadeFoldWidgets: boolean; + showFoldWidgets: boolean; + showLineNumbers: boolean; + displayIndentGuides: boolean; + highlightIndentGuides: boolean; + highlightGutterLine: boolean; + hScrollBarAlwaysVisible: boolean; + vScrollBarAlwaysVisible: boolean; + fontSize: number; + fontFamily: string; + maxLines: number; + minLines: number; + scrollPastEnd: boolean; + fixedWidthGutter: boolean; + customScrollbar: boolean; + theme: string; + hasCssTransforms: boolean; + maxPixelHeight: number; + useSvgGutterIcons: boolean; + showFoldedAnnotations: boolean; + useResizeObserver: boolean; + } + + interface MouseHandlerOptions { + scrollSpeed: number; + dragDelay: number; + dragEnabled: boolean; + focusTimeout: number; + tooltipFollowsMouse: boolean; + } + + interface EditorOptions extends EditSessionOptions, + MouseHandlerOptions, + VirtualRendererOptions { + selectionStyle: string; + highlightActiveLine: boolean; + highlightSelectedWord: boolean; + readOnly: boolean; + copyWithEmptySelection: boolean; + cursorStyle: 'ace' | 'slim' | 'smooth' | 'wide'; + mergeUndoDeltas: true | false | 'always'; + behavioursEnabled: boolean; + wrapBehavioursEnabled: boolean; + enableAutoIndent: boolean; + enableBasicAutocompletion: boolean | Completer[]; + enableLiveAutocompletion: boolean | Completer[]; + liveAutocompletionDelay: number; + liveAutocompletionThreshold: number; + enableSnippets: boolean; + autoScrollEditorIntoView: boolean; + keyboardHandler: string | null; + placeholder: string; + value: string; + session: EditSession; + relativeLineNumbers: boolean; + enableMultiselect: boolean; + enableKeyboardAccessibility: boolean; + } + + class EventEmitter { + once?(name: string, callback: Function): void; + + setDefaultHandler?(name: string, callback: Function): void; + + removeDefaultHandler?(name: string, callback: Function): void; + + on?(name: string, callback: Function, capturing?: boolean): Function; + + addEventListener?(name: string, callback: Function, capturing?: boolean): Function; + + off?(name: string, callback: Function): void; + + removeListener?(name: string, callback: Function): void; + + removeEventListener?(name: string, callback: Function): void; + + removeAllListeners?(name?: string): void; + + _signal?(eventName: string, e: any): void; + + _emit?(eventName: string, e: any): void; + } + + interface SearchOptions { + needle: string | RegExp; + preventScroll: boolean; + backwards: boolean; + start: Range; + skipCurrent: boolean; + range: Range; + preserveCase: boolean; + regExp: boolean; + wholeWord: boolean; + caseSensitive: boolean; + wrap: boolean; + } + + interface Point { + row: number; + column: number; + } + + type Position = Point; + + interface Delta { + action: 'insert' | 'remove'; + start: Point; + end: Point; + lines: string[]; + id?: number + } + + interface Annotation { + row?: number; + column?: number; + text: string; + type: string; + } + + interface MarkerGroupItem { + range: Range; + className: string; + } + + class MarkerGroup { + constructor(session: EditSession); + + setMarkers(markers: MarkerGroupItem[]): void; + + getMarkerAtPosition(pos: Position): MarkerGroupItem; + } + + + interface Command { + name?: string; + bindKey?: string | { mac?: string, win?: string }; + readOnly?: boolean; + exec: (editor: Editor, args?: any) => void; + } - class Autocomplete { - constructor(); - autoInsert?: boolean; - autoSelect?: boolean; - autoShown?: boolean; - exactMatch?: boolean; - inlineEnabled?: boolean; - parentNode?: HTMLElement; - emptyMessage?(prefix: String): String; - getPopup(): AcePopup; - showPopup(editor: Editor, options: CompletionOptions): void; - detach(): void; - destroy(): void; - } - - type AcePopupNavigation = "up" | "down" | "start" | "end"; - - class AcePopup { - constructor(parentNode: HTMLElement); - setData(list: Completion[], filterText: string): void; - getData(row: number): Completion; - getRow(): number; - getRow(line: number): void; - hide(): void; - show(pos: Point, lineHeight: number, topdownOnly: boolean): void; - tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; - goTo(where: AcePopupNavigation): void; - } + type CommandLike = Command | ((editor: Editor) => void); + + interface KeyboardHandler { + handleKeyboard: Function; + } + + interface MarkerLike { + range?: Range; + type: string; + renderer?: MarkerRenderer; + clazz: string; + inFront: boolean; + id: number; + update?: (html: string[], + // TODO maybe define Marker class + marker: any, + session: EditSession, + config: any) => void; + } + + type MarkerRenderer = (html: string[], + range: Range, + left: number, + top: number, + config: any) => void; + + interface Token { + type: string; + value: string; + index?: number; + start?: number; + } + + interface BaseCompletion { + score?: number; + meta?: string; + caption?: string; + docHTML?: string; + docText?: string; + completerId?: string; + } + + interface SnippetCompletion extends BaseCompletion { + snippet: string; + } + + interface ValueCompletion extends BaseCompletion { + value: string; + } + + type Completion = SnippetCompletion | ValueCompletion + + interface Tokenizer { + removeCapturingGroups(src: string): string; + + createSplitterRegexp(src: string, flag?: string): RegExp; + + getLineTokens(line: string, startState: string | string[]): Token[]; + } + + interface TokenIterator { + getCurrentToken(): Token; + + getCurrentTokenColumn(): number; + + getCurrentTokenRow(): number; + + getCurrentTokenPosition(): Point; + + getCurrentTokenRange(): Range; + + stepBackward(): Token; + + stepForward(): Token; + } + + type HighlightRule = { defaultToken: string } | { include: string } | { todo: string } | { + token: string | string[] | ((value: string) => string); + regex: string | RegExp; + next?: string; + push?: string; + comment?: string; + caseInsensitive?: boolean; + } + + type HighlightRulesMap = Record; + + type KeywordMapper = (keyword: string) => string; + + interface HighlightRules { + addRules(rules: HighlightRulesMap, prefix?: string): void; + + getRules(): HighlightRulesMap; + + embedRules(rules: (new () => HighlightRules) | HighlightRulesMap, prefix: string, escapeRules?: boolean, append?: boolean): void; + + getEmbeds(): string[]; + + normalizeRules(): void; + + createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; + } + + interface FoldMode { + foldingStartMarker: RegExp; + foldingStopMarker?: RegExp; + + getFoldWidget(session: EditSession, foldStyle: string, row: number): string; + + getFoldWidgetRange(session: EditSession, foldStyle: string, row: number, forceMultiline?: boolean): Range | undefined; + + indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; + + openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + + closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + } + + type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => { text: string, selection: number[] } | Range | undefined; + type BehaviorMap = Record>; + + interface Behaviour { + add(name: string, action: string, callback: BehaviorAction): void; + + addBehaviours(behaviours: BehaviorMap): void; + + remove(name: string): void; + + inherit(mode: SyntaxMode | (new () => SyntaxMode), filter: string[]): void; + + getBehaviours(filter: string[]): BehaviorMap; + } + + interface Outdent { + checkOutdent(line: string, input: string): boolean; + + autoOutdent(doc: Document, row: number): number | undefined; + } + + interface SyntaxMode { + HighlightRules: HighlightRules; + foldingRules?: FoldMode; + $behaviour?: Behaviour; + $defaultBehaviour?: Behaviour; + lineCommentStart?: string; + + getTokenizer(): Tokenizer; + + toggleCommentLines(state: any, + session: EditSession, + startRow: number, + endRow: number): void; + + toggleBlockComment(state: any, + session: EditSession, + range: Range, + cursor: Point): void; + + getNextLineIndent(state: any, line: string, tab: string): string; + + checkOutdent(state: any, line: string, input: string): boolean; + + autoOutdent(state: any, doc: Document, row: number): void; + + // TODO implement WorkerClient types + createWorker(session: EditSession): any; + + createModeDelegates(mapping: { [key: string]: string }): void; + + transformAction: BehaviorAction; + + getKeywords(append?: boolean): Array; + + getCompletions(state: string, + session: EditSession, + pos: Point, + prefix: string): Completion[]; + } + + type AfterLoadCallback = (err: Error | null, module: unknown) => void; + type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; + + interface Config { + get?(key: string): any; + + set?(key: string, value: any): void; + + all?(): { [key: string]: any }; + + moduleUrl?(name: string, component?: string): string; + + setModuleUrl?(name: string, subst: string): string; + + setLoader?(cb: LoaderFunction): void; + + setModuleLoader?(name: string, onLoad: Function): void; + + loadModule?(moduleName: string | [string, string], + onLoad?: (module: any) => void): void; + + init?(packaged: any): any; + + defineOptions?(obj: any, path: string, options: { [key: string]: any }): Config; + + resetOptions?(obj: any): void; + + setDefaultValue?(path: string, name: string, value: any): void; + + setDefaultValues?(path: string, optionHash: { [key: string]: any }): void; + } + + interface OptionsBase { + [key: string]: any; + } + + class OptionsProvider { + setOptions?(optList: Partial): void; + + getOptions?(optionNames?: Array | Partial): Partial; + + setOption?(name: K, value: K[T]): void; + + getOption?(name: K): T[K]; + } + + + interface KeyBinding { + setDefaultHandler(handler: KeyboardHandler): void; + + setKeyboardHandler(handler: KeyboardHandler): void; + + addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; + + removeKeyboardHandler(handler: KeyboardHandler): boolean; + + getKeyboardHandler(): KeyboardHandler; + + getStatusText(): string; + + onCommandKey(e: any, hashId: number, keyCode: number): boolean; + + onTextInput(text: string): boolean; + } + + interface CommandMap { + [name: string]: Command; + } + + type execEventHandler = (obj: { + editor: Editor, + command: Command, + args: any[] + }) => void; + + interface CommandManager extends EventEmitter { + byName: CommandMap, + commands: CommandMap, + + on(name: 'exec', callback: execEventHandler): Function; + + on(name: 'afterExec', callback: execEventHandler): Function; + + once(name: string, callback: Function): void; + + setDefaultHandler(name: string, callback: Function): void; + + removeDefaultHandler(name: string, callback: Function): void; + + on(name: string, callback: Function, capturing?: boolean): void; + + addEventListener(name: string, callback: Function, capturing?: boolean): void; + + off(name: string, callback: Function): void; + + removeListener(name: string, callback: Function): void; + + removeEventListener(name: string, callback: Function): void; + + exec(command: string, editor: Editor, args: any): boolean; + + toggleRecording(editor: Editor): void; + + replay(editor: Editor): void; + + addCommand(command: Command): void; + + addCommands(command: Command[]): void; + + removeCommand(command: Command | string, keepCommand?: boolean): void; + + removeCommands(command: Command[]): void; + + bindKey(key: string | { mac?: string, win?: string }, + command: CommandLike, + position?: number): void; + + bindKeys(keys: { [s: string]: Function }): void; + + parseKeys(keyPart: string): { key: string, hashId: number }; + + findKeyCommand(hashId: number, keyString: string): string | undefined; + + handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | { command: string }; + + getStatusText(editor: Editor, data: {}): string; + } + + interface VirtualRenderer extends OptionsProvider, EventEmitter { + readonly container: HTMLElement; + readonly scroller: HTMLElement; + readonly content: HTMLElement; + readonly characterWidth: number; + readonly lineHeight: number; + readonly scrollLeft: number; + readonly scrollTop: number; + readonly $padding: number; + + setOption(name: T, value: VirtualRendererOptions[T]): void; + + getOption(name: T): VirtualRendererOptions[T]; + + setSession(session: EditSession): void; + + updateLines(firstRow: number, lastRow: number, force?: boolean): void; + + updateText(): void; + + updateFull(force?: boolean): void; + + updateFontSize(): void; + + adjustWrapLimit(): boolean; + + setAnimatedScroll(shouldAnimate: boolean): void; + + getAnimatedScroll(): boolean; + + setShowInvisibles(showInvisibles: boolean): void; + + getShowInvisibles(): boolean; + + setDisplayIndentGuides(display: boolean): void; + + getDisplayIndentGuides(): boolean; + + setShowPrintMargin(showPrintMargin: boolean): void; + + getShowPrintMargin(): boolean; + + setPrintMarginColumn(showPrintMargin: boolean): void; + + getPrintMarginColumn(): boolean; + + setShowGutter(show: boolean): void; + + getShowGutter(): boolean; + + setFadeFoldWidgets(show: boolean): void; + + getFadeFoldWidgets(): boolean; + + setHighlightGutterLine(shouldHighlight: boolean): void; + + getHighlightGutterLine(): boolean; + + getContainerElement(): HTMLElement; + + getMouseEventTarget(): HTMLElement; + + getTextAreaContainer(): HTMLElement; + + getFirstVisibleRow(): number; + + getFirstFullyVisibleRow(): number; + + getLastFullyVisibleRow(): number; + + getLastVisibleRow(): number; + + setPadding(padding: number): void; + + setScrollMargin(top: number, + bottom: number, + left: number, + right: number): void; + + setHScrollBarAlwaysVisible(alwaysVisible: boolean): void; + + getHScrollBarAlwaysVisible(): boolean; + + setVScrollBarAlwaysVisible(alwaysVisible: boolean): void; + + getVScrollBarAlwaysVisible(): boolean; + + freeze(): void; + + unfreeze(): void; + + updateFrontMarkers(): void; + + updateBackMarkers(): void; + + updateBreakpoints(): void; + + setAnnotations(annotations: Annotation[]): void; + + updateCursor(): void; + + hideCursor(): void; + + showCursor(): void; + + scrollSelectionIntoView(anchor: Position, + lead: Position, + offset?: number): void; + + scrollCursorIntoView(cursor: Position, offset?: number): void; + + getScrollTop(): number; + + getScrollLeft(): number; + + getScrollTopRow(): number; + + getScrollBottomRow(): number; + + scrollToRow(row: number): void; + + alignCursor(cursor: Position | number, alignment: number): number; + + scrollToLine(line: number, + center: boolean, + animate: boolean, + callback: () => void): void; + + animateScrolling(fromValue: number, callback: () => void): void; + + scrollToY(scrollTop: number): void; + + scrollToX(scrollLeft: number): void; + + scrollTo(x: number, y: number): void; + + scrollBy(deltaX: number, deltaY: number): void; + + isScrollableBy(deltaX: number, deltaY: number): boolean; + + textToScreenCoordinates(row: number, column: number): { pageX: number, pageY: number }; + + pixelToScreenCoordinates(x: number, y: number): { row: number, column: number, side: 1 | -1, offsetX: number }; + + visualizeFocus(): void; + + visualizeBlur(): void; + + showComposition(position: number): void; + + setCompositionText(text: string): void; + + hideComposition(): void; + + setGhostText(text: string, position: Point): void; + + removeGhostText(): void; + + setTheme(theme: string, callback?: () => void): void; + + getTheme(): string; + + setStyle(style: string, include?: boolean): void; + + unsetStyle(style: string): void; + + setCursorStyle(style: string): void; + + setMouseCursor(cursorStyle: string): void; + + attachToShadowRoot(): void; + + destroy(): void; + } + + + interface Selection extends EventEmitter { + moveCursorWordLeft(): void; + + moveCursorWordRight(): void; + + fromOrientedRange(range: Range): void; + + setSelectionRange(match: any): void; + + getAllRanges(): Range[]; + + addRange(range: Range): void; + + isEmpty(): boolean; + + isMultiLine(): boolean; + + setCursor(row: number, column: number): void; + + setAnchor(row: number, column: number): void; + + getAnchor(): Position; + + getCursor(): Position; + + isBackwards(): boolean; + + getRange(): Range; + + clearSelection(): void; + + selectAll(): void; + + setRange(range: Range, reverse?: boolean): void; + + selectTo(row: number, column: number): void; + + selectToPosition(pos: any): void; + + selectUp(): void; + + selectDown(): void; + + selectRight(): void; + + selectLeft(): void; + + selectLineStart(): void; + + selectLineEnd(): void; + + selectFileEnd(): void; + + selectFileStart(): void; + + selectWordRight(): void; + + selectWordLeft(): void; + + getWordRange(): void; + + selectWord(): void; + + selectAWord(): void; + + selectLine(): void; + + moveCursorUp(): void; + + moveCursorDown(): void; + + moveCursorLeft(): void; + + moveCursorRight(): void; + + moveCursorLineStart(): void; + + moveCursorLineEnd(): void; + + moveCursorFileEnd(): void; + + moveCursorFileStart(): void; + + moveCursorLongWordRight(): void; + + moveCursorLongWordLeft(): void; + + moveCursorBy(rows: number, chars: number): void; + + moveCursorToPosition(position: any): void; + + moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void; + + moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void; + + toJSON(): SavedSelection | SavedSelection[]; + + fromJSON(selection: SavedSelection | SavedSelection[]): void; + } + + interface SavedSelection { + start: Point; + end: Point; + isBackwards: boolean; + } + + var Selection: { + new(session: EditSession): Selection; + } + + interface TextInput { + resetSelection(): void; + + setAriaOption(activeDescendant: string, role: string): void; + } + + + class Editor { + once?(name: string, callback: Function): void; + + setDefaultHandler?(name: string, callback: Function): void; + + removeDefaultHandler?(name: string, callback: Function): void; + + on(name: string, callback: Function, capturing?: boolean): void; + + addEventListener?(name: string, callback: Function, capturing?: boolean): void; + + off?(name: string, callback: Function): void; + + removeListener?(name: string, callback: Function): void; + + removeEventListener?(name: string, callback: Function): void; + + removeAllListeners?(name?: string): void; + + _signal?(eventName: string, e: any): void; + } + + type CompleterCallback = (error: any, completions: Completion[]) => void; + + interface Completer { + identifierRegexps?: Array, + + getCompletions(editor: Editor, + session: EditSession, + position: Point, + prefix: string, + callback: CompleterCallback): void; + + getDocTooltip?(item: Completion): undefined | string | Completion; + + cancel?(): void; + + id?: string; + triggerCharacters?: string[] + } + + class AceInline { + show(editor: Editor, completion: Completion, prefix: string): void; + + isOpen(): void; + + hide(): void; + + destroy(): void; + } + + interface CompletionOptions { + matches?: Completion[]; + } + + type CompletionProviderOptions = { + exactMatch?: boolean; + ignoreCaption?: boolean; + } + + type CompletionRecord = { + all: Completion[]; + filtered: Completion[]; + filterText: string; + } | CompletionProviderOptions + + type GatherCompletionRecord = { + prefix: string; + matches: Completion[]; + finished: boolean; + } + + type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; + type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; + + class CompletionProvider { + insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; + + insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; + + completions: CompletionRecord; + + gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; + + provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; + + detach(): void; + } + + class Autocomplete { + constructor(); + + autoInsert?: boolean; + autoSelect?: boolean; + autoShown?: boolean; + exactMatch?: boolean; + inlineEnabled?: boolean; + parentNode?: HTMLElement; + + emptyMessage?(prefix: String): String; + + getPopup(): AcePopup; + + showPopup(editor: Editor, options: CompletionOptions): void; + + detach(): void; + + destroy(): void; + } + + type AcePopupNavigation = "up" | "down" | "start" | "end"; + + class AcePopup { + constructor(parentNode: HTMLElement); + + setData(list: Completion[], filterText: string): void; + + getData(row: number): Completion; + + getRow(): number; + getRow(line: number): void; + + hide(): void; + + show(pos: Point, lineHeight: number, topdownOnly: boolean): void; + + tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; + + goTo(where: AcePopupNavigation): void; + } } declare const version: string; declare const config: Ace.Config; + declare function require(name: string): any; + declare function edit(el: Element | string, options?: Partial): Ace.Editor; + declare function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; @@ -787,41 +1024,64 @@ type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; type TooltipCommandFunction = (editor: Ace.Editor) => T; interface TooltipCommand extends Ace.Command { - enabled: TooltipCommandFunction | boolean, - getValue?: TooltipCommandFunction, - type: "button" | "text" | "checkbox" - iconCssClass: string, - cssClass: string + enabled: TooltipCommandFunction | boolean, + getValue?: TooltipCommandFunction, + type: "button" | "text" | "checkbox" + iconCssClass: string, + cssClass: string } declare class InlineAutocomplete { - constructor(); - getInlineRenderer(): Ace.AceInline; - getInlineTooltip(): CommandBarTooltip; - getCompletionProvider(): Ace.CompletionProvider; - show(editor: Ace.Editor): void; - isOpen(): boolean; - detach(): void; - destroy(): void; - goTo(action: InlineAutocompleteAction): void; - tooltipEnabled: boolean; - commands: Record - getIndex(): number; - setIndex(value: number): void; - getLength(): number; - getData(index?: number): Ace.Completion | undefined; - updateCompletions(options: Ace.CompletionOptions): void; + constructor(); + + getInlineRenderer(): Ace.AceInline; + + getInlineTooltip(): CommandBarTooltip; + + getCompletionProvider(): Ace.CompletionProvider; + + show(editor: Ace.Editor): void; + + isOpen(): boolean; + + detach(): void; + + destroy(): void; + + goTo(action: InlineAutocompleteAction): void; + + tooltipEnabled: boolean; + commands: Record + + getIndex(): number; + + setIndex(value: number): void; + + getLength(): number; + + getData(index?: number): Ace.Completion | undefined; + + updateCompletions(options: Ace.CompletionOptions): void; } declare class CommandBarTooltip { - constructor(parentElement: HTMLElement); - registerCommand(id: string, command: TooltipCommand): void; - attach(editor: Ace.Editor): void; - updatePosition(): void; - update(): void; - isShown(): boolean; - getAlwaysShow(): boolean; - setAlwaysShow(alwaysShow: boolean): void; - detach(): void; - destroy(): void; + constructor(parentElement: HTMLElement); + + registerCommand(id: string, command: TooltipCommand): void; + + attach(editor: Ace.Editor): void; + + updatePosition(): void; + + update(): void; + + isShown(): boolean; + + getAlwaysShow(): boolean; + + setAlwaysShow(alwaysShow: boolean): void; + + detach(): void; + + destroy(): void; } diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index 76d1ba9bee1..b5880571248 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -1,14 +1,27 @@ "use strict"; - +/** + * @typedef ICommandManager + * @type {CommandManager & Ace.EventEmitter} + * @export + */ +/** + * + * @typedef IEditor + * @type {import("../editor").IEditor} + */ var oop = require("../lib/oop"); var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler; var EventEmitter = require("../lib/event_emitter").EventEmitter; +/** + * @type {ICommandManager} + */ class CommandManager extends MultiHashHandler{ /** * new CommandManager(platform, commands) * @param {String} platform Identifier for the platform; must be either `"mac"` or `"win"` - * @param {Array} commands A list of commands + * @param {any[]} commands A list of commands + * @this {ICommandManager} **/ constructor(platform, commands) { super(commands, platform); @@ -20,7 +33,15 @@ class CommandManager extends MultiHashHandler{ return e.command.exec(e.editor, e.args, e.event, false); }); } - + + /** + * + * @param command + * @param {IEditor} editor + * @param {any} args + * @returns {boolean} + * @this {ICommandManager} + */ exec(command, editor, args) { if (Array.isArray(command)) { for (var i = command.length; i--; ) { @@ -48,6 +69,11 @@ class CommandManager extends MultiHashHandler{ return e.returnValue === false ? false : true; } + /** + * @param {IEditor} editor + * @returns {boolean} + * @this {ICommandManager} + */ toggleRecording(editor) { if (this.$inReplay) return; diff --git a/src/edit_session.js b/src/edit_session.js index 654908a4ade..45f87af7d02 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,15 +1,24 @@ /// "use strict"; -/** - * @typedef IEditSession - * @type {EditSession & Ace.OptionsProvider & Ace.Folding & Ace.EventEmitter & Ace.EditSessionProperties & import("./edit_session/bracket_match").BracketMatch} - * @export - */ /** * @typedef IDocument * @type {import("./document").IDocument} */ +/** + * @typedef IFolding + * @type {import("./edit_session/folding").Folding} + */ +/** + * @typedef UndoManager + * @type {import("./undomanager").UndoManager} + */ +/** + * @typedef IEditSession + * @type {EditSession & Ace.OptionsProvider & IFolding & Ace.EventEmitter & Ace.EditSessionProperties & import("./edit_session/bracket_match").BracketMatch} + * @export + */ + var oop = require("./lib/oop"); var lang = require("./lib/lang"); @@ -125,7 +134,7 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; */ class EditSession { /** - * @type {Document} + * @type {IDocument} */ doc; @@ -929,6 +938,9 @@ class EditSession { * @type {RegExp} */ this.tokenRe = mode.tokenRe; + /** + * @type {RegExp} + */ this.nonTokenRe = mode.nonTokenRe; @@ -1021,7 +1033,11 @@ class EditSession { return Math.max(this.getLineWidgetMaxWidth(), this.screenWidth); return this.screenWidth; } - + + /** + * @return {number} + * @this {IEditSession} + */ getLineWidgetMaxWidth() { if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth; var width = 0; @@ -2417,10 +2433,10 @@ class EditSession { return screenRows; } - + /** - * @private - * + * @this {IEditSession} + * @param {import("./layer/font_metrics").FontMetrics} fm */ $setFontMetrics(fm) { if (!this.$enableVarChar) return; @@ -2448,7 +2464,10 @@ class EditSession { return [screenColumn, column]; }; } - + + /** + * @this {IEditSession} + */ destroy() { if (!this.destroyed) { this.bgTokenizer.setDocument(null); @@ -2590,7 +2609,10 @@ config.defineOptions(EditSession.prototype, "session", { handlesSet: true }, wrapMethod: { - // code|text|auto + /** + * @this {IEditSession} + * @param {"code"|"text"|"auto"|boolean} val + */ set: function(val) { val = val == "auto" ? this.$mode.type != "text" @@ -2619,6 +2641,10 @@ config.defineOptions(EditSession.prototype, "session", { initialValue: 1 }, useWorker: { + /** + * @this {IEditSession} + * @param {boolean} useWorker + */ set: function(useWorker) { this.$useWorker = useWorker; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 50ce67d0443..291d77ecb12 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -1,17 +1,31 @@ "use strict"; + +/** + * + * @typedef IEditSession + * @type {import("../edit_session").IEditSession} + */ var Range = require("../range").Range; var FoldLine = require("./fold_line").FoldLine; var Fold = require("./fold").Fold; var TokenIterator = require("../token_iterator").TokenIterator; var MouseEvent = require("../mouse/mouse_event").MouseEvent; +/** + * @class Folding + * @export + */ function Folding() { - /* + /** * Looks up a fold at a given row/column. Possible values for side: * -1: ignore a fold if fold.start = row/column * +1: ignore a fold if fold.end = row/column - */ + * @param {number} row + * @param {number} column + * @param {number} [side] + * @return {Fold} + **/ this.getFoldAt = function(row, column, side) { var foldLine = this.getFoldLine(row); if (!foldLine) @@ -31,10 +45,12 @@ function Folding() { } }; - /* + /** * Returns all folds in the given range. Note, that this will return folds - * - */ + * @this {IEditSession} + * @param {Range| Ace.Delta} range + * @returns {Fold[]} + **/ this.getFoldsInRange = function(range) { var start = range.start; var end = range.end; @@ -79,8 +95,17 @@ function Folding() { return foundFolds; }; + /** + * + * @param {Range[]|Range}ranges + * @returns {Fold[]} + * @this {IEditSession} + */ this.getFoldsInRangeList = function(ranges) { if (Array.isArray(ranges)) { + /** + * @type {Fold[]} + */ var folds = []; ranges.forEach(function(range) { folds = folds.concat(this.getFoldsInRange(range)); @@ -91,8 +116,10 @@ function Folding() { return folds; }; - /* + /** * Returns all folds in the document + * @this {IEditSession} + * @returns {Fold[]} */ this.getAllFolds = function() { var folds = []; @@ -105,7 +132,7 @@ function Folding() { return folds; }; - /* + /** * Returns the string between folds at the given position. * E.g. * foob|arwolrd -> "bar" @@ -121,6 +148,12 @@ function Folding() { * foob|arwolrd -trim=-1> "b" * foobarwol|rd -trim=+1> "rld" * fo|obarwolrd -trim=00> "foo" + * @this {IEditSession} + * @param {number} row + * @param {number} column + * @param {number} [trim] + * @param {FoldLine} [foldLine] + * @returns {string | null} */ this.getFoldStringAt = function(row, column, trim, foldLine) { foldLine = foldLine || this.getFoldLine(row); @@ -157,6 +190,13 @@ function Folding() { return str; }; + /** + * + * @param {number} docRow + * @param {FoldLine} [startFoldLine] + * @returns {null|FoldLine} + * @this {IEditSession} + */ this.getFoldLine = function(docRow, startFoldLine) { var foldData = this.$foldData; var i = 0; @@ -175,7 +215,13 @@ function Folding() { return null; }; - // returns the fold which starts after or contains docRow + /** + * Returns the fold which starts after or contains docRow + * @param {number} docRow + * @param {FoldLine} [startFoldLine] + * @returns {null|FoldLine} + * @this {IEditSession} + */ this.getNextFoldLine = function(docRow, startFoldLine) { var foldData = this.$foldData; var i = 0; @@ -192,6 +238,13 @@ function Folding() { return null; }; + /** + * + * @param {number} first + * @param {number} last + * @return {number} + * @this {IEditSession} + */ this.getFoldedRowCount = function(first, last) { var foldData = this.$foldData, rowCount = last-first+1; for (var i = 0; i < foldData.length; i++) { @@ -216,6 +269,12 @@ function Folding() { return rowCount; }; + /** + * + * @param {FoldLine}foldLine + * @return {FoldLine} + * @this {IEditSession} + */ this.$addFoldLine = function(foldLine) { this.$foldData.push(foldLine); this.$foldData.sort(function(a, b) { @@ -227,9 +286,12 @@ function Folding() { /** * Adds a new fold. * - * @returns + * @param {Fold|String} placeholder + * @param {Range} [range] + * @returns {Fold} * The new created Fold object or an existing fold object in case the * passed in range fits an existing fold exactly. + * @this {IEditSession} */ this.addFold = function(placeholder, range) { var foldData = this.$foldData; @@ -312,12 +374,20 @@ function Folding() { return fold; }; + /** + * @param {Fold[]} folds + */ this.addFolds = function(folds) { folds.forEach(function(fold) { this.addFold(fold); }, this); }; + /** + * + * @param {Fold} fold + * @this {IEditSession} + */ this.removeFold = function(fold) { var foldLine = fold.foldLine; var startRow = foldLine.start.row; @@ -371,6 +441,10 @@ function Folding() { this._signal("changeFold", { data: fold, action: "remove" }); }; + /** + * + * @param {Fold[]} folds + */ this.removeFolds = function(folds) { // We need to clone the folds array passed in as it might be the folds // array of a fold line and as we call this.removeFold(fold), folds @@ -386,6 +460,10 @@ function Folding() { this.$modified = true; }; + /** + * @param {Fold} fold + * @this {IEditSession} + */ this.expandFold = function(fold) { this.removeFold(fold); fold.subFolds.forEach(function(subFold) { @@ -398,12 +476,22 @@ function Folding() { fold.subFolds = []; }; + /** + * @param {Fold[]}folds + */ this.expandFolds = function(folds) { folds.forEach(function(fold) { this.expandFold(fold); }, this); }; + /** + * + * @param {number|null|Ace.Point|Range|Range[]} [location] + * @param {boolean} [expandInner] + * @return {Fold[]| undefined} + * @this {IEditSession} + */ this.unfold = function(location, expandInner) { var range, folds; if (location == null) { @@ -445,24 +533,51 @@ function Folding() { return outermostFolds; }; - /* + /** * Checks if a given documentRow is folded. This is true if there are some * folded parts such that some parts of the line is still visible. + * @param {number} docRow + * @param {FoldLine} [startFoldRow] + * @returns {boolean} + * @this {IEditSession} **/ this.isRowFolded = function(docRow, startFoldRow) { return !!this.getFoldLine(docRow, startFoldRow); }; + /** + * + * @param {number} docRow + * @param {FoldLine} [startFoldRow] + * @return {number} + * @this {IEditSession} + */ this.getRowFoldEnd = function(docRow, startFoldRow) { var foldLine = this.getFoldLine(docRow, startFoldRow); return foldLine ? foldLine.end.row : docRow; }; + /** + * + * @param {number} docRow + * @param {FoldLine} [startFoldRow] + * @returns {number} + */ this.getRowFoldStart = function(docRow, startFoldRow) { var foldLine = this.getFoldLine(docRow, startFoldRow); return foldLine ? foldLine.start.row : docRow; }; + /** + * + * @param {FoldLine} foldLine + * @param {number | null} [endRow] + * @param {number | null} [endColumn] + * @param {number | null} [startRow] + * @param {number | null} [startColumn] + * @return {string} + * @this {IEditSession} + */ this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) { if (startRow == null) startRow = foldLine.start.row; @@ -496,6 +611,15 @@ function Folding() { return textLine; }; + /** + * + * @param {number} row + * @param {number | null} endColumn + * @param {number | null} startRow + * @param {number | null} startColumn + * @return {string} + * @this {IEditSession} + */ this.getDisplayLine = function(row, endColumn, startRow, startColumn) { var foldLine = this.getFoldLine(row); @@ -509,6 +633,10 @@ function Folding() { } }; + /** + * @return {FoldLine[]} + * @this {IEditSession} + */ this.$cloneFoldData = function() { var fd = []; fd = this.$foldData.map(function(foldLine) { @@ -521,6 +649,10 @@ function Folding() { return fd; }; + /** + * @param {boolean} [tryToUnfold] + * @this {IEditSession} + */ this.toggleFold = function(tryToUnfold) { var selection = this.selection; var range = selection.getRange(); @@ -581,6 +713,14 @@ function Folding() { this.addFold(placeholder, range); }; + /** + * + * @param {number} row + * @param {number} column + * @param {number} [dir] + * @return {Range | undefined} + * @this {IEditSession} + */ this.getCommentFoldRange = function(row, column, dir) { var iterator = new TokenIterator(this, row, column); var token = iterator.getCurrentToken(); @@ -628,6 +768,14 @@ function Folding() { } }; + /** + * + * @param {number | null} [startRow] + * @param {number | null} [endRow] + * @param {number | null} [depth] + * @param {Function} [test] + * @this {IEditSession} + */ this.foldAll = function(startRow, endRow, depth, test) { if (depth == undefined) depth = 100000; // JSON.stringify doesn't hanle Infinity @@ -656,13 +804,22 @@ function Folding() { } } }; - + + /** + * + * @param {number} level + * @this {IEditSession} + */ this.foldToLevel = function(level) { this.foldAll(); while (level-- > 0) this.unfold(null, false); }; - + + /** + * + * @this {IEditSession} + */ this.foldAllComments = function() { var session = this; this.foldAll(null, null, null, function(row) { @@ -685,6 +842,11 @@ function Folding() { "markbeginend": 1 }; this.$foldStyle = "markbegin"; + + /** + * @param {string} style + * @this {IEditSession} + */ this.setFoldStyle = function(style) { if (!this.$foldStyles[style]) throw new Error("invalid fold style: " + style + "[" + Object.keys(this.$foldStyles).join(", ") + "]"); @@ -703,6 +865,10 @@ function Folding() { this.$setFolding(mode); }; + /** + * @param {FoldMode} foldMode + * @this {IEditSession} + */ this.$setFolding = function(foldMode) { if (this.$foldMode == foldMode) return; @@ -727,7 +893,12 @@ function Folding() { this.on('change', this.$updateFoldWidgets); this.on('tokenizerUpdate', this.$tokenizerUpdateFoldWidgets); }; - + /** + * @param {number} row + * @param {boolean} [ignoreCurrent] + * @return {{range: Range, firstRange: Range} | {}} + * @this {IEditSession} + */ this.getParentFoldRangeData = function (row, ignoreCurrent) { var fw = this.foldWidgets; if (!fw || (ignoreCurrent && fw[row])) @@ -755,6 +926,11 @@ function Folding() { }; }; + /** + * + * @param {number} row + * @param {any} e + */ this.onFoldWidgetClick = function(row, e) { if (e instanceof MouseEvent) e = e.domEvent; @@ -772,7 +948,14 @@ function Folding() { el.className += " ace_invalid"; } }; - + + /** + * + * @param {number} row + * @param options + * @return {Fold|*} + * @this {IEditSession} + */ this.$toggleFoldWidget = function(row, options) { if (!this.getFoldWidget) return; @@ -819,8 +1002,11 @@ function Folding() { return range; }; - - + /** + * + * @param {boolean} [toggleParent] + * @this {IEditSession} + */ this.toggleFoldWidget = function(toggleParent) { var row = this.selection.getCursor().row; row = this.getRowFoldStart(row); @@ -844,6 +1030,10 @@ function Folding() { } }; + /** + * @param {Ace.Delta} delta + * @this {IEditSession} + */ this.updateFoldWidgets = function(delta) { var firstRow = delta.start.row; var len = delta.end.row - firstRow; @@ -858,6 +1048,10 @@ function Folding() { this.foldWidgets.splice.apply(this.foldWidgets, args); } }; + /** + * @param e + * @this {IEditSession} + */ this.tokenizerUpdateFoldWidgets = function(e) { var rows = e.data; if (rows.first != rows.last) { diff --git a/src/editor.js b/src/editor.js index 227375d6631..752224dfe4f 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,4 +1,10 @@ "use strict"; +/** + * @typedef IEditor + * @type {Editor & Ace.EventEmitter & Ace.OptionsProvider & Ace.EditorProperties & Ace.EditorMultiSelectProperties} + * @export + */ + /** * * @typedef IEditSession @@ -8,10 +14,10 @@ * @typedef IVirtualRenderer * @type {import("./virtual_renderer").IVirtualRenderer} */ + /** - * @typedef IEditor - * @type {Editor & Ace.EventEmitter & Ace.OptionsProvider & Ace.EditorProperties & Ace.EditorMultiSelectProperties} - * @export + * @typedef ICommandManager + * @type {import("./commands/command_manager").ICommandManager} */ var oop = require("./lib/oop"); @@ -80,7 +86,7 @@ class Editor { */ this.id = "editor" + (++Editor.$uid); /** - * @type {CommandManager} + * @type {ICommandManager} */ this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands); if (typeof document == "object") { @@ -700,7 +706,9 @@ class Editor { */ $updateHighlightActiveLine() { var session = this.getSession(); - + /** + * @type {Ace.Point|false} + */ var highlight; if (this.$highlightActiveLine) { if (this.$selectionStyle != "line" || !this.selection.isMultiLine()) @@ -3014,7 +3022,9 @@ config.defineOptions(Editor.prototype, "editor", { this.focus(); } }; - + /** + * @type {GutterKeyboardHandler} + */ var gutterKeyboardHandler; // If keyboard a11y mode is enabled we: diff --git a/src/undomanager.js b/src/undomanager.js index 6128177c93e..623e24ed9b5 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -1,9 +1,18 @@ "use strict"; +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ /** * This object maintains the undo stack for an [[EditSession `EditSession`]]. **/ class UndoManager { + /** + * @type {boolean} + */ + $keepRedoStack; /** * Resets the current undo state and creates a new `UndoManager`. @@ -14,7 +23,11 @@ class UndoManager { this.$undoDepth = Infinity; this.reset(); } - + + /** + * + * @param {IEditSession} session + */ addSession(session) { this.$session = session; } @@ -24,8 +37,9 @@ class UndoManager { * - `args[0]` is an array of deltas * - `args[1]` is the document to associate with * - * @param {Object} options Contains additional properties - * + * @param {Ace.Delta} delta + * @param {boolean} allowMerge + * @param {IEditSession} session **/ add(delta, allowMerge, session) { if (this.$fromUndo) return; @@ -44,7 +58,12 @@ class UndoManager { this.$lastDelta = delta; this.lastDeltas.push(delta); } - + + /** + * + * @param {string} selection + * @param {number} [rev] + */ addSelection(selection, rev) { this.selections.push({ value: selection, @@ -56,7 +75,12 @@ class UndoManager { this.lastDeltas = null; return this.$rev; } - + + /** + * + * @param {number} from + * @param {number} [to] + */ markIgnored(from, to) { if (to == null) to = this.$rev + 1; var stack = this.$undoStack; @@ -69,7 +93,13 @@ class UndoManager { } this.lastDeltas = null; } - + + /** + * + * @param {number} rev + * @param {boolean} [after] + * @return {{ value: string, rev: number }} + */ getSelection(rev, after) { var stack = this.selections; for (var i = stack.length; i--;) { @@ -81,11 +111,20 @@ class UndoManager { } } } - + + /** + * @return {number} + */ getRevision() { return this.$rev; } - + + /** + * + * @param {number} from + * @param {number} [to] + * @return {Ace.Delta[]} + */ getDeltas(from, to) { if (to == null) to = this.$rev + 1; var stack = this.$undoStack; @@ -101,12 +140,21 @@ class UndoManager { } return stack.slice(start, end); } - + + /** + * + * @param {number} from + * @param {number} [to] + */ getChangedRanges(from, to) { if (to == null) to = this.$rev + 1; - } - + + /** + * + * @param {number} from + * @param {number} [to] + */ getChangedLines(from, to) { if (to == null) to = this.$rev + 1; @@ -114,10 +162,8 @@ class UndoManager { /** * [Perform an undo operation on the document, reverting the last change.]{: #UndoManager.undo} - * @param {EditSession} session - * @param {Boolean} dontSelect {:dontSelect} - * - * @returns {Range} The range of the undo. + * @param {IEditSession} session + * @param {Boolean} [dontSelect] {:dontSelect} **/ undo(session, dontSelect) { this.lastDeltas = null; @@ -149,7 +195,8 @@ class UndoManager { /** * [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo} - * @param {Boolean} dontSelect {:dontSelect} + * @param {IEditSession} session + * @param {Boolean} [dontSelect] {:dontSelect} * **/ redo(session, dontSelect) { @@ -218,10 +265,11 @@ class UndoManager { canRedo() { return this.$redoStack.length > 0; } - + /** * Marks the current status clean - **/ + * @param {number} [rev] + */ bookmark(rev) { if (rev == undefined) rev = this.$rev; @@ -251,6 +299,7 @@ class UndoManager { } } + UndoManager.prototype.hasUndo = UndoManager.prototype.canUndo; UndoManager.prototype.hasRedo = UndoManager.prototype.canRedo; UndoManager.prototype.isClean = UndoManager.prototype.isAtBookmark; diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 5ca6d97f6e6..17f0dfae5ef 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IVirtualRenderer - * @type {VirtualRenderer & Ace.EventEmitter & Ace.OptionsProvider} + * @type {VirtualRenderer & EventEmitter & Ace.OptionsProvider & Ace.VirtualRendererProperties} */ /** * @@ -36,6 +36,10 @@ dom.importCssString(editorCss, "ace_editor.css", false); * @type {IVirtualRenderer} **/ class VirtualRenderer { + /** + * @type {IEditSession} + */ + session; /** * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`. * @param {Element} container The root element of the editor @@ -323,7 +327,7 @@ class VirtualRenderer { * @param {Number} [gutterWidth] The width of the gutter in pixels * @param {Number} [width] The width of the editor in pixels * @param {Number} [height] The hiehgt of the editor, in pixels - * + * @this {IVirtualRenderer} **/ onResize(force, gutterWidth, width, height) { if (this.resizing > 2) @@ -433,6 +437,7 @@ class VirtualRenderer { /** * * @param {number} width + * @this {IVirtualRenderer} */ onGutterResize(width) { var gutterWidth = this.$showGutter ? width : 0; @@ -450,6 +455,7 @@ class VirtualRenderer { /** * Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen. + * @this {IVirtualRenderer} **/ adjustWrapLimit() { var availableWidth = this.$size.scrollerWidth - this.$padding * 2; @@ -469,6 +475,7 @@ class VirtualRenderer { /** * Returns whether an animated scroll happens or not. * @returns {Boolean} + * @this {IVirtualRenderer} **/ getAnimatedScroll() { return this.$animatedScroll; @@ -610,6 +617,9 @@ class VirtualRenderer { return this.getOption("highlightGutterLine"); } + /** + * @this {IVirtualRenderer} + */ $updatePrintMargin() { if (!this.$showPrintMargin && !this.$printMarginEl) return; @@ -660,6 +670,9 @@ class VirtualRenderer { // move text input over the cursor // this is required for IME + /** + * @this {IVirtualRenderer} + */ $moveTextAreaToCursor() { if (this.$isMousePressed) return; var style = this.textarea.style; @@ -808,6 +821,7 @@ class VirtualRenderer { /** * Returns whether the horizontal scrollbar is set to be always visible. * @returns {Boolean} + * @this {IVirtualRenderer} **/ getHScrollBarAlwaysVisible() { return this.$hScrollBarAlwaysVisible; @@ -824,6 +838,7 @@ class VirtualRenderer { /** * Returns whether the horizontal scrollbar is set to be always visible. * @returns {Boolean} + * @this {IVirtualRenderer} **/ getVScrollBarAlwaysVisible() { return this.$vScrollBarAlwaysVisible; @@ -838,6 +853,9 @@ class VirtualRenderer { this.setOption("vScrollBarAlwaysVisible", alwaysVisible); } + /** + * @this {IVirtualRenderer} + */ $updateScrollBarV() { var scrollHeight = this.layerConfig.maxHeight; var scrollerHeight = this.$size.scrollerHeight; @@ -1176,6 +1194,7 @@ class VirtualRenderer { /** * @returns {boolean | undefined} + * @this {IVirtualRenderer} */ $updateLines() { if (!this.$changedLines) return; @@ -1204,6 +1223,7 @@ class VirtualRenderer { /** * * @returns {number} + * @this {IVirtualRenderer} */ $getLongestLine() { var charCount = this.session.getScreenWidth(); @@ -1467,6 +1487,12 @@ class VirtualRenderer { this.animateScrolling(initialScroll, callback); } + /** + * + * @param fromValue + * @param [callback] + * @this {IVirtualRenderer} + */ animateScrolling(fromValue, callback) { var toValue = this.scrollTop; if (!this.$animatedScroll) @@ -1591,6 +1617,7 @@ class VirtualRenderer { * @param {number} x * @param {number} y * @returns {{row: number, column: number, side: 1|-1, offsetX: number}} + * @this {IVirtualRenderer} */ pixelToScreenCoordinates(x, y) { var canvasPos; @@ -1616,6 +1643,7 @@ class VirtualRenderer { * @param {number} x * @param {number} y * @returns {Ace.Point} + * @this {IVirtualRenderer} */ screenToTextCoordinates(x, y) { var canvasPos; @@ -1678,6 +1706,7 @@ class VirtualRenderer { /** * @param {Object} composition + * @this {IVirtualRenderer} **/ showComposition(composition) { this.$composition = composition; @@ -1712,6 +1741,7 @@ class VirtualRenderer { /** * * Hides the current composition. + * @this {IVirtualRenderer} **/ hideComposition() { if (!this.$composition) @@ -2006,6 +2036,10 @@ oop.implement(VirtualRenderer.prototype, EventEmitter); config.defineOptions(VirtualRenderer.prototype, "renderer", { useResizeObserver: { + /** + * @param value + * @this {IVirtualRenderer} + */ set: function(value) { if (!value && this.$resizeObserver) { this.$resizeObserver.disconnect(); @@ -2033,6 +2067,10 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { initialValue: 80 }, printMargin: { + /** + * @param val + * @this {IVirtualRenderer} + */ set: function(val) { if (typeof val == "number") this.$printMarginColumn = val; @@ -2136,6 +2174,10 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { } }, minLines: { + /** + * @param val + * @this {IVirtualRenderer} + */ set: function(val) { if (!(this.$minLines < 0x1ffffffffffff)) this.$minLines = 0; @@ -2149,6 +2191,10 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { initialValue: 0 }, scrollPastEnd: { + /** + * @param val + * @this {IVirtualRenderer} + */ set: function(val) { val = +val || 0; if (this.$scrollPastEnd == val) From 9110b45612ebead9f4eab625d0f8b4c042f69da5 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sat, 26 Aug 2023 18:25:53 +0400 Subject: [PATCH 03/36] convert to es6 class --- src/selection.js | 335 +++++++++++++++++++++++------------------------ 1 file changed, 166 insertions(+), 169 deletions(-) diff --git a/src/selection.js b/src/selection.js index 12cb18ca525..1400695c2ff 100644 --- a/src/selection.js +++ b/src/selection.js @@ -23,69 +23,65 @@ var Range = require("./range").Range; * * @event changeSelection **/ -/** - * Creates a new `Selection` object. - * @param {EditSession} session The session to use - * - * @constructor - **/ -var Selection = function(session) { - this.session = session; - this.doc = session.getDocument(); - - this.clearSelection(); - this.cursor = this.lead = this.doc.createAnchor(0, 0); - this.anchor = this.doc.createAnchor(0, 0); - this.$silent = false; - - var self = this; - this.cursor.on("change", function(e) { - self.$cursorChanged = true; - if (!self.$silent) - self._emit("changeCursor"); - if (!self.$isEmpty && !self.$silent) - self._emit("changeSelection"); - if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column) - self.$desiredColumn = null; - }); - - this.anchor.on("change", function() { - self.$anchorChanged = true; - if (!self.$isEmpty && !self.$silent) - self._emit("changeSelection"); - }); -}; - -(function() { - - oop.implement(this, EventEmitter); - +class Selection { + /** + * Creates a new `Selection` object. + * @param {EditSession} session The session to use + * + **/ + constructor(session) { + this.session = session; + this.doc = session.getDocument(); + + this.clearSelection(); + this.cursor = this.lead = this.doc.createAnchor(0, 0); + this.anchor = this.doc.createAnchor(0, 0); + this.$silent = false; + + var self = this; + this.cursor.on("change", function(e) { + self.$cursorChanged = true; + if (!self.$silent) + self._emit("changeCursor"); + if (!self.$isEmpty && !self.$silent) + self._emit("changeSelection"); + if (!self.$keepDesiredColumnOnChange && e.old.column != e.value.column) + self.$desiredColumn = null; + }); + + this.anchor.on("change", function() { + self.$anchorChanged = true; + if (!self.$isEmpty && !self.$silent) + self._emit("changeSelection"); + }); + } + /** * Returns `true` if the selection is empty. * @returns {Boolean} **/ - this.isEmpty = function() { + isEmpty() { return this.$isEmpty || ( this.anchor.row == this.lead.row && this.anchor.column == this.lead.column ); - }; + } /** * Returns `true` if the selection is a multi-line. * @returns {Boolean} **/ - this.isMultiLine = function() { + isMultiLine() { return !this.$isEmpty && this.anchor.row != this.cursor.row; - }; + } /** * Returns an object containing the `row` and `column` current position of the cursor. * @returns {Object} **/ - this.getCursor = function() { + getCursor() { return this.lead.getPosition(); - }; + } /** * Sets the row and column position of the anchor. This function also emits the `'changeSelection'` event. @@ -93,16 +89,11 @@ var Selection = function(session) { * @param {Number} column The new column * **/ - this.setAnchor = function(row, column) { + setAnchor(row, column) { this.$isEmpty = false; this.anchor.setPosition(row, column); - }; + } - /** - * Left for backward compatibility - * @deprecated - */ - this.setSelectionAnchor = this.setAnchor; /** * Returns an object containing the `row` and `column` of the calling selection anchor. @@ -110,42 +101,37 @@ var Selection = function(session) { * @returns {Object} * @related Anchor.getPosition **/ - this.getAnchor = function() { + getAnchor() { if (this.$isEmpty) return this.getSelectionLead(); return this.anchor.getPosition(); - }; + } - /** - * Left for backward compatibility - * @deprecated - */ - this.getSelectionAnchor = this.getAnchor; /** * Returns an object containing the `row` and `column` of the calling selection lead. * @returns {Object} **/ - this.getSelectionLead = function() { + getSelectionLead() { return this.lead.getPosition(); - }; + } /** * Returns `true` if the selection is going backwards in the document. * @returns {Boolean} **/ - this.isBackwards = function() { + isBackwards() { var anchor = this.anchor; var lead = this.lead; return (anchor.row > lead.row || (anchor.row == lead.row && anchor.column > lead.column)); - }; + } /** * [Returns the [[Range]] for the selected text.]{: #Selection.getRange} * @returns {Range} **/ - this.getRange = function() { + getRange() { var anchor = this.anchor; var lead = this.lead; @@ -155,41 +141,38 @@ var Selection = function(session) { return this.isBackwards() ? Range.fromPoints(lead, anchor) : Range.fromPoints(anchor, lead); - }; + } /** * [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection} **/ - this.clearSelection = function() { + clearSelection() { if (!this.$isEmpty) { this.$isEmpty = true; this._emit("changeSelection"); } - }; + } /** * Selects all the text in the document. **/ - this.selectAll = function() { + selectAll() { this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE); - }; + } /** * Sets the selection to the provided range. * @param {Range} range The range of text to select * @param {Boolean} reverse Indicates if the range should go backwards (`true`) or not * - * @method setSelectionRange - * @alias setRange **/ - this.setRange = - this.setSelectionRange = function(range, reverse) { + setRange(range, reverse) { var start = reverse ? range.end : range.start; var end = reverse ? range.start : range.end; this.$setSelection(start.row, start.column, end.row, end.column); - }; + } - this.$setSelection = function(anchorRow, anchorColumn, cursorRow, cursorColumn) { + $setSelection(anchorRow, anchorColumn, cursorRow, cursorColumn) { if (this.$silent) return; var wasEmpty = this.$isEmpty; @@ -204,36 +187,36 @@ var Selection = function(session) { this._emit("changeCursor"); if (this.$cursorChanged || this.$anchorChanged || wasEmpty != this.$isEmpty || wasMultiselect) this._emit("changeSelection"); - }; + } - this.$moveSelection = function(mover) { + $moveSelection(mover) { var lead = this.lead; if (this.$isEmpty) this.setSelectionAnchor(lead.row, lead.column); mover.call(this); - }; + } /** * Moves the selection cursor to the indicated row and column. * @param {Number} row The row to select to * @param {Number} column The column to select to **/ - this.selectTo = function(row, column) { + selectTo(row, column) { this.$moveSelection(function() { this.moveCursorTo(row, column); }); - }; + } /** * Moves the selection cursor to the row and column indicated by `pos`. * @param {Object} pos An object containing the row and column **/ - this.selectToPosition = function(pos) { + selectToPosition(pos) { this.$moveSelection(function() { this.moveCursorToPosition(pos); }); - }; + } /** * Moves the selection cursor to the indicated row and column. @@ -241,122 +224,122 @@ var Selection = function(session) { * @param {Number} column The column to select to * **/ - this.moveTo = function(row, column) { + moveTo(row, column) { this.clearSelection(); this.moveCursorTo(row, column); - }; + } /** * Moves the selection cursor to the row and column indicated by `pos`. * @param {Object} pos An object containing the row and column **/ - this.moveToPosition = function(pos) { + moveToPosition(pos) { this.clearSelection(); this.moveCursorToPosition(pos); - }; + } /** * Moves the selection up one row. **/ - this.selectUp = function() { + selectUp() { this.$moveSelection(this.moveCursorUp); - }; + } /** * Moves the selection down one row. **/ - this.selectDown = function() { + selectDown() { this.$moveSelection(this.moveCursorDown); - }; + } /** * Moves the selection right one column. **/ - this.selectRight = function() { + selectRight() { this.$moveSelection(this.moveCursorRight); - }; + } /** * Moves the selection left one column. **/ - this.selectLeft = function() { + selectLeft() { this.$moveSelection(this.moveCursorLeft); - }; + } /** * Moves the selection to the beginning of the current line. **/ - this.selectLineStart = function() { + selectLineStart() { this.$moveSelection(this.moveCursorLineStart); - }; + } /** * Moves the selection to the end of the current line. **/ - this.selectLineEnd = function() { + selectLineEnd() { this.$moveSelection(this.moveCursorLineEnd); - }; + } /** * Moves the selection to the end of the file. **/ - this.selectFileEnd = function() { + selectFileEnd() { this.$moveSelection(this.moveCursorFileEnd); - }; + } /** * Moves the selection to the start of the file. **/ - this.selectFileStart = function() { + selectFileStart() { this.$moveSelection(this.moveCursorFileStart); - }; + } /** * Moves the selection to the first word on the right. **/ - this.selectWordRight = function() { + selectWordRight() { this.$moveSelection(this.moveCursorWordRight); - }; + } /** * Moves the selection to the first word on the left. **/ - this.selectWordLeft = function() { + selectWordLeft() { this.$moveSelection(this.moveCursorWordLeft); - }; + } /** * Moves the selection to highlight the entire word. * @related EditSession.getWordRange **/ - this.getWordRange = function(row, column) { + getWordRange(row, column) { if (typeof column == "undefined") { var cursor = row || this.lead; row = cursor.row; column = cursor.column; } return this.session.getWordRange(row, column); - }; + } /** * Selects an entire word boundary. **/ - this.selectWord = function() { + selectWord() { this.setSelectionRange(this.getWordRange()); - }; + } /** * Selects a word, including its right whitespace. * @related EditSession.getAWordRange **/ - this.selectAWord = function() { + selectAWord() { var cursor = this.getCursor(); var range = this.session.getAWordRange(cursor.row, cursor.column); this.setSelectionRange(range); - }; + } - this.getLineRange = function(row, excludeLastChar) { + getLineRange(row, excludeLastChar) { var rowStart = typeof row == "number" ? row : this.lead.row; var rowEnd; @@ -371,28 +354,28 @@ var Selection = function(session) { return new Range(rowStart, 0, rowEnd, this.session.getLine(rowEnd).length); else return new Range(rowStart, 0, rowEnd + 1, 0); - }; + } /** * Selects the entire line. **/ - this.selectLine = function() { + selectLine() { this.setSelectionRange(this.getLineRange()); - }; + } /** * Moves the cursor up one row. **/ - this.moveCursorUp = function() { + moveCursorUp() { this.moveCursorBy(-1, 0); - }; + } /** * Moves the cursor down one row. **/ - this.moveCursorDown = function() { + moveCursorDown() { this.moveCursorBy(1, 0); - }; + } /** * @@ -401,7 +384,7 @@ var Selection = function(session) { * @param {Number} tabSize the tab size * @param {Number} direction 1 for right, -1 for left */ - this.wouldMoveIntoSoftTab = function(cursor, tabSize, direction) { + wouldMoveIntoSoftTab(cursor, tabSize, direction) { var start = cursor.column; var end = cursor.column + tabSize; @@ -410,12 +393,12 @@ var Selection = function(session) { end = cursor.column; } return this.session.isTabStop(cursor) && this.doc.getLine(cursor.row).slice(start, end).split(" ").length-1 == tabSize; - }; + } /** * Moves the cursor left one column. **/ - this.moveCursorLeft = function() { + moveCursorLeft() { var cursor = this.lead.getPosition(), fold; @@ -435,12 +418,12 @@ var Selection = function(session) { this.moveCursorBy(0, -1); } } - }; + } /** * Moves the cursor right one column. **/ - this.moveCursorRight = function() { + moveCursorRight() { var cursor = this.lead.getPosition(), fold; if (fold = this.session.getFoldAt(cursor.row, cursor.column, 1)) { @@ -460,12 +443,12 @@ var Selection = function(session) { this.moveCursorBy(0, 1); } } - }; + } /** * Moves the cursor to the start of the line. **/ - this.moveCursorLineStart = function() { + moveCursorLineStart() { var row = this.lead.row; var column = this.lead.column; var screenRow = this.session.documentToScreenRow(row, column); @@ -484,12 +467,12 @@ var Selection = function(session) { if (leadingSpace[0].length != column && !this.session.$useEmacsStyleLineStart) firstColumnPosition.column += leadingSpace[0].length; this.moveCursorToPosition(firstColumnPosition); - }; + } /** * Moves the cursor to the end of the line. **/ - this.moveCursorLineEnd = function() { + moveCursorLineEnd() { var lead = this.lead; var lineEnd = this.session.getDocumentLastRowColumnPosition(lead.row, lead.column); if (this.lead.column == lineEnd.column) { @@ -502,28 +485,28 @@ var Selection = function(session) { } this.moveCursorTo(lineEnd.row, lineEnd.column); - }; + } /** * Moves the cursor to the end of the file. **/ - this.moveCursorFileEnd = function() { + moveCursorFileEnd() { var row = this.doc.getLength() - 1; var column = this.doc.getLine(row).length; this.moveCursorTo(row, column); - }; + } /** * Moves the cursor to the start of the file. **/ - this.moveCursorFileStart = function() { + moveCursorFileStart() { this.moveCursorTo(0, 0); - }; + } /** * Moves the cursor to the word on the right. **/ - this.moveCursorLongWordRight = function() { + moveCursorLongWordRight() { var row = this.lead.row; var column = this.lead.column; var line = this.doc.getLine(row); @@ -562,13 +545,13 @@ var Selection = function(session) { } this.moveCursorTo(row, column); - }; + } /** * * Moves the cursor to the word on the left. **/ - this.moveCursorLongWordLeft = function() { + moveCursorLongWordLeft() { var row = this.lead.row; var column = this.lead.column; @@ -611,9 +594,9 @@ var Selection = function(session) { } this.moveCursorTo(row, column); - }; + } - this.$shortWordEndIndex = function(rightOfCursor) { + $shortWordEndIndex(rightOfCursor) { var index = 0, ch; var whitespaceRe = /\s/; var tokenRe = this.session.tokenRe; @@ -647,9 +630,9 @@ var Selection = function(session) { tokenRe.lastIndex = 0; return index; - }; + } - this.moveCursorShortWordRight = function() { + moveCursorShortWordRight() { var row = this.lead.row; var column = this.lead.column; var line = this.doc.getLine(row); @@ -674,9 +657,9 @@ var Selection = function(session) { var index = this.$shortWordEndIndex(rightOfCursor); this.moveCursorTo(row, column + index); - }; + } - this.moveCursorShortWordLeft = function() { + moveCursorShortWordLeft() { var row = this.lead.row; var column = this.lead.column; @@ -700,21 +683,21 @@ var Selection = function(session) { var index = this.$shortWordEndIndex(leftOfCursor); return this.moveCursorTo(row, column - index); - }; + } - this.moveCursorWordRight = function() { + moveCursorWordRight() { if (this.session.$selectLongWords) this.moveCursorLongWordRight(); else this.moveCursorShortWordRight(); - }; + } - this.moveCursorWordLeft = function() { + moveCursorWordLeft() { if (this.session.$selectLongWords) this.moveCursorLongWordLeft(); else this.moveCursorShortWordLeft(); - }; + } /** * Moves the cursor to position indicated by the parameters. Negative numbers move the cursor backwards in the document. @@ -723,7 +706,7 @@ var Selection = function(session) { * * @related EditSession.documentToScreenPosition **/ - this.moveCursorBy = function(rows, chars) { + moveCursorBy(rows, chars) { var screenPos = this.session.documentToScreenPosition( this.lead.row, this.lead.column @@ -763,15 +746,15 @@ var Selection = function(session) { // move the cursor and update the desired column this.moveCursorTo(docPos.row, docPos.column + chars, chars === 0); - }; + } /** * Moves the selection to the position indicated by its `row` and `column`. * @param {Object} position The position to move to **/ - this.moveCursorToPosition = function(position) { + moveCursorToPosition(position) { this.moveCursorTo(position.row, position.column); - }; + } /** * Moves the cursor to the row and column provided. [If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.]{: #preventUpdateBoolDesc} @@ -780,7 +763,7 @@ var Selection = function(session) { * @param {Boolean} keepDesiredColumn [If `true`, the cursor move does not respect the previous column]{: #preventUpdateBool} * **/ - this.moveCursorTo = function(row, column, keepDesiredColumn) { + moveCursorTo(row, column, keepDesiredColumn) { // Ensure the row/column is not inside of a fold. var fold = this.session.getFoldAt(row, column, 1); if (fold) { @@ -802,7 +785,7 @@ var Selection = function(session) { if (!keepDesiredColumn) this.$desiredColumn = null; - }; + } /** * Moves the cursor to the screen position indicated by row and column. {:preventUpdateBoolDesc} @@ -811,23 +794,23 @@ var Selection = function(session) { * @param {Boolean} keepDesiredColumn {:preventUpdateBool} * **/ - this.moveCursorToScreen = function(row, column, keepDesiredColumn) { + moveCursorToScreen(row, column, keepDesiredColumn) { var pos = this.session.screenToDocumentPosition(row, column); this.moveCursorTo(pos.row, pos.column, keepDesiredColumn); - }; + } // remove listeners from document - this.detach = function() { + detach() { this.lead.detach(); this.anchor.detach(); - }; + } - this.fromOrientedRange = function(range) { + fromOrientedRange(range) { this.setSelectionRange(range, range.cursor == range.start); this.$desiredColumn = range.desiredColumn || this.$desiredColumn; - }; + } - this.toOrientedRange = function(range) { + toOrientedRange(range) { var r = this.getRange(); if (range) { range.start.column = r.start.column; @@ -841,7 +824,7 @@ var Selection = function(session) { range.cursor = this.isBackwards() ? range.start : range.end; range.desiredColumn = this.$desiredColumn; return range; - }; + } /** * Saves the current cursor position and calls `func` that can change the cursor @@ -851,7 +834,7 @@ var Selection = function(session) { * @returns {Range} * **/ - this.getRangeOfMovements = function(func) { + getRangeOfMovements(func) { var start = this.getCursor(); try { func(this); @@ -862,9 +845,9 @@ var Selection = function(session) { } finally { this.moveCursorToPosition(start); } - }; + } - this.toJSON = function() { + toJSON() { if (this.rangeCount) { var data = this.ranges.map(function(r) { var r1 = r.clone(); @@ -876,9 +859,9 @@ var Selection = function(session) { data.isBackwards = this.isBackwards(); } return data; - }; + } - this.fromJSON = function(data) { + fromJSON(data) { if (data.start == undefined) { if (this.rangeList && data.length > 1) { this.toSingleRange(data[0]); @@ -896,9 +879,9 @@ var Selection = function(session) { if (this.rangeList) this.toSingleRange(data); this.setSelectionRange(data, data.isBackwards); - }; + } - this.isEqual = function(data) { + isEqual(data) { if ((data.length || this.rangeCount) && data.length != this.rangeCount) return false; if (!data.length || !this.ranges) @@ -909,8 +892,22 @@ var Selection = function(session) { return false; } return true; - }; + } + +} + +/** + * Left for backward compatibility + * @deprecated + */ +Selection.prototype.setSelectionAnchor = Selection.prototype.setAnchor; +/** + * Left for backward compatibility + * @deprecated + */ +Selection.prototype.getSelectionAnchor = Selection.prototype.getAnchor; -}).call(Selection.prototype); +Selection.prototype.setSelectionRange = Selection.prototype.setRange; +oop.implement(Selection.prototype, EventEmitter); exports.Selection = Selection; From ab962b95d9fdc4c347a9ad4089b66eddb4569568 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 27 Aug 2023 18:24:44 +0400 Subject: [PATCH 04/36] continue providing types --- ace.d.ts | 129 +++++++++++++------------ src/ace.js | 6 +- src/anchor.js | 6 +- src/autocomplete/popup.js | 181 ++++++++++++++++++++++-------------- src/background_tokenizer.js | 40 ++++++-- src/bidihandler.js | 7 +- src/config.js | 39 +++++++- src/document.js | 14 ++- src/edit_session.js | 27 ++++-- src/lib/app_config.js | 43 +++++++-- src/lib/bidiutil.js | 6 +- src/line_widgets.js | 99 +++++++++++++++++--- src/placeholder.js | 35 ++++--- src/tooltip.js | 8 +- tsconfig.json | 1 + 15 files changed, 445 insertions(+), 196 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index ed68d231ccd..585c62574aa 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,7 +1,68 @@ /// + declare namespace Ace { + interface AcePopupProperties { + setSelectOnHover?: (val: boolean) => void, + setRow?: (line: number) => void, + getRow?: () => number, + getHoveredRow?: () => number, + filterText?: string, + isOpen?: boolean, + isTopdown?: boolean, + autoSelect?: boolean, + data?: Completion[], + setData?: (data: Completion[], filterText: string) => void, + getData?: (row: number) => Completion, + hide?: () => void, + anchor?: "top" | "bottom", + anchorPosition?: Point, + tryShow?: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, + $borderSize?: number, + show?: (pos: any, lineHeight: number, topdownOnly: boolean) => void, + goTo?: (where: AcePopupNavigation) => void, + getTextLeftOffset?: () => number, + $imageSize?: number, + anchorPos?: any + } + interface ISelection { + session: IEditSession; + doc: IDocument; + cursor: Anchor; + anchor: Anchor; + $silent: boolean; + lead: Anchor; + $cursorChanged?:boolean; + $isEmpty?:boolean; + } + interface IRange { + start: Point; + end: Point; + } + interface LineWidget { + el: HTMLElement; + rowCount: number; + hidden: boolean; + _inDocument: boolean; + column?: number; + row?: number; + $oldWidget?: LineWidget, + session: IEditSession, + html?: string, + text?: string, + className?: string, + coverGutter?: boolean, + pixelHeight?: number, + $fold?: Fold, + editor: IEditor, + coverLine?: boolean, + fixedWidth?: boolean, + fullWidth?: boolean, + screenWidth?: number, + rowsAbove?: number, + } + interface EditorProperties { $mergeUndoDeltas?: any, $highlightSelectedWord?: boolean, @@ -14,6 +75,7 @@ declare namespace Ace { $copyWithEmptySelection?: any $selectionStyle?: string, env?: any; + widgetManager?: LineWidgets } interface EditSessionProperties { @@ -36,6 +98,12 @@ declare namespace Ace { scrollTop: number }, lineWidgetsWidth?: number, + $getWidgetScreenLength?: () => number, + _changedWidgets?: any, + $options:any, + $wrapMethod?: any, + $enableVarChar?: any, + $wrap?:any } interface EditorMultiSelectProperties { @@ -455,39 +523,7 @@ declare namespace Ace { pos: Point, prefix: string): Completion[]; } - - type AfterLoadCallback = (err: Error | null, module: unknown) => void; - type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; - - interface Config { - get?(key: string): any; - - set?(key: string, value: any): void; - - all?(): { [key: string]: any }; - - moduleUrl?(name: string, component?: string): string; - - setModuleUrl?(name: string, subst: string): string; - - setLoader?(cb: LoaderFunction): void; - - setModuleLoader?(name: string, onLoad: Function): void; - - loadModule?(moduleName: string | [string, string], - onLoad?: (module: any) => void): void; - - init?(packaged: any): any; - - defineOptions?(obj: any, path: string, options: { [key: string]: any }): Config; - - resetOptions?(obj: any): void; - - setDefaultValue?(path: string, name: string, value: any): void; - - setDefaultValues?(path: string, optionHash: { [key: string]: any }): void; - } - + interface OptionsBase { [key: string]: any; } @@ -875,30 +911,7 @@ declare namespace Ace { setAriaOption(activeDescendant: string, role: string): void; } - - - class Editor { - once?(name: string, callback: Function): void; - - setDefaultHandler?(name: string, callback: Function): void; - - removeDefaultHandler?(name: string, callback: Function): void; - - on(name: string, callback: Function, capturing?: boolean): void; - - addEventListener?(name: string, callback: Function, capturing?: boolean): void; - - off?(name: string, callback: Function): void; - - removeListener?(name: string, callback: Function): void; - - removeEventListener?(name: string, callback: Function): void; - - removeAllListeners?(name?: string): void; - - _signal?(eventName: string, e: any): void; - } - + type CompleterCallback = (error: any, completions: Completion[]) => void; interface Completer { @@ -1015,9 +1028,7 @@ declare const config: Ace.Config; declare function require(name: string): any; -declare function edit(el: Element | string, options?: Partial): Ace.Editor; -declare function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; diff --git a/src/ace.js b/src/ace.js index 6e1a0246db9..542232348ec 100644 --- a/src/ace.js +++ b/src/ace.js @@ -87,14 +87,12 @@ exports.edit = function(el, options) { * Creates a new [[EditSession]], and returns the associated [[Document]]. * @param {import('./document').Document | String} text {:textParam} * @param {import("./edit_session").TextMode} [mode] {:modeParam} - * + * @returns {IEditSession} **/ exports.createEditSession = function(text, mode) { - /** - * @type {IEditSession} - */ var doc = new EditSession(text, mode); doc.setUndoManager(new UndoManager()); + // @ts-ignore return doc; }; exports.Range = Range; diff --git a/src/anchor.js b/src/anchor.js index ff94384ec44..acf081add15 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -3,6 +3,10 @@ * @typedef IDocument * @type {import("./document").Document} */ +/** + * @typedef IAnchor + * @type {Anchor & Ace.EventEmitter & {markerId?: number}} + */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -77,7 +81,7 @@ class Anchor { * @param {Number} row The row index to move the anchor to * @param {Number} column The column index to move the anchor to * @param {Boolean} [noClip] Identifies if you want the position to be clipped - * + * @this {IAnchor} **/ setPosition(row, column, noClip) { var pos; diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 2749fd2009e..18c329d8210 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -1,5 +1,14 @@ "use strict"; - +/** + * + * @typedef IEditor + * @type {import("../editor").IEditor} + */ +/** + * @typedef IAcePopup + * @type {IEditor & Ace.AcePopupProperties} + * @export + */ var Renderer = require("../virtual_renderer").VirtualRenderer; var Editor = require("../editor").Editor; var Range = require("../range").Range; @@ -8,11 +17,16 @@ var lang = require("../lib/lang"); var dom = require("../lib/dom"); var nls = require("../config").nls; -var getAriaId = function(index) { +var getAriaId = function (index) { return `suggest-aria-id:${index}`; }; -var $singleLineEditor = function(el) { +/** + * + * @param {HTMLElement} el + * @return {IEditor} + */ +var $singleLineEditor = function (el) { var renderer = new Renderer(el); renderer.$maxLines = 4; @@ -32,14 +46,19 @@ var $singleLineEditor = function(el) { /** * This object is used in some places where needed to show popups - like prompt; autocomplete etc. + * @type {IAcePopup} */ class AcePopup { /** * Creates and renders single line editor in popup window. If `parentNode` param is isset, then attaching it to this element. - * @param {Element} parentNode + * @param {Element} [parentNode] */ constructor(parentNode) { var el = dom.createElement("div"); + /** + * + * @type {IAcePopup} + */ var popup = $singleLineEditor(el); if (parentNode) { @@ -57,7 +76,8 @@ class AcePopup { popup.setOption("displayIndentGuides", false); popup.setOption("dragDelay", 150); - var noop = function(){}; + var noop = function () { + }; popup.focus = noop; popup.$isFocused = true; @@ -73,7 +93,7 @@ class AcePopup { popup.session.highlight(""); popup.session.$searchHighlight.clazz = "ace_highlight-marker"; - popup.on("mousedown", function(e) { + popup.on("mousedown", function (e) { var pos = e.getDocumentPosition(); popup.selection.moveToPosition(pos); selectionMarker.start.row = selectionMarker.end.row = pos.row; @@ -81,19 +101,20 @@ class AcePopup { }); var lastMouseEvent; - var hoverMarker = new Range(-1,0,-1,Infinity); - var selectionMarker = new Range(-1,0,-1,Infinity); + var hoverMarker = new Range(-1, 0, -1, Infinity); + var selectionMarker = new Range(-1, 0, -1, Infinity); selectionMarker.id = popup.session.addMarker(selectionMarker, "ace_active-line", "fullLine"); - popup.setSelectOnHover = function(val) { + popup.setSelectOnHover = function (val) { if (!val) { hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); - } else if (hoverMarker.id) { + } + else if (hoverMarker.id) { popup.session.removeMarker(hoverMarker.id); hoverMarker.id = null; } }; popup.setSelectOnHover(false); - popup.on("mousemove", function(e) { + popup.on("mousemove", function (e) { if (!lastMouseEvent) { lastMouseEvent = e; return; @@ -105,21 +126,19 @@ class AcePopup { lastMouseEvent.scrollTop = popup.renderer.scrollTop; var row = lastMouseEvent.getDocumentPosition().row; if (hoverMarker.start.row != row) { - if (!hoverMarker.id) - popup.setRow(row); + if (!hoverMarker.id) popup.setRow(row); setHoverMarker(row); } }); - popup.renderer.on("beforeRender", function() { + popup.renderer.on("beforeRender", function () { if (lastMouseEvent && hoverMarker.start.row != -1) { lastMouseEvent.$pos = null; var row = lastMouseEvent.getDocumentPosition().row; - if (!hoverMarker.id) - popup.setRow(row); + if (!hoverMarker.id) popup.setRow(row); setHoverMarker(row, true); } }); - popup.renderer.on("afterRender", function() { + popup.renderer.on("afterRender", function () { var row = popup.getRow(); var t = popup.renderer.$textLayer; var selected = t.element.childNodes[row - t.config.firstRow]; @@ -139,20 +158,21 @@ class AcePopup { selected.setAttribute("role", "option"); selected.setAttribute("aria-label", popup.getData(row).value); selected.setAttribute("aria-setsize", popup.data.length); - selected.setAttribute("aria-posinset", row+1); + selected.setAttribute("aria-posinset", row + 1); selected.setAttribute("aria-describedby", "doc-tooltip"); } }); - var hideHoverMarker = function() { setHoverMarker(-1); }; - var setHoverMarker = function(row, suppressRedraw) { + var hideHoverMarker = function () { + setHoverMarker(-1); + }; + var setHoverMarker = function (row, suppressRedraw) { if (row !== hoverMarker.start.row) { hoverMarker.start.row = hoverMarker.end.row = row; - if (!suppressRedraw) - popup.session._emit("changeBackMarker"); + if (!suppressRedraw) popup.session._emit("changeBackMarker"); popup._emit("changeHoverMarker"); } }; - popup.getHoveredRow = function() { + popup.getHoveredRow = function () { return hoverMarker.start.row; }; @@ -160,24 +180,24 @@ class AcePopup { popup.on("hide", hideHoverMarker); popup.on("changeSelection", hideHoverMarker); - popup.session.doc.getLength = function() { + popup.session.doc.getLength = function () { return popup.data.length; }; - popup.session.doc.getLine = function(i) { + popup.session.doc.getLine = function (i) { var data = popup.data[i]; - if (typeof data == "string") - return data; + if (typeof data == "string") return data; return (data && data.value) || ""; }; var bgTokenizer = popup.session.bgTokenizer; - bgTokenizer.$tokenizeRow = function(row) { + bgTokenizer.$tokenizeRow = function (row) { + /** + * @type {Ace.Completion} + */ var data = popup.data[row]; var tokens = []; - if (!data) - return tokens; - if (typeof data == "string") - data = {value: data}; + if (!data) return tokens; + if (typeof data == "string") data = {value: data}; var caption = data.caption || data.value || data.name; function addToken(value, className) { @@ -204,18 +224,25 @@ class AcePopup { } addToken(caption.slice(lastIndex, caption.length), ""); - tokens.push({type: "completion-spacer", value: " "}); - if (data.meta) - tokens.push({type: "completion-meta", value: data.meta}); - if (data.message) - tokens.push({type: "completion-message", value: data.message}); + tokens.push({ + type: "completion-spacer", + value: " " + }); + if (data.meta) tokens.push({ + type: "completion-meta", + value: data.meta + }); + if (data.message) tokens.push({ + type: "completion-message", + value: data.message + }); return tokens; }; bgTokenizer.$updateOnChange = noop; bgTokenizer.start = noop; - popup.session.$computeWidth = function() { + popup.session.$computeWidth = function () { return this.screenWidth = 0; }; @@ -226,38 +253,36 @@ class AcePopup { popup.filterText = ""; popup.data = []; - popup.setData = function(list, filterText) { + popup.setData = function (list, filterText) { popup.filterText = filterText || ""; popup.setValue(lang.stringRepeat("\n", list.length), -1); popup.data = list || []; popup.setRow(0); }; - popup.getData = function(row) { + popup.getData = function (row) { return popup.data[row]; }; - popup.getRow = function() { + popup.getRow = function () { return selectionMarker.start.row; }; - popup.setRow = function(line) { + popup.setRow = function (line) { line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line)); if (selectionMarker.start.row != line) { popup.selection.clearSelection(); selectionMarker.start.row = selectionMarker.end.row = line || 0; popup.session._emit("changeBackMarker"); popup.moveCursorTo(line || 0, 0); - if (popup.isOpen) - popup._signal("select"); + if (popup.isOpen) popup._signal("select"); } }; - popup.on("changeSelection", function() { - if (popup.isOpen) - popup.setRow(popup.selection.lead.row); + popup.on("changeSelection", function () { + if (popup.isOpen) popup.setRow(popup.selection.lead.row); popup.renderer.scrollCursorIntoView(); }); - popup.hide = function() { + popup.hide = function () { this.container.style.display = "none"; popup.anchorPos = null; popup.anchor = null; @@ -272,17 +297,15 @@ class AcePopup { * If the anchor is not specified it tries to align to bottom and right as much as possible. * If the popup does not have enough space to be rendered with the given anchors, it returns false without rendering the popup. * The forceShow flag can be used to render the popup in these cases, which slides the popup so it entirely fits on the screen. - * @param {Point} pos + * @param {any} pos * @param {number} lineHeight * @param {"top" | "bottom" | undefined} anchor * @param {boolean} forceShow * @returns {boolean} */ - popup.tryShow = function(pos, lineHeight, anchor, forceShow) { - if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor && - popup.anchorPos.top === pos.top && popup.anchorPos.left === pos.left && - popup.anchor === anchor - ) { + popup.tryShow = function (pos, lineHeight, anchor, forceShow) { + if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor && popup.anchorPos.top === pos.top + && popup.anchorPos.left === pos.left && popup.anchor === anchor) { return true; } @@ -292,14 +315,19 @@ class AcePopup { var renderer = this.renderer; // var maxLines = Math.min(renderer.$maxLines, this.session.getLength()); var maxH = renderer.$maxLines * lineHeight * 1.4; - var dims = { top: 0, bottom: 0, left: 0 }; + var dims = { + top: 0, + bottom: 0, + left: 0 + }; var spaceBelow = screenHeight - pos.top - 3 * this.$borderSize - lineHeight; var spaceAbove = pos.top - 3 * this.$borderSize; if (!anchor) { if (spaceAbove <= spaceBelow || spaceBelow >= maxH) { anchor = "bottom"; - } else { + } + else { anchor = "top"; } } @@ -307,7 +335,8 @@ class AcePopup { if (anchor === "top") { dims.bottom = pos.top - this.$borderSize; dims.top = dims.bottom - maxH; - } else if (anchor === "bottom") { + } + else if (anchor === "bottom") { dims.top = pos.top + lineHeight + this.$borderSize; dims.bottom = dims.top + maxH; } @@ -321,10 +350,12 @@ class AcePopup { if (!fitsX) { if (anchor === "top") { renderer.$maxPixelHeight = spaceAbove; - } else { + } + else { renderer.$maxPixelHeight = spaceBelow; } - } else { + } + else { renderer.$maxPixelHeight = null; } @@ -333,7 +364,8 @@ class AcePopup { el.style.top = ""; el.style.bottom = (screenHeight - dims.bottom) + "px"; popup.isTopdown = false; - } else { + } + else { el.style.top = dims.top + "px"; el.style.bottom = ""; popup.isTopdown = true; @@ -342,8 +374,7 @@ class AcePopup { el.style.display = ""; var left = pos.left; - if (left + el.offsetWidth > screenWidth) - left = screenWidth - el.offsetWidth; + if (left + el.offsetWidth > screenWidth) left = screenWidth - el.offsetWidth; el.style.left = left + "px"; el.style.right = ""; @@ -360,26 +391,34 @@ class AcePopup { return true; }; - popup.show = function(pos, lineHeight, topdownOnly) { + popup.show = function (pos, lineHeight, topdownOnly) { this.tryShow(pos, lineHeight, topdownOnly ? "bottom" : undefined, true); }; - popup.goTo = function(where) { + popup.goTo = function (where) { var row = this.getRow(); var max = this.session.getLength() - 1; - switch(where) { - case "up": row = row <= 0 ? max : row - 1; break; - case "down": row = row >= max ? -1 : row + 1; break; - case "start": row = 0; break; - case "end": row = max; break; + switch (where) { + case "up": + row = row <= 0 ? max : row - 1; + break; + case "down": + row = row >= max ? -1 : row + 1; + break; + case "start": + row = 0; + break; + case "end": + row = max; + break; } this.setRow(row); }; - popup.getTextLeftOffset = function() { + popup.getTextLeftOffset = function () { return this.$borderSize + this.renderer.$padding + this.$imageSize; }; @@ -388,7 +427,7 @@ class AcePopup { return popup; } -} +} dom.importCssString(` .ace_editor.ace_autocomplete .ace_marker-layer .ace_active-line { diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 2729e38d93e..9518617a0fe 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -1,5 +1,20 @@ "use strict"; - +/** + * @typedef IDocument + * @type {import("./document").IDocument} + */ +/** + * @typedef IEditor + * @type {import("./editor").IEditor} + */ +/** + * @typedef ITokenizer + * @type {import("./tokenizer").Tokenizer} + */ +/** + * @typedef IBackgroundTokenizer + * @type {BackgroundTokenizer & Ace.EventEmitter} + */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -13,10 +28,13 @@ class BackgroundTokenizer { /** * Creates a new `BackgroundTokenizer` object. - * @param {Tokenizer} tokenizer The tokenizer to use - * @param {Editor} editor The editor to associate with + * @param {ITokenizer} tokenizer The tokenizer to use + * @param {IEditor} editor The editor to associate with **/ constructor(tokenizer, editor) { + /** + * @type {false|number} + */ this.running = false; this.lines = []; this.states = []; @@ -66,7 +84,7 @@ class BackgroundTokenizer { /** * Sets a new tokenizer for this object. - * @param {Tokenizer} tokenizer The new tokenizer to use + * @param {ITokenizer} tokenizer The new tokenizer to use **/ setTokenizer(tokenizer) { this.tokenizer = tokenizer; @@ -78,7 +96,7 @@ class BackgroundTokenizer { /** * Sets a new document to associate with this object. - * @param {Document} doc The new document to associate with + * @param {IDocument} doc The new document to associate with **/ setDocument(doc) { this.doc = doc; @@ -99,6 +117,7 @@ class BackgroundTokenizer { * Emits the `'update'` event. `firstRow` and `lastRow` are used to define the boundaries of the region to be updated. * @param {Number} firstRow The starting row region * @param {Number} lastRow The final row region + * @this {IBackgroundTokenizer} **/ fireUpdateEvent(firstRow, lastRow) { var data = { @@ -132,6 +151,9 @@ class BackgroundTokenizer { this.running = setTimeout(this.$worker, 700); } + /** + * @param {Ace.Delta} delta + */ $updateOnChange(delta) { var startRow = delta.start.row; var len = delta.end.row - startRow; @@ -165,7 +187,7 @@ class BackgroundTokenizer { /** * Gives list of [[Token]]'s of the row. (tokens are cached) * @param {Number} row The row to get tokens at - * @returns {Token[]} + * @returns {Ace.Token[]} **/ getTokens(row) { return this.lines[row] || this.$tokenizeRow(row); @@ -182,6 +204,9 @@ class BackgroundTokenizer { return this.states[row] || "start"; } + /** + * @param {number} row + */ $tokenizeRow(row) { var line = this.doc.getLine(row); var state = this.states[row - 1]; @@ -200,6 +225,9 @@ class BackgroundTokenizer { return this.lines[row] = data.tokens; } + /** + * @this {IBackgroundTokenizer} + */ cleanup() { this.running = false; this.lines = []; diff --git a/src/bidihandler.js b/src/bidihandler.js index 8b065f83da6..77a1e2ed6be 100644 --- a/src/bidihandler.js +++ b/src/bidihandler.js @@ -1,5 +1,8 @@ "use strict"; - +/** + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ var bidiUtil = require("./lib/bidiutil"); var lang = require("./lib/lang"); var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/; @@ -11,7 +14,7 @@ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/; class BidiHandler { /** * Creates a new `BidiHandler` object - * @param {EditSession} session The session to use + * @param {IEditSession} session The session to use **/ constructor(session) { this.session = session; diff --git a/src/config.js b/src/config.js index 7ed0a1d1e6d..1a82e26baec 100644 --- a/src/config.js +++ b/src/config.js @@ -1,10 +1,17 @@ "no use strict"; +/** + * @typedef IAppConfig + * @type {import("./lib/app_config").IAppConfig} + */ var lang = require("./lib/lang"); var net = require("./lib/net"); var dom = require("./lib/dom"); var AppConfig = require("./lib/app_config").AppConfig; +/** + * @type {IAppConfig & exports} + */ module.exports = exports = new AppConfig(); var options = { @@ -20,12 +27,20 @@ var options = { useStrictCSP: null }; +/** + * @param {string} key + * @return {*} + */ exports.get = function(key) { if (!options.hasOwnProperty(key)) throw new Error("Unknown config key: " + key); return options[key]; }; +/** + * @param {string} key + * @param value + */ exports.set = function(key, value) { if (options.hasOwnProperty(key)) options[key] = value; @@ -34,14 +49,21 @@ exports.set = function(key, value) { if (key == "useStrictCSP") dom.useStrictCSP(value); }; - +/** + * @return {{[key: string]: any}} + */ exports.all = function() { return lang.copyObject(options); }; exports.$modes = {}; -// module loading +/** + * module loading + * @param {string} name + * @param {string} [component] + * @returns {string} + */ exports.moduleUrl = function(name, component) { if (options.$moduleUrls[name]) return options.$moduleUrls[name]; @@ -69,7 +91,11 @@ exports.moduleUrl = function(name, component) { path += "/"; return path + component + sep + base + this.get("suffix"); }; - +/** + * @param {string} name + * @param {string} subst + * @returns {string} + */ exports.setModuleUrl = function(name, subst) { return options.$moduleUrls[name] = subst; }; @@ -82,6 +108,9 @@ var loader = function(moduleName, cb) { console.error("loader is not configured"); }; var customLoader; +/** + * @param {(moduleName: string, afterLoad: (err: Error | null, module: unknown) => void) => void}cb + */ exports.setLoader = function(cb) { customLoader = cb; }; @@ -89,6 +118,10 @@ exports.setLoader = function(cb) { exports.dynamicModules = Object.create(null); exports.$loading = {}; exports.$loaded = {}; +/** + * @param {string | [string, string]} moduleName + * @param {(module: any) => void} onLoad + */ exports.loadModule = function(moduleName, onLoad) { var loadedModule, moduleType; if (Array.isArray(moduleName)) { diff --git a/src/document.js b/src/document.js index b2535c22abc..d56125538f2 100644 --- a/src/document.js +++ b/src/document.js @@ -4,6 +4,10 @@ * @type {Document & Ace.EventEmitter} * @export */ +/** + * @typedef IAnchor + * @type {import("./anchor").IAnchor} + */ var oop = require("./lib/oop"); var applyDelta = require("./apply_delta").applyDelta; var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -60,7 +64,7 @@ class Document { * Creates a new `Anchor` to define a floating point in the document. * @param {Number} row The row number to use * @param {Number} column The column number to use - * @returns {Anchor} + * @returns {IAnchor} **/ createAnchor(row, column) { return new Anchor(this, row, column); @@ -161,7 +165,7 @@ class Document { /** * Returns all the text within `range` as a single string. - * @param {Range} range The range to work with. + * @param {Ace.IRange} range The range to work with. * * @returns {String} **/ @@ -171,7 +175,7 @@ class Document { /** * Returns all the text within `range` as an array of lines. - * @param {Range} range The range to work with. + * @param {Ace.IRange} range The range to work with. * * @returns {string[]} **/ @@ -382,7 +386,7 @@ class Document { /** * Removes the `range` from the document. - * @param {Range} range A specified Range to remove + * @param {Ace.IRange} range A specified Range to remove * @returns {Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -474,7 +478,7 @@ class Document { /** * Replaces a range in the document with the new `text`. - * @param {Range | {start: Ace.Point, end: Ace.Point}} range A specified Range to replace + * @param {Range | Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement * @returns {Ace.Point} Returns an object containing the final row and column, like this: * {row: endRow, column: 0} diff --git a/src/edit_session.js b/src/edit_session.js index 45f87af7d02..50b67e39880 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -23,10 +23,6 @@ var oop = require("./lib/oop"); var lang = require("./lib/lang"); var BidiHandler = require("./bidihandler").BidiHandler; -/** - * - * @type {import("./lib/app_config").AppConfigWithAllOptions} - */ var config = require("./config"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Selection = require("./selection").Selection; @@ -152,6 +148,9 @@ class EditSession { this.$markerId = 1; this.$undoSelect = true; + /** + * @type {FoldLine[]} + */ this.$foldData = []; this.id = "session" + (++EditSession.$uid); this.$foldData.toString = function() { @@ -216,7 +215,13 @@ class EditSession { **/ $resetRowCache(docRow) { if (!docRow) { + /** + * @type {number[]} + */ this.$docRowCache = []; + /** + * @type {number[]} + */ this.$screenRowCache = []; return; } @@ -373,8 +378,6 @@ class EditSession { /** * Sets the undo manager. * @param {UndoManager} undoManager The new undo manager - * - * **/ setUndoManager(undoManager) { this.$undoManager = undoManager; @@ -2299,7 +2302,6 @@ class EditSession { var rowEnd, row = 0; - var rowCache = this.$docRowCache; var i = this.$getRowCacheIndex(rowCache, docRow); var l = rowCache.length; @@ -2517,6 +2519,10 @@ EditSession.prototype.$wrapLimitRange = { min : null, max : null }; +/** + * + * @type {null | Ace.LineWidget[]} + */ EditSession.prototype.lineWidgets = null; EditSession.prototype.isFullWidth = isFullWidth; @@ -2575,6 +2581,10 @@ require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype) config.defineOptions(EditSession.prototype, "session", { wrap: { + /** + * @this {IEditSession} + * @param {string | boolean | number} value + */ set: function(value) { if (!value || value == "off") value = false; @@ -2628,6 +2638,9 @@ config.defineOptions(EditSession.prototype, "session", { initialValue: "auto" }, indentedSoftWrap: { + /** + * @this {IEditSession} + */ set: function() { if (this.$useWrapMode) { this.$useWrapMode = false; diff --git a/src/lib/app_config.js b/src/lib/app_config.js index 874441e4dc3..b471fe051e2 100644 --- a/src/lib/app_config.js +++ b/src/lib/app_config.js @@ -1,5 +1,9 @@ "no use strict"; - +/** + * @typedef IAppConfig + * @type {AppConfig & Ace.EventEmitter} + * @export + */ var oop = require("./oop"); var EventEmitter = require("./event_emitter").EventEmitter; @@ -57,6 +61,9 @@ function warn(message) { } function reportError(msg, data) { + /** + * @type {Error & {data?: any}}} + */ var e = new Error(msg); e.data = data; if (typeof console == "object" && console.error) @@ -67,17 +74,18 @@ function reportError(msg, data) { var messages; /** - * @typedef AppConfigWithAllOptions - * @type {AppConfig & Ace.OptionsProvider & Ace.EventEmitter & Ace.Config} - * @export + * @type {IAppConfig} */ class AppConfig { constructor() { this.$defaultOptions = {}; } - /* - * option {name, value, initialValue, setterName, set, get } + /** + * @param {Object} obj + * @param {string} path + * @param {{ [key: string]: any }} options + * @returns {IAppConfig} */ defineOptions(obj, path, options) { if (!obj.$options) @@ -100,6 +108,9 @@ class AppConfig { return this; } + /** + * @param {Object} obj + */ resetOptions(obj) { Object.keys(obj.$options).forEach(function(key) { var opt = obj.$options[key]; @@ -108,6 +119,11 @@ class AppConfig { }); } + /** + * @param {string} path + * @param {string} name + * @param {any} value + */ setDefaultValue(path, name, value) { if (!path) { for (path in this.$defaultOptions) @@ -125,16 +141,27 @@ class AppConfig { } } + /** + * @param {string} path + * @param {{ [key: string]: any; }} optionHash + */ setDefaultValues(path, optionHash) { Object.keys(optionHash).forEach(function(key) { this.setDefaultValue(path, key, optionHash[key]); }, this); } - + + /** + * @param {any} value + */ setMessages(value) { messages = value; } - + + /** + * @param {string} string + * @param {{ [x: string]: any; }} params + */ nls(string, params) { if (messages && !messages[string]) { warn("No message found for '" + string + "' in the provided messages, falling back to default English message."); diff --git a/src/lib/bidiutil.js b/src/lib/bidiutil.js index 72af40779c9..38e318b9b1d 100644 --- a/src/lib/bidiutil.js +++ b/src/lib/bidiutil.js @@ -298,8 +298,8 @@ exports.DOT = "\xB7"; * Performs text reordering by implementing Unicode Bidi algorithm * with aim to produce logical<->visual map and Bidi levels * @param {String} text string to be reordered - * @param {Array} unicode character types produced by call to 'hasBidiCharacters' - * @param {Boolean} 'true' for right-to-left text direction, otherwise 'false' + * @param {Array} textCharTypes unicode character types produced by call to 'hasBidiCharacters' + * @param {Boolean} isRtl 'true' for right-to-left text direction, otherwise 'false' * * @return {Object} An object containing logicalFromVisual map and Bidi levels **/ @@ -347,7 +347,7 @@ exports.doBidiReorder = function(text, textCharTypes, isRtl) { /** * Performs character classification, to be used in Unicode Bidi algorithm. * @param {String} text string to be reordered - * @param {Array} unicode character types (to be filled by this method) + * @param {Array} textCharTypes unicode character types (to be filled by this method) * * @return {Boolean} 'true' if text contains Bidi characters, otherwise 'false' **/ diff --git a/src/line_widgets.js b/src/line_widgets.js index ad19e2f5821..7608ebb1a6c 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -1,10 +1,38 @@ "use strict"; +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ +/** + * + * @typedef IEditor + * @type {import("./editor").IEditor} + */ +/** + * + * @typedef IVirtualRenderer + * @type {import("./virtual_renderer").IVirtualRenderer} + */ var dom = require("./lib/dom"); - class LineWidgets { + /** + * @type {Ace.LineWidget[]} + */ + lineWidgets; + /** + * @type {IEditor} + */ + editor; + $useWrapMode; + $wrapData; + + /** + * @param {IEditSession} session + */ constructor(session) { this.session = session; this.session.widgetManager = this; @@ -20,7 +48,11 @@ class LineWidgets { this.session.on("changeFold", this.updateOnFold); this.session.on("changeEditor", this.$onChangeEditor); } - + + /** + * @param {number} row + * @return {number} + */ getRowLength(row) { var h; if (this.lineWidgets) @@ -34,6 +66,9 @@ class LineWidgets { } } + /** + * @return {number} + */ $getWidgetScreenLength() { var screenRows = 0; this.lineWidgets.forEach(function(w){ @@ -46,7 +81,11 @@ class LineWidgets { $onChangeEditor(e) { this.attach(e.editor); } - + + /** + * + * @param {IEditor} editor + */ attach(editor) { if (editor && editor.widgetManager && editor.widgetManager != this) editor.widgetManager.detach(); @@ -82,6 +121,11 @@ class LineWidgets { }); } + /** + * + * @param e + * @param {IEditSession} session + */ updateOnFold(e, session) { var lineWidgets = session.lineWidgets; if (!lineWidgets || !e.action) @@ -107,7 +151,11 @@ class LineWidgets { } } } - + + /** + * + * @param {Ace.Delta} delta + */ updateOnChange(delta) { var lineWidgets = this.session.lineWidgets; if (!lineWidgets) return; @@ -156,6 +204,11 @@ class LineWidgets { this.session.lineWidgets = null; } + /** + * + * @param {Ace.LineWidget} w + * @return {Ace.LineWidget} + */ $registerLineWidget(w) { if (!this.session.lineWidgets) this.session.lineWidgets = new Array(this.session.getLength()); @@ -172,7 +225,12 @@ class LineWidgets { this.session.lineWidgets[w.row] = w; return w; } - + + /** + * + * @param {Ace.LineWidget} w + * @return {Ace.LineWidget} + */ addLineWidget(w) { this.$registerLineWidget(w); w.session = this.session; @@ -194,12 +252,12 @@ class LineWidgets { dom.addCssClass(w.el, w.className); } w.el.style.position = "absolute"; - w.el.style.zIndex = 5; + w.el.style.zIndex = "5"; renderer.container.appendChild(w.el); w._inDocument = true; if (!w.coverGutter) { - w.el.style.zIndex = 3; + w.el.style.zIndex = "3"; } if (w.pixelHeight == null) { w.pixelHeight = w.el.offsetHeight; @@ -227,6 +285,9 @@ class LineWidgets { return w; } + /** + * @param {Ace.LineWidget} w + */ removeLineWidget(w) { w._inDocument = false; w.session = null; @@ -254,7 +315,12 @@ class LineWidgets { this.session._emit("changeFold", {data:{start:{row: w.row}}}); this.$updateRows(); } - + + /** + * + * @param {number} row + * @return {Ace.LineWidget[]} + */ getWidgetsAtRow(row) { var lineWidgets = this.session.lineWidgets; var w = lineWidgets && lineWidgets[row]; @@ -265,12 +331,19 @@ class LineWidgets { } return list; } - + + /** + * @param {Ace.LineWidget} w + */ onWidgetChanged(w) { this.session._changedWidgets.push(w); this.editor && this.editor.renderer.updateFull(); } - + + /** + * @param {any} e + * @param {IVirtualRenderer} renderer + */ measureWidgets(e, renderer) { var changedWidgets = this.session._changedWidgets; var config = renderer.layerConfig; @@ -313,7 +386,11 @@ class LineWidgets { } this.session._changedWidgets = []; } - + + /** + * @param {any} e + * @param {IVirtualRenderer} renderer + */ renderWidgets(e, renderer) { var config = renderer.layerConfig; var lineWidgets = this.session.lineWidgets; diff --git a/src/placeholder.js b/src/placeholder.js index a90ea2e5f95..35372d49ce6 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -1,15 +1,22 @@ "use strict"; - +/** + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ +/** + * @typedef IPlaceHolder + * @type {PlaceHolder & Ace.EventEmitter} + */ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var oop = require("./lib/oop"); class PlaceHolder { /** - * @param {Document} session The document to associate with the anchor - * @param {Number} length The starting row position - * @param {Number} pos The starting column position - * @param {String} others + * @param {IEditSession} session + * @param {Number} length + * @param {Ace.Point} pos + * @param {any[]} others * @param {String} mainClass * @param {String} othersClass **/ @@ -103,8 +110,8 @@ class PlaceHolder { * PlaceHolder@onUpdate(e) * * Emitted when the place holder updates. - * - **/ + * @param {Ace.Delta} delta + */ onUpdate(delta) { if (this.$updating) return this.updateAnchors(delta); @@ -141,7 +148,10 @@ class PlaceHolder { this.$updating = false; this.updateMarkers(); } - + + /** + * @param {Ace.Delta} delta + */ updateAnchors(delta) { this.pos.onChange(delta); for (var i = this.others.length; i--;) @@ -162,14 +172,15 @@ class PlaceHolder { for (var i = this.others.length; i--;) updateMarker(this.others[i], this.othersClass); } - + + /** * PlaceHolder@onCursorChange(e) * * Emitted when the cursor changes. - * - **/ - + * @param {any} [event] + * @this {IPlaceHolder} + */ onCursorChange(event) { if (this.$updating || !this.session) return; var pos = this.session.selection.getCursor(); diff --git a/src/tooltip.js b/src/tooltip.js index 4372e55ce93..0f538f401ee 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -66,9 +66,9 @@ class Tooltip { } /** - * @param {String} text - * @param {Number} x - * @param {Number} y + * @param {String} [text] + * @param {Number} [x] + * @param {Number} [y] **/ show(text, x, y) { if (text != null) @@ -366,4 +366,4 @@ class HoverTooltip extends Tooltip { } } -exports.HoverTooltip = HoverTooltip; \ No newline at end of file +exports.HoverTooltip = HoverTooltip; diff --git a/tsconfig.json b/tsconfig.json index d92e0aeecd4..5e6d89a5708 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,7 @@ "exclude": [ "node_modules", "src/test", + "src/keyboard", "src/**/*_test.js", "./src/mode/**/*", "./types/**/*", From 84d383b7929d22f91fb3800b302ec32cd54d5f6a Mon Sep 17 00:00:00 2001 From: mkslanc Date: Wed, 30 Aug 2023 17:24:36 +0400 Subject: [PATCH 05/36] continue providing types --- ace.d.ts | 159 ++++++++---------------------- src/ace.js | 6 +- src/apply_delta.js | 6 ++ src/autocomplete.js | 80 +++++++++++++-- src/autocomplete/popup.js | 4 +- src/commands/command_manager.js | 5 +- src/document.js | 1 + src/edit_session.js | 45 +++++++-- src/edit_session/bracket_match.js | 38 ++++++- src/edit_session/fold.js | 47 ++++++++- src/edit_session/fold_line.js | 48 ++++++++- src/edit_session/folding.js | 35 +++---- src/editor.js | 4 - src/layer/text.js | 64 +++++++++++- src/marker_group.js | 31 +++++- src/placeholder.js | 4 +- src/range.js | 22 +++-- src/search.js | 17 ++-- src/token_iterator.js | 16 +-- src/tokenizer.js | 34 ++++++- src/virtual_renderer.js | 3 + tsconfig.json | 5 +- 22 files changed, 460 insertions(+), 214 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 585c62574aa..166442a522a 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,8 +1,20 @@ /// - - declare namespace Ace { + interface FoldingProperties { + $foldMode: FoldMode, + foldWidgets: FoldWidget[], + getFoldWidget: FoldMode.getFoldWidget, + getFoldWidgetRange: FoldMode.getFoldWidgetRange, + $updateFoldWidgets: (delta: Delta) => void, + $tokenizerUpdateFoldWidgets: (e) => void, + addFold: (placeholder: Fold|String, range?: Range) => Fold, + removeFold: (fold: Fold) => void, + removeFolds: (folds: Fold[]) => void, + setFoldStyle: (style: string) => void, + $setFolding: (foldMode: FoldMode) => void, + } + interface AcePopupProperties { setSelectOnHover?: (val: boolean) => void, setRow?: (line: number) => void, @@ -20,7 +32,7 @@ declare namespace Ace { anchorPosition?: Point, tryShow?: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, $borderSize?: number, - show?: (pos: any, lineHeight: number, topdownOnly: boolean) => void, + show?: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, goTo?: (where: AcePopupNavigation) => void, getTextLeftOffset?: () => number, $imageSize?: number, @@ -75,7 +87,10 @@ declare namespace Ace { $copyWithEmptySelection?: any $selectionStyle?: string, env?: any; - widgetManager?: LineWidgets + widgetManager?: LineWidgets, + completer?: Autocomplete, + completers?: Completer[], + $highlightTagPending?: boolean, } interface EditSessionProperties { @@ -103,7 +118,8 @@ declare namespace Ace { $options:any, $wrapMethod?: any, $enableVarChar?: any, - $wrap?:any + $wrap?:any, + $navigateWithinSoftTabs?: boolean } interface EditorMultiSelectProperties { @@ -137,51 +153,10 @@ declare namespace Ace { $useTextareaForIME?: boolean, theme?: any, $theme?: any, + destroyed?: boolean, } type NewLineMode = 'auto' | 'unix' | 'windows'; - - interface FoldLine { - folds: Fold[]; - range: Range; - start: Point; - end: Point; - - shiftRow(shift: number): void; - - addFold(fold: Fold): void; - - containsRow(row: number): boolean; - - walk(callback: Function, endRow?: number, endColumn?: number): void; - - getNextFoldTo(row: number, column: number): null | { fold: Fold, kind: string }; - - addRemoveChars(row: number, column: number, len: number): void; - - split(row: number, column: number): FoldLine; - - merge(foldLineNext: FoldLine): void; - - idxToPosition(idx: number): Point; - } - - interface Fold { - range: Range; - start: Point; - end: Point; - foldLine?: FoldLine; - sameRow: boolean; - subFolds: Fold[]; - - setFoldLine(foldLine: FoldLine): void; - - clone(): Fold; - - addSubFold(fold: Fold): Fold; - - restoreRange(range: Range): void; - } interface EditSessionOptions { wrap: "off" | "free" | "printmargin" | boolean | number; @@ -314,7 +289,8 @@ declare namespace Ace { start: Point; end: Point; lines: string[]; - id?: number + id?: number, + folds?: Fold[] } interface Annotation { @@ -324,20 +300,6 @@ declare namespace Ace { type: string; } - interface MarkerGroupItem { - range: Range; - className: string; - } - - class MarkerGroup { - constructor(session: EditSession); - - setMarkers(markers: MarkerGroupItem[]): void; - - getMarkerAtPosition(pos: Position): MarkerGroupItem; - } - - interface Command { name?: string; bindKey?: string | { mac?: string, win?: string }; @@ -353,11 +315,11 @@ declare namespace Ace { interface MarkerLike { range?: Range; - type: string; + type?: string; renderer?: MarkerRenderer; - clazz: string; - inFront: boolean; - id: number; + clazz?: string; + inFront?: boolean; + id?: number; update?: (html: string[], // TODO maybe define Marker class marker: any, @@ -389,37 +351,17 @@ declare namespace Ace { interface SnippetCompletion extends BaseCompletion { snippet: string; + value?: string; } interface ValueCompletion extends BaseCompletion { value: string; + snippet?: string; } type Completion = SnippetCompletion | ValueCompletion - interface Tokenizer { - removeCapturingGroups(src: string): string; - - createSplitterRegexp(src: string, flag?: string): RegExp; - - getLineTokens(line: string, startState: string | string[]): Token[]; - } - - interface TokenIterator { - getCurrentToken(): Token; - - getCurrentTokenColumn(): number; - - getCurrentTokenRow(): number; - - getCurrentTokenPosition(): Point; - - getCurrentTokenRange(): Range; - - stepBackward(): Token; - stepForward(): Token; - } type HighlightRule = { defaultToken: string } | { include: string } | { todo: string } | { token: string | string[] | ((value: string) => string); @@ -447,20 +389,22 @@ declare namespace Ace { createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; } + + type FoldWidget = "start" | "end" | "" interface FoldMode { foldingStartMarker: RegExp; foldingStopMarker?: RegExp; - getFoldWidget(session: EditSession, foldStyle: string, row: number): string; + getFoldWidget(session: IEditSession, foldStyle: string, row: number): FoldWidget; - getFoldWidgetRange(session: EditSession, foldStyle: string, row: number, forceMultiline?: boolean): Range | undefined; + getFoldWidgetRange(session: IEditSession, foldStyle: string, row: number): Range | undefined; - indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; + indentationBlock(session: IEditSession, row: number, column?: number): Range | undefined; - openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + openingBracketBlock(session: IEditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; - closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + closingBracketBlock(session: IEditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; } type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => { text: string, selection: number[] } | Range | undefined; @@ -507,7 +451,7 @@ declare namespace Ace { checkOutdent(state: any, line: string, input: string): boolean; - autoOutdent(state: any, doc: Document, row: number): void; + autoOutdent(state: any, doc: IEditSession, row: number): void; // TODO implement WorkerClient types createWorker(session: EditSession): any; @@ -963,7 +907,7 @@ declare namespace Ace { } type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; - type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; + type CompletionProviderCallback = (this: Autocomplete, err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; class CompletionProvider { insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; @@ -972,34 +916,11 @@ declare namespace Ace { completions: CompletionRecord; - gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; - provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; detach(): void; } - - class Autocomplete { - constructor(); - - autoInsert?: boolean; - autoSelect?: boolean; - autoShown?: boolean; - exactMatch?: boolean; - inlineEnabled?: boolean; - parentNode?: HTMLElement; - - emptyMessage?(prefix: String): String; - - getPopup(): AcePopup; - - showPopup(editor: Editor, options: CompletionOptions): void; - - detach(): void; - - destroy(): void; - } - + type AcePopupNavigation = "up" | "down" | "start" | "end"; class AcePopup { diff --git a/src/ace.js b/src/ace.js index 542232348ec..1f594b0a462 100644 --- a/src/ace.js +++ b/src/ace.js @@ -1,7 +1,7 @@ /** * The main class required to set up an Ace instance in the browser. * - * @class Ace + * @namespace Ace **/ /** * @@ -90,9 +90,11 @@ exports.edit = function(el, options) { * @returns {IEditSession} **/ exports.createEditSession = function(text, mode) { + /** + * @type {any} + */ var doc = new EditSession(text, mode); doc.setUndoManager(new UndoManager()); - // @ts-ignore return doc; }; exports.Range = Range; diff --git a/src/apply_delta.js b/src/apply_delta.js index de43678f009..8ff0c6b554d 100644 --- a/src/apply_delta.js +++ b/src/apply_delta.js @@ -40,6 +40,12 @@ function validateDelta(docLines, delta) { throwDeltaError(delta, "delta.range must match delta lines"); } +/** + * Applies a delta to a document. + * @param {string[]} docLines + * @param {Ace.Delta} delta + * @param [doNotValidate] + */ exports.applyDelta = function(docLines, delta, doNotValidate) { // disabled validation since it breaks autocompletion popup // if (!doNotValidate) diff --git a/src/autocomplete.js b/src/autocomplete.js index 6dc38213797..8ff49715315 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -1,5 +1,14 @@ "use strict"; - +/** + * + * @typedef IAcePopup + * @type {import("./autocomplete/popup").IAcePopup} + */ +/** + * + * @typedef IEditor + * @type {import("./editor").IEditor} + */ var HashHandler = require("./keyboard/hash_handler").HashHandler; var AcePopup = require("./autocomplete/popup").AcePopup; var AceInline = require("./autocomplete/inline").AceInline; @@ -52,6 +61,11 @@ var destroyCompleter = function(e, editor) { * There is an autocompletion popup, an optional inline ghost text renderer and a docuent tooltip popup inside. */ class Autocomplete { + /** + * @type {IAcePopup} + */ + popup; + constructor() { this.autoInsert = false; this.autoSelect = true; @@ -76,6 +90,7 @@ class Autocomplete { } $init() { + // @ts-ignore this.popup = new AcePopup(this.parentNode || document.body || document.documentElement); this.popup.on("click", function(e) { this.insertMatch(); @@ -96,6 +111,10 @@ class Autocomplete { return this.inlineRenderer; } + /** + * + * @return {IAcePopup} + */ getPopup() { return this.popup || this.$init(); } @@ -183,6 +202,11 @@ class Autocomplete { this.popup.show(pos, lineHeight); } + /** + * @param {IEditor} editor + * @param {string} prefix + * @param {boolean} [keepPopupPosition] + */ openPopup(editor, prefix, keepPopupPosition) { if (!this.popup) this.$init(); @@ -283,6 +307,11 @@ class Autocomplete { this.popup.goTo(where); } + /** + * @param {Ace.Completion} data + * @param {undefined} [options] + * @return {boolean | void} + */ insertMatch(data, options) { if (!data) data = this.popup.getData(this.popup.getRow()); @@ -300,8 +329,8 @@ class Autocomplete { /** * This is the entry point for the autocompletion class, triggers the actions which collect and display suggestions - * @param {Editor} editor - * @param {CompletionOptions} options + * @param {IEditor} editor + * @param {Ace.CompletionOptions} options */ showPopup(editor, options) { if (this.editor) @@ -339,6 +368,10 @@ class Autocomplete { return this.getCompletionProvider().gatherCompletions(editor, callback); } + /** + * @param {boolean} keepPopupPosition + * @param {Ace.CompletionOptions} options + */ updateCompletions(keepPopupPosition, options) { if (keepPopupPosition && this.base && this.completions) { var pos = this.editor.getCursorPosition(); @@ -370,7 +403,14 @@ class Autocomplete { this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length); this.base.$insertRight = true; var completionOptions = { exactMatch: this.exactMatch }; - this.getCompletionProvider().provideCompletions(this.editor, completionOptions, function(err, completions, finished) { + + this.getCompletionProvider().provideCompletions(this.editor, completionOptions, + /** + * @type {(err: any, completions: Ace.Completion[], finished: boolean) => void | boolean} + * @this {Autocomplete} + */ + function (err, + completions, finished) { var filtered = completions.filtered; var prefix = util.getCompletionPrefix(this.editor); @@ -588,11 +628,21 @@ Autocomplete.startCommand = { * This class is responsible for providing completions and inserting them to the editor */ class CompletionProvider { + /** + * @type {Ace.CompletionRecord} + */ + completions; constructor() { this.active = true; } - + + /** + * @param {IEditor} editor + * @param {number} index + * @param {Ace.CompletionProviderOptions} [options] + * @returns {boolean} + */ insertByIndex(editor, index, options) { if (!this.completions || !this.completions.filtered) { return false; @@ -600,6 +650,12 @@ class CompletionProvider { return this.insertMatch(editor, this.completions.filtered[index], options); } + /** + * @param {IEditor} editor + * @param {Ace.Completion} data + * @param {Ace.CompletionProviderOptions} options + * @returns {boolean} + */ insertMatch(editor, data, options) { if (!data) return false; @@ -637,6 +693,10 @@ class CompletionProvider { return true; } + /** + * @param {IEditor} editor + * @param {Ace.Completion} data + */ $insertString(editor, data) { var text = data.value || data; if (data.range) { @@ -658,6 +718,10 @@ class CompletionProvider { } } + /** + * @param {IEditor} editor + * @param {Ace.CompletionCallbackFunction} callback + */ gatherCompletions(editor, callback) { var session = editor.getSession(); var pos = editor.getCursorPosition(); @@ -685,9 +749,9 @@ class CompletionProvider { /** * This is the entry point to the class, it gathers, then provides the completions asynchronously via callback. * The callback function may be called multiple times, the last invokation is marked with a `finished` flag - * @param {Editor} editor - * @param {CompletionProviderOptions} options - * @param {CompletionProviderCallback} callback + * @param {IEditor} editor + * @param {Ace.CompletionProviderOptions} options + * @param {(err: Error | undefined, completions: Ace.CompletionRecord, finished: boolean) => void} callback */ provideCompletions(editor, options, callback) { var processResults = function(results) { diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 18c329d8210..0c72f885883 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -30,7 +30,9 @@ var $singleLineEditor = function (el) { var renderer = new Renderer(el); renderer.$maxLines = 4; - + /** + * @type {IEditor} + */ var editor = new Editor(renderer); editor.setHighlightActiveLine(false); diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index b5880571248..d392967355a 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef ICommandManager - * @type {CommandManager & Ace.EventEmitter} + * @type {CommandManager & Ace.EventEmitter & {$checkCommandState?: boolean}} * @export */ /** @@ -100,6 +100,9 @@ class CommandManager extends MultiHashHandler{ return this.recording = true; } + /** + * @param {IEditor} editor + */ replay(editor) { if (this.$inReplay || !this.macro) return; diff --git a/src/document.js b/src/document.js index d56125538f2..570e1d802f9 100644 --- a/src/document.js +++ b/src/document.js @@ -489,6 +489,7 @@ class Document { replace(range, text) { if (!(range instanceof Range)) range = Range.fromPoints(range.start, range.end); + // @ts-expect-error if (text.length === 0 && range.isEmpty()) return range.start; diff --git a/src/edit_session.js b/src/edit_session.js index 50b67e39880..9d02ae427f7 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -7,12 +7,16 @@ */ /** * @typedef IFolding - * @type {import("./edit_session/folding").Folding} + * @type {import("./edit_session/folding").IFolding} */ /** * @typedef UndoManager * @type {import("./undomanager").UndoManager} */ +/** + * @typedef FoldLine + * @type {import("./edit_session/fold_line").FoldLine} + */ /** * @typedef IEditSession * @type {EditSession & Ace.OptionsProvider & IFolding & Ace.EventEmitter & Ace.EditSessionProperties & import("./edit_session/bracket_match").BracketMatch} @@ -127,6 +131,7 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; /** * @type {IEditSession} + * @this {IEditSession} */ class EditSession { /** @@ -298,7 +303,7 @@ class EditSession { /** * Sets the session text. * @param {String} text The new text to place - * + * @this {IEditSession} **/ setValue(text) { this.doc.setValue(text); @@ -378,6 +383,7 @@ class EditSession { /** * Sets the undo manager. * @param {UndoManager} undoManager The new undo manager + * @this {IEditSession} **/ setUndoManager(undoManager) { this.$undoManager = undoManager; @@ -417,6 +423,7 @@ class EditSession { /** * Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by [[EditSession.getTabSize `getTabSize()`]]); otherwise it's simply `'\t'`. * @returns {String} + * @this {IEditSession} **/ getTabString() { if (this.getUseSoftTabs()) { @@ -480,6 +487,7 @@ class EditSession { /** * Returns `true` if keyboard navigation moves the cursor within soft tabs, `false` if it moves the cursor over soft tabs. * @returns {Boolean} + * @this {IEditSession} **/ getNavigateWithinSoftTabs() { return this.$navigateWithinSoftTabs; @@ -507,6 +515,7 @@ class EditSession { /** * Sets the value of overwrite to the opposite of whatever it currently is. + * @this {IEditSession} **/ toggleOverwrite() { this.setOverwrite(!this.$overwrite); @@ -679,6 +688,7 @@ class EditSession { /** * * @param {RegExp} re + * @this {IEditSession} */ highlight(re) { if (!this.$searchHighlight) { @@ -695,6 +705,7 @@ class EditSession { * @param {string} clazz * @param {boolean} [inFront] * @return {Range} + * @this {IEditSession} */ highlightLines(startRow, endRow, clazz, inFront) { if (typeof endRow != "number") { @@ -738,6 +749,7 @@ class EditSession { /** * Clears all the annotations for this session. This function also triggers the `'changeAnnotation'` event. + * @this {IEditSession} **/ clearAnnotations() { this.setAnnotations([]); @@ -863,7 +875,7 @@ class EditSession { * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. * @param {Ace.SyntaxMode} mode Set a new text mode * @param {() => void} [cb] optional callback - * + * @this {IEditSession} **/ setMode(mode, cb) { if (mode && typeof mode === "object") { @@ -1029,6 +1041,7 @@ class EditSession { /** * Returns the width of the screen. * @returns {Number} + * @this {IEditSession} **/ getScreenWidth() { this.$computeWidth(); @@ -1051,6 +1064,10 @@ class EditSession { return this.lineWidgetWidth = width; } + /** + * @param {boolean} [force] + * @this {IEditSession} + */ $computeWidth(force) { if (this.$modified || force) { this.$modified = false; @@ -1116,7 +1133,7 @@ class EditSession { /** * {:Document.getTextRange.desc} - * @param {Range} range The range to work with + * @param {Ace.IRange} range The range to work with * * @returns {String} **/ @@ -1341,6 +1358,7 @@ class EditSession { * @param {Number} startRow Starting row * @param {Number} endRow Ending row * @param {String} indentString The indent token + * @this {IEditSession} **/ indentRows(startRow, endRow, indentString) { indentString = indentString.replace(/\t/g, this.getTabString()); @@ -1351,7 +1369,7 @@ class EditSession { /** * Outdents all the rows defined by the `start` and `end` properties of `range`. * @param {Range} range A range of rows - * + * @this {IEditSession} **/ outdentRows(range) { var rowRange = range.collapseRows(); @@ -1422,7 +1440,7 @@ class EditSession { * @param {Number} firstRow The starting row to move up * @param {Number} lastRow The final row to move up * @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1. - * + * @this {IEditSession} **/ moveLinesUp(firstRow, lastRow) { return this.$moveLines(firstRow, lastRow, -1); @@ -1433,6 +1451,7 @@ class EditSession { * @param {Number} firstRow The starting row to move down * @param {Number} lastRow The final row to move down * @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1. + * @this {IEditSession} **/ moveLinesDown(firstRow, lastRow) { return this.$moveLines(firstRow, lastRow, 1); @@ -1443,6 +1462,7 @@ class EditSession { * @param {Number} firstRow The starting row to duplicate * @param {Number} lastRow The final row to duplicate * @returns {Number} Returns the number of new rows added; in other words, `lastRow - firstRow + 1`. + * @this {IEditSession} **/ duplicateLines(firstRow, lastRow) { return this.$moveLines(firstRow, lastRow, 0); @@ -1630,6 +1650,7 @@ class EditSession { * at a minimum of the given length minus 20 chars and at a maximum * of the given number of chars. * @param {number} limit The maximum line length in chars, for soft wrapping lines. + * @this {IEditSession} */ setWrapLimit(limit) { this.setWrapLimitRange(limit, limit); @@ -1777,6 +1798,7 @@ class EditSession { * * @param {number} firstRow * @param {number} lastRow + * @this {IEditSession} */ $updateWrapData(firstRow, lastRow) { var lines = this.doc.getAllLines(); @@ -1984,6 +2006,7 @@ class EditSession { * @param {String} str The string to check * @param {Number} [offset] The value to start at * @returns {number[]} + * @this {IEditSession} **/ $getDisplayTokens(str, offset) { var arr = []; @@ -2024,6 +2047,7 @@ class EditSession { * @returns {Number[]} Returns an `int[]` array with two elements:
* The first position indicates the number of columns for `str` on screen.
* The second value contains the position of the document column that this function read until. + * @this {IEditSession} **/ $getStringScreenWidth(str, maxScreenColumn, screenColumn) { if (maxScreenColumn == 0) @@ -2084,6 +2108,7 @@ class EditSession { /** * @param {Number} screenRow * @returns {Number} + * @this {IEditSession} **/ getRowWrapIndent(screenRow) { if (this.$useWrapMode) { @@ -2101,6 +2126,7 @@ class EditSession { * @returns {Number} * * @related EditSession.documentToScreenColumn + * @this {IEditSession} **/ getScreenLastRowColumn(screenRow) { var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE); @@ -2112,6 +2138,7 @@ class EditSession { * @param {Number} docRow * @param {Number} docColumn * @returns {number} + * @this {IEditSession} **/ getDocumentLastRowColumn(docRow, docColumn) { var screenRow = this.documentToScreenRow(docRow, docColumn); @@ -2123,6 +2150,7 @@ class EditSession { * @param {Number} docRow * @param {Number} docColumn * @returns {Ace.Point} + * @this {IEditSession} **/ getDocumentLastRowColumnPosition(docRow, docColumn) { var screenRow = this.documentToScreenRow(docRow, docColumn); @@ -2157,6 +2185,7 @@ class EditSession { * @param {number} screenRow * @param {number} screenColumn * @returns {number} + * @this {IEditSession} */ screenToDocumentRow(screenRow, screenColumn) { return this.screenToDocumentPosition(screenRow, screenColumn).row; @@ -2166,6 +2195,7 @@ class EditSession { * @param {number} screenRow * @param {number} screenColumn * @returns {number} + * @this {IEditSession} */ screenToDocumentColumn(screenRow, screenColumn) { return this.screenToDocumentPosition(screenRow, screenColumn).column; @@ -2378,7 +2408,7 @@ class EditSession { * @param {Number} row * @param {Number} docColumn * @returns {Number} - * + * @this {IEditSession} **/ documentToScreenColumn(row, docColumn) { return this.documentToScreenPosition(row, docColumn).column; @@ -2389,6 +2419,7 @@ class EditSession { * @param {Number} docRow * @param {Number} docColumn * @returns {number} + * @this {IEditSession} **/ documentToScreenRow(docRow, docColumn) { return this.documentToScreenPosition(docRow, docColumn).row; diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index d2ec1ce19d2..6437eb68984 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -1,11 +1,24 @@ "use strict"; +/** + * + * @typedef IEditSession + * @type {import("../edit_session").IEditSession} + */ var TokenIterator = require("../token_iterator").TokenIterator; var Range = require("../range").Range; - +/** + * @export + * @this {IEditSession} + */ function BracketMatch() { + /** + * + * @param {Ace.Point} position + * @param {string} [chr] + */ this.findMatchingBracket = function(position, chr) { if (position.column == 0) return null; @@ -21,7 +34,11 @@ function BracketMatch() { else return this.$findOpeningBracket(match[2], position); }; - + + /** + * @param {Ace.Point} pos + * @return {null|Range} + */ this.getBracketRange = function(pos) { var line = this.getLine(pos.row); var before = true, range; @@ -68,7 +85,6 @@ function BracketMatch() { * * two Ranges if there is opening and closing brackets; * * one Range if there is only one bracket * - * @memberOf EditSession * @param {Ace.Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} @@ -111,6 +127,13 @@ function BracketMatch() { ">": "<" }; + /** + * + * @param {string} bracket + * @param {Ace.Point} position + * @param {RegExp} [typeRe] + * @return {Ace.Point|null} + */ this.$findOpeningBracket = function(bracket, position, typeRe) { var openBracket = this.$brackets[bracket]; var depth = 1; @@ -169,6 +192,13 @@ function BracketMatch() { return null; }; + /** + * + * @param {string} bracket + * @param {Ace.Point} position + * @param {RegExp} [typeRe] + * @return {Ace.Point|null} + */ this.$findClosingBracket = function(bracket, position, typeRe) { var closingBracket = this.$brackets[bracket]; var depth = 1; @@ -229,7 +259,7 @@ function BracketMatch() { /** * Returns [[Range]]'s for matching tags and tag names, if there are any - * @param {Position} pos + * @param {Ace.Point} pos * @returns {{closeTag: Range, closeTagName: Range, openTag: Range, openTagName: Range} | undefined} */ this.getMatchingTags = function (pos) { diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index a3c752fd270..2153a2bac34 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -1,11 +1,26 @@ "use strict"; - +/** + * @typedef FoldLine + * @type {import("./fold_line").FoldLine} + */ +/** + * @typedef Range + * @type {import("../range").Range} + */ var RangeList = require("../range_list").RangeList; /* * Simple fold-data struct. **/ class Fold extends RangeList { + /** + * @type {number} + */ + collapseChildren; + /** + * @param {Range} range + * @param {any} placeholder + */ constructor(range, placeholder) { super(); this.foldLine = null; @@ -15,6 +30,9 @@ class Fold extends RangeList { this.end = range.end; this.sameRow = range.start.row == range.end.row; + /** + * @type {Fold[]} + */ this.subFolds = this.ranges = []; } @@ -22,6 +40,9 @@ class Fold extends RangeList { return '"' + this.placeholder + '" ' + this.range.toString(); } + /** + * @param {FoldLine} foldLine + */ setFoldLine(foldLine) { this.foldLine = foldLine; this.subFolds.forEach(function(fold) { @@ -39,6 +60,9 @@ class Fold extends RangeList { return fold; } + /** + * @param {Fold} fold + */ addSubFold(fold) { if (this.range.isEqual(fold)) return; @@ -79,27 +103,46 @@ class Fold extends RangeList { return fold; } - + + /** + * @param {Ace.IRange} range + */ restoreRange(range) { return restoreRange(range, this.start); } } +/** + * @param {Ace.Point} point + * @param {Ace.Point} anchor + */ function consumePoint(point, anchor) { point.row -= anchor.row; if (point.row == 0) point.column -= anchor.column; } +/** + * @param {Ace.IRange} range + * @param {Ace.Point} anchor + */ function consumeRange(range, anchor) { consumePoint(range.start, anchor); consumePoint(range.end, anchor); } +/** + * @param {Ace.Point} point + * @param {Ace.Point} anchor + */ function restorePoint(point, anchor) { if (point.row == 0) point.column += anchor.column; point.row += anchor.row; } +/** + * @param {Ace.IRange} range + * @param {Ace.Point} anchor + */ function restoreRange(range, anchor) { restorePoint(range.start, anchor); restorePoint(range.end, anchor); diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index d8d7ce8e433..c1d266d1b27 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -1,14 +1,22 @@ "use strict"; - +/** + * @typedef Fold + * @type {import("./fold").Fold} + */ var Range = require("../range").Range; class FoldLine { /** * If an array is passed in, the folds are expected to be sorted already. + * @param {FoldLine[]} foldData + * @param {Fold[]|Fold} folds */ constructor(foldData, folds) { this.foldData = foldData; if (Array.isArray(folds)) { + /** + * @type {Fold[]} + */ this.folds = folds; } else { folds = this.folds = [ folds ]; @@ -24,8 +32,10 @@ class FoldLine { fold.setFoldLine(this); }, this); } - /* + + /** * Note: This doesn't update wrapData! + * @param {number} shift */ shiftRow(shift) { this.start.row += shift; @@ -36,6 +46,10 @@ class FoldLine { }); } + /** + * + * @param {Fold} fold + */ addFold(fold) { if (fold.sameRow) { if (fold.start.row < this.startRow || fold.endRow > this.endRow) { @@ -66,10 +80,18 @@ class FoldLine { fold.foldLine = this; } + /** + * @param {number} row + */ containsRow(row) { return row >= this.start.row && row <= this.end.row; } + /** + * @param {Function} callback + * @param {number} endRow + * @param {number} endColumn + */ walk(callback, endRow, endColumn) { var lastEnd = 0, folds = this.folds, @@ -108,6 +130,11 @@ class FoldLine { callback(null, endRow, endColumn, lastEnd, isNewRow); } + /** + * @param {number} row + * @param {number} column + * @return {{ fold: Fold, kind: string } | null} + */ getNextFoldTo(row, column) { var fold, cmp; for (var i = 0; i < this.folds.length; i++) { @@ -128,6 +155,11 @@ class FoldLine { return null; } + /** + * @param {number} row + * @param {number} column + * @param {number} len + */ addRemoveChars(row, column, len) { var ret = this.getNextFoldTo(row, column), fold, folds; @@ -159,6 +191,11 @@ class FoldLine { } } + /** + * @param {number} row + * @param {number} column + * @return {FoldLine | null} + */ split(row, column) { var pos = this.getNextFoldTo(row, column); @@ -183,6 +220,9 @@ class FoldLine { return newFoldLine; } + /** + * @param {FoldLine} foldLineNext + */ merge(foldLineNext) { var folds = foldLineNext.folds; for (var i = 0; i < folds.length; i++) { @@ -204,6 +244,10 @@ class FoldLine { return ret.join("\n"); } + /** + * @param {number} idx + * @return {Ace.Point} + */ idxToPosition(idx) { var lastFoldEndColumn = 0; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 291d77ecb12..0416e351832 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -1,5 +1,10 @@ "use strict"; +/** + * @typedef IFolding + * @type {Folding & Ace.FoldingProperties} + * @export + */ /** * @@ -13,8 +18,8 @@ var TokenIterator = require("../token_iterator").TokenIterator; var MouseEvent = require("../mouse/mouse_event").MouseEvent; /** - * @class Folding * @export + * @this {IEditSession} */ function Folding() { /** @@ -47,7 +52,6 @@ function Folding() { /** * Returns all folds in the given range. Note, that this will return folds - * @this {IEditSession} * @param {Range| Ace.Delta} range * @returns {Fold[]} **/ @@ -99,7 +103,6 @@ function Folding() { * * @param {Range[]|Range}ranges * @returns {Fold[]} - * @this {IEditSession} */ this.getFoldsInRangeList = function(ranges) { if (Array.isArray(ranges)) { @@ -118,7 +121,6 @@ function Folding() { /** * Returns all folds in the document - * @this {IEditSession} * @returns {Fold[]} */ this.getAllFolds = function() { @@ -148,7 +150,6 @@ function Folding() { * foob|arwolrd -trim=-1> "b" * foobarwol|rd -trim=+1> "rld" * fo|obarwolrd -trim=00> "foo" - * @this {IEditSession} * @param {number} row * @param {number} column * @param {number} [trim] @@ -195,7 +196,6 @@ function Folding() { * @param {number} docRow * @param {FoldLine} [startFoldLine] * @returns {null|FoldLine} - * @this {IEditSession} */ this.getFoldLine = function(docRow, startFoldLine) { var foldData = this.$foldData; @@ -220,7 +220,6 @@ function Folding() { * @param {number} docRow * @param {FoldLine} [startFoldLine] * @returns {null|FoldLine} - * @this {IEditSession} */ this.getNextFoldLine = function(docRow, startFoldLine) { var foldData = this.$foldData; @@ -243,7 +242,6 @@ function Folding() { * @param {number} first * @param {number} last * @return {number} - * @this {IEditSession} */ this.getFoldedRowCount = function(first, last) { var foldData = this.$foldData, rowCount = last-first+1; @@ -273,7 +271,6 @@ function Folding() { * * @param {FoldLine}foldLine * @return {FoldLine} - * @this {IEditSession} */ this.$addFoldLine = function(foldLine) { this.$foldData.push(foldLine); @@ -302,6 +299,7 @@ function Folding() { fold = placeholder; else { fold = new Fold(range, placeholder); + // @ts-ignore fold.collapseChildren = range.collapseChildren; } this.$clipRangeToDocument(fold.range); @@ -462,7 +460,6 @@ function Folding() { /** * @param {Fold} fold - * @this {IEditSession} */ this.expandFold = function(fold) { this.removeFold(fold); @@ -490,7 +487,6 @@ function Folding() { * @param {number|null|Ace.Point|Range|Range[]} [location] * @param {boolean} [expandInner] * @return {Fold[]| undefined} - * @this {IEditSession} */ this.unfold = function(location, expandInner) { var range, folds; @@ -539,7 +535,6 @@ function Folding() { * @param {number} docRow * @param {FoldLine} [startFoldRow] * @returns {boolean} - * @this {IEditSession} **/ this.isRowFolded = function(docRow, startFoldRow) { return !!this.getFoldLine(docRow, startFoldRow); @@ -550,7 +545,6 @@ function Folding() { * @param {number} docRow * @param {FoldLine} [startFoldRow] * @return {number} - * @this {IEditSession} */ this.getRowFoldEnd = function(docRow, startFoldRow) { var foldLine = this.getFoldLine(docRow, startFoldRow); @@ -576,7 +570,6 @@ function Folding() { * @param {number | null} [startRow] * @param {number | null} [startColumn] * @return {string} - * @this {IEditSession} */ this.getFoldDisplayLine = function(foldLine, endRow, endColumn, startRow, startColumn) { if (startRow == null) @@ -618,7 +611,6 @@ function Folding() { * @param {number | null} startRow * @param {number | null} startColumn * @return {string} - * @this {IEditSession} */ this.getDisplayLine = function(row, endColumn, startRow, startColumn) { var foldLine = this.getFoldLine(row); @@ -635,7 +627,6 @@ function Folding() { /** * @return {FoldLine[]} - * @this {IEditSession} */ this.$cloneFoldData = function() { var fd = []; @@ -651,7 +642,6 @@ function Folding() { /** * @param {boolean} [tryToUnfold] - * @this {IEditSession} */ this.toggleFold = function(tryToUnfold) { var selection = this.selection; @@ -719,7 +709,6 @@ function Folding() { * @param {number} column * @param {number} [dir] * @return {Range | undefined} - * @this {IEditSession} */ this.getCommentFoldRange = function(row, column, dir) { var iterator = new TokenIterator(this, row, column); @@ -774,7 +763,6 @@ function Folding() { * @param {number | null} [endRow] * @param {number | null} [depth] * @param {Function} [test] - * @this {IEditSession} */ this.foldAll = function(startRow, endRow, depth, test) { if (depth == undefined) @@ -808,7 +796,6 @@ function Folding() { /** * * @param {number} level - * @this {IEditSession} */ this.foldToLevel = function(level) { this.foldAll(); @@ -818,7 +805,6 @@ function Folding() { /** * - * @this {IEditSession} */ this.foldAllComments = function() { var session = this; @@ -866,13 +852,14 @@ function Folding() { }; /** - * @param {FoldMode} foldMode + * @param {Ace.FoldMode} foldMode * @this {IEditSession} */ this.$setFolding = function(foldMode) { if (this.$foldMode == foldMode) return; - + + this.$foldMode = foldMode; this.off('change', this.$updateFoldWidgets); @@ -896,7 +883,7 @@ function Folding() { /** * @param {number} row * @param {boolean} [ignoreCurrent] - * @return {{range: Range, firstRange: Range} | {}} + * @return {{range?: Range, firstRange?: Range}} * @this {IEditSession} */ this.getParentFoldRangeData = function (row, ignoreCurrent) { diff --git a/src/editor.js b/src/editor.js index 752224dfe4f..59be665bbac 100644 --- a/src/editor.js +++ b/src/editor.js @@ -4,7 +4,6 @@ * @type {Editor & Ace.EventEmitter & Ace.OptionsProvider & Ace.EditorProperties & Ace.EditorMultiSelectProperties} * @export */ - /** * * @typedef IEditSession @@ -34,9 +33,6 @@ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var CommandManager = require("./commands/command_manager").CommandManager; var defaultCommands = require("./commands/default_commands").commands; -/** - * @type {import("./lib/app_config").AppConfigWithAllOptions} - */ var config = require("./config"); var TokenIterator = require("./token_iterator").TokenIterator; var LineWidgets = require("./line_widgets").LineWidgets; diff --git a/src/layer/text.js b/src/layer/text.js index 37954e962c1..36edf0e2371 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -1,5 +1,15 @@ "use strict"; - +/** + * + * @typedef IEditSession + * @type {import("../edit_session").IEditSession} + */ +/** + * + * @typedef IText + * @type {Text & Ace.EventEmitter} + * @export + */ var oop = require("../lib/oop"); var dom = require("../lib/dom"); var lang = require("../lib/lang"); @@ -7,7 +17,13 @@ var Lines = require("./lines").Lines; var EventEmitter = require("../lib/event_emitter").EventEmitter; var nls = require("../config").nls; +/** + * @type {IText} + */ class Text { + /** + * @param {HTMLElement} parentEl + */ constructor(parentEl) { this.dom = dom; this.element = this.dom.createElement("div"); @@ -27,19 +43,31 @@ class Text { } } + /** + * @param {string | number} padding + */ setPadding(padding) { this.$padding = padding; this.element.style.margin = "0 " + padding + "px"; } - + + /** + * @returns {number} + */ getLineHeight() { return this.$fontMetrics.$characterSize.height || 0; } + /** + * @returns {number} + */ getCharacterWidth() { return this.$fontMetrics.$characterSize.width || 0; } + /** + * @param {any} measure + */ $setFontMetrics(measure) { this.$fontMetrics = measure; this.$fontMetrics.on("changeCharacterSize", function(e) { @@ -54,12 +82,22 @@ class Text { $pollSizeChanges() { return this.$pollSizeChangesTimer = this.$fontMetrics.$pollSizeChanges(); } + + /** + * @param {IEditSession} session + */ setSession(session) { + /** + * @type {IEditSession} + */ this.session = session; if (session) this.$computeTabString(); } - + + /** + * @param {string} showInvisibles + */ setShowInvisibles(showInvisibles) { if (this.showInvisibles == showInvisibles) return false; @@ -75,7 +113,10 @@ class Text { this.$computeTabString(); return true; } - + + /** + * @param {any} display + */ setDisplayIndentGuides(display) { if (this.displayIndentGuides == display) return false; @@ -84,7 +125,10 @@ class Text { this.$computeTabString(); return true; } - + + /** + * @param {any} highlight + */ setHighlightIndentGuides(highlight) { if (this.$highlightIndentGuides === highlight) return false; @@ -131,6 +175,11 @@ class Text { } } + /** + * @param {{ lastRow: number; firstRow: number; lineHeight: number; }} config + * @param {number} firstRow + * @param {number} lastRow + */ updateLines(config, firstRow, lastRow) { // Due to wrap line changes there can be new lines if e.g. // the line to updated wrapped in the meantime. @@ -644,6 +693,11 @@ class Text { } } + /** + * @param {any} row + * @param {{ walk: (arg0: (placeholder: any, row: any, column: any, lastColumn: any, isNewRow: any) => void, arg1: any, arg2: any) => void; end: { row: any; }; }} foldLine + * @return {Ace.Token[]} + */ $getFoldLineTokens(row, foldLine) { var session = this.session; var renderTokens = []; diff --git a/src/marker_group.js b/src/marker_group.js index 0e559c66cc5..a4cf380a488 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -1,4 +1,14 @@ "use strict"; +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ +/** + * @typedef MarkerGroupItem + * @type {{range: import("./range").Range, className: string}} + * @export + */ /* Potential improvements: @@ -6,15 +16,22 @@ Potential improvements: */ class MarkerGroup { + /** + * + * @param {IEditSession} session + */ constructor(session) { this.markers = []; + /** + * @type {IEditSession} + */ this.session = session; session.addDynamicMarker(this); } /** * Finds the first marker containing pos - * @param {Position} pos + * @param {Ace.Point} pos * @returns Ace.MarkerGroupItem */ getMarkerAtPosition(pos) { @@ -26,8 +43,8 @@ class MarkerGroup { /** * Comparator for Array.sort function, which sorts marker definitions by their positions * - * @param {Ace.MarkerGroupItem} a first marker. - * @param {Ace.MarkerGroupItem} b second marker. + * @param {MarkerGroupItem} a first marker. + * @param {MarkerGroupItem} b second marker. * @returns {number} negative number if a should be before b, positive number if b should be before a, 0 otherwise. */ markersComparator(a, b) { @@ -36,13 +53,19 @@ class MarkerGroup { /** * Sets marker definitions to be rendered. Limits the number of markers at MAX_MARKERS. - * @param {Ace.MarkerGroupItem[]} markers an array of marker definitions. + * @param {MarkerGroupItem[]} markers an array of marker definitions. */ setMarkers(markers) { this.markers = markers.sort(this.markersComparator).slice(0, this.MAX_MARKERS); this.session._signal("changeBackMarker"); } + /** + * @param {any} html + * @param {import("./layer/marker").Marker} markerLayer + * @param {IEditSession} session + * @param {{ firstRow: any; lastRow: any; }} config + */ update(html, markerLayer, session, config) { if (!this.markers || !this.markers.length) return; diff --git a/src/placeholder.js b/src/placeholder.js index 35372d49ce6..1e3010409de 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -39,7 +39,7 @@ class PlaceHolder { this.$pos = pos; // Used for reset - var undoStack = session.getUndoManager().$undoStack || session.getUndoManager().$undostack || {length: -1}; + var undoStack = session.getUndoManager().$undoStack || session.getUndoManager()["$undostack"] || {length: -1}; this.$undoStackDepth = undoStack.length; this.setup(); @@ -218,7 +218,7 @@ class PlaceHolder { if (this.$undoStackDepth === -1) return; var undoManager = this.session.getUndoManager(); - var undosRequired = (undoManager.$undoStack || undoManager.$undostack).length - this.$undoStackDepth; + var undosRequired = (undoManager.$undoStack || undoManager["$undostack"]).length - this.$undoStackDepth; for (var i = 0; i < undosRequired; i++) { undoManager.undo(this.session, true); } diff --git a/src/range.js b/src/range.js index 6d42f724daa..ae16ceb9e1c 100644 --- a/src/range.js +++ b/src/range.js @@ -12,15 +12,19 @@ class Range { /** - * @type {Number| undefined} + * @type {Number | undefined} */ id; + /** + * @type {Ace.Point | undefined} + */ + cursor; /** * Creates a new `Range` object with the given starting and ending rows and columns. - * @param {Number} startRow The starting row - * @param {Number} startColumn The starting column - * @param {Number} endRow The ending row - * @param {Number} endColumn The ending column + * @param {Number} [startRow] The starting row + * @param {Number} [startColumn] The starting column + * @param {Number} [endRow] The ending row + * @param {Number} [endColumn] The ending column * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { @@ -42,7 +46,7 @@ class Range { /** * Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`. - * @param {Range} range A range to check against + * @param {Ace.IRange} range A range to check against * @return {Boolean} **/ isEqual(range) { @@ -82,7 +86,7 @@ class Range { /** * Compares `this` range (A) with another range (B). - * @param {Range} range A range to compare with + * @param {Ace.IRange} range A range to compare with * @related [[Range.compare]] * @returns {Number} This method returns one of the following numbers: * * `-2`: (B) is in front of (A), and doesn't intersect with (A) @@ -133,7 +137,7 @@ class Range { /** * Checks the start and end [[Point]]'s of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range. - * @param {Range} range A range to compare with + * @param {Ace.IRange} range A range to compare with * @returns {Boolean} * @related [[Range.comparePoint]] **/ @@ -143,7 +147,7 @@ class Range { /** * Returns `true` if passed in `range` intersects with the one calling this method. - * @param {Range} range A range to compare with + * @param {Ace.IRange} range A range to compare with * @returns {Boolean} **/ intersects(range) { diff --git a/src/search.js b/src/search.js index cff236102d3..e7c872c3e94 100644 --- a/src/search.js +++ b/src/search.js @@ -1,5 +1,9 @@ "use strict"; - +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ var lang = require("./lib/lang"); var oop = require("./lib/oop"); var Range = require("./range").Range; @@ -19,7 +23,7 @@ class Search { * @property {boolean} [wholeWord] - Whether the search matches only on whole words * @property {Range|null} [range] - The [[Range]] to search within. Set this to `null` for the whole document * @property {boolean} [regExp] - Whether the search is a regular expression or not - * @property {Range|Position} [start] - The starting [[Range]] or cursor position to begin the search + * @property {Range|Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search * @property {boolean} [skipCurrent] - Whether or not to include the current line in the search * @property {boolean} [$isMultiLine] - true, if needle has \n or \r\n * @property {boolean} [preserveCase] @@ -65,7 +69,7 @@ class Search { /** * Searches for `options.needle`. If found, this method returns the [[Range `Range`]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session. - * @param {EditSession} session The session to search with + * @param {IEditSession} session The session to search with * @returns {Range|false} **/ find(session) { @@ -92,7 +96,7 @@ class Search { /** * Searches for all occurrances `options.needle`. If found, this method returns an array of [[Range `Range`s]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session. - * @param {EditSession} session The session to search with + * @param {IEditSession} session The session to search with * @returns {Range[]} **/ findAll(session) { @@ -167,7 +171,7 @@ class Search { /** * Searches for `options.needle` in `input`, and, if found, replaces it with `replacement`. * @param {String} input The text to search in - * @param {String} replacement The replacing text + * @param {any} replacement The replacing text * + (String): If `options.regExp` is `true`, this function returns `input` with the replacement already made. Otherwise, this function just returns `replacement`.
* If `options.needle` was not found, this function returns `null`. * @@ -187,7 +191,6 @@ class Search { var match = re.exec(input); if (!match || match[0].length != input.length) return null; - replacement = input.replace(re, replacement); if (options.preserveCase) { replacement = replacement.split(""); @@ -207,7 +210,7 @@ class Search { /** * * @param {SearchOptions} options - * @param $disableFakeMultiline + * @param {boolean} [$disableFakeMultiline] * @return {RegExp|boolean|*[]|*} */ $assembleRegExp(options, $disableFakeMultiline) { diff --git a/src/token_iterator.js b/src/token_iterator.js index ae1caa48a69..15879e1ec6f 100644 --- a/src/token_iterator.js +++ b/src/token_iterator.js @@ -1,5 +1,9 @@ "use strict"; - +/** + * + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ var Range = require("./range").Range; /** @@ -8,7 +12,7 @@ var Range = require("./range").Range; class TokenIterator { /** * Creates a new token iterator object. The inital token index is set to the provided row and column coordinates. - * @param {EditSession} session The session to associate with + * @param {IEditSession} session The session to associate with * @param {Number} initialRow The row to start the tokenizing at * @param {Number} initialColumn The column to start the tokenizing at **/ @@ -23,7 +27,7 @@ class TokenIterator { /** * Moves iterator position to the start of previous token. - * @returns {Token|null} + * @returns {Ace.Token|null} **/ stepBackward() { this.$tokenIndex -= 1; @@ -44,7 +48,7 @@ class TokenIterator { /** * Moves iterator position to the start of next token. - * @returns {Token|null} + * @returns {Ace.Token|null} **/ stepForward() { this.$tokenIndex += 1; @@ -68,7 +72,7 @@ class TokenIterator { /** * * Returns current token. - * @returns {Token} + * @returns {Ace.Token} **/ getCurrentToken() { return this.$rowTokens[this.$tokenIndex]; @@ -108,7 +112,7 @@ class TokenIterator { /** * Return the current token position. - * @returns {Position} + * @returns {Ace.Point} */ getCurrentTokenPosition() { return {row: this.$row, column: this.getCurrentTokenColumn()}; diff --git a/src/tokenizer.js b/src/tokenizer.js index 353ab56ecd8..81f2ed02173 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -7,7 +7,10 @@ var MAX_TOKEN_COUNT = 2000; * This class takes a set of highlighting rules, and creates a tokenizer out of them. For more information, see [the wiki on extending highlighters](https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#wiki-extendingTheHighlighter). **/ class Tokenizer { - + /** + * @type {RegExp} + */ + splitRegex; /** * Constructs a new tokenizer based on the given rules and flags. * @param {Object} rules The highlighting rules @@ -100,11 +103,18 @@ class Tokenizer { this.regExps[key] = new RegExp("(" + ruleRegExps.join(")|(") + ")|($)", flag); } } - + + /** + * @param {number} m + */ $setMaxTokenCount(m) { MAX_TOKEN_COUNT = m | 0; } - + + /** + * @param {string} str + * @return {Ace.Token[]} + */ $applyToken(str) { var values = this.splitRegex.exec(str).slice(1); var types = this.token.apply(this, values); @@ -124,6 +134,10 @@ class Tokenizer { return tokens; } + /** + * @param {string} str + * @return {Ace.Token[] | string} + */ $arrayTokens(str) { if (!str) return []; @@ -142,6 +156,10 @@ class Tokenizer { return tokens; } + /** + * @param {string} src + * @returns {string} + */ removeCapturingGroups(src) { var r = src.replace( /\\.|\[(?:\\.|[^\\\]])*|\(\?[:=!<]|(\()/g, @@ -150,6 +168,10 @@ class Tokenizer { return r; } + /** + * @param {string} src + * @param {string} flag + */ createSplitterRegexp(src, flag) { if (src.indexOf("(?=") != -1) { var stack = 0; @@ -191,8 +213,10 @@ class Tokenizer { /** * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state. - * @returns {Object} - **/ + * @param {string} line + * @param {string | string[]} startState + * @returns {{tokens:Ace.Token[], state: string|string[]}} + */ getLineTokens(line, startState) { if (startState && typeof startState != "string") { var stack = startState.slice(0); diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 17f0dfae5ef..71dc36fb45d 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1993,6 +1993,9 @@ class VirtualRenderer { } } + /** + * @this {IVirtualRenderer} + */ $addResizeObserver() { if (!window.ResizeObserver || this.$resizeObserver) return; var self = this; diff --git a/tsconfig.json b/tsconfig.json index 5e6d89a5708..e4cbcf22b6d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,10 +20,11 @@ "src/keyboard", "src/**/*_test.js", "./src/mode/**/*", - "./types/**/*", + "types", ], "include": [ "./src/**/*", - "./ace.d.ts" + "./ace.d.ts", + "src/mode/text.js" ] } From f60e6320c000f46c7ba36baee53e21b19cfbc64f Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 14 Sep 2023 20:01:25 +0400 Subject: [PATCH 06/36] continue providing types --- ace.d.ts | 665 ++++++------------ package.json | 2 +- src/anchor.js | 13 +- src/apply_delta.js | 2 +- src/autocomplete.js | 121 ++-- src/autocomplete/inline.js | 4 +- src/autocomplete/popup.js | 12 +- src/autocomplete/util.js | 4 + src/background_tokenizer.js | 7 +- src/bidihandler.js | 4 +- src/clipboard.js | 6 +- src/commands/command_manager.js | 3 +- src/commands/incremental_search_commands.js | 4 + src/document.js | 118 ++-- src/edit_session.js | 107 ++- src/edit_session/bracket_match.js | 20 +- src/edit_session/fold.js | 18 +- src/edit_session/fold_line.js | 2 +- src/edit_session/folding.js | 16 +- src/editor.js | 67 +- src/ext/beautify.js | 8 + src/ext/code_lens.js | 20 + src/ext/command_bar.js | 68 +- src/ext/elastic_tabstops_lite.js | 50 +- src/ext/emmet.js | 8 +- src/ext/error_marker.js | 4 + src/ext/hardwrap.js | 4 + src/ext/keybinding_menu.js | 91 ++- .../get_editor_keyboard_shortcuts.js | 5 +- src/ext/menu_tools/overlay_page.js | 5 +- src/ext/options.js | 37 +- src/ext/prompt.js | 73 +- src/ext/searchbox.js | 74 +- src/ext/settings_menu.js | 11 +- src/ext/static_highlight.js | 38 +- src/ext/statusbar.js | 15 +- src/ext/textarea.js | 2 +- src/ext/whitespace.js | 33 +- src/keyboard/gutter_handler.js | 86 +-- src/keyboard/hash_handler.js | 3 +- src/keyboard/keybinding.js | 3 + src/keyboard/textinput.js | 32 +- src/layer/font_metrics.js | 25 +- src/layer/gutter.js | 73 +- src/layer/marker.js | 26 +- src/layer/text.js | 14 +- src/lib/app_config.js | 3 +- src/lib/dom.js | 97 ++- src/lib/event.js | 10 +- src/lib/lang.js | 4 +- src/lib/net.js | 3 + src/line_widgets.js | 30 +- src/marker_group.js | 4 +- src/mode/text.js | 66 +- src/mouse/default_gutter_handler.js | 4 +- src/mouse/default_handlers.js | 50 +- src/mouse/dragdrop_handler.js | 31 +- src/mouse/mouse_event.js | 3 + src/mouse/mouse_handler.js | 13 + src/multi_select.js | 233 +++++- src/occur.js | 46 +- src/placeholder.js | 13 +- src/range.js | 40 +- src/range_list.js | 33 + src/scrollbar.js | 9 + src/scrollbar_custom.js | 6 + src/search.js | 9 +- src/selection.js | 126 +++- src/snippets.js | 49 +- src/split.js | 62 +- src/token_iterator.js | 8 +- src/tokenizer.js | 6 +- src/undomanager.js | 10 +- src/virtual_renderer.js | 26 +- tsconfig.json | 8 +- 75 files changed, 1959 insertions(+), 1046 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 166442a522a..f6fd3b320e9 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,20 +1,84 @@ /// -declare namespace Ace { +export namespace Ace { + type Anchor = import("./src/anchor").IAnchor; + type Editor = import("./src/editor").IEditor; + type EditSession = import("./src/edit_session").IEditSession; + type Document = import("./src/document").IDocument; + type Folding = import("./src/edit_session/folding").IFolding; + type Fold = import("./src/edit_session/fold").Fold; + type FoldLine = import("./src/edit_session/fold_line").FoldLine; + type Range = import("./src/range").Range; + type VirtualRenderer = import("./src/virtual_renderer").IVirtualRenderer; + type UndoManager = import("./src/undomanager").UndoManager; + type Tokenizer = import("./src/tokenizer").Tokenizer; + type TokenIterator = import("./src/token_iterator").TokenIterator; + type Selection = import("./src/selection").ISelection; + type Autocomplete = import("./src/autocomplete").Autocomplete; + type CompletionProvider = import("./src/autocomplete").CompletionProvider; + type AcePopup = import("./src/autocomplete/popup").IAcePopup; + type Config = import("./src/config").IConfig; + + interface ScrollBar { + setVisible(visible: boolean): void; + [key: string]: any; + } + + interface HScrollbar extends ScrollBar { + setWidth(width: number): void; + } + + interface VScrollbar extends ScrollBar { + setHeight(width: number): void; + } + + interface LayerConfig { + width : number, + padding : number, + firstRow : number, + firstRowScreen: number, + lastRow : number, + lineHeight : number, + characterWidth : number, + minHeight : number, + maxHeight : number, + offset : number, + height : number, + gutterOffset: number + } + interface HardWrapOptions { + startRow: number; + endRow: number; + allowMerge?: boolean; + column?: number; + } + + interface CommandBarOptions { + maxElementsOnTooltip: number; + alwaysShow: boolean; + showDelay: number; + hideDelay: number; + } + interface ScreenCoordinates { + row: number, + column: number, + side: 1 | -1, + offsetX: number + } interface FoldingProperties { $foldMode: FoldMode, foldWidgets: FoldWidget[], - getFoldWidget: FoldMode.getFoldWidget, - getFoldWidgetRange: FoldMode.getFoldWidgetRange, - $updateFoldWidgets: (delta: Delta) => void, - $tokenizerUpdateFoldWidgets: (e) => void, - addFold: (placeholder: Fold|String, range?: Range) => Fold, - removeFold: (fold: Fold) => void, - removeFolds: (folds: Fold[]) => void, - setFoldStyle: (style: string) => void, - $setFolding: (foldMode: FoldMode) => void, + getFoldWidget: Function, + getFoldWidgetRange: Function, + $updateFoldWidgets(delta: Delta): void, + $tokenizerUpdateFoldWidgets(e): void, + addFold(placeholder: Fold|String, range?: Range): Fold, + removeFold(fold: Fold): void, + removeFolds(folds: Fold[]): void, + setFoldStyle(style: string): void, + $setFolding(foldMode: FoldMode): void, } - + interface AcePopupProperties { setSelectOnHover?: (val: boolean) => void, setRow?: (line: number) => void, @@ -39,14 +103,7 @@ declare namespace Ace { anchorPos?: any } interface ISelection { - session: IEditSession; - doc: IDocument; - cursor: Anchor; - anchor: Anchor; - $silent: boolean; - lead: Anchor; - $cursorChanged?:boolean; - $isEmpty?:boolean; + [key: string]: any; } interface IRange { start: Point; @@ -60,43 +117,47 @@ declare namespace Ace { column?: number; row?: number; $oldWidget?: LineWidget, - session: IEditSession, + session: EditSession, html?: string, text?: string, className?: string, coverGutter?: boolean, pixelHeight?: number, $fold?: Fold, - editor: IEditor, + editor: Editor, coverLine?: boolean, fixedWidth?: boolean, fullWidth?: boolean, screenWidth?: number, rowsAbove?: number, + lenses?: any[], } - + interface EditorProperties { $mergeUndoDeltas?: any, $highlightSelectedWord?: boolean, $updatePlaceholder?: Function, $cursorStyle?: string, $readOnly?: any, - searchBox?: any, $highlightActiveLine?: any, $enableAutoIndent?: any, $copyWithEmptySelection?: any $selectionStyle?: string, env?: any; - widgetManager?: LineWidgets, - completer?: Autocomplete, - completers?: Completer[], + widgetManager?: import("./src/line_widgets").LineWidgets, + completer?: import("./src/autocomplete").Autocomplete, + completers: Completer[], $highlightTagPending?: boolean, + showKeyboardShortcuts?: () => void, + showSettingsMenu?: () => void, + searchBox?: import("./src/ext/searchbox").SearchBox + [key: string]: any; } interface EditSessionProperties { $highlightLineMarker?: { - start: Ace.Point, - end: Ace.Point, + start: Point, + end: Point, id?: number } $useSoftTabs?: boolean, @@ -120,12 +181,13 @@ declare namespace Ace { $enableVarChar?: any, $wrap?:any, $navigateWithinSoftTabs?: boolean + [key: string]: any; } interface EditorMultiSelectProperties { inMultiSelectMode?: boolean, forEachSelection?: Function, - exitMultiSelectMode?: Function + exitMultiSelectMode?: Function, } interface VirtualRendererProperties { @@ -157,7 +219,7 @@ declare namespace Ace { } type NewLineMode = 'auto' | 'unix' | 'windows'; - + interface EditSessionOptions { wrap: "off" | "free" | "printmargin" | boolean | number; wrapMethod: 'code' | 'text' | 'auto'; @@ -188,7 +250,7 @@ declare namespace Ace { highlightGutterLine: boolean; hScrollBarAlwaysVisible: boolean; vScrollBarAlwaysVisible: boolean; - fontSize: number; + fontSize: string; fontFamily: string; maxLines: number; minLines: number; @@ -214,7 +276,7 @@ declare namespace Ace { interface EditorOptions extends EditSessionOptions, MouseHandlerOptions, VirtualRendererOptions { - selectionStyle: string; + selectionStyle: "fullLine" | "screenLine" | "text" | "line"; highlightActiveLine: boolean; highlightSelectedWord: boolean; readOnly: boolean; @@ -237,30 +299,31 @@ declare namespace Ace { relativeLineNumbers: boolean; enableMultiselect: boolean; enableKeyboardAccessibility: boolean; + enableCodeLens: boolean; } class EventEmitter { - once?(name: string, callback: Function): void; + once(name: string, callback: Function): void; - setDefaultHandler?(name: string, callback: Function): void; + setDefaultHandler(name: string, callback: Function): void; - removeDefaultHandler?(name: string, callback: Function): void; + removeDefaultHandler(name: string, callback: Function): void; - on?(name: string, callback: Function, capturing?: boolean): Function; + on(name: string, callback: Function, capturing?: boolean): Function; - addEventListener?(name: string, callback: Function, capturing?: boolean): Function; + addEventListener(name: string, callback: Function, capturing?: boolean): Function; - off?(name: string, callback: Function): void; + off(name: string, callback: Function): void; - removeListener?(name: string, callback: Function): void; + removeListener(name: string, callback: Function): void; - removeEventListener?(name: string, callback: Function): void; + removeEventListener(name: string, callback: Function): void; - removeAllListeners?(name?: string): void; + removeAllListeners(name?: string): void; - _signal?(eventName: string, e: any): void; + _signal(eventName: string, e: any): void; - _emit?(eventName: string, e: any): void; + _emit(eventName: string, e: any): void; } interface SearchOptions { @@ -275,6 +338,7 @@ declare namespace Ace { wholeWord: boolean; caseSensitive: boolean; wrap: boolean; + re: RegExp; } interface Point { @@ -300,7 +364,19 @@ declare namespace Ace { type: string; } - interface Command { + export interface MarkerGroupItem { + range: Range; + className: string; + } + + export class MarkerGroup { + constructor(session: EditSession); + setMarkers(markers: MarkerGroupItem[]): void; + getMarkerAtPosition(pos: Position): MarkerGroupItem; + } + + + export interface Command { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; @@ -313,11 +389,11 @@ declare namespace Ace { handleKeyboard: Function; } - interface MarkerLike { + export interface MarkerLike { range?: Range; - type?: string; + type: string; renderer?: MarkerRenderer; - clazz?: string; + clazz: string; inFront?: boolean; id?: number; update?: (html: string[], @@ -325,6 +401,7 @@ declare namespace Ace { marker: any, session: EditSession, config: any) => void; + [key: string]: any; } type MarkerRenderer = (html: string[], @@ -340,43 +417,31 @@ declare namespace Ace { start?: number; } - interface BaseCompletion { - score?: number; - meta?: string; - caption?: string; - docHTML?: string; - docText?: string; - completerId?: string; - } - - interface SnippetCompletion extends BaseCompletion { - snippet: string; - value?: string; - } - - interface ValueCompletion extends BaseCompletion { - value: string; - snippet?: string; - } + type BaseCompletion = import("./src/autocomplete").BaseCompletion; + type SnippetCompletion = import("./src/autocomplete").SnippetCompletion; + type ValueCompletion = import("./src/autocomplete").ValueCompletion; + type Completion = import("./src/autocomplete").Completion; - type Completion = SnippetCompletion | ValueCompletion - - - - type HighlightRule = { defaultToken: string } | { include: string } | { todo: string } | { + type HighlightRule = ({ defaultToken: string } | { include: string } | { todo: string } | { token: string | string[] | ((value: string) => string); regex: string | RegExp; - next?: string; + next?: string | (() => void); push?: string; comment?: string; caseInsensitive?: boolean; - } + nextState?: string; + }) & { [key: string]: any }; type HighlightRulesMap = Record; type KeywordMapper = (keyword: string) => string; interface HighlightRules { + $rules: HighlightRulesMap; + $embeds: string[]; + $keywords: any[]; + $keywordList: string[]; + addRules(rules: HighlightRulesMap, prefix?: string): void; getRules(): HighlightRulesMap; @@ -389,25 +454,25 @@ declare namespace Ace { createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; } - + type FoldWidget = "start" | "end" | "" interface FoldMode { foldingStartMarker: RegExp; foldingStopMarker?: RegExp; - getFoldWidget(session: IEditSession, foldStyle: string, row: number): FoldWidget; + getFoldWidget(session: EditSession, foldStyle: string, row: number): FoldWidget; - getFoldWidgetRange(session: IEditSession, foldStyle: string, row: number): Range | undefined; + getFoldWidgetRange(session: EditSession, foldStyle: string, row: number): Range | undefined; - indentationBlock(session: IEditSession, row: number, column?: number): Range | undefined; + indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; - openingBracketBlock(session: IEditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; - closingBracketBlock(session: IEditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; } - type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => { text: string, selection: number[] } | Range | undefined; + type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string | Range) => ({ text: string, selection: number[] } | Range) & {[key: string]: any} | undefined; type BehaviorMap = Record>; interface Behaviour { @@ -419,7 +484,7 @@ declare namespace Ace { inherit(mode: SyntaxMode | (new () => SyntaxMode), filter: string[]): void; - getBehaviours(filter: string[]): BehaviorMap; + getBehaviours(filter?: string[]): BehaviorMap; } interface Outdent { @@ -429,11 +494,36 @@ declare namespace Ace { } interface SyntaxMode { - HighlightRules: HighlightRules; + /** + * quotes used by language mode + */ + $quotes: {[quote: string]: string}; + HighlightRules: HighlightRules; //TODO: fix this foldingRules?: FoldMode; $behaviour?: Behaviour; $defaultBehaviour?: Behaviour; + /** + * characters that indicate the start of a line comment + */ lineCommentStart?: string; + /** + * characters that indicate the start and end of a block comment + */ + blockComment?: {start: string, end: string} + tokenRe?: RegExp; + nonTokenRe?: RegExp; + /** + * An object containing conditions to determine whether to apply matching quote or not. + */ + $pairQuotesAfter: {[quote: string]: RegExp} + $tokenizer: Tokenizer; + $highlightRules: HighlightRules; + $embeds?: string[]; + $modes?: SyntaxMode[]; + $keywordList?: string[]; + $highlightRuleConfig?: any; + completionKeywords: string[]; + transformAction: BehaviorAction; getTokenizer(): Tokenizer; @@ -451,35 +541,37 @@ declare namespace Ace { checkOutdent(state: any, line: string, input: string): boolean; - autoOutdent(state: any, doc: IEditSession, row: number): void; + autoOutdent(state: any, doc: EditSession, row: number): void; // TODO implement WorkerClient types createWorker(session: EditSession): any; createModeDelegates(mapping: { [key: string]: string }): void; - transformAction: BehaviorAction; - getKeywords(append?: boolean): Array; getCompletions(state: string, session: EditSession, pos: Point, prefix: string): Completion[]; + + $getIndent(line: string): string; + $createKeywordList(): string[]; + } - + interface OptionsBase { [key: string]: any; } class OptionsProvider { - setOptions?(optList: Partial): void; + setOptions(optList: Partial): void; - getOptions?(optionNames?: Array | Partial): Partial; + getOptions(optionNames?: Array | Partial): Partial; - setOption?(name: K, value: K[T]): void; + setOption(name: K, value: T[K]): void; - getOption?(name: K): T[K]; + getOption(name: K): T[K]; } @@ -519,22 +611,6 @@ declare namespace Ace { on(name: 'afterExec', callback: execEventHandler): Function; - once(name: string, callback: Function): void; - - setDefaultHandler(name: string, callback: Function): void; - - removeDefaultHandler(name: string, callback: Function): void; - - on(name: string, callback: Function, capturing?: boolean): void; - - addEventListener(name: string, callback: Function, capturing?: boolean): void; - - off(name: string, callback: Function): void; - - removeListener(name: string, callback: Function): void; - - removeEventListener(name: string, callback: Function): void; - exec(command: string, editor: Editor, args: any): boolean; toggleRecording(editor: Editor): void; @@ -564,282 +640,6 @@ declare namespace Ace { getStatusText(editor: Editor, data: {}): string; } - interface VirtualRenderer extends OptionsProvider, EventEmitter { - readonly container: HTMLElement; - readonly scroller: HTMLElement; - readonly content: HTMLElement; - readonly characterWidth: number; - readonly lineHeight: number; - readonly scrollLeft: number; - readonly scrollTop: number; - readonly $padding: number; - - setOption(name: T, value: VirtualRendererOptions[T]): void; - - getOption(name: T): VirtualRendererOptions[T]; - - setSession(session: EditSession): void; - - updateLines(firstRow: number, lastRow: number, force?: boolean): void; - - updateText(): void; - - updateFull(force?: boolean): void; - - updateFontSize(): void; - - adjustWrapLimit(): boolean; - - setAnimatedScroll(shouldAnimate: boolean): void; - - getAnimatedScroll(): boolean; - - setShowInvisibles(showInvisibles: boolean): void; - - getShowInvisibles(): boolean; - - setDisplayIndentGuides(display: boolean): void; - - getDisplayIndentGuides(): boolean; - - setShowPrintMargin(showPrintMargin: boolean): void; - - getShowPrintMargin(): boolean; - - setPrintMarginColumn(showPrintMargin: boolean): void; - - getPrintMarginColumn(): boolean; - - setShowGutter(show: boolean): void; - - getShowGutter(): boolean; - - setFadeFoldWidgets(show: boolean): void; - - getFadeFoldWidgets(): boolean; - - setHighlightGutterLine(shouldHighlight: boolean): void; - - getHighlightGutterLine(): boolean; - - getContainerElement(): HTMLElement; - - getMouseEventTarget(): HTMLElement; - - getTextAreaContainer(): HTMLElement; - - getFirstVisibleRow(): number; - - getFirstFullyVisibleRow(): number; - - getLastFullyVisibleRow(): number; - - getLastVisibleRow(): number; - - setPadding(padding: number): void; - - setScrollMargin(top: number, - bottom: number, - left: number, - right: number): void; - - setHScrollBarAlwaysVisible(alwaysVisible: boolean): void; - - getHScrollBarAlwaysVisible(): boolean; - - setVScrollBarAlwaysVisible(alwaysVisible: boolean): void; - - getVScrollBarAlwaysVisible(): boolean; - - freeze(): void; - - unfreeze(): void; - - updateFrontMarkers(): void; - - updateBackMarkers(): void; - - updateBreakpoints(): void; - - setAnnotations(annotations: Annotation[]): void; - - updateCursor(): void; - - hideCursor(): void; - - showCursor(): void; - - scrollSelectionIntoView(anchor: Position, - lead: Position, - offset?: number): void; - - scrollCursorIntoView(cursor: Position, offset?: number): void; - - getScrollTop(): number; - - getScrollLeft(): number; - - getScrollTopRow(): number; - - getScrollBottomRow(): number; - - scrollToRow(row: number): void; - - alignCursor(cursor: Position | number, alignment: number): number; - - scrollToLine(line: number, - center: boolean, - animate: boolean, - callback: () => void): void; - - animateScrolling(fromValue: number, callback: () => void): void; - - scrollToY(scrollTop: number): void; - - scrollToX(scrollLeft: number): void; - - scrollTo(x: number, y: number): void; - - scrollBy(deltaX: number, deltaY: number): void; - - isScrollableBy(deltaX: number, deltaY: number): boolean; - - textToScreenCoordinates(row: number, column: number): { pageX: number, pageY: number }; - - pixelToScreenCoordinates(x: number, y: number): { row: number, column: number, side: 1 | -1, offsetX: number }; - - visualizeFocus(): void; - - visualizeBlur(): void; - - showComposition(position: number): void; - - setCompositionText(text: string): void; - - hideComposition(): void; - - setGhostText(text: string, position: Point): void; - - removeGhostText(): void; - - setTheme(theme: string, callback?: () => void): void; - - getTheme(): string; - - setStyle(style: string, include?: boolean): void; - - unsetStyle(style: string): void; - - setCursorStyle(style: string): void; - - setMouseCursor(cursorStyle: string): void; - - attachToShadowRoot(): void; - - destroy(): void; - } - - - interface Selection extends EventEmitter { - moveCursorWordLeft(): void; - - moveCursorWordRight(): void; - - fromOrientedRange(range: Range): void; - - setSelectionRange(match: any): void; - - getAllRanges(): Range[]; - - addRange(range: Range): void; - - isEmpty(): boolean; - - isMultiLine(): boolean; - - setCursor(row: number, column: number): void; - - setAnchor(row: number, column: number): void; - - getAnchor(): Position; - - getCursor(): Position; - - isBackwards(): boolean; - - getRange(): Range; - - clearSelection(): void; - - selectAll(): void; - - setRange(range: Range, reverse?: boolean): void; - - selectTo(row: number, column: number): void; - - selectToPosition(pos: any): void; - - selectUp(): void; - - selectDown(): void; - - selectRight(): void; - - selectLeft(): void; - - selectLineStart(): void; - - selectLineEnd(): void; - - selectFileEnd(): void; - - selectFileStart(): void; - - selectWordRight(): void; - - selectWordLeft(): void; - - getWordRange(): void; - - selectWord(): void; - - selectAWord(): void; - - selectLine(): void; - - moveCursorUp(): void; - - moveCursorDown(): void; - - moveCursorLeft(): void; - - moveCursorRight(): void; - - moveCursorLineStart(): void; - - moveCursorLineEnd(): void; - - moveCursorFileEnd(): void; - - moveCursorFileStart(): void; - - moveCursorLongWordRight(): void; - - moveCursorLongWordLeft(): void; - - moveCursorBy(rows: number, chars: number): void; - - moveCursorToPosition(position: any): void; - - moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void; - - moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void; - - toJSON(): SavedSelection | SavedSelection[]; - - fromJSON(selection: SavedSelection | SavedSelection[]): void; - } - interface SavedSelection { start: Point; end: Point; @@ -855,7 +655,7 @@ declare namespace Ace { setAriaOption(activeDescendant: string, role: string): void; } - + type CompleterCallback = (error: any, completions: Completion[]) => void; interface Completer { @@ -894,12 +694,6 @@ declare namespace Ace { ignoreCaption?: boolean; } - type CompletionRecord = { - all: Completion[]; - filtered: Completion[]; - filterText: string; - } | CompletionProviderOptions - type GatherCompletionRecord = { prefix: string; matches: Completion[]; @@ -907,113 +701,80 @@ declare namespace Ace { } type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; - type CompletionProviderCallback = (this: Autocomplete, err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; - - class CompletionProvider { - insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; - - insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; - - completions: CompletionRecord; - + type CompletionProviderCallback = (this: import("./src/autocomplete").Autocomplete, err: Error | undefined, completions: import("./src/autocomplete").FilteredList, finished: boolean) => void; - - detach(): void; - } - type AcePopupNavigation = "up" | "down" | "start" | "end"; - class AcePopup { - constructor(parentNode: HTMLElement); - - setData(list: Completion[], filterText: string): void; - - getData(row: number): Completion; - - getRow(): number; - getRow(line: number): void; - - hide(): void; - - show(pos: Point, lineHeight: number, topdownOnly: boolean): void; - - tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; - - goTo(where: AcePopupNavigation): void; - } } -declare const version: string; -declare const config: Ace.Config; - -declare function require(name: string): any; - +export const version: string; +export const config: Ace.Config; +export function require(name: string): any; +export function edit(el: string | (Element & { + env?; + value?; +}), options?: Partial): Ace.Editor; +export function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; +export const VirtualRenderer: { + new(container: HTMLElement, theme?: string): Ace.VirtualRenderer; +}; +export const EditSession: { + new(text: string | Ace.Document, mode?: Ace.SyntaxMode): Ace.EditSession; +}; +export const UndoManager: { + new(): Ace.UndoManager; +}; +export const Editor: { + new(): Ace.Editor; +}; +export const Range: { + new(startRow: number, startColumn: number, endRow: number, endColumn: number): Ace.Range; + fromPoints(start: Ace.Point, end: Ace.Point): Ace.Range; + comparePoints(p1: Ace.Point, p2: Ace.Point): number; +}; type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; type TooltipCommandFunction = (editor: Ace.Editor) => T; -interface TooltipCommand extends Ace.Command { +export interface TooltipCommand extends Ace.Command { enabled: TooltipCommandFunction | boolean, getValue?: TooltipCommandFunction, type: "button" | "text" | "checkbox" - iconCssClass: string, - cssClass: string + iconCssClass?: string, + cssClass?: string } -declare class InlineAutocomplete { +export class InlineAutocomplete { constructor(); - getInlineRenderer(): Ace.AceInline; - getInlineTooltip(): CommandBarTooltip; - getCompletionProvider(): Ace.CompletionProvider; - show(editor: Ace.Editor): void; - isOpen(): boolean; - detach(): void; - destroy(): void; - goTo(action: InlineAutocompleteAction): void; - tooltipEnabled: boolean; commands: Record - getIndex(): number; - setIndex(value: number): void; - getLength(): number; - getData(index?: number): Ace.Completion | undefined; - updateCompletions(options: Ace.CompletionOptions): void; } -declare class CommandBarTooltip { +export class CommandBarTooltip { constructor(parentElement: HTMLElement); - registerCommand(id: string, command: TooltipCommand): void; - attach(editor: Ace.Editor): void; - updatePosition(): void; - update(): void; - isShown(): boolean; - getAlwaysShow(): boolean; - setAlwaysShow(alwaysShow: boolean): void; - detach(): void; - destroy(): void; } diff --git a/package.json b/package.json index 15da2c35963..1b7cad1db8f 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "author": "Fabian Jakobs ", "main": "src/ace.js", - "typings": "types/ace.d.ts", + "typings": "ace.d.ts", "repository": { "type": "git", "url": "http://github.com/ajaxorg/ace.git" diff --git a/src/anchor.js b/src/anchor.js index acf081add15..e90985cd882 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -5,21 +5,23 @@ */ /** * @typedef IAnchor - * @type {Anchor & Ace.EventEmitter & {markerId?: number}} + * @type {Anchor & import("../ace").Ace.EventEmitter & {markerId?: number}} */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; /** * Defines a floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the anchor is updated. + * @this {IAnchor} **/ class Anchor { /** * Creates a new `Anchor` and associates it with a document. * * @param {IDocument} doc The document to associate with the anchor - * @param {Number|Ace.Point} row The starting row position + * @param {Number|import("../ace").Ace.Point} row The starting row position * @param {Number} [column] The starting column position + * @this {IAnchor} **/ constructor(doc, row, column) { this.$onChange = this.onChange.bind(this); @@ -33,7 +35,7 @@ class Anchor { /** * Returns an object identifying the `row` and `column` position of the current anchor. - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} **/ getPosition() { return this.$clipPositionToDocument(this.row, this.column); @@ -63,7 +65,8 @@ class Anchor { **/ /** * Internal function called when `"change"` event fired. - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta + * @this {IAnchor} */ onChange(delta) { if (delta.start.row == delta.end.row && delta.start.row != this.row) @@ -132,7 +135,7 @@ class Anchor { * Clips the anchor position to the specified row and column. * @param {Number} row The row index to clip the anchor to * @param {Number} column The column index to clip the anchor to - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} * **/ $clipPositionToDocument(row, column) { diff --git a/src/apply_delta.js b/src/apply_delta.js index 8ff0c6b554d..97fc4a7a8f5 100644 --- a/src/apply_delta.js +++ b/src/apply_delta.js @@ -43,7 +43,7 @@ function validateDelta(docLines, delta) { /** * Applies a delta to a document. * @param {string[]} docLines - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta * @param [doNotValidate] */ exports.applyDelta = function(docLines, delta, doNotValidate) { diff --git a/src/autocomplete.js b/src/autocomplete.js index 48413bc7479..2607d6c6f96 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -1,13 +1,9 @@ "use strict"; /** - * - * @typedef IAcePopup - * @type {import("./autocomplete/popup").IAcePopup} + * @typedef {import("./autocomplete/popup").IAcePopup} IAcePopup */ /** - * - * @typedef IEditor - * @type {import("./editor").IEditor} + * @typedef {import("./editor").IEditor} IEditor */ var HashHandler = require("./keyboard/hash_handler").HashHandler; var AcePopup = require("./autocomplete/popup").AcePopup; @@ -30,26 +26,33 @@ var config = require("./config"); * @property {string} [docText] - a plain text that would be displayed as an additional popup. If `docHTML` exists, * it would be used instead of `docText`. * @property {string} [completerId] - the identifier of the completer - * @property {Ace.Range} [range] - An object specifying the range of text to be replaced with the new completion value (experimental) + * @property {import("../ace").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental) * @property {string} [command] - A command to be executed after the completion is inserted (experimental) + * @property {string} [snippet] - a text snippet that would be inserted when the completion is selected + * @property {string} [value] - The text that would be inserted when selecting this completion. + * @property {{insertMatch:(editor: IEditor, data: Completion) => void}} [completer] + * @export */ /** - * @extends BaseCompletion - * @typedef SnippetCompletion - * @property {string} snippet - a text snippet that would be inserted when the completion is selected + * @typedef {BaseCompletion & {snippet: string}} SnippetCompletion + * @property {string} snippet + * @property {string} [value] + * @export */ /** - * @extends BaseCompletion - * @typedef ValueCompletion - * @property {string} value - The text that would be inserted when selecting this completion. + * @typedef {BaseCompletion & {value: string}} ValueCompletion + * @property {string} value + * @property {string} [snippet] + * @export */ /** * Represents a suggested text snippet intended to complete a user's input * @typedef Completion * @type {SnippetCompletion|ValueCompletion} + * @export */ var destroyCompleter = function(e, editor) { @@ -308,7 +311,7 @@ class Autocomplete { } /** - * @param {Ace.Completion} data + * @param {Completion} data * @param {undefined} [options] * @return {boolean | void} */ @@ -330,7 +333,7 @@ class Autocomplete { /** * This is the entry point for the autocompletion class, triggers the actions which collect and display suggestions * @param {IEditor} editor - * @param {Ace.CompletionOptions} options + * @param {import("../ace").Ace.CompletionOptions} options */ showPopup(editor, options) { if (this.editor) @@ -370,7 +373,7 @@ class Autocomplete { /** * @param {boolean} keepPopupPosition - * @param {Ace.CompletionOptions} options + * @param {import("../ace").Ace.CompletionOptions} options */ updateCompletions(keepPopupPosition, options) { if (keepPopupPosition && this.base && this.completions) { @@ -408,42 +411,44 @@ class Autocomplete { pos }).provideCompletions(this.editor, completionOptions, /** - * @type {(err: any, completions: Ace.Completion[], finished: boolean) => void | boolean} - * @this {Autocomplete} + * @type {(err: any, completions: FilteredList, finished: boolean) => void | boolean} + * @this {Autocomplete & {emptyMessage}} */ - function(err, completions, finished) { - var filtered = completions.filtered; - var prefix = util.getCompletionPrefix(this.editor); - - if (finished) { - // No results - if (!filtered.length) { - var emptyMessage = !this.autoShown && this.emptyMessage; - if ( typeof emptyMessage == "function") - emptyMessage = this.emptyMessage(prefix); - if (emptyMessage) { - var completionsForEmpty = [{ - caption: this.emptyMessage(prefix), - value: "" - }]; - this.completions = new FilteredList(completionsForEmpty); - this.openPopup(this.editor, prefix, keepPopupPosition); - return; + function (err, completions, finished) { + var filtered = completions.filtered; + var prefix = util.getCompletionPrefix(this.editor); + + if (finished) { + // No results + if (!filtered.length) { + var emptyMessage = !this.autoShown && this.emptyMessage; + if (typeof emptyMessage == "function") emptyMessage = this.emptyMessage(prefix); + if (emptyMessage) { + var completionsForEmpty = [ + { + caption: this.emptyMessage(prefix), + value: "" + } + ]; + this.completions = new FilteredList(completionsForEmpty); + this.openPopup(this.editor, prefix, keepPopupPosition); + return; + } + return this.detach(); } - return this.detach(); - } - // One result equals to the prefix - if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet) - return this.detach(); + // One result equals to the prefix + if (filtered.length == 1 && filtered[0].value == prefix + && !filtered[0].snippet) return this.detach(); - // Autoinsert if one result - if (this.autoInsert && !this.autoShown && filtered.length == 1) - return this.insertMatch(filtered[0]); - } - this.completions = completions; - this.openPopup(this.editor, prefix, keepPopupPosition); - }.bind(this)); + // Autoinsert if one result + if (this.autoInsert && !this.autoShown && filtered.length == 1) return this.insertMatch( + filtered[0]); + } + this.completions = completions; + this.openPopup(this.editor, prefix, keepPopupPosition); + }.bind(this) + ); } cancelContextMenu() { @@ -479,7 +484,7 @@ class Autocomplete { showDocTooltip(item) { if (!this.tooltipNode) { this.tooltipNode = dom.createElement("div"); - this.tooltipNode.style.margin = 0; + this.tooltipNode.style.margin = "0"; this.tooltipNode.style.pointerEvents = "auto"; this.tooltipNode.tabIndex = -1; this.tooltipNode.onblur = this.blurListener.bind(this); @@ -630,12 +635,12 @@ Autocomplete.startCommand = { */ class CompletionProvider { /** - * @type {Ace.CompletionRecord} + * @type {FilteredList} */ completions; /** - * @param {{pos: Position, prefix: string}} initialPosition + * @param {{pos: import("../ace").Ace.Position, prefix: string}} initialPosition */ constructor(initialPosition) { this.initialPosition = initialPosition; @@ -645,7 +650,7 @@ class CompletionProvider { /** * @param {IEditor} editor * @param {number} index - * @param {Ace.CompletionProviderOptions} [options] + * @param {import("../ace").Ace.CompletionProviderOptions} [options] * @returns {boolean} */ insertByIndex(editor, index, options) { @@ -657,8 +662,8 @@ class CompletionProvider { /** * @param {IEditor} editor - * @param {Ace.Completion} data - * @param {Ace.CompletionProviderOptions} options + * @param {Completion} data + * @param {import("../ace").Ace.CompletionProviderOptions} [options] * @returns {boolean} */ insertMatch(editor, data, options) { @@ -713,7 +718,7 @@ class CompletionProvider { /** * @param {IEditor} editor - * @param {Ace.Completion} data + * @param {Completion} data */ $insertString(editor, data) { var text = data.value || data; @@ -722,7 +727,7 @@ class CompletionProvider { /** * @param {IEditor} editor - * @param {Ace.CompletionCallbackFunction} callback + * @param {import("../ace").Ace.CompletionCallbackFunction} callback */ gatherCompletions(editor, callback) { var session = editor.getSession(); @@ -752,8 +757,8 @@ class CompletionProvider { * This is the entry point to the class, it gathers, then provides the completions asynchronously via callback. * The callback function may be called multiple times, the last invokation is marked with a `finished` flag * @param {IEditor} editor - * @param {Ace.CompletionProviderOptions} options - * @param {(err: Error | undefined, completions: Ace.CompletionRecord, finished: boolean) => void} callback + * @param {import("../ace").Ace.CompletionProviderOptions} options + * @param {(err: Error | undefined, completions: FilteredList | [], finished: boolean) => void} callback */ provideCompletions(editor, options, callback) { var processResults = function(results) { diff --git a/src/autocomplete/inline.js b/src/autocomplete/inline.js index 7239aee2c64..e0fabe2fd27 100644 --- a/src/autocomplete/inline.js +++ b/src/autocomplete/inline.js @@ -15,8 +15,8 @@ class AceInline { /** * Renders the completion as ghost text to the current cursor position - * @param {Editor} editor - * @param {Completion} completion + * @param {import("../editor").IEditor} editor + * @param {import("../../ace").Ace.Completion} completion * @param {string} prefix * @returns {boolean} True if the completion could be rendered to the editor, false otherwise */ diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 0c72f885883..460d454c85c 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -6,10 +6,13 @@ */ /** * @typedef IAcePopup - * @type {IEditor & Ace.AcePopupProperties} + * @type {IEditor & import("../../ace").Ace.AcePopupProperties} * @export */ var Renderer = require("../virtual_renderer").VirtualRenderer; +/** + * @type {any} + */ var Editor = require("../editor").Editor; var Range = require("../range").Range; var event = require("../lib/event"); @@ -23,10 +26,13 @@ var getAriaId = function (index) { /** * - * @param {HTMLElement} el + * @param {HTMLElement} [el] * @return {IEditor} */ var $singleLineEditor = function (el) { + /** + * @type {Renderer & {$maxLines?: number}}} + */ var renderer = new Renderer(el); renderer.$maxLines = 4; @@ -194,7 +200,7 @@ class AcePopup { var bgTokenizer = popup.session.bgTokenizer; bgTokenizer.$tokenizeRow = function (row) { /** - * @type {Ace.Completion} + * @type {import("../../ace").Ace.Completion} */ var data = popup.data[row]; var tokens = []; diff --git a/src/autocomplete/util.js b/src/autocomplete/util.js index 97228e94376..51619407a87 100644 --- a/src/autocomplete/util.js +++ b/src/autocomplete/util.js @@ -40,6 +40,10 @@ exports.retrieveFollowingIdentifier = function(text, pos, regex) { return buf; }; +/** + * @param editor + * @return {string} + */ exports.getCompletionPrefix = function (editor) { var pos = editor.getCursorPosition(); var line = editor.session.getLine(pos.row); diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 9518617a0fe..2e877eb15bc 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -13,7 +13,7 @@ */ /** * @typedef IBackgroundTokenizer - * @type {BackgroundTokenizer & Ace.EventEmitter} + * @type {BackgroundTokenizer & import("../ace").Ace.EventEmitter} */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -30,6 +30,7 @@ class BackgroundTokenizer { * Creates a new `BackgroundTokenizer` object. * @param {ITokenizer} tokenizer The tokenizer to use * @param {IEditor} editor The editor to associate with + * @this {IBackgroundTokenizer} **/ constructor(tokenizer, editor) { /** @@ -152,7 +153,7 @@ class BackgroundTokenizer { } /** - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta */ $updateOnChange(delta) { var startRow = delta.start.row; @@ -187,7 +188,7 @@ class BackgroundTokenizer { /** * Gives list of [[Token]]'s of the row. (tokens are cached) * @param {Number} row The row to get tokens at - * @returns {Ace.Token[]} + * @returns {import("../ace").Ace.Token[]} **/ getTokens(row) { return this.lines[row] || this.$tokenizeRow(row); diff --git a/src/bidihandler.js b/src/bidihandler.js index 77a1e2ed6be..ae3fc576074 100644 --- a/src/bidihandler.js +++ b/src/bidihandler.js @@ -45,8 +45,8 @@ class BidiHandler { * creates Bidi map to be used in operations related to selection * (keyboard arrays, mouse click, select) * @param {Number} screenRow the screen row to be checked - * @param {Number} docRow the document row to be checked [optional] - * @param {Number} splitIndex the wrapped screen line index [ optional] + * @param {Number} [docRow] the document row to be checked [optional] + * @param {Number} [splitIndex] the wrapped screen line index [ optional] **/ isBidiRow(screenRow, docRow, splitIndex) { if (!this.seenBidi) diff --git a/src/clipboard.js b/src/clipboard.js index 4f83a07b04d..ff4ace683c9 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -1,12 +1,8 @@ "use strict"; var $cancelT; -/** - * - * @type {{cancel: Function, lineMode: boolean|string, pasteCancelled: ((function(): (boolean))|*)}} - */ module.exports = { - lineMode: false, + /** @type {string|false} */lineMode: false, pasteCancelled: function() { if ($cancelT && $cancelT > Date.now() - 50) return true; diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index d392967355a..01d8686ee27 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef ICommandManager - * @type {CommandManager & Ace.EventEmitter & {$checkCommandState?: boolean}} + * @type {CommandManager & import("../../ace").Ace.EventEmitter & {$checkCommandState?: boolean}} * @export */ /** @@ -102,6 +102,7 @@ class CommandManager extends MultiHashHandler{ /** * @param {IEditor} editor + * @this {ICommandManager} */ replay(editor) { if (this.$inReplay || !this.macro) diff --git a/src/commands/incremental_search_commands.js b/src/commands/incremental_search_commands.js index c228df9bb49..9f96c8cf4b5 100644 --- a/src/commands/incremental_search_commands.js +++ b/src/commands/incremental_search_commands.js @@ -139,6 +139,10 @@ oop.inherits(IncrementalSearchKeyboardHandler, HashHandler); (function() { + /** + * @param editor + * @this {IncrementalSearchKeyboardHandler & this} + */ this.attach = function(editor) { var iSearch = this.$iSearch; HashHandler.call(this, exports.iSearchCommands, editor.commands.platform); diff --git a/src/document.js b/src/document.js index 570e1d802f9..496a4e781f3 100644 --- a/src/document.js +++ b/src/document.js @@ -1,17 +1,18 @@ "use strict"; /** - * @typedef IDocument - * @type {Document & Ace.EventEmitter} + * @typedef {Document & import("../ace").Ace.EventEmitter} IDocument * @export */ /** - * @typedef IAnchor - * @type {import("./anchor").IAnchor} + * @typedef {import("./anchor").IAnchor} IAnchor */ var oop = require("./lib/oop"); var applyDelta = require("./apply_delta").applyDelta; var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; +/** + * @type {any} + */ var Anchor = require("./anchor").Anchor; /** @@ -23,6 +24,7 @@ class Document { * * Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty. * @param {String | String[]} textOrLines text The starting text + * @this {IDocument} **/ constructor(textOrLines) { /** @@ -45,6 +47,7 @@ class Document { * Replaces all the lines in the current `Document` with the value of `text`. * * @param {String} text The text to use + * @this {IDocument} **/ setValue(text) { var len = this.getLength() - 1; @@ -100,7 +103,7 @@ class Document { /** * [Sets the new line mode.]{: #Document.setNewLineMode.desc} - * @param {Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} + * @param {import("../ace").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} * @this {IDocument} **/ setNewLineMode(newLineMode) { @@ -113,7 +116,7 @@ class Document { /** * [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode} - * @returns {Ace.NewLineMode} + * @returns {import("../ace").Ace.NewLineMode} **/ getNewLineMode() { return this.$newLineMode; @@ -165,7 +168,7 @@ class Document { /** * Returns all the text within `range` as a single string. - * @param {Ace.IRange} range The range to work with. + * @param {import("../ace").Ace.IRange} range The range to work with. * * @returns {String} **/ @@ -175,7 +178,7 @@ class Document { /** * Returns all the text within `range` as an array of lines. - * @param {Ace.IRange} range The range to work with. + * @param {import("../ace").Ace.IRange} range The range to work with. * * @returns {string[]} **/ @@ -196,14 +199,36 @@ class Document { } // Deprecated methods retained for backwards compatibility. + /** + * @param row + * @param lines + * @this {IDocument} + * @deprecated + */ insertLines(row, lines) { console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead."); return this.insertFullLines(row, lines); } + + /** + * + * @param firstRow + * @param lastRow + * @returns {String[]} + * @this {IDocument} + * @deprecated + */ removeLines(firstRow, lastRow) { console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead."); return this.removeFullLines(firstRow, lastRow); } + + /** + * @param position + * @returns {import("../ace").Ace.Point} + * @this {IDocument} + * @deprecated + */ insertNewLine(position) { console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead."); return this.insertMergedLines(position, ["", ""]); @@ -211,10 +236,10 @@ class Document { /** * Inserts a block of `text` at the indicated `position`. - * @param {Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` + * @param {import("../ace").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text to insert - * @returns {Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. - * + * @returns {import("../ace").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @this {IDocument} **/ insert(position, text) { // Only detect new lines if the document has no line break yet. @@ -231,12 +256,13 @@ class Document { * 1. This does NOT handle newline characters (single-line text only). * 2. This is faster than the `insert` method for single-line text insertions. * - * @param {Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` + * @param {import("../ace").Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text - * @returns {Ace.Point} Returns an object containing the final row and column, like this: + * @returns {import("../ace").Ace.Point} Returns an object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` + * @this {IDocument} **/ insertInLine(position, text) { var start = this.clippedPos(position.row, position.column); @@ -256,7 +282,7 @@ class Document { * * @param {number} row * @param {number} column - * @return {Ace.Point} + * @return {import("../ace").Ace.Point} */ clippedPos(row, column) { var length = this.getLength(); @@ -276,8 +302,8 @@ class Document { } /** - * @param {Ace.Point} pos - * @return {Ace.Point} + * @param {import("../ace").Ace.Point} pos + * @return {import("../ace").Ace.Point} */ clonePos(pos) { return {row: pos.row, column: pos.column}; @@ -286,15 +312,15 @@ class Document { /** * @param {number} row * @param {number} column - * @return {Ace.Point} + * @return {import("../ace").Ace.Point} */ pos(row, column) { return {row: row, column: column}; } /** - * @param {Ace.Point} position - * @return {Ace.Point} + * @param {import("../ace").Ace.Point} position + * @return {import("../ace").Ace.Point} * @private */ $clipPosition(position) { @@ -330,6 +356,7 @@ class Document { * Inserts the elements in `lines` into the document as full lines (does not merge with existing line), starting at the row index given by `row`. This method also triggers the `"change"` event. * @param {Number} row The index of the row to insert at * @param {string[]} lines An array of strings + * @this {IDocument} **/ insertFullLines(row, lines) { // Clip to document. @@ -355,9 +382,9 @@ class Document { /** * Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event. - * @param {Ace.Position} position + * @param {import("../ace").Ace.Position} position * @param {string[]} lines An array of strings - * @returns {Ace.Point} Contains the final row and column, like this: + * @returns {import("../ace").Ace.Point} Contains the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -365,7 +392,7 @@ class Document { * ``` * {row: row, column: 0} * ``` - * + * @this {IDocument} **/ insertMergedLines(position, lines) { var start = this.clippedPos(position.row, position.column); @@ -386,8 +413,9 @@ class Document { /** * Removes the `range` from the document. - * @param {Ace.IRange} range A specified Range to remove - * @returns {Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @param {import("../ace").Ace.IRange} range A specified Range to remove + * @returns {import("../ace").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @this {IDocument} **/ remove(range) { var start = this.clippedPos(range.start.row, range.start.column); @@ -406,8 +434,8 @@ class Document { * @param {Number} row The row to remove from * @param {Number} startColumn The column to start removing at * @param {Number} endColumn The column to stop removing at - * @returns {Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. - * + * @returns {import("../ace").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. + * @this {IDocument} **/ removeInLine(row, startColumn, endColumn) { var start = this.clippedPos(row, startColumn); @@ -428,7 +456,7 @@ class Document { * @param {Number} firstRow The first row to be removed * @param {Number} lastRow The last row to be removed * @returns {String[]} Returns all the removed lines. - * + * @this {IDocument} **/ removeFullLines(firstRow, lastRow) { // Clip to document. @@ -463,7 +491,7 @@ class Document { /** * Removes the new line between `row` and the row immediately following it. This method also triggers the `"change"` event. * @param {Number} row The row to check - * + * @this {IDocument} **/ removeNewLine(row) { if (row < this.getLength() - 1 && row >= 0) { @@ -478,13 +506,13 @@ class Document { /** * Replaces a range in the document with the new `text`. - * @param {Range | Ace.IRange} range A specified Range to replace + * @param {Range | import("../ace").Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {Ace.Point} Returns an object containing the final row and column, like this: + * @returns {import("../ace").Ace.Point} Returns an object containing the final row and column, like this: * {row: endRow, column: 0} * If the text and range are empty, this function returns an object containing the current `range.start` value. * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value. - * + * @this {IDocument} **/ replace(range, text) { if (!(range instanceof Range)) @@ -512,7 +540,8 @@ class Document { /** * Applies all changes in `deltas` to the document. - * @param {Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @param {import("../ace").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @this {IDocument} **/ applyDeltas(deltas) { for (var i=0; i=0; i--) { @@ -532,8 +562,8 @@ class Document { /** * Applies `delta` to the document. - * @param {Ace.Delta} delta A delta object (can include "insert" and "remove" actions) - * @param [doNotValidate] + * @param {import("../ace").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {boolean} [doNotValidate] * @this {IDocument} **/ applyDelta(delta, doNotValidate) { @@ -554,8 +584,8 @@ class Document { } /** - * - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta + * @this {IDocument} */ $safeApplyDelta(delta) { var docLength = this.$lines.length; @@ -570,8 +600,9 @@ class Document { /** * - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta * @param {number} MAX + * @this {IDocument} */ $splitAndapplyLargeDelta(delta, MAX) { // Split large insert deltas. This is necessary because: @@ -607,7 +638,8 @@ class Document { /** * Reverts `delta` from the document. - * @param {Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {import("../ace").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @this {IDocument} **/ revertDelta(delta) { this.$safeApplyDelta({ @@ -631,8 +663,8 @@ class Document { * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second. * * @param {Number} index An index to convert - * @param {Number} startRow=0 The row from which to start the conversion - * @returns {Ace.Point} A `{row, column}` object of the `index` position + * @param {Number} [startRow=0] The row from which to start the conversion + * @returns {import("../ace").Ace.Point} A `{row, column}` object of the `index` position */ indexToPosition(index, startRow) { var lines = this.$lines || this.getAllLines(); @@ -657,8 +689,8 @@ class Document { * * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second. * - * @param {Ace.Point} pos The `{row, column}` to convert - * @param {Number} startRow=0 The row from which to start the conversion + * @param {import("../ace").Ace.Point} pos The `{row, column}` to convert + * @param {Number} [startRow=0] The row from which to start the conversion * @returns {Number} The index position in the document */ positionToIndex(pos, startRow) { diff --git a/src/edit_session.js b/src/edit_session.js index 9d02ae427f7..5438d85407f 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,13 +1,8 @@ -/// - "use strict"; /** - * @typedef IDocument - * @type {import("./document").IDocument} - */ -/** - * @typedef IFolding - * @type {import("./edit_session/folding").IFolding} + * @typedef IEditSession + * @type {EditSession & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EventEmitter & import("../ace").Ace.EditSessionProperties & import("./edit_session/folding").IFolding & import("./edit_session/bracket_match").BracketMatch} + * @export */ /** * @typedef UndoManager @@ -18,22 +13,23 @@ * @type {import("./edit_session/fold_line").FoldLine} */ /** - * @typedef IEditSession - * @type {EditSession & Ace.OptionsProvider & IFolding & Ace.EventEmitter & Ace.EditSessionProperties & import("./edit_session/bracket_match").BracketMatch} - * @export + * @typedef ISelection + * @type {import("./selection").ISelection} */ - var oop = require("./lib/oop"); var lang = require("./lib/lang"); var BidiHandler = require("./bidihandler").BidiHandler; var config = require("./config"); var EventEmitter = require("./lib/event_emitter").EventEmitter; +/** + * @type {any} + */ var Selection = require("./selection").Selection; var TextMode = require("./mode/text").Mode; var Range = require("./range").Range; -var Document = require("./document").Document; -var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer; +/** @type {any} */var Document = require("./document").Document; +/** @type {any} */var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer; var SearchHighlight = require("./search_highlight").SearchHighlight; //{ events @@ -126,23 +122,19 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; /** * @typedef TextMode - * @type {Ace.SyntaxMode} + * @type {import("../ace").Ace.SyntaxMode} */ -/** - * @type {IEditSession} - * @this {IEditSession} - */ class EditSession { /** - * @type {IDocument} + * @type {import("../ace").Ace.Document} */ doc; /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. - * @param {IDocument | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} - * @param {Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} + * @param {import("../ace").Ace.Document | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} + * @param {import("../ace").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} * @this {IEditSession} **/ constructor(text, mode) { @@ -163,6 +155,9 @@ class EditSession { }; // Set default background tokenizer with Text mode until editor session mode is set + /** + * @type {import("./background_tokenizer").IBackgroundTokenizer} + */ this.bgTokenizer = new BackgroundTokenizer((new TextMode()).getTokenizer(), this); @@ -178,6 +173,9 @@ class EditSession { text = new Document(text); this.setDocument(text); + /** + * @type {ISelection}} + */ this.selection = new Selection(this); this.$bidiHandler = new BidiHandler(this); @@ -191,7 +189,7 @@ class EditSession { /** * Sets the `EditSession` to point to a new `Document`. If a `BackgroundTokenizer` exists, it also points to `doc`. * - * @param {IDocument} doc The new `Document` to use + * @param {import("../ace").Ace.Document} doc The new `Document` to use * **/ setDocument(doc) { @@ -208,7 +206,7 @@ class EditSession { /** * Returns the `Document` associated with this session. - * @return {IDocument} + * @return {import("../ace").Ace.Document} **/ getDocument() { return this.doc; @@ -273,7 +271,7 @@ class EditSession { /** * - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta * @this {IEditSession} */ onChange(delta) { @@ -327,7 +325,7 @@ class EditSession { /** * Returns selection object. - * @returns {Selection} + * @returns {ISelection} **/ getSelection() { return this.selection; @@ -346,7 +344,7 @@ class EditSession { /** * Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows. * @param {Number} row The row to start at - * @returns {Ace.Token[]} + * @returns {import("../ace").Ace.Token[]} **/ getTokens(row) { return this.bgTokenizer.getTokens(row); @@ -356,7 +354,7 @@ class EditSession { * Returns an object indicating the token at the current row. The object has two properties: `index` and `start`. * @param {Number} row The row number to retrieve from * @param {Number} column The column number to retrieve from - * @returns {Ace.Token} + * @returns {import("../ace").Ace.Token} * **/ getTokenAt(row, column) { @@ -462,6 +460,7 @@ class EditSession { /** * Returns the current tab size. * @this {IEditSession} + * @return {number} **/ getTabSize() { return this.$tabSize; @@ -469,7 +468,7 @@ class EditSession { /** * Returns `true` if the character at the position is a soft tab. - * @param {Ace.Point} position The position to check + * @param {import("../ace").Ace.Point} position The position to check * @this {IEditSession} **/ isTabStop(position) { @@ -605,7 +604,7 @@ class EditSession { * Adds a new marker to the given `Range`. If `inFront` is `true`, a front marker is defined, and the `'changeFrontMarker'` event fires; otherwise, the `'changeBackMarker'` event fires. * @param {Range} range Define the range of the marker * @param {String} clazz Set the CSS class for the marker - * @param {Ace.MarkerRenderer | "fullLine" | "screenLine" | "text"} type Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. + * @param {import("../ace").Ace.MarkerRenderer | "fullLine" | "screenLine" | "text" | "line"} [type] Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. * @param {Boolean} [inFront] Set to `true` to establish a front marker * * @return {Number} The new marker id @@ -636,10 +635,10 @@ class EditSession { /** * Adds a dynamic marker to the session. - * @param {Ace.MarkerLike} marker object with update method + * @param {import("../ace").Ace.MarkerLike} marker object with update method * @param {Boolean} [inFront] Set to `true` to establish a front marker * - * @return {Ace.MarkerLike} The added marker + * @return {import("../ace").Ace.MarkerLike} The added marker * @this {IEditSession} **/ addDynamicMarker(marker, inFront) { @@ -679,7 +678,7 @@ class EditSession { * Returns an object containing all of the markers, either front or back. * @param {Boolean} [inFront] If `true`, indicates you only want front markers; `false` indicates only back markers * - * @returns {{[id: number]: Ace.MarkerLike}} + * @returns {{[id: number]: import("../ace").Ace.MarkerLike}} **/ getMarkers(inFront) { return inFront ? this.$frontMarkers : this.$backMarkers; @@ -731,7 +730,7 @@ class EditSession { */ /** * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event. - * @param {Ace.Annotation[]} annotations A list of annotations + * @param {import("../ace").Ace.Annotation[]} annotations A list of annotations * @this {IEditSession} **/ setAnnotations(annotations) { @@ -741,7 +740,7 @@ class EditSession { /** * Returns the annotations for the `EditSession`. - * @returns {Ace.Annotation[]} + * @returns {import("../ace").Ace.Annotation[]} **/ getAnnotations() { return this.$annotations || []; @@ -829,7 +828,7 @@ class EditSession { /** * {:Document.setNewLineMode.desc} - * @param {Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} + * @param {import("../ace").Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} * * * @related Document.setNewLineMode @@ -841,7 +840,7 @@ class EditSession { /** * * Returns the current new line mode. - * @returns {Ace.NewLineMode} + * @returns {import("../ace").Ace.NewLineMode} * @related Document.getNewLineMode **/ getNewLineMode() { @@ -873,7 +872,7 @@ class EditSession { /** * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. - * @param {Ace.SyntaxMode} mode Set a new text mode + * @param {import("../ace").Ace.SyntaxMode | string} mode Set a new text mode * @param {() => void} [cb] optional callback * @this {IEditSession} **/ @@ -1133,7 +1132,7 @@ class EditSession { /** * {:Document.getTextRange.desc} - * @param {Ace.IRange} range The range to work with + * @param {import("../ace").Ace.IRange} [range] The range to work with * * @returns {String} **/ @@ -1143,9 +1142,9 @@ class EditSession { /** * Inserts a block of `text` and the indicated `position`. - * @param {Ace.Point} position The position {row, column} to start inserting at + * @param {import("../ace").Ace.Point} position The position {row, column} to start inserting at * @param {String} text A chunk of text to insert - * @returns {Ace.Point} The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @returns {import("../ace").Ace.Point} The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. **/ insert(position, text) { return this.doc.insert(position, text); @@ -1154,7 +1153,7 @@ class EditSession { /** * Removes the `range` from the document. * @param {Range} range A specified Range to remove - * @returns {Ace.Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @returns {import("../ace").Ace.Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { return this.doc.remove(range); @@ -1175,7 +1174,7 @@ class EditSession { /** * Reverts previous changes to your document. - * @param {Ace.Delta[]} deltas An array of previous changes + * @param {import("../ace").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] [If `true`, doesn't select the range of where the change occured]{: #dontSelect} * @this {IEditSession} **/ @@ -1203,7 +1202,7 @@ class EditSession { /** * Re-implements a previously undone change to your document. - * @param {Ace.Delta[]} deltas An array of previous changes + * @param {import("../ace").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] {:dontSelect} **/ redoChanges(deltas, dontSelect) { @@ -1238,7 +1237,7 @@ class EditSession { /** * - * @param {Ace.Delta[]} deltas + * @param {import("../ace").Ace.Delta[]} deltas * @param {boolean} [isUndo] * @return {Range} */ @@ -1285,7 +1284,7 @@ class EditSession { * * @param {Range} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {Ace.Point} An object containing the final row and column, like this: + * @returns {import("../ace").Ace.Point} An object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -1304,7 +1303,7 @@ class EditSession { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} fromRange The range of text you want moved within the document - * @param {Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {import("../ace").Ace.Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * @returns {Range} The new range where the text was moved to. * @this {IEditSession} @@ -1489,7 +1488,7 @@ class EditSession { /** * @param {number} row * @param {number} column - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} */ $clipPositionToDocument(row, column) { column = Math.max(0, column); @@ -1673,7 +1672,7 @@ class EditSession { /** * - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta * @this {IEditSession} */ $updateInternalDataOnChange(delta) { @@ -2149,7 +2148,7 @@ class EditSession { * For the given document row and column, this returns the document position of the last row. * @param {Number} docRow * @param {Number} docColumn - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} * @this {IEditSession} **/ getDocumentLastRowColumnPosition(docRow, docColumn) { @@ -2207,7 +2206,7 @@ class EditSession { * @param {Number} screenColumn The screen column to check * @param {Number} [offsetX] screen character x-offset [optional] * - * @returns {Ace.Point} The object returned has two properties: `row` and `column`. + * @returns {import("../ace").Ace.Point} The object returned has two properties: `row` and `column`. * * @related EditSession.documentToScreenPosition * @this {IEditSession} @@ -2302,9 +2301,9 @@ class EditSession { /** * Converts document coordinates to screen coordinates. {:conversionConsiderations} - * @param {Number|Ace.Point} docRow The document row to check + * @param {Number|import("../ace").Ace.Point} docRow The document row to check * @param {Number|undefined} [docColumn] The document column to check - * @returns {Ace.Point} The object returned by this method has two properties: `row` and `column`. + * @returns {import("../ace").Ace.Point} The object returned by this method has two properties: `row` and `column`. * * @related EditSession.screenToDocumentPosition * @this {IEditSession} @@ -2552,7 +2551,7 @@ EditSession.prototype.$wrapLimitRange = { }; /** * - * @type {null | Ace.LineWidget[]} + * @type {null | import("../ace").Ace.LineWidget[]} */ EditSession.prototype.lineWidgets = null; EditSession.prototype.isFullWidth = isFullWidth; diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index 6437eb68984..05700a5aaa6 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -1,8 +1,6 @@ "use strict"; /** - * - * @typedef IEditSession - * @type {import("../edit_session").IEditSession} + * @typedef {import("../edit_session").IEditSession} IEditSession */ var TokenIterator = require("../token_iterator").TokenIterator; @@ -16,7 +14,7 @@ function BracketMatch() { /** * - * @param {Ace.Point} position + * @param {import("../../ace").Ace.Point} position * @param {string} [chr] */ this.findMatchingBracket = function(position, chr) { @@ -36,7 +34,7 @@ function BracketMatch() { }; /** - * @param {Ace.Point} pos + * @param {import("../../ace").Ace.Point} pos * @return {null|Range} */ this.getBracketRange = function(pos) { @@ -85,7 +83,7 @@ function BracketMatch() { * * two Ranges if there is opening and closing brackets; * * one Range if there is only one bracket * - * @param {Ace.Point} pos + * @param {import("../../ace").Ace.Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} */ @@ -130,9 +128,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {Ace.Point} position + * @param {import("../../ace").Ace.Point} position * @param {RegExp} [typeRe] - * @return {Ace.Point|null} + * @return {import("../../ace").Ace.Point|null} */ this.$findOpeningBracket = function(bracket, position, typeRe) { var openBracket = this.$brackets[bracket]; @@ -195,9 +193,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {Ace.Point} position + * @param {import("../../ace").Ace.Point} position * @param {RegExp} [typeRe] - * @return {Ace.Point|null} + * @return {import("../../ace").Ace.Point|null} */ this.$findClosingBracket = function(bracket, position, typeRe) { var closingBracket = this.$brackets[bracket]; @@ -259,7 +257,7 @@ function BracketMatch() { /** * Returns [[Range]]'s for matching tags and tag names, if there are any - * @param {Ace.Point} pos + * @param {import("../../ace").Ace.Point} pos * @returns {{closeTag: Range, closeTagName: Range, openTag: Range, openTagName: Range} | undefined} */ this.getMatchingTags = function (pos) { diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index 2153a2bac34..e6f8ff704bf 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -105,7 +105,7 @@ class Fold extends RangeList { } /** - * @param {Ace.IRange} range + * @param {import("../../ace").Ace.IRange} range */ restoreRange(range) { return restoreRange(range, this.start); @@ -114,8 +114,8 @@ class Fold extends RangeList { } /** - * @param {Ace.Point} point - * @param {Ace.Point} anchor + * @param {import("../../ace").Ace.Point} point + * @param {import("../../ace").Ace.Point} anchor */ function consumePoint(point, anchor) { point.row -= anchor.row; @@ -123,16 +123,16 @@ function consumePoint(point, anchor) { point.column -= anchor.column; } /** - * @param {Ace.IRange} range - * @param {Ace.Point} anchor + * @param {import("../../ace").Ace.IRange} range + * @param {import("../../ace").Ace.Point} anchor */ function consumeRange(range, anchor) { consumePoint(range.start, anchor); consumePoint(range.end, anchor); } /** - * @param {Ace.Point} point - * @param {Ace.Point} anchor + * @param {import("../../ace").Ace.Point} point + * @param {import("../../ace").Ace.Point} anchor */ function restorePoint(point, anchor) { if (point.row == 0) @@ -140,8 +140,8 @@ function restorePoint(point, anchor) { point.row += anchor.row; } /** - * @param {Ace.IRange} range - * @param {Ace.Point} anchor + * @param {import("../../ace").Ace.IRange} range + * @param {import("../../ace").Ace.Point} anchor */ function restoreRange(range, anchor) { restorePoint(range.start, anchor); diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index c1d266d1b27..7317e1c938b 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -246,7 +246,7 @@ class FoldLine { /** * @param {number} idx - * @return {Ace.Point} + * @return {import("../../ace").Ace.Point} */ idxToPosition(idx) { var lastFoldEndColumn = 0; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 0416e351832..1999572a9c7 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -1,15 +1,12 @@ "use strict"; /** - * @typedef IFolding - * @type {Folding & Ace.FoldingProperties} + * @typedef {Folding & import("../../ace").Ace.FoldingProperties} IFolding * @export */ /** - * - * @typedef IEditSession - * @type {import("../edit_session").IEditSession} + * @typedef {import("../edit_session").IEditSession} IEditSession */ var Range = require("../range").Range; var FoldLine = require("./fold_line").FoldLine; @@ -30,6 +27,7 @@ function Folding() { * @param {number} column * @param {number} [side] * @return {Fold} + * @this {IEditSession} **/ this.getFoldAt = function(row, column, side) { var foldLine = this.getFoldLine(row); @@ -52,7 +50,7 @@ function Folding() { /** * Returns all folds in the given range. Note, that this will return folds - * @param {Range| Ace.Delta} range + * @param {Range| import("../../ace").Ace.Delta} range * @returns {Fold[]} **/ this.getFoldsInRange = function(range) { @@ -484,7 +482,7 @@ function Folding() { /** * - * @param {number|null|Ace.Point|Range|Range[]} [location] + * @param {number|null|import("../../ace").Ace.Point|Range|Range[]} [location] * @param {boolean} [expandInner] * @return {Fold[]| undefined} */ @@ -852,7 +850,7 @@ function Folding() { }; /** - * @param {Ace.FoldMode} foldMode + * @param {import("../../ace").Ace.FoldMode} foldMode * @this {IEditSession} */ this.$setFolding = function(foldMode) { @@ -1018,7 +1016,7 @@ function Folding() { }; /** - * @param {Ace.Delta} delta + * @param {import("../../ace").Ace.Delta} delta * @this {IEditSession} */ this.updateFoldWidgets = function(delta) { diff --git a/src/editor.js b/src/editor.js index 59be665bbac..b6d15d291a4 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IEditor - * @type {Editor & Ace.EventEmitter & Ace.OptionsProvider & Ace.EditorProperties & Ace.EditorMultiSelectProperties} + * @type {Editor & import("../ace").Ace.EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EditorProperties & import("../ace").Ace.EditorMultiSelectProperties} * @export */ /** @@ -31,7 +31,7 @@ var EditSession = require("./edit_session").EditSession; var Search = require("./search").Search; var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; -var CommandManager = require("./commands/command_manager").CommandManager; +/** @type {any} */var CommandManager = require("./commands/command_manager").CommandManager; var defaultCommands = require("./commands/default_commands").commands; var config = require("./config"); var TokenIterator = require("./token_iterator").TokenIterator; @@ -269,7 +269,7 @@ class Editor { /** * Sets a new key handler, such as "vim" or "windows". - * @param {String | Ace.KeyboardHandler | null} keyboardHandler The new key handler + * @param {String | import("../ace").Ace.KeyboardHandler | null} keyboardHandler The new key handler * @param {() => void} [cb] **/ setKeyboardHandler(keyboardHandler, cb) { @@ -290,7 +290,7 @@ class Editor { /** * Returns the keyboard handler, such as "vim" or "windows". - * @returns {string} + * @returns {Object} **/ getKeyboardHandler() { return this.keyBinding.getKeyboardHandler(); @@ -650,6 +650,9 @@ class Editor { this._emit("blur", e); } + /** + * @this {IEditor} + */ $cursorChange() { this.renderer.updateCursor(); this.$highlightBrackets(); @@ -659,7 +662,7 @@ class Editor { /** * Emitted whenever the document is changed. * @event change - * @param {Ace.Delta} delta Contains a single property, `data`, which has the delta of changes + * @param {import("../ace").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes * @this {IEditor} **/ onDocumentChange(delta) { @@ -703,7 +706,7 @@ class Editor { $updateHighlightActiveLine() { var session = this.getSession(); /** - * @type {Ace.Point|false} + * @type {import("../ace").Ace.Point|false} */ var highlight; if (this.$highlightActiveLine) { @@ -824,6 +827,9 @@ class Editor { } + /** + * @this {IEditor} + */ onChangeFold() { // Update the active line marker as due to folding changes the current // line range on the screen might have changed. @@ -874,6 +880,7 @@ class Editor { /** * Called whenever a text "copy" happens. + * @this {IEditor} **/ onCopy() { this.commands.exec("copy", this); @@ -881,6 +888,7 @@ class Editor { /** * Called whenever a text "cut" happens. + * @this {IEditor} **/ onCut() { this.commands.exec("cut", this); @@ -897,7 +905,7 @@ class Editor { * Called whenever a text "paste" happens. * @param {String} text The pasted text * @param {any} event - * + * @this {IEditor} **/ onPaste(text, event) { var e = {text: text, event: event}; @@ -947,9 +955,10 @@ class Editor { /** * - * @param {string | string[]}command + * @param {string | string[]} command * @param [args] * @return {boolean} + * @this {IEditor} */ execCommand(command, args) { return this.commands.exec(command, this, args); @@ -1099,7 +1108,12 @@ class Editor { applyComposition(); this.endOperation(); } - + + /** + * @param {string} [text] + * @param {any} [composition] + * @this {IEditor} + */ applyComposition(text, composition) { if (composition.extendLeft || composition.extendRight) { var r = this.selection.getRange(); @@ -1206,7 +1220,7 @@ class Editor { /** * Returns the current selection style. * @this {IEditor} - * @returns {String} + * @returns {import("../ace").Ace.EditorOptions["selectionStyle"]} **/ getSelectionStyle() { return this.getOption("selectionStyle"); @@ -1447,7 +1461,7 @@ class Editor { /** * Removes the current selection or one character. * @param {'left' | 'right'} [dir] The direction of the deletion to occur, either "left" or "right" - * + * @this {IEditor} **/ remove(dir) { if (this.selection.isEmpty()){ @@ -1533,6 +1547,7 @@ class Editor { /** * Splits the line at the current selection (by inserting an `'\n'`). + * @this {IEditor} **/ splitLine() { if (!this.selection.isEmpty()) { @@ -1551,7 +1566,7 @@ class Editor { * inline in the editor such as, for example, code completions. * * @param {String} text Text to be inserted as "ghost" text - * @param {Ace.Point} position Position to insert text to + * @param {import("../ace").Ace.Point} [position] Position to insert text to */ setGhostText(text, position) { if (!this.session.widgetManager) { @@ -1631,6 +1646,7 @@ class Editor { * Inserts an indentation into the current cursor position or indents the selected lines. * * @related EditSession.indentRows + * @this {IEditor} **/ indent() { var session = this.session; @@ -1754,7 +1770,7 @@ class Editor { /** * If the character before the cursor is a number, this functions changes its value by `amount`. * @param {Number} amount The value to change the numeral by (can be negative to decrease value) - * + * @this {IEditor} **/ modifyNumber(amount) { var row = this.selection.getCursor().row; @@ -1799,7 +1815,10 @@ class Editor { this.toggleWord(); } } - + + /** + * @this {IEditor} + */ toggleWord() { var row = this.selection.getCursor().row; var column = this.selection.getCursor().column; @@ -1937,7 +1956,7 @@ class Editor { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} range The range of text you want moved within the document - * @param {Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {import("../ace").Ace.Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * * @returns {Range} The new range where the text was moved to. @@ -2199,7 +2218,7 @@ class Editor { /** * Gets the current position of the cursor. - * @returns {Ace.Point} An object that looks something like this: + * @returns {import("../ace").Ace.Point} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -2213,7 +2232,7 @@ class Editor { /** * Returns the screen position of the cursor. - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} * @related EditSession.documentToScreenPosition **/ getCursorPositionScreen() { @@ -2257,7 +2276,7 @@ class Editor { /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. - * @param {Ace.Point} pos An object with two properties, row and column + * @param {import("../ace").Ace.Point} pos An object with two properties, row and column * @related Selection.moveCursorToPosition **/ moveCursorToPosition(pos) { @@ -2567,7 +2586,7 @@ class Editor { /** * Replaces the first occurrence of `options.needle` with the value in `replacement`. * @param {String} replacement The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replace(replacement, options) { @@ -2592,7 +2611,7 @@ class Editor { /** * Replaces all occurrences of `options.needle` with the value in `replacement`. * @param {String} replacement The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replaceAll(replacement, options) { @@ -2633,7 +2652,7 @@ class Editor { /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions - * @returns {Partial} + * @returns {Partial} **/ getLastSearchOptions() { return this.$search.getOptions(); @@ -2642,7 +2661,7 @@ class Editor { /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String|RegExp|Object} needle The text to search for (optional) - * @param {Partial} [options] An object defining various search properties + * @param {Partial} [options] An object defining various search properties * @param {Boolean} [animate] If `true` animate scrolling * @related Search.find **/ @@ -2687,7 +2706,7 @@ class Editor { /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find @@ -2698,7 +2717,7 @@ class Editor { /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find diff --git a/src/ext/beautify.js b/src/ext/beautify.js index 10e7548bf00..ee22f4ec049 100644 --- a/src/ext/beautify.js +++ b/src/ext/beautify.js @@ -13,10 +13,18 @@ exports.singletonTags = ["area", "base", "br", "col", "command", "embed", "hr", // insert a line break after block level tags exports.blockTags = ["article", "aside", "blockquote", "body", "div", "dl", "fieldset", "footer", "form", "head", "header", "html", "nav", "ol", "p", "script", "section", "style", "table", "tbody", "tfoot", "thead", "ul"]; +/** + * + * @type {{lineBreaksAfterCommasInCurlyBlock?: boolean}} + */ exports.formatOptions = { lineBreaksAfterCommasInCurlyBlock: true }; +/** + * + * @param {import("../edit_session").IEditSession} session + */ exports.beautify = function(session) { var iterator = new TokenIterator(session, 0, 0); var token = iterator.getCurrentToken(); diff --git a/src/ext/code_lens.js b/src/ext/code_lens.js index 74947ff56e6..36ba3688e51 100644 --- a/src/ext/code_lens.js +++ b/src/ext/code_lens.js @@ -1,4 +1,9 @@ "use strict"; +/** + * @typedef IEditSession + * @type {import("../edit_session").IEditSession} + */ + var LineWidgets = require("../line_widgets").LineWidgets; var event = require("../lib/event"); var lang = require("../lib/lang"); @@ -92,6 +97,12 @@ function clearCodeLensWidgets(session) { }); } +/** + * + * @param {IEditSession} session + * @param lenses + * @return {number} + */ exports.setLenses = function(session, lenses) { var firstRow = Number.MAX_VALUE; @@ -186,12 +197,21 @@ function detachFromEditor(editor) { editor.container.removeEventListener("click", editor.$codeLensClickHandler); } +/** + * + * @param {import("../editor").IEditor} editor + * @param codeLensProvider + */ exports.registerCodeLensProvider = function(editor, codeLensProvider) { editor.setOption("enableCodeLens", true); editor.codeLensProviders.push(codeLensProvider); editor.$updateLensesOnInput(); }; +/** + * + * @param {IEditSession} session + */ exports.clear = function(session) { exports.setLenses(session, null); }; diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 537da0b3e22..72aa5f766ba 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -1,3 +1,13 @@ +/** + * @typedef ICommandBarTooltip + * @type {CommandBarTooltip & import("../../ace").Ace.EventEmitter & {[key: string]: any}} + */ + +/** + * @typedef IEditor + * @type {import("../editor").IEditor} + */ + var Tooltip = require("../tooltip").Tooltip; var EventEmitter = require("../lib/event_emitter").EventEmitter; var lang = require("../lib/lang"); @@ -46,7 +56,14 @@ var keyDisplayMap = { * When attached to an editor, it is either always shown or only when the active line is hovered * with mouse, depending on the alwaysShow property. */ +/** + * @type {ICommandBarTooltip} + */ class CommandBarTooltip { + /** + * @param {Element} parentNode + * @param {Partial} [options] + */ constructor(parentNode, options) { options = options || {}; this.parentNode = parentNode; @@ -82,15 +99,20 @@ class CommandBarTooltip { * The commands are added in sequential order. If there is not enough space on the main * toolbar, the remaining elements are added to the overflow menu. * - * @param {string} id - * @param {TooltipCommand} command + * @param {string} id + * @param {import("../../ace").TooltipCommand} command + * @this {ICommandBarTooltip} */ registerCommand(id, command) { var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip; if (!registerForMainTooltip && !this.elements[MORE_OPTIONS_BUTTON_ID]) { this.$createCommand(MORE_OPTIONS_BUTTON_ID, { name: "···", - exec: function() { + exec: + /** + * @this {ICommandBarTooltip} + */ + function() { this.$shouldHideMoreOptions = false; this.$setMoreOptionsVisibility(!this.isMoreOptionsShown()); }.bind(this), @@ -125,7 +147,8 @@ class CommandBarTooltip { * When true, the tooltip is always displayed while it is attached to an editor. * When false, the tooltip is displayed only when the mouse hovers over the active editor line. * - * @param {Editor} editor + * @param {boolean} alwaysShow + * @this {ICommandBarTooltip} */ setAlwaysShow(alwaysShow) { this.$alwaysShow = alwaysShow; @@ -139,7 +162,8 @@ class CommandBarTooltip { * Depending on the alwaysShow parameter it either displays the tooltip immediately, * or subscribes to the necessary events to display the tooltip on hover. * - * @param {Editor} editor + * @param {IEditor} editor + * @this {ICommandBarTooltip} */ attach(editor) { if (!editor || (this.isShown() && this.editor === editor)) { @@ -164,6 +188,7 @@ class CommandBarTooltip { /** * Updates the position of the command bar tooltip. It aligns itself above the active line in the editor. + * @this {ICommandBarTooltip} */ updatePosition() { if (!this.editor) { @@ -275,6 +300,11 @@ class CommandBarTooltip { this.tooltip = this.moreOptions = this.parentNode = null; } + /** + * @param {string} id + * @param {import("../../ace").TooltipCommand} command + * @param {boolean} forMainTooltip + */ $createCommand(id, command, forMainTooltip) { var parentEl = forMainTooltip ? this.tooltipEl : this.moreOptionsEl; var keyParts = []; @@ -298,6 +328,9 @@ class CommandBarTooltip { }); } + /** + * @type {any[]} + */ var buttonNode; if (forMainTooltip && command.iconCssClass) { //Only support icon button for main tooltip, otherwise fall back to text button @@ -328,8 +361,12 @@ class CommandBarTooltip { dom.buildDom(['div', { class: [BUTTON_CLASS_NAME, command.cssClass || ""].join(" "), ref: id }, buttonNode], parentEl, this.elements); this.commands[id] = command; - - var eventListener = function(e) { + + var eventListener = + /** + * @this {ICommandBarTooltip} + */ + function(e) { if (this.editor) { this.editor.focus(); } @@ -349,6 +386,10 @@ class CommandBarTooltip { this.$updateElement(id); } + /** + * @param {boolean} visible + * @this {ICommandBarTooltip} + */ $setMoreOptionsVisibility(visible) { if (visible) { this.moreOptions.setTheme(this.editor.renderer.theme); @@ -425,6 +466,9 @@ class CommandBarTooltip { } } + /** + * @param {boolean} [enableHover] + */ $updateOnHoverHandlers(enableHover) { var tooltipEl = this.tooltip.getElement(); var moreOptionsEl = this.moreOptions.getElement(); @@ -449,6 +493,9 @@ class CommandBarTooltip { } } + /** + * @this {ICommandBarTooltip} + */ $showTooltip() { if (this.isShown()) { return; @@ -460,7 +507,9 @@ class CommandBarTooltip { this.updatePosition(); this._signal("show"); } - + /** + * @this {ICommandBarTooltip} + */ $hideTooltip() { this.$mouseInTooltip = false; if (!this.isShown()) { @@ -471,6 +520,9 @@ class CommandBarTooltip { this._signal("hide"); } + /** + * @param {string} id + */ $updateElement(id) { var command = this.commands[id]; if (!command) { diff --git a/src/ext/elastic_tabstops_lite.js b/src/ext/elastic_tabstops_lite.js index f5726991789..68d0a0d1ed8 100644 --- a/src/ext/elastic_tabstops_lite.js +++ b/src/ext/elastic_tabstops_lite.js @@ -1,6 +1,9 @@ "use strict"; class ElasticTabstopsLite { + /** + * @param {import("../editor").IEditor} editor + */ constructor(editor) { this.$editor = editor; var self = this; @@ -23,7 +26,10 @@ class ElasticTabstopsLite { } }; } - + + /** + * @param {number[]} rows + */ processRows(rows) { this.$inChange = true; var checkedRows = []; @@ -48,6 +54,9 @@ class ElasticTabstopsLite { this.$inChange = false; } + /** + * @param {number} row + */ $findCellWidthsForBlock(row) { var cellWidths = [], widths; @@ -80,6 +89,10 @@ class ElasticTabstopsLite { return { cellWidths: cellWidths, firstRow: firstRow }; } + /** + * @param {number} row + * @returns {number[]} + */ $cellWidthsForRow(row) { var selectionColumns = this.$selectionColumnsForRow(row); // todo: support multicursor @@ -100,6 +113,10 @@ class ElasticTabstopsLite { return widths; } + /** + * @param {number} row + * @returns {number[]} + */ $selectionColumnsForRow(row) { var selections = [], cursor = this.$editor.getCursorPosition(); if (this.$editor.session.getSelection().isEmpty()) { @@ -111,6 +128,9 @@ class ElasticTabstopsLite { return selections; } + /** + * @param {number[][]} cellWidths + */ $setBlockCellWidthsToMax(cellWidths) { var startingNewBlock = true, blockStartRow, blockEndRow, maxWidth; var columnInfo = this.$izip_longest(cellWidths); @@ -149,6 +169,11 @@ class ElasticTabstopsLite { return cellWidths; } + /** + * @param {number[]} selectionColumns + * @param {number} cellRightEdge + * @returns {number} + */ $rightmostSelectionInCell(selectionColumns, cellRightEdge) { var rightmost = 0; @@ -166,6 +191,10 @@ class ElasticTabstopsLite { return rightmost; } + /** + * @param {number} row + * @returns {number[]} + */ $tabsForRow(row) { var rowTabs = [], line = this.$editor.session.getLine(row), re = /\t/g, match; @@ -177,6 +206,10 @@ class ElasticTabstopsLite { return rowTabs; } + /** + * @param {number} row + * @param {number[]} widths + */ $adjustRow(row, widths) { var rowTabs = this.$tabsForRow(row); @@ -217,7 +250,10 @@ class ElasticTabstopsLite { } } - // the is a (naive) Python port--but works for these purposes + /** + * The is a (naive) Python port--but works for these purposes + * @param {any[][]} iterables + */ $izip_longest(iterables) { if (!iterables[0]) return []; @@ -248,7 +284,11 @@ class ElasticTabstopsLite { return expandedSet; } - // an even more (naive) Python port + /** + * an even more (naive) Python port + * @param {string | any[]} widths + * @param {string | any[]} tabs + */ $izip(widths, tabs) { // grab the shorter size var size = widths.length >= tabs.length ? tabs.length : widths.length; @@ -268,6 +308,10 @@ exports.ElasticTabstopsLite = ElasticTabstopsLite; var Editor = require("../editor").Editor; require("../config").defineOptions(Editor.prototype, "editor", { useElasticTabstops: { + /** + * @param {boolean} val + * @this {import("../editor").IEditor} + */ set: function(val) { if (val) { if (!this.elasticTabstops) diff --git a/src/ext/emmet.js b/src/ext/emmet.js index ba2ad441fc8..b083a2a2e54 100644 --- a/src/ext/emmet.js +++ b/src/ext/emmet.js @@ -11,11 +11,14 @@ var emmet, emmetPath; */ class AceEmmetEditor { + /** + * @param {import("../editor").IEditor} editor + */ setupContext(editor) { this.ace = editor; this.indentation = editor.session.getTabString(); if (!emmet) - emmet = window.emmet; + emmet = window["emmet"]; var resources = emmet.resources || emmet.require("resources"); resources.setVariable("indentation", this.indentation); this.$syntax = null; @@ -233,6 +236,9 @@ class AceEmmetEditor { // tabstops as ${0}, so we have upgrade all caret tabstops with unique // positions but make sure that all other tabstops are not linked accidentally // based on https://github.com/sergeche/emmet-sublime/blob/master/editor.js#L119-L171 + /** + * @param {string} value + */ $updateTabstops(value) { var base = 1000; var zeroBase = 0; diff --git a/src/ext/error_marker.js b/src/ext/error_marker.js index afdae823878..30ea768a75f 100644 --- a/src/ext/error_marker.js +++ b/src/ext/error_marker.js @@ -59,6 +59,10 @@ function findAnnotations(session, row, dir) { return matched.length && matched; } +/** + * @param {import("../editor").IEditor} editor + * @param {number} dir + */ exports.showErrorMarker = function(editor, dir) { var session = editor.session; if (!session.widgetManager) { diff --git a/src/ext/hardwrap.js b/src/ext/hardwrap.js index d54340d2fea..634d63d1c62 100644 --- a/src/ext/hardwrap.js +++ b/src/ext/hardwrap.js @@ -2,6 +2,10 @@ var Range = require("../range").Range; +/** + * @param {import("../editor").IEditor} editor + * @param {import("../../ace").Ace.HardWrapOptions} options + */ function hardWrap(editor, options) { var max = options.column || editor.getOption("printMarginColumn"); var allowMerge = options.allowMerge != false; diff --git a/src/ext/keybinding_menu.js b/src/ext/keybinding_menu.js index f13f46c9b4d..57de93c7c16 100644 --- a/src/ext/keybinding_menu.js +++ b/src/ext/keybinding_menu.js @@ -10,42 +10,61 @@ * ☭ Hial Atropa!! ☭ */ - "use strict"; - var Editor = require("../editor").Editor; - /** - * Generates a menu which displays the keyboard shortcuts. - * @author - * Matthew Christopher Kastor-Inare III
- * ☭ Hial Atropa!! ☭ - * @param {ace.Editor} editor An instance of the ace editor. - */ - function showKeyboardShortcuts (editor) { - // make sure the menu isn't open already. - if(!document.getElementById('kbshortcutmenu')) { - var overlayPage = require('./menu_tools/overlay_page').overlayPage; - var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts; - var kb = getEditorKeybordShortcuts(editor); - var el = document.createElement('div'); - var commands = kb.reduce(function(previous, current) { - return previous + '
' - + current.command + ' : ' - + '' + current.key + '
'; - }, ''); +"use strict"; +/** + * @typedef IEditor + * @type {import("../editor").IEditor} + */ - el.id = 'kbshortcutmenu'; - el.innerHTML = '

Keyboard Shortcuts

' + commands + ''; - overlayPage(editor, el); - } +/** @type {any} */var Editor = require("../editor").Editor; + +/** + * Generates a menu which displays the keyboard shortcuts. + * @author + * Matthew Christopher Kastor-Inare III
+ * ☭ Hial Atropa!! ☭ + * @param {IEditor} editor An instance of the ace editor. + */ +function showKeyboardShortcuts(editor) { + // make sure the menu isn't open already. + if (!document.getElementById('kbshortcutmenu')) { + var overlayPage = require('./menu_tools/overlay_page').overlayPage; + var getEditorKeybordShortcuts = require('./menu_tools/get_editor_keyboard_shortcuts').getEditorKeybordShortcuts; + var kb = getEditorKeybordShortcuts(editor); + var el = document.createElement('div'); + var commands = kb.reduce(function (previous, current) { + return previous + '
' + + current.command + ' : ' + + '' + current.key + '
'; + }, ''); + + el.id = 'kbshortcutmenu'; + el.innerHTML = '

Keyboard Shortcuts

' + commands + ''; + overlayPage(editor, el); } - module.exports.init = function(editor) { - Editor.prototype.showKeyboardShortcuts = function() { - showKeyboardShortcuts(this); - }; - editor.commands.addCommands([{ - name: "showKeyboardShortcuts", - bindKey: {win: "Ctrl-Alt-h", mac: "Command-Alt-h"}, - exec: function(editor, line) { - editor.showKeyboardShortcuts(); - } - }]); +} + +/** + * @param {IEditor} editor + */ +module.exports.init = function (editor) { + Editor.prototype.showKeyboardShortcuts = function () { + showKeyboardShortcuts(this); }; + editor.commands.addCommands([{ + name: "showKeyboardShortcuts", + bindKey: { + win: "Ctrl-Alt-h", + mac: "Command-Alt-h" + }, + exec: + /** + * + * @param {IEditor} editor + * @param [line] + */ + function (editor, line) { + editor.showKeyboardShortcuts(); + } + }]); +}; diff --git a/src/ext/menu_tools/get_editor_keyboard_shortcuts.js b/src/ext/menu_tools/get_editor_keyboard_shortcuts.js index 1f3d05c94ed..b920e945ce2 100644 --- a/src/ext/menu_tools/get_editor_keyboard_shortcuts.js +++ b/src/ext/menu_tools/get_editor_keyboard_shortcuts.js @@ -11,14 +11,15 @@ */ "use strict"; -var keys = require("../../lib/keys"); + +/** @type{any} */var keys = require("../../lib/keys"); /** * Gets a map of keyboard shortcuts to command names for the current platform. * @author * Matthew Christopher Kastor-Inare III
* ☭ Hial Atropa!! ☭ - * @param {ace.Editor} editor An editor instance. + * @param {import("../../editor").IEditor} editor An editor instance. * @returns {Array} Returns an array of objects representing the keyboard * shortcuts for the given editor. * @example diff --git a/src/ext/menu_tools/overlay_page.js b/src/ext/menu_tools/overlay_page.js index b216354bb7d..d1cb87e6c3e 100644 --- a/src/ext/menu_tools/overlay_page.js +++ b/src/ext/menu_tools/overlay_page.js @@ -22,10 +22,11 @@ dom.importCssString(cssText, "settings_menu.css", false); * @author * Matthew Christopher Kastor-Inare III
* ☭ Hial Atropa!! ☭ - * @param {Element} contentElement Any element which may be presented inside + * @param editor + * @param {HTMLElement} contentElement Any element which may be presented inside * a div. + * @param [callback] */ - module.exports.overlayPage = function overlayPage(editor, contentElement, callback) { var closer = document.createElement('div'); var ignoreFocusOut = false; diff --git a/src/ext/options.js b/src/ext/options.js index f82b82dcc5e..d46c51dd5f0 100644 --- a/src/ext/options.js +++ b/src/ext/options.js @@ -211,7 +211,16 @@ var optionGroups = { } }; +/** + * @typedef IOptionPanel + * @type {OptionPanel & import("../../ace").Ace.EventEmitter} + */ class OptionPanel { + /** + * + * @param {import("../editor").IEditor} editor + * @param {HTMLElement} [element] + */ constructor(editor, element) { this.editor = editor; this.container = element || document.createElement("div"); @@ -225,7 +234,8 @@ class OptionPanel { if (config.More) oop.mixin(optionGroups.More, config.More); } - + + render() { this.container.innerHTML = ""; buildDom(["table", {role: "presentation", id: "controls"}, @@ -253,7 +263,12 @@ class OptionPanel { return this.renderOption(item.label, item); }, this); } - + + /** + * @param {string} key + * @param {Object} option + * @this {IOptionPanel} + */ renderOptionControl(key, option) { var self = this; if (Array.isArray(option)) { @@ -261,6 +276,9 @@ class OptionPanel { return self.renderOptionControl(key, x); }); } + /** + * @type {any} + */ var control; var value = self.getOption(option); @@ -339,7 +357,13 @@ class OptionPanel { } return control; } - + + /** + * + * @param key + * @param option + * @this {IOptionPanel} + */ renderOption(key, option) { if (option.path && !option.onchange && !this.editor.$options[option.path]) return; @@ -352,7 +376,12 @@ class OptionPanel { ["label", {for: safeKey, id: safeId}, key] ], ["td", control]]; } - + + /** + * @param {string | number | Object} option + * @param {string | number | boolean} value + * @this {IOptionPanel} + */ setOption(option, value) { if (typeof option == "string") option = this.options[option]; diff --git a/src/ext/prompt.js b/src/ext/prompt.js index bb38277c236..259cea54f36 100644 --- a/src/ext/prompt.js +++ b/src/ext/prompt.js @@ -1,24 +1,8 @@ /** - * Prompt plugin is used for getting input from user. - * - * @param {Object} editor Ouside editor related to this prompt. Will be blurred when prompt is open. - * @param {String} message Predefined value of prompt input box. - * @param {Object} options Cusomizable options for this prompt. - * @param {String} options.name Prompt name. - * @param {String} options.$type Use prompt of specific type (gotoLine|commands|modes or default if empty). - * @param {[start, end]} options.selection Defines which part of the predefined value should be highlited. - * @param {Boolean} options.hasDescription Set to true if prompt has description below input box. - * @param {String} options.prompt Description below input box. - * @param {String} options.placeholder Placeholder for value. - * @param {Object} options.$rules Specific rules for input like password or regexp. - * @param {Boolean} options.ignoreFocusOut Set to true to keep the prompt open when focus moves to another part of the editor. - * @param {Function} options.getCompletions Function for defining list of options for value. - * @param {Function} options.getPrefix Function for defining current value prefix. - * @param {Function} options.onAccept Function called when Enter is pressed. - * @param {Function} options.onInput Function called when input is added to prompt input box. - * @param {Function} options.onCancel Function called when Esc|Shift-Esc is pressed. - * @param {Function} callback Function called after done. - * */ + * @typedef IEditor + * @type {import("../editor").IEditor} + */ + "use strict"; @@ -26,6 +10,9 @@ var nls = require("../config").nls; var Range = require("../range").Range; var dom = require("../lib/dom"); var FilteredList= require("../autocomplete").FilteredList; +/** + * @type {any} + */ var AcePopup = require('../autocomplete/popup').AcePopup; var $singleLineEditor = require('../autocomplete/popup').$singleLineEditor; var UndoManager = require("../undomanager").UndoManager; @@ -34,6 +21,34 @@ var overlayPage = require("./menu_tools/overlay_page").overlayPage; var modelist = require("./modelist"); var openPrompt; +/** + * @typedef PromptOptions + * @property {String} name Prompt name. + * @property {String} $type Use prompt of specific type (gotoLine|commands|modes or default if empty). + * @property {[start: number, end: number]} selection Defines which part of the predefined value should be highlited. + * @property {Boolean} hasDescription Set to true if prompt has description below input box. + * @property {String} prompt Description below input box. + * @property {String} placeholder Placeholder for value. + * @property {Object} $rules Specific rules for input like password or regexp. + * @property {Boolean} ignoreFocusOut Set to true to keep the prompt open when focus moves to another part of the editor. + * @property {Function} getCompletions Function for defining list of options for value. + * @property {Function} getPrefix Function for defining current value prefix. + * @property {Function} onAccept Function called when Enter is pressed. + * @property {Function} onInput Function called when input is added to prompt input box. + * @property {Function} onCancel Function called when Esc|Shift-Esc is pressed. + * @property {Function} history Function for defining history list. + * @property {number} maxHistoryCount + * @property {Function} addToHistory + */ + +/** + * Prompt plugin is used for getting input from user. + * + * @param {IEditor} editor Ouside editor related to this prompt. Will be blurred when prompt is open. + * @param {String} message Predefined value of prompt input box. + * @param {Partial} options Cusomizable options for this prompt. + * @param {Function} [callback] Function called after done. + * */ function prompt(editor, message, options, callback) { if (typeof message == "object") { return prompt(editor, "", message, options); @@ -70,6 +85,9 @@ function prompt(editor, message, options, callback) { } if (options.getCompletions) { + /** + * @type {import("../autocomplete/popup").IAcePopup} + */ var popup = new AcePopup(); popup.renderer.setStyle("ace_autocomplete_inline"); popup.container.style.display = "block"; @@ -193,6 +211,11 @@ function prompt(editor, message, options, callback) { }; } +/** + * + * @param {IEditor} editor + * @param {Function} [callback] + */ prompt.gotoLine = function(editor, callback) { function stringifySelection(selection) { if (!Array.isArray(selection)) @@ -300,6 +323,11 @@ prompt.gotoLine = function(editor, callback) { }); }; +/** + * + * @param {IEditor} editor + * @param {Function} [callback] + */ prompt.commands = function(editor, callback) { function normalizeName(name) { return (name || "").replace(/^./, function(x) { @@ -430,6 +458,11 @@ prompt.commands = function(editor, callback) { }); }; +/** + * + * @param {IEditor} editor + * @param {Function} [callback] + */ prompt.modes = function(editor, callback) { var modesArray = modelist.modes; modesArray = modesArray.map(function(item) { diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index 3b766dd68a4..729ce9ed947 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -1,5 +1,8 @@ "use strict"; - +/** + * @typedef IEditor + * @type {import("../editor").IEditor} + */ var dom = require("../lib/dom"); var lang = require("../lib/lang"); var event = require("../lib/event"); @@ -13,6 +16,12 @@ var MAX_COUNT = 999; dom.importCssString(searchboxCss, "ace_searchbox", false); class SearchBox { + activeInput; + /** + * @param {IEditor} editor + * @param {undefined} [range] + * @param {undefined} [showReplaceForm] + */ constructor(editor, range, showReplaceForm) { var div = dom.createElement("div"); dom.buildDom(["div", {class:"ace_search right"}, @@ -46,7 +55,10 @@ class SearchBox { this.setEditor(editor); dom.importCssString(searchboxCss, "ace_searchbox", editor.container); } - + + /** + * @param {IEditor} editor + */ setEditor(editor) { editor.searchBox = this; editor.renderer.scroller.appendChild(this.element); @@ -58,16 +70,49 @@ class SearchBox { this.$syncOptions(true); } + /** + * @param {HTMLElement} sb + */ $initElements(sb) { + /** + * @type {HTMLElement} + */ this.searchBox = sb.querySelector(".ace_search_form"); + /** + * @type {HTMLElement} + */ this.replaceBox = sb.querySelector(".ace_replace_form"); + /** + * @type {HTMLInputElement} + */ this.searchOption = sb.querySelector("[action=searchInSelection]"); + /** + * @type {HTMLInputElement} + */ this.replaceOption = sb.querySelector("[action=toggleReplace]"); + /** + * @type {HTMLInputElement} + */ this.regExpOption = sb.querySelector("[action=toggleRegexpMode]"); + /** + * @type {HTMLInputElement} + */ this.caseSensitiveOption = sb.querySelector("[action=toggleCaseSensitive]"); + /** + * @type {HTMLInputElement} + */ this.wholeWordOption = sb.querySelector("[action=toggleWholeWords]"); + /** + * @type {HTMLInputElement} + */ this.searchInput = this.searchBox.querySelector(".ace_search_field"); + /** + * @type {HTMLInputElement} + */ this.replaceInput = this.replaceBox.querySelector(".ace_search_field"); + /** + * @type {HTMLElement} + */ this.searchCounter = sb.querySelector(".ace_search_counter"); } @@ -118,7 +163,7 @@ class SearchBox { _this.searchInput.value && _this.highlight(); }); } - + setSearchRange(range) { this.searchRange = range; if (range) { @@ -129,6 +174,9 @@ class SearchBox { } } + /** + * @param {boolean} preventScroll + */ $syncOptions(preventScroll) { dom.setCssClass(this.replaceOption, "checked", this.searchRange); dom.setCssClass(this.searchOption, "checked", this.searchOption.checked); @@ -142,11 +190,19 @@ class SearchBox { this.find(false, false, preventScroll); } + /** + * @param {RegExp} [re] + */ highlight(re) { this.editor.session.highlight(re || this.editor.$search.$options.re); this.editor.renderer.updateBackMarkers(); } - + + /** + * @param {boolean} skipCurrent + * @param {boolean} backwards + * @param {any} [preventScroll] + */ find(skipCurrent, backwards, preventScroll) { var range = this.editor.find(this.searchInput.value, { skipCurrent: skipCurrent, @@ -238,6 +294,11 @@ class SearchBox { this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb); this.editor.focus(); } + + /** + * @param {string} value + * @param {boolean} [isReplace] + */ show(value, isReplace) { this.active = true; this.editor.on("changeSession", this.setSession); @@ -357,6 +418,11 @@ SearchBox.prototype.$closeSearchBarKb = $closeSearchBarKb; exports.SearchBox = SearchBox; +/** + * + * @param {IEditor} editor + * @param {boolean} [isReplace] + */ exports.Search = function(editor, isReplace) { var sb = editor.searchBox || new SearchBox(editor); sb.show(editor.session.getTextRange(), isReplace); diff --git a/src/ext/settings_menu.js b/src/ext/settings_menu.js index 495997f0a52..ea959b52816 100644 --- a/src/ext/settings_menu.js +++ b/src/ext/settings_menu.js @@ -14,12 +14,17 @@ "use strict"; var OptionPanel = require("./options").OptionPanel; var overlayPage = require('./menu_tools/overlay_page').overlayPage; + +/** + * @typedef IEditor + * @type {import("../editor").IEditor} + */ /** * This displays the settings menu if it is not already being shown. * @author * Matthew Christopher Kastor-Inare III
* ☭ Hial Atropa!! ☭ - * @param {ace.Editor} editor An instance of the ace editor. + * @param {IEditor} editor An instance of the ace editor. */ function showSettingsMenu(editor) { // show if the menu isn't open already. @@ -36,9 +41,11 @@ function showSettingsMenu(editor) { * Initializes the settings menu extension. It adds the showSettingsMenu * method to the given editor object and adds the showSettingsMenu command * to the editor with appropriate keyboard shortcuts. - * @param {ace.Editor} editor An instance of the Editor. */ module.exports.init = function() { + /** + * @type {any} + */ var Editor = require("../editor").Editor; Editor.prototype.showSettingsMenu = function() { showSettingsMenu(this); diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index 191ebc80ddd..175a5404e60 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -1,5 +1,8 @@ "use strict"; +/** + * @type {any} + */ var EditSession = require("../edit_session").EditSession; var TextLayer = require("../layer/text").Text; var baseStyles = require("./static-css"); @@ -8,6 +11,7 @@ var dom = require("../lib/dom"); var escapeHTML = require("../lib/lang").escapeHTML; class Element { + /** @type{string} */className; constructor(type) { this.type = type; this.style = {}; @@ -63,12 +67,22 @@ var simpleDom = { }; +/** + * @type {any} + */ var SimpleTextLayer = function() { this.config = {}; this.dom = simpleDom; }; SimpleTextLayer.prototype = TextLayer.prototype; +/** + * + * @param {HTMLElement} el + * @param opts + * @param [callback] + * @returns {boolean} + */ var highlight = function(el, opts, callback) { var m = el.className.match(/lang-(\w+)/); var mode = opts.mode || m && ("ace/mode/" + m[1]); @@ -114,16 +128,16 @@ var highlight = function(el, opts, callback) { * Transforms a given input code snippet into HTML using the given mode * * @param {string} input Code snippet - * @param {string|mode} mode String specifying the mode to load such as + * @param {string|import("../../ace").Ace.SyntaxMode} mode String specifying the mode to load such as * `ace/mode/javascript` or, a mode loaded from `/ace/mode` * (use 'ServerSideHiglighter.getMode'). - * @param {string|theme} theme String specifying the theme to load such as + * @param {string} theme String specifying the theme to load such as * `ace/theme/twilight` or, a theme loaded from `/ace/theme`. * @param {number} lineStart A number indicating the first line number. Defaults * to 1. * @param {boolean} disableGutter Specifies whether or not to disable the gutter. * `true` disables the gutter, `false` enables the gutter. Defaults to `false`. - * @param {function} callback When specifying the mode or theme as a string, + * @param {function} [callback] When specifying the mode or theme as a string, * this method has no return value and you must specify a callback function. The * callback will receive the rendered object containing the properties `html` * and `css`. @@ -151,9 +165,9 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba if (typeof mode == "string") { waiting++; config.loadModule(['mode', mode], function(m) { - if (!modeCache[mode] || modeOptions) - modeCache[mode] = new m.Mode(modeOptions); - mode = modeCache[mode]; + if (!modeCache[/**@type{string}*/(mode)] || modeOptions) + modeCache[/**@type{string}*/(mode)] = new m.Mode(modeOptions); + mode = modeCache[/**@type{string}*/(mode)]; --waiting || done(); }); } @@ -169,17 +183,25 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba /** * Transforms a given input code snippet into HTML using the given mode * @param {string} input Code snippet - * @param {mode} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') - * @param {string} r Code snippet + * @param {import("../../ace").Ace.SyntaxMode|string} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') + * @param {any} theme + * @param {any} lineStart + * @param {boolean} disableGutter * @returns {object} An object containing: html, css */ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) { lineStart = parseInt(lineStart || 1, 10); + /** + * @type {import("../edit_session").IEditSession} + */ var session = new EditSession(""); session.setUseWorker(false); session.setMode(mode); + /** + * @type {TextLayer} + */ var textLayer = new SimpleTextLayer(); textLayer.setSession(session); Object.keys(textLayer.$tabStrings).forEach(function(k) { diff --git a/src/ext/statusbar.js b/src/ext/statusbar.js index ece9d0fede2..8d0006a54d1 100644 --- a/src/ext/statusbar.js +++ b/src/ext/statusbar.js @@ -1,10 +1,18 @@ "use strict"; - +/** + * + * @typedef IEditor + * @type {import("../editor").IEditor} + */ var dom = require("../lib/dom"); var lang = require("../lib/lang"); /** simple statusbar **/ class StatusBar{ + /** + * @param {IEditor} editor + * @param {HTMLElement} parentNode + */ constructor(editor, parentNode) { this.element = dom.createElement("div"); this.element.className = "ace_status-indicator"; @@ -19,7 +27,10 @@ class StatusBar{ editor.on("changeSelection", statusUpdate); editor.on("keyboardActivity", statusUpdate); } - + + /** + * @param {IEditor} editor + */ updateStatus(editor) { var status = []; function add(str, separator) { diff --git a/src/ext/textarea.js b/src/ext/textarea.js index e2c74f4d438..1d11901f9e3 100644 --- a/src/ext/textarea.js +++ b/src/ext/textarea.js @@ -216,7 +216,7 @@ exports.transformTextarea = function(element, options) { editor.setDisplaySettings(); return; } - container.style.zIndex = 100000; + container.style.zIndex = "100000"; var rect = container.getBoundingClientRect(); var startX = rect.width + rect.left - e.clientX; var startY = rect.height + rect.top - e.clientY; diff --git a/src/ext/whitespace.js b/src/ext/whitespace.js index 90e3b21e836..153c1dbade8 100644 --- a/src/ext/whitespace.js +++ b/src/ext/whitespace.js @@ -1,8 +1,20 @@ "use strict"; +/** + * + * @typedef IEditSession + * @type {import("../edit_session").IEditSession} + */ + var lang = require("../lib/lang"); // based on http://www.freehackers.org/Indent_Finder +/** + * + * @param {string[]} lines + * @param [fallback] + * @returns {{ch?: string, length?: number}} + */ exports.$detectIndentation = function(lines, fallback) { var stats = []; var changes = []; @@ -74,6 +86,10 @@ exports.$detectIndentation = function(lines, fallback) { return {ch: " ", length: tabLength}; }; +/** + * @param {IEditSession} session + * @returns {{ch?: string, length?: number}|{}} + */ exports.detectIndentation = function(session) { var lines = session.getLines(0, 1000); var indent = exports.$detectIndentation(lines) || {}; @@ -87,9 +103,10 @@ exports.detectIndentation = function(session) { }; /** - * EditSession session - * options.trimEmpty trim empty lines too - * options.keepCursorPosition do not trim whitespace before the cursor + * @param {IEditSession} session + * @param {Object} options + * @param {boolean} [options.trimEmpty] trim empty lines too + * @param {boolean} [options.keepCursorPosition] do not trim whitespace before the cursor */ exports.trimTrailingSpace = function(session, options) { var doc = session.getDocument(); @@ -128,6 +145,11 @@ exports.trimTrailingSpace = function(session, options) { } }; +/** + * @param {IEditSession} session + * @param {string} ch + * @param {number} len + */ exports.convertIndentation = function(session, ch, len) { var oldCh = session.getTabString()[0]; var oldLen = session.getTabSize(); @@ -161,6 +183,11 @@ exports.convertIndentation = function(session, ch, len) { session.setUseSoftTabs(ch == " "); }; +/** + * + * @param {string} text + * @returns {{}} + */ exports.$parseStringArg = function(text) { var indent = {}; if (/t/.test(text)) diff --git a/src/keyboard/gutter_handler.js b/src/keyboard/gutter_handler.js index cc7d6ce8225..df94dee9da5 100644 --- a/src/keyboard/gutter_handler.js +++ b/src/keyboard/gutter_handler.js @@ -50,40 +50,42 @@ class GutterKeyboardHandler { this.editor.scrollToLine(row, true, true); // After scrolling is completed, find the nearest gutter icon and set focus to it. - setTimeout(function() { - var index = this.$rowToRowIndex(this.gutterLayer.$cursorCell.row); - var nearestFoldIndex = this.$findNearestFoldWidget(index); - var nearestAnnotationIndex = this.$findNearestAnnotation(index); - - if (nearestFoldIndex === null && nearestAnnotationIndex === null) - return; - - if (nearestFoldIndex === null && nearestAnnotationIndex !== null){ - this.activeRowIndex = nearestAnnotationIndex; - this.activeLane = "annotation"; - this.$focusAnnotation(this.activeRowIndex); - return; - } - - if (nearestFoldIndex !== null && nearestAnnotationIndex === null){ - this.activeRowIndex = nearestFoldIndex; - this.activeLane = "fold"; - this.$focusFoldWidget(this.activeRowIndex); - return; - } - - if (Math.abs(nearestAnnotationIndex - index) < Math.abs(nearestFoldIndex - index)){ - this.activeRowIndex = nearestAnnotationIndex; - this.activeLane = "annotation"; - this.$focusAnnotation(this.activeRowIndex); - return; - } else { - this.activeRowIndex = nearestFoldIndex; - this.activeLane = "fold"; - this.$focusFoldWidget(this.activeRowIndex); - return; - } - }.bind(this), 10); + setTimeout( + /** @this {GutterKeyboardHandler} */ + function () { + var index = this.$rowToRowIndex(this.gutterLayer.$cursorCell.row); + var nearestFoldIndex = this.$findNearestFoldWidget(index); + var nearestAnnotationIndex = this.$findNearestAnnotation(index); + + if (nearestFoldIndex === null && nearestAnnotationIndex === null) return; + + if (nearestFoldIndex === null && nearestAnnotationIndex !== null) { + this.activeRowIndex = nearestAnnotationIndex; + this.activeLane = "annotation"; + this.$focusAnnotation(this.activeRowIndex); + return; + } + + if (nearestFoldIndex !== null && nearestAnnotationIndex === null) { + this.activeRowIndex = nearestFoldIndex; + this.activeLane = "fold"; + this.$focusFoldWidget(this.activeRowIndex); + return; + } + + if (Math.abs(nearestAnnotationIndex - index) < Math.abs(nearestFoldIndex - index)) { + this.activeRowIndex = nearestAnnotationIndex; + this.activeLane = "annotation"; + this.$focusAnnotation(this.activeRowIndex); + return; + } + else { + this.activeRowIndex = nearestFoldIndex; + this.activeLane = "fold"; + this.$focusFoldWidget(this.activeRowIndex); + return; + } + }.bind(this), 10); return; } @@ -168,12 +170,14 @@ class GutterKeyboardHandler { // After folding, check that the right fold widget is still in focus. // If not (e.g. folding close to bottom of doc), put right widget in focus. - setTimeout(function() { - if (this.$rowIndexToRow(this.activeRowIndex) !== rowFoldingWidget){ - this.$blurFoldWidget(this.activeRowIndex); - this.activeRowIndex = this.$rowToRowIndex(rowFoldingWidget); - this.$focusFoldWidget(this.activeRowIndex); - } + setTimeout( + /** @this {GutterKeyboardHandler} */ + function () { + if (this.$rowIndexToRow(this.activeRowIndex) !== rowFoldingWidget) { + this.$blurFoldWidget(this.activeRowIndex); + this.activeRowIndex = this.$rowToRowIndex(rowFoldingWidget); + this.$focusFoldWidget(this.activeRowIndex); + } }.bind(this), 10); break; @@ -481,4 +485,4 @@ class GutterKeyboardEvent { } } -exports.GutterKeyboardEvent = GutterKeyboardEvent; \ No newline at end of file +exports.GutterKeyboardEvent = GutterKeyboardEvent; diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index f5be98745fe..13a7f55ee0c 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -1,6 +1,7 @@ "use strict"; -var keyUtil = require("../lib/keys"); + +/** @type {any} */var keyUtil = require("../lib/keys"); var useragent = require("../lib/useragent"); var KEY_MODS = keyUtil.KEY_MODS; diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 70c2897f5cc..454ebebc093 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -5,6 +5,9 @@ var event = require("../lib/event"); class KeyBinding { + /** + * @param {import("../editor").IEditor} editor + */ constructor(editor) { this.$editor = editor; this.$data = {editor: editor}; diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index 8ee1f919992..9727cbe0ee1 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -11,32 +11,38 @@ var USE_IE_MIME_TYPE = useragent.isIE; var HAS_FOCUS_ARGS = useragent.isChrome > 63; var MAX_LINE_LENGTH = 400; +/** + * + * @type {{[key: string]: any}} + */ var KEYS = require("../lib/keys"); var MODS = KEYS.KEY_MODS; var isIOS = useragent.isIOS; var valueResetRegex = isIOS ? /\s/ : /\n/; var isMobile = useragent.isMobile; -/** - * @type Class - * @param parentNode - * @param host - * @constructor - */ -var TextInput = function(parentNode, host) { +var TextInput +TextInput= function(parentNode, host) { + /** + * @type {HTMLTextAreaElement & {msGetInputContext?: () => {compositionStartOffset: number}, getInputContext?: () => {compositionStartOffset: number}}} + */ var text = dom.createElement("textarea"); text.className = "ace_text-input"; text.setAttribute("wrap", "off"); text.setAttribute("autocorrect", "off"); text.setAttribute("autocapitalize", "off"); - text.setAttribute("spellcheck", false); + text.setAttribute("spellcheck", "false"); text.style.opacity = "0"; parentNode.insertBefore(text, parentNode.firstChild); var copied = false; var pasted = false; + /** + * + * @type {false | {[key: string]: any}}} + */ var inComposition = false; var sendingText = false; var tempStyle = ''; @@ -117,6 +123,10 @@ var TextInput = function(parentNode, host) { else resetSelection(); }, host); + /** + * + * @type {boolean | string} + */ this.$focusScroll = false; this.focus = function() { // On focusing on the textarea, read active row number to assistive tech. @@ -141,7 +151,7 @@ var TextInput = function(parentNode, host) { var t = text.parentElement; while (t && t.nodeType == 1) { ancestors.push(t); - t.setAttribute("ace_nocontext", true); + t.setAttribute("ace_nocontext", "true"); if (!t.parentElement && t.getRootNode) t = t.getRootNode().host; else @@ -217,8 +227,8 @@ var TextInput = function(parentNode, host) { // modifying selection of blured textarea can focus it (chrome mac/linux) if (!isFocused && !afterContextMenu) return; - // this prevents infinite recursion on safari 8 // see https://github.com/ajaxorg/ace/issues/2114 + // @ts-expect-error this prevents infinite recursion on safari 8 inComposition = true; var selectionStart = 0; @@ -437,7 +447,7 @@ var TextInput = function(parentNode, host) { }; var handleClipboardData = function(e, data, forceIEMime) { - var clipboardData = e.clipboardData || window.clipboardData; + var clipboardData = e.clipboardData || window["clipboardData"]; if (!clipboardData || BROKEN_SETDATA) return; // using "Text" doesn't work on old webkit but ie needs it diff --git a/src/layer/font_metrics.js b/src/layer/font_metrics.js index adb95c0480c..abf6ebf07a4 100644 --- a/src/layer/font_metrics.js +++ b/src/layer/font_metrics.js @@ -10,7 +10,11 @@ var USE_OBSERVER = typeof ResizeObserver == "function"; var L = 200; class FontMetrics { - + + /** + * @param {HTMLElement} parentEl + * @this {FontMetrics & import("../../ace").Ace.EventEmitter} + */ constructor(parentEl) { this.el = dom.createElement("div"); this.$setMeasureNodeStyles(this.el.style, true); @@ -52,6 +56,10 @@ class FontMetrics { style.overflow = isRoot ? "hidden" : "visible"; } + /** + * @param size + * @this {FontMetrics & import("../../ace").Ace.EventEmitter} + */ checkForSizeChanges(size) { if (size === undefined) size = this.$measureSizes(); @@ -65,7 +73,10 @@ class FontMetrics { this._emit("changeCharacterSize", {data: size}); } } - + + /** + * @this {FontMetrics & import("../../ace").Ace.EventEmitter} + */ $addObserver() { var self = this; this.$observer = new window.ResizeObserver(function(e) { @@ -75,6 +86,10 @@ class FontMetrics { this.$observer.observe(this.$measureNode); } + /** + * @this {FontMetrics & import("../../ace").Ace.EventEmitter} + * @return {number} + */ $pollSizeChanges() { if (this.$pollSizeChangesTimer || this.$observer) return this.$pollSizeChangesTimer; @@ -85,7 +100,11 @@ class FontMetrics { event.onIdle(cb, 500); }, 500); } - + + /** + * @param {boolean} val + * @this {FontMetrics & import("../../ace").Ace.EventEmitter} + */ setPolling(val) { if (val) { this.$pollSizeChanges(); diff --git a/src/layer/gutter.js b/src/layer/gutter.js index 8e3772dbf65..aab11c6e3cb 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -1,5 +1,8 @@ "use strict"; - +/** + * @typedef IGutter + * @type {Gutter & import("../../ace").Ace.EventEmitter & {[key: string]: any}}} + */ var dom = require("../lib/dom"); var oop = require("../lib/oop"); var lang = require("../lib/lang"); @@ -8,6 +11,9 @@ var Lines = require("./lines").Lines; var nls = require("../config").nls; class Gutter{ + /** + * @param {HTMLElement} parentEl + */ constructor(parentEl) { this.element = dom.createElement("div"); this.element.className = "ace_layer ace_gutter-layer"; @@ -23,6 +29,9 @@ class Gutter{ this.$lines.$offsetCoefficient = 1; } + /** + * @param {import("../edit_session").IEditSession} session + */ setSession(session) { if (this.session) this.session.off("change", this.$updateAnnotations); @@ -31,18 +40,29 @@ class Gutter{ session.on("change", this.$updateAnnotations); } + /** + * @param {number} row + * @param {string} className + */ addGutterDecoration(row, className) { if (window.console) console.warn && console.warn("deprecated use session.addGutterDecoration"); this.session.addGutterDecoration(row, className); } + /** + * @param {number} row + * @param {string} className + */ removeGutterDecoration(row, className) { if (window.console) console.warn && console.warn("deprecated use session.removeGutterDecoration"); this.session.removeGutterDecoration(row, className); } + /** + * @param {any[]} annotations + */ setAnnotations(annotations) { // iterate over sparse array this.$annotations = []; @@ -74,6 +94,9 @@ class Gutter{ } } + /** + * @param {import("../../ace").Ace.Delta} delta + */ $updateAnnotations(delta) { if (!this.$annotations.length) return; @@ -90,6 +113,10 @@ class Gutter{ } } + /** + * @param {import("../../ace").Ace.LayerConfig} config + * @this {IGutter} + */ update(config) { this.config = config; @@ -140,6 +167,10 @@ class Gutter{ this.$updateGutterWidth(config); } + /** + * @param {import("../../ace").Ace.LayerConfig} config + * @this {IGutter} + */ $updateGutterWidth(config) { var session = this.session; @@ -204,7 +235,11 @@ class Gutter{ } } } - + + /** + * @param {import("../../ace").Ace.LayerConfig} config + * @this {IGutter} + */ scrollLines(config) { var oldConfig = this.config; this.config = config; @@ -248,6 +283,12 @@ class Gutter{ this.$updateGutterWidth(config); } + /** + * @param {import("../../ace").Ace.LayerConfig} config + * @param {number} firstRow + * @param {number} lastRow + * @this {IGutter} + */ $renderLines(config, firstRow, lastRow) { var fragment = []; var row = firstRow; @@ -271,7 +312,15 @@ class Gutter{ } return fragment; } - + + + /** + * @param {any} cell + * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../edit_session/fold").Fold} [fold] //TODO: + * @param {number} row + * @this {IGutter} + */ $renderCell(cell, config, fold, row) { var element = cell.element; @@ -443,11 +492,17 @@ class Gutter{ return cell; } - + + /** + * @param {boolean} highlightGutterLine + */ setHighlightGutterLine(highlightGutterLine) { this.$highlightGutterLine = highlightGutterLine; } - + + /** + * @param {boolean} show + */ setShowLineNumbers(show) { this.$renderer = !show && { getWidth: function() {return 0;}, @@ -458,7 +513,10 @@ class Gutter{ getShowLineNumbers() { return this.$showLineNumbers; } - + + /** + * @param {boolean} [show] + */ setShowFoldWidgets(show) { if (show) dom.addCssClass(this.element, "ace_folding-enabled"); @@ -485,6 +543,9 @@ class Gutter{ return this.$padding; } + /** + * @param {{ x: number; }} point + */ getRegion(point) { var padding = this.$padding || this.$computePadding(); var rect = this.element.getBoundingClientRect(); diff --git a/src/layer/marker.js b/src/layer/marker.js index f7edb09e58a..3c683ce42fd 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -5,24 +5,44 @@ var dom = require("../lib/dom"); class Marker { + /** + * @param {HTMLElement} parentEl + */ constructor(parentEl) { this.element = dom.createElement("div"); this.element.className = "ace_layer ace_marker-layer"; parentEl.appendChild(this.element); } - + + /** + * @param {number} padding + */ setPadding(padding) { this.$padding = padding; } + + /** + * @param {import("../edit_session").IEditSession} session + */ setSession(session) { this.session = session; } - + + /** + * @param {{ [x: number]: import("../../ace").Ace.MarkerLike; }} markers + */ setMarkers(markers) { this.markers = markers; } - + + /** + * @param {string} className + * @param {string} css + */ elt(className, css) { + /** + * @type {any} + */ var x = this.i != -1 && this.element.childNodes[this.i]; if (!x) { x = document.createElement("div"); diff --git a/src/layer/text.js b/src/layer/text.js index 36edf0e2371..702ceec80c9 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -7,7 +7,7 @@ /** * * @typedef IText - * @type {Text & Ace.EventEmitter} + * @type {Text & import("../../ace").Ace.EventEmitter} * @export */ var oop = require("../lib/oop"); @@ -70,8 +70,12 @@ class Text { */ $setFontMetrics(measure) { this.$fontMetrics = measure; - this.$fontMetrics.on("changeCharacterSize", function(e) { - this._signal("changeCharacterSize", e); + this.$fontMetrics.on("changeCharacterSize", + /** + * @this {IText} + */ + function (e) { + this._signal("changeCharacterSize", e); }.bind(this)); this.$pollSizeChanges(); } @@ -381,7 +385,7 @@ class Text { span.textContent = lang.stringRepeat(self.SPACE_CHAR, simpleSpace.length); valueFragment.appendChild(span); } else { - valueFragment.appendChild(this.com.createTextNode(simpleSpace, this.element)); + valueFragment.appendChild(this.dom.createTextNode(simpleSpace, this.element)); } } else if (controlCharacter) { var span = this.dom.createElement("span"); @@ -696,7 +700,7 @@ class Text { /** * @param {any} row * @param {{ walk: (arg0: (placeholder: any, row: any, column: any, lastColumn: any, isNewRow: any) => void, arg1: any, arg2: any) => void; end: { row: any; }; }} foldLine - * @return {Ace.Token[]} + * @return {import("../../ace").Ace.Token[]} */ $getFoldLineTokens(row, foldLine) { var session = this.session; diff --git a/src/lib/app_config.js b/src/lib/app_config.js index b471fe051e2..c5cc5d5c4da 100644 --- a/src/lib/app_config.js +++ b/src/lib/app_config.js @@ -1,7 +1,7 @@ "no use strict"; /** * @typedef IAppConfig - * @type {AppConfig & Ace.EventEmitter} + * @type {AppConfig & import("../../ace").Ace.EventEmitter} * @export */ var oop = require("./oop"); @@ -86,6 +86,7 @@ class AppConfig { * @param {string} path * @param {{ [key: string]: any }} options * @returns {IAppConfig} + * @this {IAppConfig} */ defineOptions(obj, path, options) { if (!obj.$options) diff --git a/src/lib/dom.js b/src/lib/dom.js index fc3125fa490..fea84547060 100644 --- a/src/lib/dom.js +++ b/src/lib/dom.js @@ -3,6 +3,13 @@ var useragent = require("./useragent"); var XHTML_NS = "http://www.w3.org/1999/xhtml"; +/** + * + * @param {any} arr + * @param {HTMLElement} [parent] + * @param [refs] + * @returns {HTMLElement | Text | any[]} + */ exports.buildDom = function buildDom(arr, parent, refs) { if (typeof arr == "string" && arr) { var txt = document.createTextNode(arr); @@ -53,39 +60,71 @@ exports.buildDom = function buildDom(arr, parent, refs) { return el; }; +/** + * + * @param {Document} [doc] + * @returns {HTMLHeadElement|HTMLElement} + */ exports.getDocumentHead = function(doc) { if (!doc) doc = document; return doc.head || doc.getElementsByTagName("head")[0] || doc.documentElement; }; + +/** + * @template {keyof HTMLElementTagNameMap} T + * @param {T | string} tag + * @param {string} [ns] + * @returns {HTMLElementTagNameMap[T]} + */ exports.createElement = function(tag, ns) { + // @ts-ignore return document.createElementNS ? document.createElementNS(ns || XHTML_NS, tag) : document.createElement(tag); }; +/** + * @param {HTMLElement} element + */ exports.removeChildren = function(element) { element.innerHTML = ""; }; +/** + * @param {string} textContent + * @param {HTMLElement} [element] + * @returns {Text} + */ exports.createTextNode = function(textContent, element) { var doc = element ? element.ownerDocument : document; return doc.createTextNode(textContent); }; +/** + * @param {HTMLElement} [element] + * @returns {DocumentFragment} + */ exports.createFragment = function(element) { var doc = element ? element.ownerDocument : document; return doc.createDocumentFragment(); }; +/** + * @param {HTMLElement} el + * @param {string} name + * @returns {boolean} + */ exports.hasCssClass = function(el, name) { var classes = (el.className + "").split(/\s+/g); return classes.indexOf(name) !== -1; }; -/* -* Add a CSS class to the list of classes on the given node +/** + * Add a CSS class to the list of classes on the given node + * @param {HTMLElement} el + * @param {string} name */ exports.addCssClass = function(el, name) { if (!exports.hasCssClass(el, name)) { @@ -93,9 +132,11 @@ exports.addCssClass = function(el, name) { } }; -/* -* Remove a CSS class from the list of classes on the given node -*/ +/** + * Remove a CSS class from the list of classes on the given node + * @param {HTMLElement} el + * @param {string} name + */ exports.removeCssClass = function(el, name) { var classes = el.className.split(/\s+/g); while (true) { @@ -108,6 +149,11 @@ exports.removeCssClass = function(el, name) { el.className = classes.join(" "); }; +/** + * @param {HTMLElement} el + * @param {string} name + * @returns {boolean} + */ exports.toggleCssClass = function(el, name) { var classes = el.className.split(/\s+/g), add = true; while (true) { @@ -125,11 +171,13 @@ exports.toggleCssClass = function(el, name) { return add; }; - -/* - * Add or remove a CSS class from the list of classes on the given node - * depending on the value of include - */ +/** + * Add or remove a CSS class from the list of classes on the given node + * depending on the value of include + * @param {HTMLElement} node + * @param {string} className + * @param {boolean} include + */ exports.setCssClass = function(node, className, include) { if (include) { exports.addCssClass(node, className); @@ -138,6 +186,11 @@ exports.setCssClass = function(node, className, include) { } }; +/** + * @param {string} id + * @param {Document} [doc] + * @returns {boolean} + */ exports.hasCssString = function(id, doc) { var index = 0, sheets; doc = doc || document; @@ -150,6 +203,10 @@ exports.hasCssString = function(id, doc) { } }; +/** + * @param {string} id + * @param {Document} [doc] + */ exports.removeElementById = function(id, doc) { doc = doc || document; if(doc.getElementById(id)) { @@ -214,9 +271,18 @@ function importCssString(cssText, id, target) { } exports.importCssString = importCssString; +/** + * @param {string} uri + * @param {Document} [doc] + */ exports.importCssStylsheet = function(uri, doc) { exports.buildDom(["link", {rel: "stylesheet", href: uri}], exports.getDocumentHead(doc)); }; + +/** + * @param {Document} [doc] + * @returns {number} + */ exports.scrollbarWidth = function(doc) { var inner = exports.createElement("ace_inner"); inner.style.width = "100%"; @@ -256,10 +322,21 @@ exports.scrollbarWidth = function(doc) { return noScrollbar - withScrollbar; }; +/** + * @param {HTMLElement} element + * @param [style] + * @returns {Partial} + */ exports.computedStyle = function(element, style) { return window.getComputedStyle(element, "") || {}; }; +/** + * + * @param {CSSStyleDeclaration} styles + * @param {string} property + * @param {string} value + */ exports.setStyle = function(styles, property, value) { if (styles[property] !== value) { //console.log("set style", property, styles[property], value); diff --git a/src/lib/event.js b/src/lib/event.js index 39af434d246..dcc0c5e3b5a 100644 --- a/src/lib/event.js +++ b/src/lib/event.js @@ -1,6 +1,6 @@ "use strict"; -var keys = require("./keys"); +/** @type {any} */var keys = require("./keys"); var useragent = require("./useragent"); var pressedKeys = null; @@ -322,10 +322,10 @@ exports.blockIdle = function(delay) { }; exports.nextFrame = typeof window == "object" && (window.requestAnimationFrame - || window.mozRequestAnimationFrame - || window.webkitRequestAnimationFrame - || window.msRequestAnimationFrame - || window.oRequestAnimationFrame); + || window["mozRequestAnimationFrame"] + || window["webkitRequestAnimationFrame"] + || window["msRequestAnimationFrame"] + || window["oRequestAnimationFrame"]); if (exports.nextFrame) exports.nextFrame = exports.nextFrame.bind(window); diff --git a/src/lib/lang.js b/src/lib/lang.js index 0a7732e3346..c466dfa12f5 100644 --- a/src/lib/lang.js +++ b/src/lib/lang.js @@ -56,7 +56,7 @@ exports.deepCopy = function deepCopy(obj) { var copy; if (Array.isArray(obj)) { copy = []; - for (var key = 0; key < obj.length; key++) { + for (let key = 0; key < obj.length; key++) { copy[key] = deepCopy(obj[key]); } return copy; @@ -65,7 +65,7 @@ exports.deepCopy = function deepCopy(obj) { return obj; copy = {}; - for (var key in obj) + for (let key in obj) copy[key] = deepCopy(obj[key]); return copy; }; diff --git a/src/lib/net.js b/src/lib/net.js index 93873984d12..0f3670a24d8 100644 --- a/src/lib/net.js +++ b/src/lib/net.js @@ -24,6 +24,9 @@ exports.get = function (url, callback) { exports.loadScript = function(path, callback) { var head = dom.getDocumentHead(); + /** + * @type {HTMLScriptElement & {onload?: Function, onreadystatechange?: Function, readyState?: string}} + */ var s = document.createElement('script'); s.src = path; diff --git a/src/line_widgets.js b/src/line_widgets.js index 7608ebb1a6c..3eababc087b 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -1,18 +1,12 @@ "use strict"; /** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").IEditSession} IEditSession */ /** - * - * @typedef IEditor - * @type {import("./editor").IEditor} + * @typedef {import("./editor").IEditor} IEditor */ /** - * - * @typedef IVirtualRenderer - * @type {import("./virtual_renderer").IVirtualRenderer} + * @typedef {import("./virtual_renderer").IVirtualRenderer} IVirtualRenderer */ var dom = require("./lib/dom"); @@ -20,7 +14,7 @@ var dom = require("./lib/dom"); class LineWidgets { /** - * @type {Ace.LineWidget[]} + * @type {import("../ace").Ace.LineWidget[]} */ lineWidgets; /** @@ -154,7 +148,7 @@ class LineWidgets { /** * - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta */ updateOnChange(delta) { var lineWidgets = this.session.lineWidgets; @@ -206,8 +200,8 @@ class LineWidgets { /** * - * @param {Ace.LineWidget} w - * @return {Ace.LineWidget} + * @param {import("../ace").Ace.LineWidget} w + * @return {import("../ace").Ace.LineWidget} */ $registerLineWidget(w) { if (!this.session.lineWidgets) @@ -228,8 +222,8 @@ class LineWidgets { /** * - * @param {Ace.LineWidget} w - * @return {Ace.LineWidget} + * @param {import("../ace").Ace.LineWidget} w + * @return {import("../ace").Ace.LineWidget} */ addLineWidget(w) { this.$registerLineWidget(w); @@ -286,7 +280,7 @@ class LineWidgets { } /** - * @param {Ace.LineWidget} w + * @param {import("../ace").Ace.LineWidget} w */ removeLineWidget(w) { w._inDocument = false; @@ -319,7 +313,7 @@ class LineWidgets { /** * * @param {number} row - * @return {Ace.LineWidget[]} + * @return {import("../ace").Ace.LineWidget[]} */ getWidgetsAtRow(row) { var lineWidgets = this.session.lineWidgets; @@ -333,7 +327,7 @@ class LineWidgets { } /** - * @param {Ace.LineWidget} w + * @param {import("../ace").Ace.LineWidget} w */ onWidgetChanged(w) { this.session._changedWidgets.push(w); diff --git a/src/marker_group.js b/src/marker_group.js index a4cf380a488..2484a01e773 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -31,8 +31,8 @@ class MarkerGroup { /** * Finds the first marker containing pos - * @param {Ace.Point} pos - * @returns Ace.MarkerGroupItem + * @param {import("../ace").Ace.Point} pos + * @returns import("../ace").Ace.MarkerGroupItem */ getMarkerAtPosition(pos) { return this.markers.find(function(marker) { diff --git a/src/mode/text.js b/src/mode/text.js index 05c3c8cd14a..ad50a0c3a39 100644 --- a/src/mode/text.js +++ b/src/mode/text.js @@ -2,6 +2,7 @@ var config = require("../config"); var Tokenizer = require("../tokenizer").Tokenizer; + var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; var unicode = require("../unicode"); @@ -9,22 +10,10 @@ var lang = require("../lib/lang"); var TokenIterator = require("../token_iterator").TokenIterator; var Range = require("../range").Range; -/** - * - * @constructor - * @alias TextMode - * @property {{[quote: string]: string}} [$quotes] - quotes used by language mode - * @property {string} lineCommentStart - characters that indicate the start of a line comment - * @property {{start: string, end: string}} [blockComment] - characters that indicate the start and end of a block comment - * @property {TextHighlightRules} HighlightRules - language specific highlighters - * @property {FoldMode} foldingRules - language specific folding rules - * @property {MatchingBraceOutdent} $outdent - * @property {RegExp} tokenRe - * @property {RegExp} nonTokenRe - * @property {{[quote: string]: RegExp}} [$pairQuotesAfter] - An object containing conditions to determine whether to apply matching quote or not. - */ -var Mode = function() { +var Mode; +Mode = function() { this.HighlightRules = TextHighlightRules; + new this.HighlightRules().getRules(); }; (function() { @@ -34,6 +23,9 @@ var Mode = function() { this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g"); + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.getTokenizer = function() { if (!this.$tokenizer) { this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig); @@ -45,6 +37,9 @@ var Mode = function() { this.lineCommentStart = ""; this.blockComment = ""; + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.toggleCommentLines = function(state, session, startRow, endRow) { var doc = session.doc; @@ -57,8 +52,14 @@ var Mode = function() { if (!this.lineCommentStart) { if (!this.blockComment) return false; + /** + * @type {any} + */ var lineCommentStart = this.blockComment.start; var lineCommentEnd = this.blockComment.end; + /** + * @type {any} + */ var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")"); var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$"); @@ -90,10 +91,19 @@ var Mode = function() { }; } else { if (Array.isArray(this.lineCommentStart)) { + /** + * @type {any} + */ var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|"); + /** + * @type {any} + */ var lineCommentStart = this.lineCommentStart[0]; } else { var regexpStart = lang.escapeRegExp(this.lineCommentStart); + /** + * @type {any} + */ var lineCommentStart = this.lineCommentStart; } regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?"); @@ -168,6 +178,9 @@ var Mode = function() { iter(shouldRemove ? uncomment : comment); }; + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.toggleBlockComment = function(state, session, range, cursor) { var comment = this.blockComment; if (!comment) @@ -250,7 +263,7 @@ var Mode = function() { this.createModeDelegates = function (mapping) { this.$embeds = []; this.$modes = {}; - for (var i in mapping) { + for (let i in mapping) { if (mapping[i]) { var Mode = mapping[i]; var id = Mode.prototype.$id; @@ -267,7 +280,7 @@ var Mode = function() { var delegations = ["toggleBlockComment", "toggleCommentLines", "getNextLineIndent", "checkOutdent", "autoOutdent", "transformAction", "getCompletions"]; - for (var i = 0; i < delegations.length; i++) { + for (let i = 0; i < delegations.length; i++) { (function(scope) { var functionName = delegations[i]; var defaultHandler = scope[functionName]; @@ -278,6 +291,9 @@ var Mode = function() { } }; + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.$delegator = function(method, args, defaultHandler) { var state = args[0] || "start"; if (typeof state != "string") { @@ -304,6 +320,9 @@ var Mode = function() { return defaultHandler ? ret : undefined; }; + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.transformAction = function(state, action, editor, session, param) { if (this.$behaviour) { var behaviours = this.$behaviour.getBehaviours(); @@ -317,7 +336,10 @@ var Mode = function() { } } }; - + + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.getKeywords = function(append) { // this is for autocompletion to pick up regexp'ed keywords if (!this.completionKeywords) { @@ -348,13 +370,19 @@ var Mode = function() { return this.$keywordList; return completionKeywords.concat(this.$keywordList || []); }; - + + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.$createKeywordList = function() { if (!this.$highlightRules) this.getTokenizer(); return this.$keywordList = this.$highlightRules.$keywordList || []; }; + /** + * @this {import("../../ace").Ace.SyntaxMode} + */ this.getCompletions = function(state, session, pos, prefix) { var keywords = this.$keywordList || this.$createKeywordList(); return keywords.map(function(word) { diff --git a/src/mouse/default_gutter_handler.js b/src/mouse/default_gutter_handler.js index 91c78ad37bb..ce2498741fc 100644 --- a/src/mouse/default_gutter_handler.js +++ b/src/mouse/default_gutter_handler.js @@ -167,7 +167,7 @@ class GutterTooltip extends Tooltip { var annotationsInFold = {error: [], warning: [], info: []}; var mostSevereAnnotationInFoldType; - for (var i = row + 1; i <= fold.end.row; i++){ + for (let i = row + 1; i <= fold.end.row; i++){ if (!gutter.$annotations[i]) continue; @@ -202,7 +202,7 @@ class GutterTooltip extends Tooltip { var iconClassName = gutter.$useSvgGutterIcons ? "ace_icon_svg" : "ace_icon"; // Construct the contents of the tooltip. - for (var i = 0; i < annotation.text.length; i++) { + for (let i = 0; i < annotation.text.length; i++) { var line = ` ${annotation.text[i]}`; annotationMessages[annotation.type[i].replace("_fold","")].push(line); } diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index de020471ee5..18acc2c82d1 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -1,11 +1,16 @@ "use strict"; - +/** + * @typedef {import("./mouse_handler").IMouseHandler} IMouseHandler + */ var useragent = require("../lib/useragent"); var DRAG_OFFSET = 0; // pixels var SCROLL_COOLDOWN_T = 550; // milliseconds class DefaultHandlers { + /** + * @param {IMouseHandler} mouseHandler + */ constructor(mouseHandler) { mouseHandler.$clickSelection = null; @@ -27,6 +32,10 @@ class DefaultHandlers { mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange"); } + /** + * @param ev + * @this {IMouseHandler} + */ onMouseDown(ev) { var inSelection = ev.inSelection(); var pos = ev.getDocumentPosition(); @@ -67,6 +76,12 @@ class DefaultHandlers { return ev.preventDefault(); } + /** + * + * @param {import("../../ace").Ace.Position} [pos] + * @param {boolean} [waitForClickSelection] + * @this {IMouseHandler} + */ startSelect(pos, waitForClickSelection) { pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y); var editor = this.editor; @@ -82,6 +97,9 @@ class DefaultHandlers { this.setState("select"); } + /** + * @this {IMouseHandler} + */ select() { var anchor, editor = this.editor; var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y); @@ -103,6 +121,10 @@ class DefaultHandlers { editor.renderer.scrollCursorIntoView(); } + /** + * @param {string | number} unitName + * @this {IMouseHandler} + */ extendSelectionBy(unitName) { var anchor, editor = this.editor; var cursor = editor.renderer.screenToTextCoordinates(this.x, this.y); @@ -132,12 +154,18 @@ class DefaultHandlers { editor.selection.selectToPosition(cursor); editor.renderer.scrollCursorIntoView(); } - + + /** + * @this {IMouseHandler} + */ selectByLinesEnd() { this.$clickSelection = null; this.editor.unsetStyle("ace_selecting"); } + /** + * @this {IMouseHandler} + */ focusWait() { var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y); var time = Date.now(); @@ -145,7 +173,11 @@ class DefaultHandlers { if (distance > DRAG_OFFSET || time - this.mousedownEvent.time > this.$focusTimeout) this.startSelect(this.mousedownEvent.getDocumentPosition()); } - + + /** + * @param {import("./mouse_event").MouseEvent} ev + * @this {IMouseHandler} + */ onDoubleClick(ev) { var pos = ev.getDocumentPosition(); var editor = this.editor; @@ -166,6 +198,10 @@ class DefaultHandlers { this.select(); } + /** + * @param {import("./mouse_event").MouseEvent} ev + * @this {IMouseHandler} + */ onTripleClick(ev) { var pos = ev.getDocumentPosition(); var editor = this.editor; @@ -181,6 +217,10 @@ class DefaultHandlers { this.select(); } + /** + * @param {import("./mouse_event").MouseEvent} ev + * @this {IMouseHandler} + */ onQuadClick(ev) { var editor = this.editor; @@ -189,6 +229,10 @@ class DefaultHandlers { this.setState("selectAll"); } + /** + * @param {import("./mouse_event").MouseEvent} ev + * @this {IMouseHandler} + */ onMouseWheel(ev) { if (ev.getAccelKey()) return; diff --git a/src/mouse/dragdrop_handler.js b/src/mouse/dragdrop_handler.js index 0f7cb2c0a0f..b49536866f5 100644 --- a/src/mouse/dragdrop_handler.js +++ b/src/mouse/dragdrop_handler.js @@ -1,5 +1,7 @@ "use strict"; - +/** + * @typedef {import("./mouse_handler").IMouseHandler} IMouseHandler + */ var dom = require("../lib/dom"); var event = require("../lib/event"); var useragent = require("../lib/useragent"); @@ -8,6 +10,12 @@ var AUTOSCROLL_DELAY = 200; var SCROLL_CURSOR_DELAY = 200; var SCROLL_CURSOR_HYSTERESIS = 5; +/** + * + * @param {IMouseHandler} mouseHandler + * @constructor + * @this {IMouseHandler} + */ function DragdropHandler(mouseHandler) { var editor = mouseHandler.editor; @@ -291,14 +299,23 @@ function DragdropHandler(mouseHandler) { } } +/** + * @this {IMouseHandler} + */ (function() { + /** + * @this {IMouseHandler & this} + */ this.dragWait = function() { var interval = Date.now() - this.mousedownEvent.time; if (interval > this.editor.getDragDelay()) this.startDrag(); }; + /** + * @this {IMouseHandler & this} + */ this.dragWaitEnd = function() { var target = this.editor.container; target.draggable = false; @@ -306,6 +323,9 @@ function DragdropHandler(mouseHandler) { this.selectEnd(); }; + /** + * @this {IMouseHandler & this} + */ this.dragReadyEnd = function(e) { this.editor.$resetCursorStyle(); this.editor.unsetStyle("ace_dragging"); @@ -313,6 +333,9 @@ function DragdropHandler(mouseHandler) { this.dragWaitEnd(); }; + /** + * @this {IMouseHandler & this} + */ this.startDrag = function(){ this.cancelDrag = false; var editor = this.editor; @@ -325,6 +348,9 @@ function DragdropHandler(mouseHandler) { this.setState("dragReady"); }; + /** + * @this {IMouseHandler & this} + */ this.onMouseDrag = function(e) { var target = this.editor.container; if (useragent.isIE && this.state == "dragReady") { @@ -342,6 +368,9 @@ function DragdropHandler(mouseHandler) { } }; + /** + * @this {IMouseHandler & this} + */ this.onMouseDown = function(e) { if (!this.$dragEnabled) return; diff --git a/src/mouse/mouse_event.js b/src/mouse/mouse_event.js index eca34f95ce3..45daa75284e 100644 --- a/src/mouse/mouse_event.js +++ b/src/mouse/mouse_event.js @@ -7,6 +7,9 @@ var useragent = require("../lib/useragent"); * Custom Ace mouse event */ class MouseEvent { + /** @type {number} */speed; + /** @type {number} */wheelX; + /** @type {number} */wheelY; constructor(domEvent, editor) { this.domEvent = domEvent; this.editor = editor; diff --git a/src/mouse/mouse_handler.js b/src/mouse/mouse_handler.js index 35cca30d300..926624fa767 100644 --- a/src/mouse/mouse_handler.js +++ b/src/mouse/mouse_handler.js @@ -1,4 +1,8 @@ "use strict"; +/** + * @typedef {MouseHandler & import("./default_handlers").DefaultHandlers & import("./default_gutter_handler").GutterHandler & import("./dragdrop_handler").DragdropHandler} IMouseHandler + * @export + */ var event = require("../lib/event"); var useragent = require("../lib/useragent"); @@ -10,6 +14,15 @@ var addTouchListeners = require("./touch_handler").addTouchListeners; var config = require("../config"); class MouseHandler { + /** @type {boolean} */$dragDelay; + /** @type {boolean} */$dragEnabled; + /** @type {boolean} */$mouseMoved; + /** @type {MouseEvent} */mouseEvent; + /** @type {number} */$focusTimeout; + /** + * @param {import("../editor").IEditor} editor + * @this {IMouseHandler} + */ constructor(editor) { var _self = this; this.editor = editor; diff --git a/src/multi_select.js b/src/multi_select.js index 5a3c3c848b0..5146f83ed7e 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -1,5 +1,21 @@ +/** + * @typedef {import("./selection").ISelection} ISelection + */ +/** + * @typedef {import("./editor").IEditor} IEditor + */ +/** + * @typedef {import("./edit_session").IEditSession} IEditSession + */ +/** + * @typedef {import("./anchor").Anchor} Anchor + */ + var RangeList = require("./range_list").RangeList; var Range = require("./range").Range; +/** + * @type {any} + */ var Selection = require("./selection").Selection; var onMouseDown = require("./mouse/multi_select_handler").onMouseDown; var event = require("./lib/event"); @@ -21,17 +37,79 @@ function find(session, needle, dir) { // extend EditSession var EditSession = require("./edit_session").EditSession; (function() { + /** + * @this {IEditSession} + */ this.getSelectionMarkers = function() { return this.$selectionMarkers; }; }).call(EditSession.prototype); + + +/** + * + * @type {RangeList|null} + */ +Selection.prototype.rangeList = null; +/** + * + * @param {Range} range + * @param {boolean} [$blockChangeEvents] + * @this {ISelection} + */ +Selection.prototype.addRange = function(range, $blockChangeEvents) { + if (!range) + return; + + if (!this.inMultiSelectMode && this.rangeCount === 0) { + var oldRange = this.toOrientedRange(); + this.rangeList.add(oldRange); + this.rangeList.add(range); + if (this.rangeList.ranges.length != 2) { + this.rangeList.removeAll(); + return $blockChangeEvents || this.fromOrientedRange(range); + } + this.rangeList.removeAll(); + this.rangeList.add(oldRange); + this.$onAddRange(oldRange); + } + + if (!range.cursor) + range.cursor = range.end; + + var removed = this.rangeList.add(range); + + this.$onAddRange(range); + + if (removed.length) + this.$onRemoveRange(removed); + + if (this.rangeCount > 1 && !this.inMultiSelectMode) { + this._signal("multiSelect"); + this.inMultiSelectMode = true; + this.session.$undoSelect = false; + this.rangeList.attach(this.session); + } + + return $blockChangeEvents || this.fromOrientedRange(range); +}; + // extend Selection +/** + */ (function() { // list of ranges in reverse addition order + /** + * @this {ISelection} + * @type {Range[]|null} + */ this.ranges = null; // automatically sorted list of ranges + /** + * @type {RangeList | null} + */ this.rangeList = null; /** @@ -39,6 +117,7 @@ var EditSession = require("./edit_session").EditSession; * @param {Range} range The new range to add * @param {Boolean} $blockChangeEvents Whether or not to block changing events * @method Selection.addRange + * @this {ISelection} **/ this.addRange = function(range, $blockChangeEvents) { if (!range) @@ -78,7 +157,8 @@ var EditSession = require("./edit_session").EditSession; }; /** - * @method Selection.toSingleRange + * @param {Range} [range] + * @this {ISelection} **/ this.toSingleRange = function(range) { range = range || this.ranges[0]; @@ -91,8 +171,8 @@ var EditSession = require("./edit_session").EditSession; /** * Removes a Range containing pos (if it exists). - * @param {Range} pos The position to remove, as a `{row, column}` object - * @method Selection.substractPoint + * @param {import("../ace").Ace.Point} pos The position to remove, as a `{row, column}` object + * @this {ISelection} **/ this.substractPoint = function(pos) { var removed = this.rangeList.substractPoint(pos); @@ -104,7 +184,7 @@ var EditSession = require("./edit_session").EditSession; /** * Merges overlapping ranges ensuring consistency after changes - * @method Selection.mergeOverlappingRanges + * @this {ISelection} **/ this.mergeOverlappingRanges = function() { var removed = this.rangeList.merge(); @@ -112,12 +192,21 @@ var EditSession = require("./edit_session").EditSession; this.$onRemoveRange(removed); }; + /** + * @param {Range} range + * @this {ISelection} + */ this.$onAddRange = function(range) { this.rangeCount = this.rangeList.ranges.length; this.ranges.unshift(range); this._signal("addRange", {range: range}); }; + /** + * + * @param {Range[]} removed + * @this {ISelection} + */ this.$onRemoveRange = function(removed) { this.rangeCount = this.rangeList.ranges.length; if (this.rangeCount == 1 && this.inMultiSelectMode) { @@ -145,7 +234,10 @@ var EditSession = require("./edit_session").EditSession; this.fromOrientedRange(lastRange); }; - // adds multicursor support to selection + /** + * adds multicursor support to selection + * @this {ISelection} + */ this.$initRangeList = function() { if (this.rangeList) return; @@ -158,7 +250,7 @@ var EditSession = require("./edit_session").EditSession; /** * Returns a concatenation of all the ranges. * @returns {Range[]} - * @method Selection.getAllRanges + * @this {ISelection} **/ this.getAllRanges = function() { return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()]; @@ -166,7 +258,7 @@ var EditSession = require("./edit_session").EditSession; /** * Splits all the ranges into lines. - * @method Selection.splitIntoLines + * @this {ISelection} **/ this.splitIntoLines = function () { var ranges = this.ranges.length ? this.ranges : [this.getRange()]; @@ -190,7 +282,10 @@ var EditSession = require("./edit_session").EditSession; for (var i = newRanges.length; i--;) this.addRange(newRanges[i]); }; - + + /** + * @this {ISelection} + */ this.joinSelections = function () { var ranges = this.rangeList.ranges; var lastRange = ranges[ranges.length - 1]; @@ -201,7 +296,7 @@ var EditSession = require("./edit_session").EditSession; }; /** - * @method Selection.toggleBlockSelection + * @this {ISelection} **/ this.toggleBlockSelection = function () { if (this.rangeCount > 1) { @@ -224,11 +319,11 @@ var EditSession = require("./edit_session").EditSession; * * Gets list of ranges composing rectangular block on the screen * - * @param {Position} screenCursor The cursor to use - * @param {Position} screenAnchor The anchor to use + * @param {import("../ace").Ace.ScreenCoordinates} screenCursor The cursor to use + * @param {import("../ace").Ace.ScreenCoordinates} screenAnchor The anchor to use * @param {Boolean} includeEmptyLines If true, this includes ranges inside the block which are empty due to clipping - * @returns {Range} - * @method Selection.rectangularRangeBlock + * @returns {Range[]} + * @this {ISelection} **/ this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) { var rectSel = []; @@ -308,7 +403,7 @@ var Editor = require("./editor").Editor; * * Updates the cursor and marker layers. * @method Editor.updateSelectionMarkers - * + * @this {IEditor} **/ this.updateSelectionMarkers = function() { this.renderer.updateCursor(); @@ -317,9 +412,9 @@ var Editor = require("./editor").Editor; /** * Adds the selection and cursor. - * @param {Range} orientedRange A range containing a cursor - * @returns {Range} - * @method Editor.addSelectionMarker + * @param {Range & {marker?}} orientedRange A range containing a cursor + * @returns {Range & {marker?}} + * @this {IEditor} **/ this.addSelectionMarker = function(orientedRange) { if (!orientedRange.cursor) @@ -335,8 +430,8 @@ var Editor = require("./editor").Editor; /** * Removes the selection marker. - * @param {Range} range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. - * @method Editor.removeSelectionMarker + * @param {Range & {marker?}} range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. + * @this {IEditor} **/ this.removeSelectionMarker = function(range) { if (!range.marker) @@ -348,6 +443,11 @@ var Editor = require("./editor").Editor; this.session.selectionMarkerCount = this.session.$selectionMarkers.length; }; + /** + * + * @param {(Range & {marker?})[]} ranges + * @this {IEditor} + */ this.removeSelectionMarkers = function(ranges) { var markerList = this.session.$selectionMarkers; for (var i = ranges.length; i--; ) { @@ -362,18 +462,30 @@ var Editor = require("./editor").Editor; this.session.selectionMarkerCount = markerList.length; }; + /** + * @param e + * @this {IEditor} + */ this.$onAddRange = function(e) { this.addSelectionMarker(e.range); this.renderer.updateCursor(); this.renderer.updateBackMarkers(); }; + /** + * @param e + * @this {IEditor} + */ this.$onRemoveRange = function(e) { this.removeSelectionMarkers(e.ranges); this.renderer.updateCursor(); this.renderer.updateBackMarkers(); }; + /** + * @param e + * @this {IEditor} + */ this.$onMultiSelect = function(e) { if (this.inMultiSelectMode) return; @@ -387,6 +499,10 @@ var Editor = require("./editor").Editor; this.renderer.updateBackMarkers(); }; + /** + * @param e + * @this {IEditor} + */ this.$onSingleSelect = function(e) { if (this.session.multiSelect.inVirtualMode) return; @@ -401,6 +517,10 @@ var Editor = require("./editor").Editor; this._emit("changeSelection"); }; + /** + * @param e + * @this {IEditor} + */ this.$onMultiSelectExec = function(e) { var command = e.command; var editor = e.editor; @@ -427,7 +547,7 @@ var Editor = require("./editor").Editor; * Executes a command for each selection range. * @param {Object} cmd The command to execute * @param {String} args Any arguments for the command - * @method Editor.forEachSelection + * @this {IEditor} **/ this.forEachSelection = function(cmd, args, options) { if (this.inVirtualSelectionMode) @@ -445,7 +565,9 @@ var Editor = require("./editor").Editor; var reg = selection._eventRegistry; selection._eventRegistry = {}; - + /** + * @type {ISelection} + */ var tmpSel = new Selection(session); this.inVirtualSelectionMode = true; for (var i = ranges.length; i--;) { @@ -481,7 +603,7 @@ var Editor = require("./editor").Editor; /** * Removes all the selections except the last added one. - * @method Editor.exitMultiSelectMode + * @this {IEditor} **/ this.exitMultiSelectMode = function() { if (!this.inMultiSelectMode || this.inVirtualSelectionMode) @@ -489,6 +611,10 @@ var Editor = require("./editor").Editor; this.multiSelect.toSingleRange(); }; + /** + * @this {IEditor} + * @return {string} + */ this.getSelectedText = function() { var text = ""; if (this.inMultiSelectMode && !this.inVirtualSelectionMode) { @@ -506,7 +632,13 @@ var Editor = require("./editor").Editor; } return text; }; - + + /** + * + * @param e + * @param {Anchor} anchor + * @this {IEditor} + */ this.$checkMultiselectChange = function(e, anchor) { if (this.inMultiSelectMode && !this.inVirtualSelectionMode) { var range = this.multiSelect.ranges[0]; @@ -525,12 +657,12 @@ var Editor = require("./editor").Editor; /** * Finds and selects all the occurrences of `needle`. - * @param {String} The text to find - * @param {Object} The search options - * @param {Boolean} keeps + * @param {String} needle The text to find + * @param {Partial} options The search options + * @param {Boolean} additive keeps * * @returns {Number} The cumulative count of all found matches - * @method Editor.findAll + * @this {IEditor} **/ this.findAll = function(needle, options, additive) { options = options || {}; @@ -566,9 +698,9 @@ var Editor = require("./editor").Editor; * Adds a cursor above or below the active cursor. * * @param {Number} dir The direction of lines to select: -1 for up, 1 for down - * @param {Boolean} skip If `true`, removes the active selection range + * @param {Boolean} [skip] If `true`, removes the active selection range * - * @method Editor.selectMoreLines + * @this {IEditor} */ this.selectMoreLines = function(dir, skip) { var range = this.selection.toOrientedRange(); @@ -588,9 +720,15 @@ var Editor = require("./editor").Editor; } if (isBackwards) { + /** + * @type {Range & {desiredColumn?: number}} + */ var newRange = Range.fromPoints(lead, anchor); newRange.cursor = newRange.start; } else { + /** + * @type {Range & {desiredColumn?: number}} + */ var newRange = Range.fromPoints(anchor, lead); newRange.cursor = newRange.end; } @@ -611,7 +749,7 @@ var Editor = require("./editor").Editor; /** * Transposes the selected ranges. * @param {Number} dir The direction to rotate selections - * @method Editor.transposeSelections + * @this {IEditor} **/ this.transposeSelections = function(dir) { var session = this.session; @@ -655,7 +793,8 @@ var Editor = require("./editor").Editor; * Finds the next occurrence of text in an active selection and adds it to the selections. * @param {Number} dir The direction of lines to select: -1 for up, 1 for down * @param {Boolean} skip If `true`, removes the active selection range - * @method Editor.selectMore + * @param {Boolean} [stopAtFirst] + * @this {IEditor} **/ this.selectMore = function(dir, skip, stopAtFirst) { var session = this.session; @@ -684,7 +823,7 @@ var Editor = require("./editor").Editor; /** * Aligns the cursors or selected text. - * @method Editor.alignCursors + * @this {IEditor} **/ this.alignCursors = function() { var session = this.session; @@ -762,6 +901,13 @@ var Editor = require("./editor").Editor; } }; + /** + * + * @param {string[]} lines + * @param {boolean} [forceLeft] + * @return {*} + * @this {IEditor} + */ this.$reAlignText = function(lines, forceLeft) { var isLeftAligned = true, isRightAligned = true; var startW, textW, endW; @@ -817,12 +963,21 @@ var Editor = require("./editor").Editor; }).call(Editor.prototype); +/** + * @param {import("../ace").Ace.Point} p1 + * @param {import("../ace").Ace.Point} p2 + */ function isSamePoint(p1, p2) { return p1.row == p2.row && p1.column == p2.column; } -// patch -// adds multicursor support to a session + +/** + * patch + * adds multicursor support to a session + * @this {IEditor} + * @type {(e) => void} + */ exports.onSessionChange = function(e) { var session = e.session; if (session && !session.multiSelect) { @@ -862,6 +1017,9 @@ exports.onSessionChange = function(e) { // MultiSelect(editor) // adds multiple selection support to the editor // (note: should be called only once for each editor instance) +/** + * @param {IEditor} editor + */ function MultiSelect(editor) { if (editor.$multiselectOnSessionChange) return; @@ -881,6 +1039,9 @@ function MultiSelect(editor) { addAltCursorListeners(editor); } +/** + * @param {IEditor} editor + */ function addAltCursorListeners(editor){ if (!editor.textInput) return; var el = editor.textInput.getElement(); @@ -914,6 +1075,10 @@ exports.MultiSelect = MultiSelect; require("./config").defineOptions(Editor.prototype, "editor", { enableMultiselect: { + /** + * @param {boolean} val + * @this {IEditor} + */ set: function(val) { MultiSelect(this); if (val) { diff --git a/src/occur.js b/src/occur.js index 34c03f34fde..270a0fd8375 100644 --- a/src/occur.js +++ b/src/occur.js @@ -1,17 +1,23 @@ "use strict"; +/** + * @typedef {import("./editor").IEditor} IEditor + */ +/** + * @typedef {import("./edit_session").IEditSession} IEditSession + */ var oop = require("./lib/oop"); var Search = require("./search").Search; +/** + * @type {any} + */ var EditSession = require("./edit_session").EditSession; var SearchHighlight = require("./search_highlight").SearchHighlight; /** - * @class Occur - * * Finds all lines matching a search term in the current [[Document * `Document`]] and displays them instead of the original `Document`. Keeps * track of the mapping between the occur doc and the original doc. - * **/ class Occur extends Search { @@ -21,7 +27,7 @@ class Occur extends Search { * and these are then used as the content of a new [[Document * `Document`]]. The current cursor position of editor will be translated * so that the cursor is on the matching row/column as it was before. - * @param {Editor} editor + * @param {IEditor} editor * @param {Object} options options.needle should be a String * @return {Boolean} Whether occur activation was successful * @@ -39,7 +45,7 @@ class Occur extends Search { * Disables occur mode. Resets the [[Sessions `EditSession`]] [[Document * `Document`]] back to the original doc. If options.translatePosition is * truthy also maps the [[Editors `Editor`]] cursor position accordingly. - * @param {Editor} editor + * @param {IEditor} editor * @param {Object} options options.translatePosition * @return {Boolean} Whether occur deactivation was successful * @@ -53,6 +59,10 @@ class Occur extends Search { return true; } + /** + * @param {IEditSession} sess + * @param {RegExp} regexp + */ highlight(sess, regexp) { var hl = sess.$occurHighlight = sess.$occurHighlight || sess.addDynamicMarker( new SearchHighlight(null, "ace_occur-highlight", "text")); @@ -60,11 +70,18 @@ class Occur extends Search { sess._emit("changeBackMarker"); // force highlight layer redraw } + /** + * @param {IEditor} editor + * @param {Partial} options + */ displayOccurContent(editor, options) { // this.setSession(session || new EditSession("")) this.$originalSession = editor.session; var found = this.matchingLines(editor.session, options); var lines = found.map(function(foundLine) { return foundLine.content; }); + /** + * @type {IEditSession} + */ var occurSession = new EditSession(lines.join('\n')); occurSession.$occur = this; occurSession.$occurMatchingLines = found; @@ -75,6 +92,9 @@ class Occur extends Search { occurSession._emit('changeBackMarker'); } + /** + * @param {IEditor} editor + */ displayOriginalContent(editor) { editor.setSession(this.$originalSession); this.$originalSession.$useEmacsStyleLineStart = this.$useEmacsStyleLineStart; @@ -84,9 +104,9 @@ class Occur extends Search { * Translates the position from the original document to the occur lines in * the document or the beginning if the doc {row: 0, column: 0} if not * found. - * @param {EditSession} session The occur session - * @param {Object} pos The position in the original document - * @return {Object} position in occur doc + * @param {IEditSession} session The occur session + * @param {import("../ace").Ace.Point} pos The position in the original document + * @return {import("../ace").Ace.Point} position in occur doc **/ originalToOccurPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -102,9 +122,9 @@ class Occur extends Search { /** * Translates the position from the occur document to the original document * or `pos` if not found. - * @param {EditSession} session The occur session - * @param {Object} pos The position in the occur session document - * @return {Object} position + * @param {IEditSession} session The occur session + * @param {import("../ace").Ace.Point} pos The position in the occur session document + * @return {import("../ace").Ace.Point} position **/ occurToOriginalPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -113,6 +133,10 @@ class Occur extends Search { return {row: lines[pos.row].row, column: pos.column}; } + /** + * @param {IEditSession} session + * @param {Partial} options + */ matchingLines(session, options) { options = oop.mixin({}, options); if (!session || !options.needle) return []; diff --git a/src/placeholder.js b/src/placeholder.js index 1e3010409de..32d0421b5aa 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -1,11 +1,9 @@ "use strict"; /** - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").IEditSession} IEditSession */ /** - * @typedef IPlaceHolder - * @type {PlaceHolder & Ace.EventEmitter} + * @typedef {PlaceHolder & import("../ace").Ace.EventEmitter} IPlaceHolder */ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -15,10 +13,11 @@ class PlaceHolder { /** * @param {IEditSession} session * @param {Number} length - * @param {Ace.Point} pos + * @param {import("../ace").Ace.Point} pos * @param {any[]} others * @param {String} mainClass * @param {String} othersClass + * @this {IPlaceHolder} **/ constructor(session, length, pos, others, mainClass, othersClass) { var _self = this; @@ -110,7 +109,7 @@ class PlaceHolder { * PlaceHolder@onUpdate(e) * * Emitted when the place holder updates. - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta */ onUpdate(delta) { if (this.$updating) @@ -150,7 +149,7 @@ class PlaceHolder { } /** - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta */ updateAnchors(delta) { this.pos.onChange(delta); diff --git a/src/range.js b/src/range.js index ae16ceb9e1c..e11f0fd19ce 100644 --- a/src/range.js +++ b/src/range.js @@ -1,22 +1,18 @@ "use strict"; /** - * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. - * @class Range - * @export - **/ -/** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").IEditSession} IEditSession */ +/** + * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. + **/ class Range { /** * @type {Number | undefined} */ id; /** - * @type {Ace.Point | undefined} + * @type {import("../ace").Ace.Point | undefined} */ cursor; /** @@ -29,14 +25,14 @@ class Range { **/ constructor(startRow, startColumn, endRow, endColumn) { /** - * @type {Ace.Point} + * @type {import("../ace").Ace.Point} */ this.start = { row: startRow, column: startColumn }; /** - * @type {Ace.Point} + * @type {import("../ace").Ace.Point} */ this.end = { row: endRow, @@ -46,7 +42,7 @@ class Range { /** * Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`. - * @param {Ace.IRange} range A range to check against + * @param {import("../ace").Ace.IRange} range A range to check against * @return {Boolean} **/ isEqual(range) { @@ -86,7 +82,7 @@ class Range { /** * Compares `this` range (A) with another range (B). - * @param {Ace.IRange} range A range to compare with + * @param {import("../ace").Ace.IRange} range A range to compare with * @related [[Range.compare]] * @returns {Number} This method returns one of the following numbers: * * `-2`: (B) is in front of (A), and doesn't intersect with (A) @@ -127,7 +123,7 @@ class Range { /** * Compares the row and column of `p` with the starting and ending [[Point]]'s of the calling range (by calling [[Range.compare]]). - * @param {Ace.Point} p A point to compare with + * @param {import("../ace").Ace.Point} p A point to compare with * @related [[Range.compare]] * @returns {Number} **/ @@ -137,7 +133,7 @@ class Range { /** * Checks the start and end [[Point]]'s of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range. - * @param {Ace.IRange} range A range to compare with + * @param {import("../ace").Ace.IRange} range A range to compare with * @returns {Boolean} * @related [[Range.comparePoint]] **/ @@ -147,7 +143,7 @@ class Range { /** * Returns `true` if passed in `range` intersects with the one calling this method. - * @param {Ace.IRange} range A range to compare with + * @param {import("../ace").Ace.IRange} range A range to compare with * @returns {Boolean} **/ intersects(range) { @@ -177,7 +173,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|Ace.Point} row A row to set + * @param {Number|import("../ace").Ace.Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -193,7 +189,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|Ace.Point} row A row to set + * @param {Number|import("../ace").Ace.Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -458,8 +454,8 @@ class Range { /** * Creates and returns a new `Range` based on the `start` [[Point]] and `end` [[Point]] of the given parameters. - * @param {Ace.Point} start A starting point to use - * @param {Ace.Point} end An ending point to use + * @param {import("../ace").Ace.Point} start A starting point to use + * @param {import("../ace").Ace.Point} end An ending point to use * @returns {Range} **/ Range.fromPoints = function(start, end) { @@ -468,8 +464,8 @@ Range.fromPoints = function(start, end) { /** * Compares `p1` and `p2` [[Point]]'s, useful for sorting - * @param {Ace.Point} p1 - * @param {Ace.Point} p2 + * @param {import("../ace").Ace.Point} p1 + * @param {import("../ace").Ace.Point} p2 * @returns {Number} */ Range.comparePoints = function(p1, p2) { diff --git a/src/range_list.js b/src/range_list.js index bc5322caaa5..22b626cfd97 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -9,6 +9,12 @@ class RangeList { this.$bias = 1; } + /** + * @param {import("../ace").Ace.Point} pos + * @param {boolean} [excludeEdges] + * @param {number} [startIndex] + * @return {number} + */ pointIndex(pos, excludeEdges, startIndex) { var list = this.ranges; @@ -28,6 +34,9 @@ class RangeList { return -i - 1; } + /** + * @param {Range} range + */ add(range) { var excludeEdges = !range.isEmpty(); var startIndex = this.pointIndex(range.start, excludeEdges); @@ -51,6 +60,9 @@ class RangeList { return removed; } + /** + * @param {import("../ace").Ace.Point} pos + */ substractPoint(pos) { var i = this.pointIndex(pos); @@ -94,14 +106,24 @@ class RangeList { return removed; } + /** + * @param {number} row + * @param {number} column + */ contains(row, column) { return this.pointIndex({row: row, column: column}) >= 0; } + /** + * @param {import("../ace").Ace.Point} pos + */ containsPoint(pos) { return this.pointIndex(pos) >= 0; } + /** + * @param {import("../ace").Ace.Point} pos + */ rangeAtPoint(pos) { var i = this.pointIndex(pos); if (i >= 0) @@ -109,6 +131,10 @@ class RangeList { } + /** + * @param {number} startRow + * @param {number} endRow + */ clipRows(startRow, endRow) { var list = this.ranges; if (list[0].start.row > endRow || list[list.length - 1].start.row < startRow) @@ -117,6 +143,7 @@ class RangeList { var startIndex = this.pointIndex({row: startRow, column: 0}); if (startIndex < 0) startIndex = -startIndex - 1; + //TODO: seems mistake var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex); if (endIndex < 0) endIndex = -endIndex - 1; @@ -132,6 +159,9 @@ class RangeList { return this.ranges.splice(0, this.ranges.length); } + /** + * @param {any} session + */ attach(session) { if (this.session) this.detach(); @@ -149,6 +179,9 @@ class RangeList { this.session = null; } + /** + * @param {import("../ace").Ace.Delta} delta + */ $onChange(delta) { var start = delta.start; var end = delta.end; diff --git a/src/scrollbar.js b/src/scrollbar.js index 1098aaa5b25..c1a89b4ce33 100644 --- a/src/scrollbar.js +++ b/src/scrollbar.js @@ -33,6 +33,7 @@ class Scrollbar { this.setVisible(false); this.skipEvent = false; + // @ts-expect-error event.addListener(this.element, "scroll", this.onScroll.bind(this)); event.addListener(this.element, "mousedown", event.preventDefault); } @@ -77,6 +78,10 @@ class VScrollBar extends Scrollbar { * @event scroll * @param {Object} e Contains one property, `"data"`, which indicates the current scroll top position **/ + + /** + * @this {VScrollBar & import("../ace").Ace.EventEmitter} + */ onScroll() { if (!this.skipEvent) { this.scrollTop = this.element.scrollTop; @@ -172,6 +177,10 @@ class HScrollBar extends Scrollbar { * @event scroll * @param {Object} e Contains one property, `"data"`, which indicates the current scroll left position **/ + + /** + * @this {HScrollBar & import("../ace").Ace.EventEmitter} + */ onScroll() { if (!this.skipEvent) { this.scrollLeft = this.element.scrollLeft; diff --git a/src/scrollbar_custom.js b/src/scrollbar_custom.js index 095d2038ba8..408f71758dc 100644 --- a/src/scrollbar_custom.js +++ b/src/scrollbar_custom.js @@ -105,6 +105,7 @@ class VScrollBar extends ScrollBar { /** * Emitted when the scroll thumb dragged or scrollbar canvas clicked. + * @this {VScrollBar & import("../ace").Ace.EventEmitter} **/ onMouseDown(eType, e) { if (eType !== "mousedown") return; @@ -175,6 +176,7 @@ class VScrollBar extends ScrollBar { /** * Sets the height of the scroll bar, in pixels. * @param {Number} height The new height + * @this {VScrollBar & import("../ace").Ace.EventEmitter} **/ setHeight(height) { this.height = Math.max(0, height); @@ -189,6 +191,7 @@ class VScrollBar extends ScrollBar { * @param {Number} height The new inner height * * @param {boolean} force Forcely update height + * @this {VScrollBar & import("../ace").Ace.EventEmitter} **/ setScrollHeight(height, force) { if (this.pageHeight === height && !force) return; @@ -241,6 +244,7 @@ class HScrollBar extends ScrollBar { /** * Emitted when the scroll thumb dragged or scrollbar canvas clicked. + * @this {HScrollBar & import("../ace").Ace.EventEmitter} **/ onMouseDown(eType, e) { if (eType !== "mousedown") return; @@ -309,6 +313,7 @@ class HScrollBar extends ScrollBar { /** * Sets the width of the scroll bar, in pixels. * @param {Number} width The new width + * @this {HScrollBar & import("../ace").Ace.EventEmitter} **/ setWidth(width) { this.width = Math.max(0, width); @@ -323,6 +328,7 @@ class HScrollBar extends ScrollBar { * Sets the inner and scroll width of the scroll bar, in pixels. * @param {Number} width The new inner width * @param {boolean} force Forcely update width + * @this {HScrollBar & import("../ace").Ace.EventEmitter} **/ setScrollWidth(width, force) { if (this.pageWidth === width && !force) return; diff --git a/src/search.js b/src/search.js index e7c872c3e94..3751ba9a323 100644 --- a/src/search.js +++ b/src/search.js @@ -23,7 +23,7 @@ class Search { * @property {boolean} [wholeWord] - Whether the search matches only on whole words * @property {Range|null} [range] - The [[Range]] to search within. Set this to `null` for the whole document * @property {boolean} [regExp] - Whether the search is a regular expression or not - * @property {Range|Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search + * @property {Range|import("../ace").Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search * @property {boolean} [skipCurrent] - Whether or not to include the current line in the search * @property {boolean} [$isMultiLine] - true, if needle has \n or \r\n * @property {boolean} [preserveCase] @@ -41,7 +41,7 @@ class Search { /** * Sets the search options via the `options` parameter. - * @param {Partial} options An object containing all the new search properties + * @param {Partial} options An object containing all the new search properties * @returns {Search} * @chainable **/ @@ -52,7 +52,7 @@ class Search { /** * [Returns an object containing all the search options.]{: #Search.getOptions} - * @returns {Partial} + * @returns {Partial} **/ getOptions() { return lang.copyObject(this.$options); @@ -249,6 +249,9 @@ class Search { return options.re = this.$assembleMultilineRegExp(needle, modifier); try { + /** + * @type {RegExp|false} + */ var re = new RegExp(needle, modifier); } catch(e) { re = false; diff --git a/src/selection.js b/src/selection.js index ba17733ca96..0727b823d61 100644 --- a/src/selection.js +++ b/src/selection.js @@ -4,9 +4,23 @@ var oop = require("./lib/oop"); var lang = require("./lib/lang"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; - - - +/** + * @typedef ISelection + * @type {Selection & import("../ace").Ace.ISelection & import("../ace").Ace.EventEmitter} + * @export + */ +/** + * @typedef IEditSession + * @type {import("./edit_session").IEditSession} + */ +/** + * @typedef IDocument + * @type {import("./document").IDocument} + */ +/** + * @typedef IAnchor + * @type {import("./anchor").IAnchor} + */ /** * Emitted when the cursor position changes. @@ -18,18 +32,34 @@ var Range = require("./range").Range; * * @event changeSelection **/ +/** + * @type {ISelection} + */ class Selection { /** * Creates a new `Selection` object. - * @param {EditSession} session The session to use - * + * @param {IEditSession} session The session to use + * @this {ISelection} + * @constructor **/ constructor(session) { + /** + * @type {IEditSession} + */ this.session = session; + /** + * @type {IDocument} + */ this.doc = session.getDocument(); this.clearSelection(); + /** + * @type {IAnchor} + */ this.cursor = this.lead = this.doc.createAnchor(0, 0); + /** + * @type {IAnchor} + */ this.anchor = this.doc.createAnchor(0, 0); this.$silent = false; @@ -72,7 +102,7 @@ class Selection { /** * Returns an object containing the `row` and `column` current position of the cursor. - * @returns {Object} + * @returns {import("../ace").Ace.Point} **/ getCursor() { return this.lead.getPosition(); @@ -93,7 +123,7 @@ class Selection { /** * Returns an object containing the `row` and `column` of the calling selection anchor. * - * @returns {Object} + * @returns {import("../ace").Ace.Point} * @related Anchor.getPosition **/ getAnchor() { @@ -140,6 +170,7 @@ class Selection { /** * [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection} + * @this {ISelection} **/ clearSelection() { if (!this.$isEmpty) { @@ -150,6 +181,7 @@ class Selection { /** * Selects all the text in the document. + * @this {ISelection} **/ selectAll() { this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE); @@ -158,8 +190,8 @@ class Selection { /** * Sets the selection to the provided range. * @param {Range} range The range of text to select - * @param {Boolean} reverse Indicates if the range should go backwards (`true`) or not - * + * @param {Boolean} [reverse] Indicates if the range should go backwards (`true`) or not + * @this {ISelection} **/ setRange(range, reverse) { var start = reverse ? range.end : range.start; @@ -167,6 +199,13 @@ class Selection { this.$setSelection(start.row, start.column, end.row, end.column); } + /** + * @param {number} anchorRow + * @param {number} anchorColumn + * @param {number} cursorRow + * @param {number} cursorColumn + * @this {ISelection} + */ $setSelection(anchorRow, anchorColumn, cursorRow, cursorColumn) { if (this.$silent) return; @@ -205,7 +244,7 @@ class Selection { /** * Moves the selection cursor to the row and column indicated by `pos`. - * @param {Object} pos An object containing the row and column + * @param {import("../ace").Ace.Point} pos An object containing the row and column **/ selectToPosition(pos) { this.$moveSelection(function() { @@ -217,7 +256,7 @@ class Selection { * Moves the selection cursor to the indicated row and column. * @param {Number} row The row to select to * @param {Number} column The column to select to - * + * @this {ISelection} **/ moveTo(row, column) { this.clearSelection(); @@ -227,6 +266,7 @@ class Selection { /** * Moves the selection cursor to the row and column indicated by `pos`. * @param {Object} pos An object containing the row and column + * @this {ISelection} **/ moveToPosition(pos) { this.clearSelection(); @@ -360,6 +400,7 @@ class Selection { /** * Moves the cursor up one row. + * @this {ISelection} **/ moveCursorUp() { this.moveCursorBy(-1, 0); @@ -367,6 +408,7 @@ class Selection { /** * Moves the cursor down one row. + * @this {ISelection} **/ moveCursorDown() { this.moveCursorBy(1, 0); @@ -375,7 +417,7 @@ class Selection { /** * * Returns `true` if moving the character next to the cursor in the specified direction is a soft tab. - * @param {Object} cursor the current cursor position + * @param {import("../ace").Ace.Point} cursor the current cursor position * @param {Number} tabSize the tab size * @param {Number} direction 1 for right, -1 for left */ @@ -392,6 +434,7 @@ class Selection { /** * Moves the cursor left one column. + * @this {ISelection} **/ moveCursorLeft() { var cursor = this.lead.getPosition(), @@ -417,6 +460,7 @@ class Selection { /** * Moves the cursor right one column. + * @this {ISelection} **/ moveCursorRight() { var cursor = this.lead.getPosition(), @@ -431,6 +475,9 @@ class Selection { } else { var tabSize = this.session.getTabSize(); + /** + * @type {import("../ace").Ace.Point} + */ var cursor = this.lead; if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) { this.moveCursorBy(0, tabSize); @@ -442,6 +489,7 @@ class Selection { /** * Moves the cursor to the start of the line. + * @this {ISelection} **/ moveCursorLineStart() { var row = this.lead.row; @@ -466,6 +514,7 @@ class Selection { /** * Moves the cursor to the end of the line. + * @this {ISelection} **/ moveCursorLineEnd() { var lead = this.lead; @@ -484,6 +533,7 @@ class Selection { /** * Moves the cursor to the end of the file. + * @this {ISelection} **/ moveCursorFileEnd() { var row = this.doc.getLength() - 1; @@ -493,6 +543,7 @@ class Selection { /** * Moves the cursor to the start of the file. + * @this {ISelection} **/ moveCursorFileStart() { this.moveCursorTo(0, 0); @@ -500,6 +551,7 @@ class Selection { /** * Moves the cursor to the word on the right. + * @this {ISelection} **/ moveCursorLongWordRight() { var row = this.lead.row; @@ -545,6 +597,7 @@ class Selection { /** * * Moves the cursor to the word on the left. + * @this {ISelection} **/ moveCursorLongWordLeft() { var row = this.lead.row; @@ -627,6 +680,9 @@ class Selection { return index; } + /** + * @this {ISelection} + */ moveCursorShortWordRight() { var row = this.lead.row; var column = this.lead.column; @@ -654,6 +710,9 @@ class Selection { this.moveCursorTo(row, column + index); } + /** + * @this {ISelection} + */ moveCursorShortWordLeft() { var row = this.lead.row; var column = this.lead.column; @@ -680,6 +739,9 @@ class Selection { return this.moveCursorTo(row, column - index); } + /** + * @this {ISelection} + */ moveCursorWordRight() { if (this.session.$selectLongWords) this.moveCursorLongWordRight(); @@ -687,6 +749,9 @@ class Selection { this.moveCursorShortWordRight(); } + /** + * @this {ISelection} + */ moveCursorWordLeft() { if (this.session.$selectLongWords) this.moveCursorLongWordLeft(); @@ -700,6 +765,7 @@ class Selection { * @param {Number} chars The number of characters to move by * * @related EditSession.documentToScreenPosition + * @this {ISelection} **/ moveCursorBy(rows, chars) { var screenPos = this.session.documentToScreenPosition( @@ -745,7 +811,8 @@ class Selection { /** * Moves the selection to the position indicated by its `row` and `column`. - * @param {Object} position The position to move to + * @param {import("../ace").Ace.Point} position The position to move to + * @this {ISelection} **/ moveCursorToPosition(position) { this.moveCursorTo(position.row, position.column); @@ -755,8 +822,8 @@ class Selection { * Moves the cursor to the row and column provided. [If `preventUpdateDesiredColumn` is `true`, then the cursor stays in the same column position as its original point.]{: #preventUpdateBoolDesc} * @param {Number} row The row to move to * @param {Number} column The column to move to - * @param {Boolean} keepDesiredColumn [If `true`, the cursor move does not respect the previous column]{: #preventUpdateBool} - * + * @param {Boolean} [keepDesiredColumn] [If `true`, the cursor move does not respect the previous column]{: #preventUpdateBool} + * @this {ISelection} **/ moveCursorTo(row, column, keepDesiredColumn) { // Ensure the row/column is not inside of a fold. @@ -787,7 +854,7 @@ class Selection { * @param {Number} row The row to move to * @param {Number} column The column to move to * @param {Boolean} keepDesiredColumn {:preventUpdateBool} - * + * @this {ISelection} **/ moveCursorToScreen(row, column, keepDesiredColumn) { var pos = this.session.screenToDocumentPosition(row, column); @@ -800,11 +867,17 @@ class Selection { this.anchor.detach(); } + /** + * @param {Range & {desiredColumn?: number}} range + */ fromOrientedRange(range) { this.setSelectionRange(range, range.cursor == range.start); this.$desiredColumn = range.desiredColumn || this.$desiredColumn; } + /** + * @param {Range & {desiredColumn?: number}} [range] + */ toOrientedRange(range) { var r = this.getRange(); if (range) { @@ -825,9 +898,9 @@ class Selection { * Saves the current cursor position and calls `func` that can change the cursor * postion. The result is the range of the starting and eventual cursor position. * Will reset the cursor position. - * @param {Function} The callback that should change the cursor position + * @param {Function} func The callback that should change the cursor position * @returns {Range} - * + * @this {ISelection} **/ getRangeOfMovements(func) { var start = this.getCursor(); @@ -842,6 +915,11 @@ class Selection { } } + /** + * + * @returns {Range|Range[]} + * @this {ISelection} + */ toJSON() { if (this.rangeCount) { var data = this.ranges.map(function(r) { @@ -850,12 +928,18 @@ class Selection { return r1; }); } else { + // @ts-ignore var data = this.getRange(); data.isBackwards = this.isBackwards(); } return data; } + /** + * + * @param data + * @this {ISelection} + */ fromJSON(data) { if (data.start == undefined) { if (this.rangeList && data.length > 1) { @@ -876,6 +960,12 @@ class Selection { this.setSelectionRange(data, data.isBackwards); } + /** + * + * @param data + * @return {Boolean|boolean|*|boolean} + * @this {ISelection} + */ isEqual(data) { if ((data.length || this.rangeCount) && data.length != this.rangeCount) return false; diff --git a/src/snippets.js b/src/snippets.js index def6de3e367..c1a06a8c2e4 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -1,4 +1,25 @@ "use strict"; +/** + * @typedef {SnippetManager & import("../ace").Ace.EventEmitter} ISnippetManager + */ +/** + * @typedef Snippet + * @property {string} [content] + * @property {string} [replaceBefore] + * @property {string} [replaceAfter] + * @property {RegExp} [startRe] + * @property {RegExp} [endRe] + * @property {RegExp} [triggerRe] + * @property {RegExp} [endTriggerRe] + * @property {string} [trigger] + * @property {string} [endTrigger] + * @property {string[]} [matchBefore] + * @property {string[]} [matchAfter] + * @property {string} [name] + * @property {string} [tabTrigger] + * @property {string} [guard] + * @property {string} [endGuard] + */ var dom = require("./lib/dom"); var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -94,7 +115,10 @@ class SnippetManager { this.variables = VARIABLES; } - + + /** + * @return {Tokenizer} + */ getTokenizer() { return SnippetManager.$tokenizer || this.createTokenizer(); } @@ -430,6 +454,9 @@ class SnippetManager { var after = line.substr(cursor.column); var snippetMap = this.snippetMap; + /** + * @type {Snippet} + */ var snippet; this.getActiveScopes(editor).some(function(scope) { var snippets = snippetMap[scope]; @@ -454,6 +481,12 @@ class SnippetManager { return true; } + /** + * @param {Snippet[]} snippetList + * @param {string} before + * @param {string} after + * @return {Snippet} + */ findMatchingSnippet(snippetList, before, after) { for (var i = snippetList.length; i--;) { var s = snippetList[i]; @@ -472,6 +505,12 @@ class SnippetManager { } } + + /** + * @param {any[]} snippets + * @param {string} scope + * @this {ISnippetManager} + */ register(snippets, scope) { var snippetMap = this.snippetMap; var snippetNameMap = this.snippetNameMap; @@ -572,7 +611,7 @@ class SnippetManager { } parseSnippetFile(str) { str = str.replace(/\r/g, ""); - var list = [], snippet = {}; + var list = [], /**@type{Snippet}*/snippet = {}; var re = /^#.*|^({[\s\S]*})\s*$|^(\S+) (.*)$|^((?:\n*\t.*)+)/gm; var m; while (m = re.exec(str)) { @@ -913,6 +952,9 @@ class TabstopManager { for (var i = 0; i < ts.length; i++) { var p = ts[i]; + /** + * @type {Range & {original?: Range, tabstop?: any, linked?: boolean}}} + */ var range = Range.fromPoints(p.start, p.end || p.start); movePoint(range.start, start); movePoint(range.end, start); @@ -1022,6 +1064,9 @@ dom.importCssString(` position: absolute; }`, "snippets.css", false); +/** + * @type {any} + */ exports.snippetManager = new SnippetManager(); diff --git a/src/split.js b/src/split.js index 0a3aa817ea6..c534c7dad88 100644 --- a/src/split.js +++ b/src/split.js @@ -3,18 +3,31 @@ var oop = require("./lib/oop"); var lang = require("./lib/lang"); var EventEmitter = require("./lib/event_emitter").EventEmitter; - +/** + * @typedef {import("./edit_session").IEditSession} IEditSession + */ +/** + * @typedef {import("./editor").IEditor} IEditor + */ var Editor = require("./editor").Editor; var Renderer = require("./virtual_renderer").VirtualRenderer; +/** + * @type {any} + */ var EditSession = require("./edit_session").EditSession; -/** - * @class Split - * - **/ +/** + * @typedef ISplit + * @type {import("../ace").Ace.EventEmitter & {[key: string]: any}} + */ -var Split = function(container, theme, splits) { +var Split; +/** + * @constructor + * @this {ISplit} + */ +Split = function(container, theme, splits) { this.BELOW = 1; this.BESIDE = 0; @@ -38,11 +51,18 @@ var Split = function(container, theme, splits) { oop.implement(this, EventEmitter); + /** + * @returns {IEditor} + * @this {ISplit} + */ this.$createEditor = function() { var el = document.createElement("div"); el.className = this.$editorCSS; el.style.cssText = "position: absolute; top:0px; bottom:0px"; this.$container.appendChild(el); + /** + * @type {any} + */ var editor = new Editor(new Renderer(el, this.$theme)); editor.on("focus", function() { @@ -54,6 +74,11 @@ var Split = function(container, theme, splits) { return editor; }; + /** + * + * @param splits + * @this {ISplit} + */ this.setSplits = function(splits) { var editor; if (splits < 1) { @@ -87,6 +112,7 @@ var Split = function(container, theme, splits) { * * Returns the number of splits. * @returns {Number} + * @this {ISplit} **/ this.getSplits = function() { return this.$splits; @@ -96,7 +122,7 @@ var Split = function(container, theme, splits) { * @param {Number} idx The index of the editor you want * * Returns the editor identified by the index `idx`. - * + * @this {ISplit} **/ this.getEditor = function(idx) { return this.$editors[idx]; @@ -106,6 +132,7 @@ var Split = function(container, theme, splits) { * * Returns the current editor. * @returns {Editor} + * @this {ISplit} **/ this.getCurrentEditor = function() { return this.$cEditor; @@ -114,6 +141,7 @@ var Split = function(container, theme, splits) { /** * Focuses the current editor. * @related Editor.focus + * @this {ISplit} **/ this.focus = function() { this.$cEditor.focus(); @@ -122,6 +150,7 @@ var Split = function(container, theme, splits) { /** * Blurs the current editor. * @related Editor.blur + * @this {ISplit} **/ this.blur = function() { this.$cEditor.blur(); @@ -133,6 +162,7 @@ var Split = function(container, theme, splits) { * * Sets a theme for each of the available editors. * @related Editor.setTheme + * @this {ISplit} **/ this.setTheme = function(theme) { this.$editors.forEach(function(editor) { @@ -146,6 +176,7 @@ var Split = function(container, theme, splits) { * * Sets the keyboard handler for the editor. * @related editor.setKeyboardHandler + * @this {ISplit} **/ this.setKeyboardHandler = function(keybinding) { this.$editors.forEach(function(editor) { @@ -159,7 +190,7 @@ var Split = function(container, theme, splits) { * @param {String} scope The default scope for the callback * * Executes `callback` on all of the available editors. - * + * @this {ISplit} **/ this.forEach = function(callback, scope) { this.$editors.forEach(callback, scope); @@ -171,7 +202,7 @@ var Split = function(container, theme, splits) { * @param {Number} size The new font size * * Sets the font size, in pixels, for all the available editors. - * + * @this {ISplit} **/ this.setFontSize = function(size) { this.$fontSize = size; @@ -180,7 +211,15 @@ var Split = function(container, theme, splits) { }); }; + /** + * + * @param {IEditSession} session + * @return {IEditSession} + */ this.$cloneSession = function(session) { + /** + * @type {IEditSession} + */ var s = new EditSession(session.getDocument(), session.getMode()); var undoManager = session.getUndoManager(); @@ -207,6 +246,7 @@ var Split = function(container, theme, splits) { * * Sets a new [[EditSession `EditSession`]] for the indicated editor. * @related Editor.setSession + * @this {ISplit} **/ this.setSession = function(session, idx) { var editor; @@ -238,6 +278,7 @@ var Split = function(container, theme, splits) { * * Returns the orientation. * @returns {Number} + * @this {ISplit} **/ this.getOrientation = function() { return this.$orientation; @@ -247,7 +288,7 @@ var Split = function(container, theme, splits) { * * Sets the orientation. * @param {Number} orientation The new orientation value - * + * @this {ISplit} * **/ this.setOrientation = function(orientation) { @@ -260,6 +301,7 @@ var Split = function(container, theme, splits) { /** * Resizes the editor. + * @this {ISplit} **/ this.resize = function() { var width = this.$container.clientWidth; diff --git a/src/token_iterator.js b/src/token_iterator.js index 15879e1ec6f..347fdda2195 100644 --- a/src/token_iterator.js +++ b/src/token_iterator.js @@ -27,7 +27,7 @@ class TokenIterator { /** * Moves iterator position to the start of previous token. - * @returns {Ace.Token|null} + * @returns {import("../ace").Ace.Token|null} **/ stepBackward() { this.$tokenIndex -= 1; @@ -48,7 +48,7 @@ class TokenIterator { /** * Moves iterator position to the start of next token. - * @returns {Ace.Token|null} + * @returns {import("../ace").Ace.Token|null} **/ stepForward() { this.$tokenIndex += 1; @@ -72,7 +72,7 @@ class TokenIterator { /** * * Returns current token. - * @returns {Ace.Token} + * @returns {import("../ace").Ace.Token} **/ getCurrentToken() { return this.$rowTokens[this.$tokenIndex]; @@ -112,7 +112,7 @@ class TokenIterator { /** * Return the current token position. - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} */ getCurrentTokenPosition() { return {row: this.$row, column: this.getCurrentTokenColumn()}; diff --git a/src/tokenizer.js b/src/tokenizer.js index 81f2ed02173..9c6b2a55e69 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -113,7 +113,7 @@ class Tokenizer { /** * @param {string} str - * @return {Ace.Token[]} + * @return {import("../ace").Ace.Token[]} */ $applyToken(str) { var values = this.splitRegex.exec(str).slice(1); @@ -136,7 +136,7 @@ class Tokenizer { /** * @param {string} str - * @return {Ace.Token[] | string} + * @return {import("../ace").Ace.Token[] | string} */ $arrayTokens(str) { if (!str) @@ -215,7 +215,7 @@ class Tokenizer { * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state. * @param {string} line * @param {string | string[]} startState - * @returns {{tokens:Ace.Token[], state: string|string[]}} + * @returns {{tokens:import("../ace").Ace.Token[], state: string|string[]}} */ getLineTokens(line, startState) { if (startState && typeof startState != "string") { diff --git a/src/undomanager.js b/src/undomanager.js index 623e24ed9b5..7e932e3146c 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -1,8 +1,6 @@ "use strict"; /** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").IEditSession} IEditSession */ /** @@ -37,9 +35,9 @@ class UndoManager { * - `args[0]` is an array of deltas * - `args[1]` is the document to associate with * - * @param {Ace.Delta} delta + * @param {import("../ace").Ace.Delta} delta * @param {boolean} allowMerge - * @param {IEditSession} session + * @param {IEditSession} [session] **/ add(delta, allowMerge, session) { if (this.$fromUndo) return; @@ -123,7 +121,7 @@ class UndoManager { * * @param {number} from * @param {number} [to] - * @return {Ace.Delta[]} + * @return {import("../ace").Ace.Delta[]} */ getDeltas(from, to) { if (to == null) to = this.$rev + 1; diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 71dc36fb45d..3475b6da266 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IVirtualRenderer - * @type {VirtualRenderer & EventEmitter & Ace.OptionsProvider & Ace.VirtualRendererProperties} + * @type {VirtualRenderer & EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.VirtualRendererProperties} */ /** * @@ -42,7 +42,7 @@ class VirtualRenderer { session; /** * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`. - * @param {Element} container The root element of the editor + * @param {Element} [container] The root element of the editor * @param {String} [theme] The starting theme * @this {IVirtualRenderer} **/ @@ -1282,7 +1282,7 @@ class VirtualRenderer { /** * Sets annotations for the gutter. - * @param {Ace.Annotation[]} annotations An array containing annotations + * @param {import("../ace").Ace.Annotation[]} annotations An array containing annotations * **/ setAnnotations(annotations) { @@ -1316,8 +1316,8 @@ class VirtualRenderer { /** * - * @param {Ace.Point} anchor - * @param {Ace.Point} lead + * @param {import("../ace").Ace.Point} anchor + * @param {import("../ace").Ace.Point} lead * @param {number} [offset] */ scrollSelectionIntoView(anchor, lead, offset) { @@ -1329,7 +1329,7 @@ class VirtualRenderer { /** * * Scrolls the cursor into the first visibile area of the editor - * @param {Ace.Point} [cursor] + * @param {import("../ace").Ace.Point} [cursor] * @param {number} [offset] * @param {{ top: any; bottom: any; }} [$viewMargin] */ @@ -1430,7 +1430,7 @@ class VirtualRenderer { /** * - * @param {Ace.Point} cursor + * @param {import("../ace").Ace.Point} cursor * @param {number} [alignment] * @returns {number} */ @@ -1616,7 +1616,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {{row: number, column: number, side: 1|-1, offsetX: number}} + * @returns {import("../ace").Ace.ScreenCoordinates} * @this {IVirtualRenderer} */ pixelToScreenCoordinates(x, y) { @@ -1642,7 +1642,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {Ace.Point} + * @returns {import("../ace").Ace.Point} * @this {IVirtualRenderer} */ screenToTextCoordinates(x, y) { @@ -1760,7 +1760,7 @@ class VirtualRenderer { /** * @param {string} text - * @param {Ace.Point} position + * @param {import("../ace").Ace.Point} [position] */ setGhostText(text, position) { var cursor = this.session.selection.cursor; @@ -1967,7 +1967,13 @@ class VirtualRenderer { delete this.$scrollDecorator; } if (val === true) { + /** + * @type {import("../ace").Ace.VScrollbar} + */ this.scrollBarV = new VScrollBarCustom(this.container, this); + /** + * @type {import("../ace").Ace.HScrollbar} + */ this.scrollBarH = new HScrollBarCustom(this.container, this); this.scrollBarV.setHeight(this.$size.scrollerHeight); this.scrollBarH.setWidth(this.$size.scrollerWidth); diff --git a/tsconfig.json b/tsconfig.json index e4cbcf22b6d..7cfa9abac4e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,14 +17,16 @@ "exclude": [ "node_modules", "src/test", - "src/keyboard", "src/**/*_test.js", - "./src/mode/**/*", + "src/keyboard/vim.js", + "src/keyboard/emacs.js", + "src/keyboard/sublime.js", + "src/keyboard/vscode.js", "types", + "src/mode" ], "include": [ "./src/**/*", "./ace.d.ts", - "src/mode/text.js" ] } From d8411db96a329ba8a32dbbc6e4fe2cb04b58ba77 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 17 Sep 2023 18:11:54 +0400 Subject: [PATCH 07/36] continue providing types --- ace.d.ts | 152 +++++------------- src/apply_delta.js | 1 + src/autocomplete.js | 16 +- src/autocomplete/popup.js | 3 +- src/background_tokenizer.js | 5 +- src/commands/command_manager.js | 2 +- src/commands/default_commands.js | 3 + src/commands/incremental_search_commands.js | 16 +- src/commands/multi_select_commands.js | 11 +- src/commands/occur_commands.js | 1 + src/config.js | 50 ++++-- src/edit_session.js | 79 +++++---- src/edit_session/fold_line.js | 1 + src/editor.js | 35 ++-- src/ext/emmet.js | 3 + src/ext/error_marker.js | 4 +- src/ext/inline_autocomplete.js | 111 +++++++++---- src/ext/language_tools.js | 7 +- .../get_editor_keyboard_shortcuts.js | 2 +- src/ext/prompt.js | 36 +++-- src/ext/searchbox.js | 14 ++ src/ext/settings_menu.js | 1 + src/ext/static_highlight.js | 7 + src/ext/statusbar.js | 2 +- src/keyboard/hash_handler.js | 62 ++++++- src/keyboard/keybinding.js | 38 ++++- src/keyboard/textarea.js | 2 +- src/keyboard/textinput.js | 2 +- src/layer/cursor.js | 3 +- src/layer/font_metrics.js | 2 +- src/layer/gutter.js | 6 +- src/lib/app_config.js | 2 +- src/lib/dom.js | 2 +- src/lib/event.js | 2 + src/lib/event_emitter.js | 10 +- src/lib/fixoldbrowsers.js | 1 + src/lib/useragent.js | 5 +- src/marker_group.js | 2 +- src/mode/behaviour.js | 35 +++- src/mode/behaviour/cstyle.js | 28 ++-- src/mode/text.js | 16 +- src/mode/text_highlight_rules.js | 39 ++++- src/mouse/default_handlers.js | 4 +- src/mouse/dragdrop_handler.js | 1 + src/mouse/mouse_handler.js | 7 +- src/multi_select.js | 2 +- src/range_list.js | 2 +- src/search.js | 4 +- src/selection.js | 9 +- src/snippets.js | 7 +- src/split.js | 1 + src/tokenizer.js | 7 +- src/tokenizer_dev.js | 8 +- src/tooltip.js | 4 + src/undomanager.js | 2 +- src/virtual_renderer.js | 11 +- src/worker/worker_client.js | 5 +- 57 files changed, 601 insertions(+), 292 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index f6fd3b320e9..9855111351e 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -18,12 +18,20 @@ export namespace Ace { type CompletionProvider = import("./src/autocomplete").CompletionProvider; type AcePopup = import("./src/autocomplete/popup").IAcePopup; type Config = import("./src/config").IConfig; - + type AceInline = import("./src/autocomplete/inline").AceInline; + + interface Theme { + cssClass?: string; + cssText?: string; + $id?: string; + padding?: number | string; + isDark?: boolean; + } interface ScrollBar { setVisible(visible: boolean): void; [key: string]: any; } - + interface HScrollbar extends ScrollBar { setWidth(width: number): void; } @@ -31,7 +39,7 @@ export namespace Ace { interface VScrollbar extends ScrollBar { setHeight(width: number): void; } - + interface LayerConfig { width : number, padding : number, @@ -145,7 +153,7 @@ export namespace Ace { $selectionStyle?: string, env?: any; widgetManager?: import("./src/line_widgets").LineWidgets, - completer?: import("./src/autocomplete").Autocomplete, + completer?: import("./src/autocomplete").Autocomplete | import("./src/ext/inline_autocomplete").InlineAutocomplete, completers: Completer[], $highlightTagPending?: boolean, showKeyboardShortcuts?: () => void, @@ -171,7 +179,8 @@ export namespace Ace { curOp?: { command: {}, args: string, - scrollTop: number + scrollTop: number, + [key: string]: any; }, lineWidgetsWidth?: number, $getWidgetScreenLength?: () => number, @@ -369,24 +378,30 @@ export namespace Ace { className: string; } - export class MarkerGroup { - constructor(session: EditSession); - setMarkers(markers: MarkerGroupItem[]): void; - getMarkerAtPosition(pos: Position): MarkerGroupItem; - } + type MarkerGroup = import("./src/marker_group").MarkerGroup; export interface Command { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; - exec: (editor: Editor, args?: any) => void; + exec?: (editor: Editor, args?: any) => void; + isAvailable?: (editor: Editor) => boolean; + description?: string, + multiSelectAction?: "forEach"|"forEachLine"|Function, + scrollIntoView?: true|"cursor"|"center"|"selectionPart"|"animate"|"selection"|"none", + aceCommandGroup?: string, + passEvent?: boolean, + level?: number, + action?: string, } type CommandLike = Command | ((editor: Editor) => void); - - interface KeyboardHandler { - handleKeyboard: Function; + + type KeyboardHandler = import("./src/keyboard/hash_handler").HashHandler & { + attach?: (editor: Editor) => void; + detach?: (editor: Editor) => void; + getStatusText?: (editor?: any, data?) => string; } export interface MarkerLike { @@ -498,7 +513,9 @@ export namespace Ace { * quotes used by language mode */ $quotes: {[quote: string]: string}; - HighlightRules: HighlightRules; //TODO: fix this + HighlightRules: { + new(config: any): HighlightRules + }; //TODO: fix this foldingRules?: FoldMode; $behaviour?: Behaviour; $defaultBehaviour?: Behaviour; @@ -524,6 +541,7 @@ export namespace Ace { $highlightRuleConfig?: any; completionKeywords: string[]; transformAction: BehaviorAction; + path?: string; getTokenizer(): Tokenizer; @@ -557,6 +575,7 @@ export namespace Ace { $getIndent(line: string): string; $createKeywordList(): string[]; + $delegator(method: string, args: IArguments, defaultHandler): any; } @@ -574,25 +593,7 @@ export namespace Ace { getOption(name: K): T[K]; } - - interface KeyBinding { - setDefaultHandler(handler: KeyboardHandler): void; - - setKeyboardHandler(handler: KeyboardHandler): void; - - addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; - - removeKeyboardHandler(handler: KeyboardHandler): boolean; - - getKeyboardHandler(): KeyboardHandler; - - getStatusText(): string; - - onCommandKey(e: any, hashId: number, keyCode: number): boolean; - - onTextInput(text: string): boolean; - } - + type KeyBinding = import("./src/keyboard/keybinding").KeyBinding; interface CommandMap { [name: string]: Command; } @@ -603,42 +604,12 @@ export namespace Ace { args: any[] }) => void; - interface CommandManager extends EventEmitter { - byName: CommandMap, - commands: CommandMap, - + interface CommandManagerEvents { on(name: 'exec', callback: execEventHandler): Function; - on(name: 'afterExec', callback: execEventHandler): Function; - - exec(command: string, editor: Editor, args: any): boolean; - - toggleRecording(editor: Editor): void; - - replay(editor: Editor): void; - - addCommand(command: Command): void; - - addCommands(command: Command[]): void; - - removeCommand(command: Command | string, keepCommand?: boolean): void; - - removeCommands(command: Command[]): void; - - bindKey(key: string | { mac?: string, win?: string }, - command: CommandLike, - position?: number): void; - - bindKeys(keys: { [s: string]: Function }): void; - - parseKeys(keyPart: string): { key: string, hashId: number }; - - findKeyCommand(hashId: number, keyString: string): string | undefined; - - handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | { command: string }; - - getStatusText(editor: Editor, data: {}): string; } + type CommandManager = import("./src/commands/command_manager").ICommandManager & CommandManagerEvents; + interface SavedSelection { start: Point; @@ -653,7 +624,7 @@ export namespace Ace { interface TextInput { resetSelection(): void; - setAriaOption(activeDescendant: string, role: string): void; + setAriaOption(options?: {activeDescendant: string, role: string, setLabel}): void; } type CompleterCallback = (error: any, completions: Completion[]) => void; @@ -667,7 +638,7 @@ export namespace Ace { prefix: string, callback: CompleterCallback): void; - getDocTooltip?(item: Completion): undefined | string | Completion; + getDocTooltip?(item: Completion): void | string | Completion; cancel?(): void; @@ -675,16 +646,6 @@ export namespace Ace { triggerCharacters?: string[] } - class AceInline { - show(editor: Editor, completion: Completion, prefix: string): void; - - isOpen(): void; - - hide(): void; - - destroy(): void; - } - interface CompletionOptions { matches?: Completion[]; } @@ -747,34 +708,5 @@ export interface TooltipCommand extends Ace.Command { cssClass?: string } -export class InlineAutocomplete { - constructor(); - getInlineRenderer(): Ace.AceInline; - getInlineTooltip(): CommandBarTooltip; - getCompletionProvider(): Ace.CompletionProvider; - show(editor: Ace.Editor): void; - isOpen(): boolean; - detach(): void; - destroy(): void; - goTo(action: InlineAutocompleteAction): void; - tooltipEnabled: boolean; - commands: Record - getIndex(): number; - setIndex(value: number): void; - getLength(): number; - getData(index?: number): Ace.Completion | undefined; - updateCompletions(options: Ace.CompletionOptions): void; -} - -export class CommandBarTooltip { - constructor(parentElement: HTMLElement); - registerCommand(id: string, command: TooltipCommand): void; - attach(editor: Ace.Editor): void; - updatePosition(): void; - update(): void; - isShown(): boolean; - getAlwaysShow(): boolean; - setAlwaysShow(alwaysShow: boolean): void; - detach(): void; - destroy(): void; -} +export type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; +export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; diff --git a/src/apply_delta.js b/src/apply_delta.js index 97fc4a7a8f5..e52c78d40b8 100644 --- a/src/apply_delta.js +++ b/src/apply_delta.js @@ -60,6 +60,7 @@ exports.applyDelta = function(docLines, delta, doNotValidate) { if (lines.length === 1) { docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn); } else { + // @ts-ignore var args = [row, 1].concat(delta.lines); docLines.splice.apply(docLines, args); docLines[row] = line.substring(0, startColumn) + docLines[row]; diff --git a/src/autocomplete.js b/src/autocomplete.js index 2607d6c6f96..9a85b7b536c 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -6,7 +6,7 @@ * @typedef {import("./editor").IEditor} IEditor */ var HashHandler = require("./keyboard/hash_handler").HashHandler; -var AcePopup = require("./autocomplete/popup").AcePopup; +/**@type{any}*/var AcePopup = require("./autocomplete/popup").AcePopup; var AceInline = require("./autocomplete/inline").AceInline; var getAriaId = require("./autocomplete/popup").getAriaId; var util = require("./autocomplete/util"); @@ -93,7 +93,9 @@ class Autocomplete { } $init() { - // @ts-ignore + /** + * @type {IAcePopup} + */ this.popup = new AcePopup(this.parentNode || document.body || document.documentElement); this.popup.on("click", function(e) { this.insertMatch(); @@ -138,6 +140,7 @@ class Autocomplete { } this.$updatePopupPosition(); } + // @ts-expect-error TODO: potential wrong arguments this.tooltipTimer.call(null, null); } @@ -156,9 +159,11 @@ class Autocomplete { this.$elements = elements; } unObserveLayoutChanges() { + // @ts-expect-error This is expected for some browsers window.removeEventListener("resize", this.onLayoutChange, {passive: true}); window.removeEventListener("wheel", this.mousewheelListener); this.$elements && this.$elements.forEach((el) => { + // @ts-expect-error This is expected for some browsers el.removeEventListener("scroll", this.onLayoutChange, {passive: true}); }); this.$elements = null; @@ -323,6 +328,7 @@ class Autocomplete { if (data.value === "") // Explicitly given nothing to insert, e.g. "No suggestion state" return this.detach(); var completions = this.completions; + // @ts-expect-error TODO: potential wrong arguments var result = this.getCompletionProvider().insertMatch(this.editor, data, completions.filterText, options); // detach only if new popup was not opened while inserting match if (this.completions == completions) @@ -606,9 +612,9 @@ Autocomplete.for = function(editor) { editor.completer = null; } if (config.get("sharedPopups")) { - if (!Autocomplete.$sharedInstance) - Autocomplete.$sharedInstance = new Autocomplete(); - editor.completer = Autocomplete.$sharedInstance; + if (!Autocomplete["$sharedInstance"]) + Autocomplete["$sharedInstance"] = new Autocomplete(); + editor.completer = Autocomplete["$sharedInstance"]; } else { editor.completer = new Autocomplete(); editor.once("destroy", destroyCompleter); diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 460d454c85c..a18911687ea 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -98,6 +98,7 @@ class AcePopup { popup.setHighlightActiveLine(false); // set default highlight color + // @ts-ignore popup.session.highlight(""); popup.session.$searchHighlight.clazz = "ace_highlight-marker"; @@ -200,7 +201,7 @@ class AcePopup { var bgTokenizer = popup.session.bgTokenizer; bgTokenizer.$tokenizeRow = function (row) { /** - * @type {import("../../ace").Ace.Completion} + * @type {import("../../ace").Ace.Completion &{name?, className?, matchMask?, message?}} */ var data = popup.data[row]; var tokens = []; diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 2e877eb15bc..5263c6f0c6d 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -29,7 +29,7 @@ class BackgroundTokenizer { /** * Creates a new `BackgroundTokenizer` object. * @param {ITokenizer} tokenizer The tokenizer to use - * @param {IEditor} editor The editor to associate with + * @param {IEditor} [editor] The editor to associate with * @this {IBackgroundTokenizer} **/ constructor(tokenizer, editor) { @@ -68,6 +68,7 @@ class BackgroundTokenizer { // only check every 5 lines processedLines ++; + // @ts-ignore if ((processedLines % 5 === 0) && (new Date() - workerStart) > 20) { self.running = setTimeout(self.$worker, 20); break; @@ -211,7 +212,7 @@ class BackgroundTokenizer { $tokenizeRow(row) { var line = this.doc.getLine(row); var state = this.states[row - 1]; - + // @ts-expect-error TODO: potential wrong argument var data = this.tokenizer.getLineTokens(line, state, row); if (this.states[row] + "" !== data.state + "") { diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index 01d8686ee27..c5e554afa58 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -36,7 +36,7 @@ class CommandManager extends MultiHashHandler{ /** * - * @param command + * @param {string | string[] | import("../../ace").Ace.Command} command * @param {IEditor} editor * @param {any} args * @returns {boolean} diff --git a/src/commands/default_commands.js b/src/commands/default_commands.js index bbe8b830ca7..0dbbd148042 100644 --- a/src/commands/default_commands.js +++ b/src/commands/default_commands.js @@ -12,6 +12,9 @@ function bindKey(win, mac) { multiSelectAction: "forEach"|"forEachLine"|function|undefined, scrollIntoView: true|"cursor"|"center"|"selectionPart" */ +/** + * @type {import("../../ace").Ace.Command[]} + */ exports.commands = [{ name: "showSettingsMenu", description: "Show settings menu", diff --git a/src/commands/incremental_search_commands.js b/src/commands/incremental_search_commands.js index 9f96c8cf4b5..cc73714a3b7 100644 --- a/src/commands/incremental_search_commands.js +++ b/src/commands/incremental_search_commands.js @@ -138,10 +138,9 @@ function IncrementalSearchKeyboardHandler(iSearch) { oop.inherits(IncrementalSearchKeyboardHandler, HashHandler); (function() { - /** * @param editor - * @this {IncrementalSearchKeyboardHandler & this} + * @this {IncrementalSearchKeyboardHandler & this & {$commandExecHandler}} */ this.attach = function(editor) { var iSearch = this.$iSearch; @@ -159,6 +158,10 @@ oop.inherits(IncrementalSearchKeyboardHandler, HashHandler); }); }; + /** + * @this {IncrementalSearchKeyboardHandler & this & {$commandExecHandler}} + * @param editor + */ this.detach = function(editor) { if (!this.$commandExecHandler) return; editor.commands.off('exec', this.$commandExecHandler); @@ -166,9 +169,18 @@ oop.inherits(IncrementalSearchKeyboardHandler, HashHandler); }; var handleKeyboard$super = this.handleKeyboard; + /** + * + * @param data + * @param hashId + * @param key + * @param keyCode + * @this {IncrementalSearchKeyboardHandler & import("../keyboard/hash_handler").HashHandler} + */ this.handleKeyboard = function(data, hashId, key, keyCode) { if (((hashId === 1/*ctrl*/ || hashId === 8/*command*/) && key === 'v') || (hashId === 1/*ctrl*/ && key === 'y')) return null; + // @ts-ignore var cmd = handleKeyboard$super.call(this, data, hashId, key, keyCode); if (cmd && cmd.command) { return cmd; } if (hashId == -1) { diff --git a/src/commands/multi_select_commands.js b/src/commands/multi_select_commands.js index 2cba5d95b56..0c5dcd02d44 100644 --- a/src/commands/multi_select_commands.js +++ b/src/commands/multi_select_commands.js @@ -1,4 +1,8 @@ -// commands to enter multiselect mode + +/** + * commands to enter multiselect mode + * @type {import("../../ace").Ace.Command[]} + */ exports.defaultCommands = [{ name: "addCursorAbove", description: "Add cursor above", @@ -86,7 +90,10 @@ exports.defaultCommands = [{ readOnly: true }]; -// commands active only in multiselect mode +/** + * commands active only in multiselect mode + * @type {import("../../ace").Ace.Command[]} + */ exports.multiSelectCommands = [{ name: "singleSelection", description: "Single selection", diff --git a/src/commands/occur_commands.js b/src/commands/occur_commands.js index dfe7268074f..572bb6bd01d 100644 --- a/src/commands/occur_commands.js +++ b/src/commands/occur_commands.js @@ -54,6 +54,7 @@ oop.inherits(OccurKeyboardHandler, HashHandler); var handleKeyboard$super = this.handleKeyboard; this.handleKeyboard = function(data, hashId, key, keyCode) { + // @ts-ignore var cmd = handleKeyboard$super.call(this, data, hashId, key, keyCode); return (cmd && cmd.command) ? cmd : undefined; }; diff --git a/src/config.js b/src/config.js index cdbaba7c158..fffe76fe351 100644 --- a/src/config.js +++ b/src/config.js @@ -1,16 +1,38 @@ "no use strict"; /** - * @typedef IAppConfig - * @type {import("./lib/app_config").IAppConfig} + * @typedef {import("./lib/app_config").IAppConfig} IAppConfig + */ +/** + * @typedef {IAppConfig & Config} IConfig + * @export + */ + +/** + * @typedef Config + * @property {(key: string) => any} get + * @property {(key: string, value: any) => void} set + * @property {() => {[key: string]: any}} all + * @property {(name: string, component?: string) => string} moduleUrl + * @property {(name: string, subst: string) => string} setModuleUrl + * @property {(moduleName: string | [string, string], cb: (module: any) => void) => void} loadModule + * @property {(cb: (moduleName: string, afterLoad: (err: Error | null, module: unknown) => void) => void) => void} setLoader + * @property {(moduleName: string, onLoad: (module: any) => void) => void} setModuleLoader + * @property {string} version + * @property {any} $modes + * @property {any} $loading + * @property {any} $loaded + * @property {any} dynamicModules + * @property {any} $require */ var lang = require("./lib/lang"); var net = require("./lib/net"); var dom = require("./lib/dom"); -var AppConfig = require("./lib/app_config").AppConfig; +/**@type{any}*/var AppConfig = require("./lib/app_config").AppConfig; /** - * @type {IAppConfig & exports} + * + * @type {IConfig} */ module.exports = exports = new AppConfig(); @@ -128,23 +150,23 @@ exports.loadModule = function(moduleName, onLoad) { moduleType = moduleName[0]; moduleName = moduleName[1]; } - + var load = function (module) { // require(moduleName) can return empty object if called after require([moduleName], callback) - if (module && !exports.$loading[moduleName]) return onLoad && onLoad(module); + if (module && !exports.$loading[/**@type {string}*/(moduleName)]) return onLoad && onLoad(module); - if (!exports.$loading[moduleName]) exports.$loading[moduleName] = []; + if (!exports.$loading[/**@type {string}*/(moduleName)]) exports.$loading[/**@type {string}*/(moduleName)] = []; - exports.$loading[moduleName].push(onLoad); + exports.$loading[/**@type {string}*/(moduleName)].push(onLoad); - if (exports.$loading[moduleName].length > 1) return; + if (exports.$loading[/**@type {string}*/(moduleName)].length > 1) return; var afterLoad = function() { loader(moduleName, function(err, module) { - if (module) exports.$loaded[moduleName] = module; + if (module) exports.$loaded[/**@type {string}*/(moduleName)] = module; exports._emit("load.module", {name: moduleName, module: module}); - var listeners = exports.$loading[moduleName]; - exports.$loading[moduleName] = null; + var listeners = exports.$loading[/**@type {string}*/(moduleName)]; + exports.$loading[/**@type {string}*/(moduleName)] = null; listeners.forEach(function(onLoad) { onLoad && onLoad(module); }); @@ -153,7 +175,7 @@ exports.loadModule = function(moduleName, onLoad) { if (!exports.get("packaged")) return afterLoad(); - net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad); + net.loadScript(exports.moduleUrl(/**@type {string}*/(moduleName), moduleType), afterLoad); reportErrorIfPathIsNotConfigured(); }; @@ -176,7 +198,7 @@ exports.loadModule = function(moduleName, onLoad) { }; exports.$require = function(moduleName) { - if (typeof module.require == "function") { + if (typeof module["require"] == "function") { var req = "require"; return module[req](moduleName); } diff --git a/src/edit_session.js b/src/edit_session.js index 5438d85407f..76d36e5f811 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -5,16 +5,19 @@ * @export */ /** - * @typedef UndoManager - * @type {import("./undomanager").UndoManager} + * @typedef {import("./undomanager").UndoManager} UndoManager */ /** - * @typedef FoldLine - * @type {import("./edit_session/fold_line").FoldLine} + * @typedef {import("./edit_session/fold_line").FoldLine} FoldLine */ /** - * @typedef ISelection - * @type {import("./selection").ISelection} + * @typedef {import("./selection").ISelection} ISelection + */ +/** + * @typedef {import("./document").IDocument} IDocument + */ +/** + * @typedef {import("../ace").Ace.Point} Point */ var oop = require("./lib/oop"); @@ -114,26 +117,28 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; **/ //} +/** + * @typedef TextMode + * @type {import("../ace").Ace.SyntaxMode} + */ + + + /** * Stores all the data about [[Editor `Editor`]] state providing easy way to change editors state. * * `EditSession` can be attached to only one [[Document `Document`]]. Same `Document` can be attached to several `EditSession`s. **/ -/** - * @typedef TextMode - * @type {import("../ace").Ace.SyntaxMode} - */ - class EditSession { /** - * @type {import("../ace").Ace.Document} + * @type {IDocument} */ doc; /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. - * @param {import("../ace").Ace.Document | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} + * @param {IDocument | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} * @param {import("../ace").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} * @this {IEditSession} **/ @@ -172,7 +177,7 @@ class EditSession { if (typeof text != "object" || !text.getLine) text = new Document(text); - this.setDocument(text); + this.setDocument(/**@type{IDocument}*/(text)); /** * @type {ISelection}} */ @@ -189,7 +194,7 @@ class EditSession { /** * Sets the `EditSession` to point to a new `Document`. If a `BackgroundTokenizer` exists, it also points to `doc`. * - * @param {import("../ace").Ace.Document} doc The new `Document` to use + * @param {IDocument} doc The new `Document` to use * **/ setDocument(doc) { @@ -206,7 +211,7 @@ class EditSession { /** * Returns the `Document` associated with this session. - * @return {import("../ace").Ace.Document} + * @return {IDocument} **/ getDocument() { return this.doc; @@ -283,6 +288,7 @@ class EditSession { if (!this.$fromUndo && this.$undoManager) { if (removedFolds && removedFolds.length) { this.$undoManager.add({ + // @ts-expect-error TODO: this action type is missing in the types action: "removeFolds", folds: removedFolds }, this.mergeUndoDeltas); @@ -415,6 +421,7 @@ class EditSession { * @returns {UndoManager} **/ getUndoManager() { + // @ts-ignore return this.$undoManager || this.$defaultUndoManager; } @@ -468,7 +475,7 @@ class EditSession { /** * Returns `true` if the character at the position is a soft tab. - * @param {import("../ace").Ace.Point} position The position to check + * @param {Point} position The position to check * @this {IEditSession} **/ isTabStop(position) { @@ -883,7 +890,7 @@ class EditSession { var options = mode; var path = options.path; } else { - path = mode || "ace/mode/text"; + path = /**@type{string}*/(mode) || "ace/mode/text"; } // this is needed if ace isn't on require path (e.g tests in node) @@ -1142,9 +1149,9 @@ class EditSession { /** * Inserts a block of `text` and the indicated `position`. - * @param {import("../ace").Ace.Point} position The position {row, column} to start inserting at + * @param {Point} position The position {row, column} to start inserting at * @param {String} text A chunk of text to insert - * @returns {import("../ace").Ace.Point} The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @returns {Point} The position of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. **/ insert(position, text) { return this.doc.insert(position, text); @@ -1152,8 +1159,8 @@ class EditSession { /** * Removes the `range` from the document. - * @param {Range} range A specified Range to remove - * @returns {import("../ace").Ace.Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @param {import("../ace").Ace.IRange} range A specified Range to remove + * @returns {Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { return this.doc.remove(range); @@ -1192,7 +1199,9 @@ class EditSession { } } if (!dontSelect && this.$undoSelect) { + //@ts-expect-error TODO: potential wrong property if (deltas.selectionBefore) + //@ts-expect-error TODO: potential wrong property this.selection.fromJSON(deltas.selectionBefore); else this.selection.setRange(this.$getUndoSelection(deltas, true)); @@ -1218,7 +1227,9 @@ class EditSession { } if (!dontSelect && this.$undoSelect) { + //@ts-expect-error TODO: potential wrong property if (deltas.selectionAfter) + //@ts-expect-error TODO: potential wrong property this.selection.fromJSON(deltas.selectionAfter); else this.selection.setRange(this.$getUndoSelection(deltas, false)); @@ -1282,9 +1293,9 @@ class EditSession { /** * Replaces a range in the document with the new `text`. * - * @param {Range} range A specified Range to replace + * @param {import("../ace").Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {import("../ace").Ace.Point} An object containing the final row and column, like this: + * @returns {Point} An object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -1303,7 +1314,7 @@ class EditSession { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} fromRange The range of text you want moved within the document - * @param {import("../ace").Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * @returns {Range} The new range where the text was moved to. * @this {IEditSession} @@ -1488,7 +1499,7 @@ class EditSession { /** * @param {number} row * @param {number} column - * @returns {import("../ace").Ace.Point} + * @returns {Point} */ $clipPositionToDocument(row, column) { column = Math.max(0, column); @@ -1898,6 +1909,7 @@ class EditSession { if (!splits.length) { indent = getWrapIndent(); + //@ts-expect-error TODO: potential wrong property splits.indent = indent; } lastDocSplit += len; @@ -2148,7 +2160,7 @@ class EditSession { * For the given document row and column, this returns the document position of the last row. * @param {Number} docRow * @param {Number} docColumn - * @returns {import("../ace").Ace.Point} + * @returns {Point} * @this {IEditSession} **/ getDocumentLastRowColumnPosition(docRow, docColumn) { @@ -2206,7 +2218,7 @@ class EditSession { * @param {Number} screenColumn The screen column to check * @param {Number} [offsetX] screen character x-offset [optional] * - * @returns {import("../ace").Ace.Point} The object returned has two properties: `row` and `column`. + * @returns {Point} The object returned has two properties: `row` and `column`. * * @related EditSession.documentToScreenPosition * @this {IEditSession} @@ -2301,9 +2313,9 @@ class EditSession { /** * Converts document coordinates to screen coordinates. {:conversionConsiderations} - * @param {Number|import("../ace").Ace.Point} docRow The document row to check + * @param {Number|Point} docRow The document row to check * @param {Number|undefined} [docColumn] The document column to check - * @returns {import("../ace").Ace.Point} The object returned by this method has two properties: `row` and `column`. + * @returns {Point} The object returned by this method has two properties: `row` and `column`. * * @related EditSession.screenToDocumentPosition * @this {IEditSession} @@ -2311,9 +2323,9 @@ class EditSession { documentToScreenPosition(docRow, docColumn) { // Normalize the passed in arguments. if (typeof docColumn === "undefined") - var pos = this.$clipPositionToDocument(docRow.row, docRow.column); + var pos = this.$clipPositionToDocument(/**@type{Point}*/(docRow).row, /**@type{Point}*/(docRow).column); else - pos = this.$clipPositionToDocument(docRow, docColumn); + pos = this.$clipPositionToDocument(/**@type{number}*/(docRow), docColumn); docRow = pos.row; docColumn = pos.column; @@ -2431,6 +2443,9 @@ class EditSession { **/ getScreenLength() { var screenRows = 0; + /** + * @type {FoldLine} + */ var fold = null; if (!this.$useWrapMode) { screenRows = this.getLength(); diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index 7317e1c938b..131c235e899 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -52,6 +52,7 @@ class FoldLine { */ addFold(fold) { if (fold.sameRow) { + // @ts-expect-error TODO: startRow, endRow are missing in Fold and FoldLine if (fold.start.row < this.startRow || fold.endRow > this.endRow) { throw new Error("Can't add a fold to this FoldLine as it has no connection"); } diff --git a/src/editor.js b/src/editor.js index b6d15d291a4..1a9f7d0f67b 100644 --- a/src/editor.js +++ b/src/editor.js @@ -13,6 +13,10 @@ * @typedef IVirtualRenderer * @type {import("./virtual_renderer").IVirtualRenderer} */ +/** + * @typedef ISelection + * @type {import("./selection").ISelection} + */ /** * @typedef ICommandManager @@ -49,7 +53,6 @@ var keys = require('./lib/keys'); * The `Editor` manages the [[EditSession]] (which manages [[Document]]s), as well as the [[VirtualRenderer]], which draws everything to the screen. * * Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them. - * @type {IEditor} **/ class Editor { /** @@ -167,6 +170,9 @@ class Editor { } this.$opResetTimer.schedule(); + /** + * @type {{[key: string]: any;}} + */ this.curOp = this.session.curOp = { command: commandEvent.command || {}, args: commandEvent.args, @@ -283,6 +289,7 @@ class Editor { }); } else { this.$keybindingId = null; + // @ts-ignore this.keyBinding.setKeyboardHandler(keyboardHandler); cb && cb(); } @@ -463,7 +470,7 @@ class Editor { /** * * Returns the currently highlighted selection. - * @returns {Selection} The selection object + * @returns {ISelection} The selection object **/ getSelection() { return this.selection; @@ -480,7 +487,7 @@ class Editor { /** * {:VirtualRenderer.setTheme} - * @param {String} theme The path to a theme + * @param {string | import("../ace").Ace.Theme} theme The path to a theme * @param {() => void} [cb] optional callback called when theme is loaded **/ setTheme(theme, cb) { @@ -1210,7 +1217,7 @@ class Editor { **/ /** * Draw selection markers spanning whole line, or only over selected text. Default value is "line" - * @param {String} val The new selection style "line"|"text" + * @param {"fullLine" | "screenLine" | "text" | "line"} val The new selection style "line"|"text" * @this {IEditor} **/ setSelectionStyle(val) { @@ -1470,7 +1477,7 @@ class Editor { else this.selection.selectRight(); } - + var range = this.getSelectionRange(); if (this.getBehavioursEnabled()) { var session = this.session; @@ -1487,6 +1494,7 @@ class Editor { } } if (new_range) + // @ts-expect-error TODO: possible bug, new_range could be not a Range range = new_range; } @@ -1781,6 +1789,7 @@ class Editor { var c = this.session.getTextRange(charRange); // if the char is a digit + // @ts-ignore if (!isNaN(parseFloat(c)) && isFinite(c)) { // get the whole number the digit is part of var nr = this.getNumberAt(row, column); @@ -2285,8 +2294,8 @@ class Editor { /** * Moves the cursor's row and column to the next matching bracket or HTML tag. - * @param {boolean} select - * @param {boolean} expand + * @param {boolean} [select] + * @param {boolean} [expand] */ jumpToMatching(select, expand) { var cursor = this.getCursorPosition(); @@ -2436,8 +2445,8 @@ class Editor { /** * Moves the cursor to the specified line number, and also into the indicated column. * @param {Number} lineNumber The line number to go to - * @param {Number} column A column number to go to - * @param {Boolean} animate If `true` animates scolling + * @param {Number} [column] A column number to go to + * @param {Boolean} [animate] If `true` animates scolling * @this {IEditor} **/ gotoLine(lineNumber, column, animate) { @@ -2585,7 +2594,7 @@ class Editor { /** * Replaces the first occurrence of `options.needle` with the value in `replacement`. - * @param {String} replacement The text to replace with + * @param {String} [replacement] The text to replace with * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ @@ -2610,7 +2619,7 @@ class Editor { /** * Replaces all occurrences of `options.needle` with the value in `replacement`. - * @param {String} replacement The text to replace with + * @param {String} [replacement] The text to replace with * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ @@ -2638,6 +2647,10 @@ class Editor { return replaced; } + /** + * @param {import("../ace").Ace.IRange} range + * @param {string} [replacement] + */ $tryReplace(range, replacement) { var input = this.session.getTextRange(range); replacement = this.$search.replace(input, replacement); diff --git a/src/ext/emmet.js b/src/ext/emmet.js index b083a2a2e54..8be9d945bcc 100644 --- a/src/ext/emmet.js +++ b/src/ext/emmet.js @@ -166,6 +166,9 @@ class AceEmmetEditor { var syntax = this.ace.session.$modeId.split("/").pop(); if (syntax == "html" || syntax == "php") { var cursor = this.ace.getCursorPosition(); + /** + * @type {string | string[]} + */ var state = this.ace.session.getState(cursor.row); if (typeof state != "string") state = state[0]; diff --git a/src/ext/error_marker.js b/src/ext/error_marker.js index 30ea768a75f..e388b14c0ef 100644 --- a/src/ext/error_marker.js +++ b/src/ext/error_marker.js @@ -131,6 +131,7 @@ exports.showErrorMarker = function(editor, dir) { w.destroy = function() { if (editor.$mouseHandler.isMousePressed) return; + // @ts-ignore editor.keyBinding.removeKeyboardHandler(kb); session.widgetManager.removeLineWidget(w); editor.off("changeSelection", w.destroy); @@ -138,7 +139,8 @@ exports.showErrorMarker = function(editor, dir) { editor.off("mouseup", w.destroy); editor.off("change", w.destroy); }; - + + // @ts-ignore editor.keyBinding.addKeyboardHandler(kb); editor.on("changeSelection", w.destroy); editor.on("changeSession", w.destroy); diff --git a/src/ext/inline_autocomplete.js b/src/ext/inline_autocomplete.js index 127d717c06b..6ba683a02d7 100644 --- a/src/ext/inline_autocomplete.js +++ b/src/ext/inline_autocomplete.js @@ -1,5 +1,7 @@ "use strict"; - +/** + * @typedef {import("./command_bar").ICommandBarTooltip} ICommandBarTooltip + */ var HashHandler = require("../keyboard/hash_handler").HashHandler; var AceInline = require("../autocomplete/inline").AceInline; var FilteredList = require("../autocomplete").FilteredList; @@ -8,7 +10,7 @@ var Editor = require("../editor").Editor; var util = require("../autocomplete/util"); var dom = require("../lib/dom"); var lang = require("../lib/lang"); -var CommandBarTooltip = require("./command_bar").CommandBarTooltip; +/**@type{any}*/var CommandBarTooltip = require("./command_bar").CommandBarTooltip; var BUTTON_CLASS_NAME = require("./command_bar").BUTTON_CLASS_NAME; var snippetCompleter = require("./language_tools").snippetCompleter; @@ -25,6 +27,9 @@ var destroyCompleter = function(e, editor) { * There is an inline ghost text renderer and an optional command bar tooltip inside. */ class InlineAutocomplete { + /** + * @param {import("../editor").IEditor} editor + */ constructor(editor) { this.editor = editor; this.keyboardHandler = new HashHandler(this.commands); @@ -38,13 +43,21 @@ class InlineAutocomplete { this.updateCompletions(); }.bind(this)); } - + + /** + * + * @return {AceInline} + */ getInlineRenderer() { if (!this.inlineRenderer) this.inlineRenderer = new AceInline(); return this.inlineRenderer; } + /** + * + * @return {ICommandBarTooltip} + */ getInlineTooltip() { if (!this.inlineTooltip) { this.inlineTooltip = InlineAutocomplete.createInlineTooltip(document.body || document.documentElement); @@ -55,7 +68,7 @@ class InlineAutocomplete { /** * This function is the entry point to the class. This triggers the gathering of the autocompletion and displaying the results; - * @param {CompletionOptions} options + * @param {import("../../ace").Ace.CompletionOptions} options */ show(options) { this.activated = true; @@ -110,6 +123,9 @@ class InlineAutocomplete { this.detach(); } + /** + * @param {import("../../ace").InlineAutocompleteAction} where + */ goTo(where) { if (!this.completions || !this.completions.filtered) { return; @@ -138,6 +154,10 @@ class InlineAutocomplete { return this.completions.filtered.length; } + /** + * @param {number} [index] + * @returns {import("../../ace").Ace.Completion | undefined} + */ getData(index) { if (index == undefined || index === null) { return this.completions.filtered[this.$index]; @@ -154,6 +174,9 @@ class InlineAutocomplete { return this.$index >= 0; } + /** + * @param {number} value + */ setIndex(value) { if (!this.completions || !this.completions.filtered) { return; @@ -165,6 +188,9 @@ class InlineAutocomplete { } } + /** + * @return {CompletionProvider} + */ getCompletionProvider(initialPosition) { if (!this.completionProvider) this.completionProvider = new CompletionProvider(initialPosition); @@ -181,6 +207,9 @@ class InlineAutocomplete { } } + /** + * @return {any} + */ $updatePrefix() { var pos = this.editor.getCursorPosition(); var prefix = this.editor.session.getTextRange({start: this.base, end: pos}); @@ -191,10 +220,14 @@ class InlineAutocomplete { && this.completions.filtered[0].value == prefix && !this.completions.filtered[0].snippet) return this.detach(); + //@ts-expect-error TODO: potential wrong arguments this.$open(this.editor, prefix); return prefix; } + /** + * @param {import("../../ace").Ace.CompletionOptions} [options] + */ updateCompletions(options) { var prefix = ""; @@ -203,6 +236,7 @@ class InlineAutocomplete { this.base = this.editor.session.doc.createAnchor(pos.row, pos.column); this.base.$insertRight = true; this.completions = new FilteredList(options.matches); + //@ts-expect-error TODO: potential wrong arguments return this.$open(this.editor, ""); } @@ -215,6 +249,8 @@ class InlineAutocomplete { var prefix = util.getCompletionPrefix(this.editor); this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length); this.base.$insertRight = true; + + // @ts-ignore var options = { exactMatch: true, ignoreCaption: true @@ -223,22 +259,28 @@ class InlineAutocomplete { prefix, base: this.base, pos - }).provideCompletions(this.editor, options, function(err, completions, finished) { - var filtered = completions.filtered; - var prefix = util.getCompletionPrefix(this.editor); - - if (finished) { - // No results - if (!filtered.length) - return this.detach(); - - // One result equals to the prefix - if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet) - return this.detach(); - } - this.completions = completions; - this.$open(this.editor, prefix); - }.bind(this)); + // @ts-ignore + }).provideCompletions(this.editor, options, + /** + * @this {InlineAutocomplete} + */ + function(err, completions, finished) { + var filtered = completions.filtered; + var prefix = util.getCompletionPrefix(this.editor); + + if (finished) { + // No results + if (!filtered.length) + return this.detach(); + + // One result equals to the prefix + if (filtered.length == 1 && filtered[0].value == prefix && !filtered[0].snippet) + return this.detach(); + } + this.completions = completions; + //@ts-expect-error TODO: potential wrong arguments + this.$open(this.editor, prefix); + }.bind(this)); } detach() { @@ -281,8 +323,15 @@ class InlineAutocomplete { this.inlineTooltip = this.editor = this.inlineRenderer = null; } + updateDocTooltip(){ + } + } +/** + * + * @type {{[key: string]: import("../../ace").Ace.Command}} + */ InlineAutocomplete.prototype.commands = { "Previous": { bindKey: "Alt-[", @@ -302,7 +351,7 @@ InlineAutocomplete.prototype.commands = { bindKey: { win: "Tab|Ctrl-Right", mac: "Tab|Cmd-Right" }, name: "Accept", exec: function(editor) { - return editor.completer.insertMatch(); + return /**@type{InlineAutocomplete}*/(editor.completer).insertMatch(); } }, "Close": { @@ -359,11 +408,15 @@ require("../config").defineOptions(Editor.prototype, "editor", { * Factory method to create a command bar tooltip for inline autocomplete. * * @param {HTMLElement} parentEl The parent element where the tooltip HTML elements will be added. - * @returns {CommandBarTooltip} The command bar tooltip for inline autocomplete + * @returns {ICommandBarTooltip} The command bar tooltip for inline autocomplete */ InlineAutocomplete.createInlineTooltip = function(parentEl) { + /** + * @type {ICommandBarTooltip} + */ var inlineTooltip = new CommandBarTooltip(parentEl); - inlineTooltip.registerCommand("Previous", + inlineTooltip.registerCommand("Previous", + // @ts-expect-error Object.assign({}, InlineAutocomplete.prototype.commands["Previous"], { enabled: true, type: "button", @@ -372,20 +425,24 @@ InlineAutocomplete.createInlineTooltip = function(parentEl) { ); inlineTooltip.registerCommand("Position", { enabled: false, - getValue: function(editor) { - return editor ? [editor.completer.getIndex() + 1, editor.completer.getLength()].join("/") : ""; + getValue: function (editor) { + return editor ? [/**@type{InlineAutocomplete}*/ + (editor.completer).getIndex() + 1, /**@type{InlineAutocomplete}*/(editor.completer).getLength() + ].join("/") : ""; }, type: "text", cssClass: "completion_position" }); - inlineTooltip.registerCommand("Next", + inlineTooltip.registerCommand("Next", + // @ts-expect-error Object.assign({}, InlineAutocomplete.prototype.commands["Next"], { enabled: true, type: "button", iconCssClass: "ace_arrow" }) ); - inlineTooltip.registerCommand("Accept", + inlineTooltip.registerCommand("Accept", + // @ts-expect-error Object.assign({}, InlineAutocomplete.prototype.commands["Accept"], { enabled: function(editor) { return !!editor && editor.completer.getIndex() >= 0; diff --git a/src/ext/language_tools.js b/src/ext/language_tools.js index 5aeb2f3c11b..b6d7ba35e50 100644 --- a/src/ext/language_tools.js +++ b/src/ext/language_tools.js @@ -7,6 +7,9 @@ var lang = require("../lib/lang"); var util = require("../autocomplete/util"); var textCompleter = require("../autocomplete/text_completer"); +/** + * @type {import("../../ace").Ace.Completer} + */ var keyWordCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { if (session.$mode.completer) { @@ -31,7 +34,9 @@ var transformSnippetTooltip = function(str) { return record[p1]; }); }; - +/** + * @type {import("../../ace").Ace.Completer} + */ var snippetCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { var scopes = []; diff --git a/src/ext/menu_tools/get_editor_keyboard_shortcuts.js b/src/ext/menu_tools/get_editor_keyboard_shortcuts.js index b920e945ce2..a000e5a914d 100644 --- a/src/ext/menu_tools/get_editor_keyboard_shortcuts.js +++ b/src/ext/menu_tools/get_editor_keyboard_shortcuts.js @@ -35,7 +35,7 @@ module.exports.getEditorKeybordShortcuts = function(editor) { var keybindings = []; var commandMap = {}; editor.keyBinding.$handlers.forEach(function(handler) { - var ckb = handler.commandKeyBinding; + var ckb = handler["commandKeyBinding"]; for (var i in ckb) { var key = i.replace(/(^|-)\w/g, function(x) { return x.toUpperCase(); }); var commands = ckb[i]; diff --git a/src/ext/prompt.js b/src/ext/prompt.js index 259cea54f36..32aeee130b4 100644 --- a/src/ext/prompt.js +++ b/src/ext/prompt.js @@ -45,12 +45,13 @@ var openPrompt; * Prompt plugin is used for getting input from user. * * @param {IEditor} editor Ouside editor related to this prompt. Will be blurred when prompt is open. - * @param {String} message Predefined value of prompt input box. + * @param {String | Partial} message Predefined value of prompt input box. * @param {Partial} options Cusomizable options for this prompt. * @param {Function} [callback] Function called after done. * */ function prompt(editor, message, options, callback) { if (typeof message == "object") { + // @ts-ignore return prompt(editor, "", message, options); } if (openPrompt) { @@ -66,6 +67,9 @@ function prompt(editor, message, options, callback) { var cmdLine = $singleLineEditor(); cmdLine.session.setUndoManager(new UndoManager()); + /** + * @type {any} + */ var el = dom.buildDom(["div", {class: "ace_prompt_container" + (options.hasDescription ? " input-box-with-description" : "")}]); var overlay = overlayPage(editor, el, done); el.appendChild(cmdLine.container); @@ -100,8 +104,8 @@ function prompt(editor, message, options, callback) { popup.setRow(-1); popup.on("click", function(e) { var data = popup.getData(popup.getRow()); - if (!data.error) { - cmdLine.setValue(data.value || data.name || data); + if (!data["error"]) { + cmdLine.setValue(data.value || data["name"] || data); accept(); e.stop(); } @@ -120,6 +124,9 @@ function prompt(editor, message, options, callback) { } if (options.hasDescription) { + /** + * @type {any} + */ var promptTextContainer = dom.buildDom(["div", {class: "ace_prompt_text_container"}]); dom.buildDom(options.prompt || "Press 'Enter' to confirm or 'Escape' to cancel", promptTextContainer); el.appendChild(promptTextContainer); @@ -135,7 +142,7 @@ function prompt(editor, message, options, callback) { val = cmdLine.getValue(); } var curData = popup ? popup.getData(popup.getRow()) : val; - if (curData && !curData.error) { + if (curData && !curData["error"]) { done(); options.onAccept && options.onAccept({ value: val, @@ -194,7 +201,7 @@ function prompt(editor, message, options, callback) { function valueFromRecentList() { var current = popup.getData(popup.getRow()); - if (current && !current.error) + if (current && !current["error"]) return current.value || current.caption || current; } @@ -241,9 +248,9 @@ prompt.gotoLine = function(editor, callback) { selection: [1, Number.MAX_VALUE], onAccept: function(data) { var value = data.value; - var _history = prompt.gotoLine._history; + var _history = prompt.gotoLine["_history"]; if (!_history) - prompt.gotoLine._history = _history = []; + prompt.gotoLine["_history"] = _history = []; if (_history.indexOf(value) != -1) _history.splice(_history.indexOf(value), 1); _history.unshift(value); @@ -298,9 +305,9 @@ prompt.gotoLine = function(editor, callback) { editor.renderer.animateScrolling(scrollTop); }, history: function() { - if (!prompt.gotoLine._history) + if (!prompt.gotoLine["_history"]) return []; - return prompt.gotoLine._history; + return prompt.gotoLine["_history"]; }, getCompletions: function(cmdLine) { @@ -340,8 +347,8 @@ prompt.commands = function(editor, callback) { var commandsByName = []; var commandMap = {}; editor.keyBinding.$handlers.forEach(function(handler) { - var platform = handler.platform; - var cbn = handler.byName; + var platform = handler["platform"]; + var cbn = handler["byName"]; for (var i in cbn) { var key = cbn[i].bindKey; if (typeof key !== "string") { @@ -401,10 +408,10 @@ prompt.commands = function(editor, callback) { if (this.maxHistoryCount > 0 && history.length > this.maxHistoryCount) { history.splice(history.length - 1, 1); } - prompt.commands.history = history; + prompt.commands["history"] = history; }, history: function() { - return prompt.commands.history || []; + return prompt.commands["history"] || []; }, getPrefix: function(cmdLine) { var currentPos = cmdLine.getCursorPosition(); @@ -464,6 +471,9 @@ prompt.commands = function(editor, callback) { * @param {Function} [callback] */ prompt.modes = function(editor, callback) { + /** + * @type {any[]} + */ var modesArray = modelist.modes; modesArray = modesArray.map(function(item) { return {value: item.caption, mode: item.name}; diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index 729ce9ed947..9ebb2411fda 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -47,6 +47,9 @@ class SearchBox { ["span", {action: "searchInSelection", class: "ace_button", title: nls("Search In Selection")}, "S"] ] ], div); + /** + * @type {any} + */ this.element = div.firstChild; this.setSession = this.setSession.bind(this); @@ -62,6 +65,9 @@ class SearchBox { setEditor(editor) { editor.searchBox = this; editor.renderer.scroller.appendChild(this.element); + /** + * @type {IEditor} + */ this.editor = editor; } @@ -134,6 +140,7 @@ class SearchBox { if (action && _this[action]) _this[action](); else if (_this.$searchBarKb.commands[action]) + // @ts-expect-error this could be different command type _this.$searchBarKb.commands[action].exec(_this); event.stopPropagation(e); }); @@ -142,6 +149,7 @@ class SearchBox { var keyString = keyUtil.keyCodeToString(keyCode); var command = _this.$searchBarKb.findKeyCommand(hashId, keyString); if (command && command.exec) { + // @ts-expect-error this could be different command type command.exec(_this); event.stopEvent(e); } @@ -214,6 +222,9 @@ class SearchBox { preventScroll: preventScroll, range: this.searchRange }); + /** + * @type {any} + */ var noMatch = !range && this.searchInput.value; dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); this.editor._emit("findSearchBox", { match: !noMatch }); @@ -264,6 +275,9 @@ class SearchBox { caseSensitive: this.caseSensitiveOption.checked, wholeWord: this.wholeWordOption.checked }); + /** + * @type {any} + */ var noMatch = !range && this.searchInput.value; dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); this.editor._emit("findSearchBox", { match: !noMatch }); diff --git a/src/ext/settings_menu.js b/src/ext/settings_menu.js index ea959b52816..a839cc3a31d 100644 --- a/src/ext/settings_menu.js +++ b/src/ext/settings_menu.js @@ -33,6 +33,7 @@ function showSettingsMenu(editor) { options.render(); options.container.id = "ace_settingsmenu"; overlayPage(editor, options.container); + // @ts-ignore options.container.querySelector("select,input,button,checkbox").focus(); } } diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index 175a5404e60..f3c2bf0fd98 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -96,6 +96,9 @@ var highlight = function(el, opts, callback) { if (el.firstElementChild) { var textLen = 0; for (var i = 0; i < el.childNodes.length; i++) { + /** + * @type {any} + */ var ch = el.childNodes[i]; if (ch.nodeType == 3) { textLen += ch.data.length; @@ -113,6 +116,10 @@ var highlight = function(el, opts, callback) { highlight.render(data, mode, theme, opts.firstLineNumber, !opts.showGutter, function (highlighted) { dom.importCssString(highlighted.css, "ace_highlight"); el.innerHTML = highlighted.html; + /** + * TODO: check if child exists + * @type {any} + */ var container = el.firstChild.firstChild; for (var i = 0; i < nodes.length; i += 2) { var pos = highlighted.session.doc.indexToPosition(nodes[i]); diff --git a/src/ext/statusbar.js b/src/ext/statusbar.js index 8d0006a54d1..61d97d1ff66 100644 --- a/src/ext/statusbar.js +++ b/src/ext/statusbar.js @@ -36,7 +36,7 @@ class StatusBar{ function add(str, separator) { str && status.push(str, separator || "|"); } - + // @ts-expect-error TODO: potential wrong argument add(editor.keyBinding.getStatusText(editor)); if (editor.commands.recording) add("REC"); diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index 13a7f55ee0c..a244d19113b 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -12,12 +12,18 @@ class MultiHashHandler { $init(config, platform, $singleCommand) { this.platform = platform || (useragent.isMac ? "mac" : "win"); + /** + * @type {Record} + */ this.commands = {}; this.commandKeyBinding = {}; this.addCommands(config); this.$singleCommand = $singleCommand; } + /** + * @param {import("../../ace").Ace.Command} command + */ addCommand(command) { if (this.commands[command.name]) this.removeCommand(command); @@ -28,6 +34,10 @@ class MultiHashHandler { this._buildKeyHash(command); } + /** + * @param {import("../../ace").Ace.Command | string} command + * @param {boolean} [keepCommand] + */ removeCommand(command, keepCommand) { var name = command && (typeof command === 'string' ? command : command.name); command = this.commands[name]; @@ -52,6 +62,11 @@ class MultiHashHandler { } } + /** + * @param {string | { win?: string; mac?: string; position?:number}} key + * @param {import("../../ace").Ace.CommandLike | string} command + * @param {number} [position] + */ bindKey(key, command, position) { if (typeof key == "object" && key) { if (position == undefined) @@ -61,9 +76,9 @@ class MultiHashHandler { if (!key) return; if (typeof command == "function") - return this.addCommand({exec: command, bindKey: key, name: command.name || key}); + return this.addCommand({exec: command, bindKey: key, name: command.name || /**@type{string}*/(key)}); - key.split("|").forEach(function(keyPart) { + /**@type{string}*/(key).split("|").forEach(function(keyPart) { var chain = ""; if (keyPart.indexOf(" ") != -1) { var parts = keyPart.split(/\s+/); @@ -81,7 +96,12 @@ class MultiHashHandler { this._addCommandToBinding(chain + id, command, position); }, this); } - + + /** + * @param {string} keyId + * @param {any} command + * @param {number} position + */ _addCommandToBinding(keyId, command, position) { var ckb = this.commandKeyBinding, i; if (!command) { @@ -110,6 +130,9 @@ class MultiHashHandler { } } + /** + * @param {Record | import("../../ace").Ace.Command[]} commands + */ addCommands(commands) { commands && Object.keys(commands).forEach(function(name) { var command = commands[name]; @@ -132,12 +155,18 @@ class MultiHashHandler { }, this); } + /** + * @param {Record} commands + */ removeCommands(commands) { Object.keys(commands).forEach(function(name) { this.removeCommand(commands[name]); }, this); } + /** + * @param {Record} keyList + */ bindKeys(keyList) { Object.keys(keyList).forEach(function(key) { this.bindKey(key, keyList[key]); @@ -148,8 +177,12 @@ class MultiHashHandler { this.bindKey(command.bindKey, command); } - // accepts keys in the form ctrl+Enter or ctrl-Enter - // keys without modifiers or shift only + /** + * Accepts keys in the form ctrl+Enter or ctrl-Enter + * keys without modifiers or shift only + * @param {string} keys + * @returns {{key: string, hashId: number} | false} + */ parseKeys(keys) { var parts = keys.toLowerCase().split(/[\-\+]([\-\+])?/).filter(function(x){return x;}); var key = parts.pop(); @@ -175,11 +208,23 @@ class MultiHashHandler { return {key: key, hashId: hashId}; } + /** + * @param {number} hashId + * @param {string} keyString + * @returns {import("../../ace").Ace.Command} + */ findKeyCommand(hashId, keyString) { var key = KEY_MODS[hashId] + keyString; return this.commandKeyBinding[key]; } + /** + * @param {{ $keyChain: string | any[]; }} data + * @param {number} hashId + * @param {string} keyString + * @param {number} keyCode + * @returns {{command: string} | void} + */ handleKeyboard(data, hashId, keyString, keyCode) { if (keyCode < 0) return; var key = KEY_MODS[hashId] + keyString; @@ -204,7 +249,12 @@ class MultiHashHandler { } return {command: command}; } - + + /** + * @param {any} [editor] + * @param {any} [data] + * @returns {string} + */ getStatusText(editor, data) { return data.$keyChain || ""; } diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 454ebebc093..48a4945c507 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -11,16 +11,25 @@ class KeyBinding { constructor(editor) { this.$editor = editor; this.$data = {editor: editor}; + /** + * @type {(import("../../ace").Ace.KeyboardHandler)[]} + */ this.$handlers = []; this.setDefaultHandler(editor.commands); } - + + /** + * @param {import("../../ace").Ace.KeyboardHandler} kb + */ setDefaultHandler(kb) { this.removeKeyboardHandler(this.$defaultHandler); this.$defaultHandler = kb; this.addKeyboardHandler(kb, 0); } + /** + * @param {import("../../ace").Ace.KeyboardHandler} kb + */ setKeyboardHandler(kb) { var h = this.$handlers; if (h[h.length - 1] == kb) @@ -32,10 +41,16 @@ class KeyBinding { this.addKeyboardHandler(kb, 1); } + /** + * @param {import("../../ace").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] + * @param {number} [pos] + */ addKeyboardHandler(kb, pos) { if (!kb) return; + // @ts-ignore if (typeof kb == "function" && !kb.handleKeyboard) + // @ts-ignore kb.handleKeyboard = kb; var i = this.$handlers.indexOf(kb); if (i != -1) @@ -50,6 +65,10 @@ class KeyBinding { kb.attach(this.$editor); } + /** + * @param {import("../../ace").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb + * @returns {boolean} + */ removeKeyboardHandler(kb) { var i = this.$handlers.indexOf(kb); if (i == -1) @@ -59,6 +78,9 @@ class KeyBinding { return true; } + /** + * @return {import("../../ace").Ace.KeyboardHandler} + */ getKeyboardHandler() { return this.$handlers[this.$handlers.length - 1]; } @@ -78,6 +100,7 @@ class KeyBinding { for (var i = this.$handlers.length; i--;) { toExecute = this.$handlers[i].handleKeyboard( + // @ts-expect-error TODO: could be wrong arguments amount this.$data, hashId, keyString, keyCode, e ); if (!toExecute || !toExecute.command) @@ -87,11 +110,12 @@ class KeyBinding { if (toExecute.command == "null") { success = true; } else { + // @ts-expect-error //TODO: potential wrong arguments amount success = commands.exec(toExecute.command, this.$editor, toExecute.args, e); } // do not stop input events to not break repeating if (success && e && hashId != -1 && - toExecute.passEvent != true && toExecute.command.passEvent != true + toExecute["passEvent"] != true && toExecute.command["passEvent"] != true ) { event.stopEvent(e); } @@ -110,11 +134,21 @@ class KeyBinding { return success; } + /** + * @param {any} e + * @param {number} hashId + * @param {number} keyCode + * @return {boolean} + */ onCommandKey(e, hashId, keyCode) { var keyString = keyUtil.keyCodeToString(keyCode); return this.$callKeyboardHandlers(hashId, keyString, keyCode, e); } + /** + * @param {string} text + * @return {boolean} + */ onTextInput(text) { return this.$callKeyboardHandlers(-1, text); } diff --git a/src/keyboard/textarea.js b/src/keyboard/textarea.js index 88936fd6c84..433f5ed093a 100644 --- a/src/keyboard/textarea.js +++ b/src/keyboard/textarea.js @@ -52,4 +52,4 @@ exports.handler = new HashHandler(); bindKey = bindKey[exports.handler.platform]; exports.handler.bindKey(bindKey, k.command); }); -exports.handler.$id = "ace/keyboard/textarea"; +exports.handler["$id"] = "ace/keyboard/textarea"; diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index 9727cbe0ee1..eb365b4db7d 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -153,7 +153,7 @@ TextInput= function(parentNode, host) { ancestors.push(t); t.setAttribute("ace_nocontext", "true"); if (!t.parentElement && t.getRootNode) - t = t.getRootNode().host; + t = t.getRootNode()["host"]; else t = t.parentElement; } diff --git a/src/layer/cursor.js b/src/layer/cursor.js index 3b369cdce38..096dbf8095d 100644 --- a/src/layer/cursor.js +++ b/src/layer/cursor.js @@ -4,6 +4,7 @@ var dom = require("../lib/dom"); class Cursor { + /**@type{number}*/timeoutId; constructor(parentEl) { this.element = dom.createElement("div"); this.element.className = "ace_layer ace_cursor-layer"; @@ -133,7 +134,7 @@ class Cursor { if (dom.HAS_CSS_ANIMATION) { this.$startCssAnimation(); } else { - var blink = function(){ + var blink = /**@this{Cursor}*/function(){ this.timeoutId = setTimeout(function() { update(false); }, 0.6 * this.blinkInterval); diff --git a/src/layer/font_metrics.js b/src/layer/font_metrics.js index abf6ebf07a4..e9583e0f8ce 100644 --- a/src/layer/font_metrics.js +++ b/src/layer/font_metrics.js @@ -152,7 +152,7 @@ class FontMetrics { $getZoom(element) { if (!element || !element.parentElement) return 1; - return (window.getComputedStyle(element).zoom || 1) * this.$getZoom(element.parentElement); + return (window.getComputedStyle(element)["zoom"] || 1) * this.$getZoom(element.parentElement); } $initTransformMeasureNodes() { diff --git a/src/layer/gutter.js b/src/layer/gutter.js index aab11c6e3cb..c6ecb82ffc7 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -190,7 +190,7 @@ class Gutter{ gutterWidth += padding.left + padding.right; if (gutterWidth !== this.gutterWidth && !isNaN(gutterWidth)) { this.gutterWidth = gutterWidth; - this.element.parentNode.style.width = + /**@type{any}*/(this.element.parentNode).style.width = this.element.style.width = Math.ceil(this.gutterWidth) + "px"; this._signal("changeGutterWidth", gutterWidth); } @@ -317,7 +317,7 @@ class Gutter{ /** * @param {any} cell * @param {import("../../ace").Ace.LayerConfig} config - * @param {import("../edit_session/fold").Fold} [fold] //TODO: + * @param {import("../../ace").Ace.IRange | undefined} fold * @param {number} row * @this {IGutter} */ @@ -534,7 +534,7 @@ class Gutter{ $computePadding() { if (!this.element.firstChild) return {left: 0, right: 0}; - var style = dom.computedStyle(this.element.firstChild); + var style = dom.computedStyle(/**@type{Element}*/(this.element.firstChild)); this.$padding = {}; this.$padding.left = (parseInt(style.borderLeftWidth) || 0) + (parseInt(style.paddingLeft) || 0) + 1; diff --git a/src/lib/app_config.js b/src/lib/app_config.js index c5cc5d5c4da..a50b809afee 100644 --- a/src/lib/app_config.js +++ b/src/lib/app_config.js @@ -161,7 +161,7 @@ class AppConfig { /** * @param {string} string - * @param {{ [x: string]: any; }} params + * @param {{ [x: string]: any; }} [params] */ nls(string, params) { if (messages && !messages[string]) { diff --git a/src/lib/dom.js b/src/lib/dom.js index fea84547060..6a53ef8ae11 100644 --- a/src/lib/dom.js +++ b/src/lib/dom.js @@ -323,7 +323,7 @@ exports.scrollbarWidth = function(doc) { }; /** - * @param {HTMLElement} element + * @param {Element} element * @param [style] * @returns {Partial} */ diff --git a/src/lib/event.js b/src/lib/event.js index dcc0c5e3b5a..3a8bf6d509d 100644 --- a/src/lib/event.js +++ b/src/lib/event.js @@ -13,6 +13,7 @@ function detectListenerOptionsSupport() { document.createComment("").addEventListener("test", function() {}, { get passive() { activeListenerOptions = {passive: false}; + return true; } }); } catch(e) {} @@ -235,6 +236,7 @@ function normalizeCommandKeys(callback, e, keyCode) { exports.addCommandKeyListener = function(el, callback, destroyer) { + // @ts-expect-error TODO: property is missing in useragent if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) { // Old versions of Gecko aka. Firefox < 4.0 didn't repeat the keydown // event if the user pressed the key for a longer time. Instead, the diff --git a/src/lib/event_emitter.js b/src/lib/event_emitter.js index f5b65e13f21..1169d9ff461 100644 --- a/src/lib/event_emitter.js +++ b/src/lib/event_emitter.js @@ -1,7 +1,6 @@ "use strict"; /** - * @class EventEmitter - * @type {{_eventRegistry?: {}, _defaultHandlers, _emit?, _dispatchEvent?, _signal?, once?, setDefaultHandler?, removeDefaultHandler?, on?, addEventListener?, off?, removeListener?, removeEventListener?, removeAllListeners?, listeners?, getListeners?, listenerCount?, emit?, dispatchEvent?, signal?, setDefaultMaxListeners?, getMaxListeners?, defaultMaxListeners?, eventNames?, init?}} + * @type {any} */ var EventEmitter = {}; var stopPropagation = function() { this.propagationStopped = true; }; @@ -64,6 +63,9 @@ EventEmitter.once = function(eventName, callback) { EventEmitter.setDefaultHandler = function(eventName, callback) { + /** + * @type {any} + */ var handlers = this._defaultHandlers; if (!handlers) handlers = this._defaultHandlers = {_disabled_: {}}; @@ -122,7 +124,9 @@ EventEmitter.removeEventListener = function(eventName, callback) { if (index !== -1) listeners.splice(index, 1); }; - +/** + * @this {EventEmitter} + */ EventEmitter.removeAllListeners = function(eventName) { if (!eventName) this._eventRegistry = this._defaultHandlers = undefined; if (this._eventRegistry) this._eventRegistry[eventName] = undefined; diff --git a/src/lib/fixoldbrowsers.js b/src/lib/fixoldbrowsers.js index 86b576f4e05..4024243ed6c 100644 --- a/src/lib/fixoldbrowsers.js +++ b/src/lib/fixoldbrowsers.js @@ -12,4 +12,5 @@ "use strict"; +// @ts-ignore require("./es6-shim"); diff --git a/src/lib/useragent.js b/src/lib/useragent.js index 8427c076c3a..31c8df88ca1 100644 --- a/src/lib/useragent.js +++ b/src/lib/useragent.js @@ -54,7 +54,8 @@ exports.isOldIE = exports.isIE && exports.isIE < 9; exports.isGecko = exports.isMozilla = ua.match(/ Gecko\/\d+/); // Is this Opera -exports.isOpera = typeof opera == "object" && Object.prototype.toString.call(window.opera) == "[object Opera]"; +// @ts-expect-error +exports.isOpera = typeof opera == "object" && Object.prototype.toString.call(window["opera"]) == "[object Opera]"; // Is the user using a browser that identifies itself as WebKit exports.isWebKit = parseFloat(ua.split("WebKit/")[1]) || undefined; @@ -69,7 +70,7 @@ exports.isAndroid = ua.indexOf("Android") >= 0; exports.isChromeOS = ua.indexOf(" CrOS ") >= 0; -exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window.MSStream; +exports.isIOS = /iPad|iPhone|iPod/.test(ua) && !window["MSStream"]; if (exports.isIOS) exports.isMac = true; diff --git a/src/marker_group.js b/src/marker_group.js index 2484a01e773..14679f1bb01 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -17,7 +17,6 @@ Potential improvements: class MarkerGroup { /** - * * @param {IEditSession} session */ constructor(session) { @@ -26,6 +25,7 @@ class MarkerGroup { * @type {IEditSession} */ this.session = session; + // @ts-expect-error TODO: could potential error here, or most likely missing checks in other places session.addDynamicMarker(this); } diff --git a/src/mode/behaviour.js b/src/mode/behaviour.js index c62b0fe1582..d32ca895625 100644 --- a/src/mode/behaviour.js +++ b/src/mode/behaviour.js @@ -1,11 +1,21 @@ "use strict"; +/** + * @typedef {Behaviour & {[key: string]: any}} IBehaviour + */ -var Behaviour = function() { +/** + * @type {any} + */ +var Behaviour; +Behaviour = function() { this.$behaviours = {}; }; (function () { + /** + * @this {Behaviour & this} + */ this.add = function (name, action, callback) { switch (undefined) { case this.$behaviours: @@ -15,7 +25,10 @@ var Behaviour = function() { } this.$behaviours[name][action] = callback; }; - + + /** + * @this {Behaviour & this} + */ this.addBehaviours = function (behaviours) { for (var key in behaviours) { for (var action in behaviours[key]) { @@ -23,13 +36,19 @@ var Behaviour = function() { } } }; - + + /** + * @this {Behaviour & this} + */ this.remove = function (name) { if (this.$behaviours && this.$behaviours[name]) { delete this.$behaviours[name]; } }; - + + /** + * @this {Behaviour & this} + */ this.inherit = function (mode, filter) { if (typeof mode === "function") { var behaviours = new mode().getBehaviours(filter); @@ -38,7 +57,13 @@ var Behaviour = function() { } this.addBehaviours(behaviours); }; - + + /** + * + * @param [filter] + * @returns {{}|*} + * @this {Behaviour & this} + */ this.getBehaviours = function (filter) { if (!filter) { return this.$behaviours; diff --git a/src/mode/behaviour/cstyle.js b/src/mode/behaviour/cstyle.js index ab6c9534968..12f545ec428 100644 --- a/src/mode/behaviour/cstyle.js +++ b/src/mode/behaviour/cstyle.js @@ -1,5 +1,4 @@ "use strict"; - var oop = require("../../lib/oop"); var Behaviour = require("../behaviour").Behaviour; var TokenIterator = require("../../token_iterator").TokenIterator; @@ -53,7 +52,8 @@ var getWrapped = function(selection, selected, opening, closing) { * @param {boolean} [options.braces] - Whether to force braces auto-pairing. * @param {boolean} [options.closeDocComment] - enables automatic insertion of closing tags for documentation comments. */ -var CstyleBehaviour = function(options) { +var CstyleBehaviour; +CstyleBehaviour = function(options) { options = options || {}; this.add("braces", "insertion", function(state, action, editor, session, text) { var cursor = editor.getCursorPosition(); @@ -337,7 +337,10 @@ var CstyleBehaviour = function(options) { } }; - +/** + * @this {CstyleBehaviour} + */ +// @ts-ignore CstyleBehaviour.isSaneInsertion = function(editor, session) { var cursor = editor.getCursorPosition(); var iterator = new TokenIterator(session, cursor.row, cursor.column); @@ -357,26 +360,25 @@ CstyleBehaviour.isSaneInsertion = function(editor, session) { return iterator.getCurrentTokenRow() !== cursor.row || this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS); }; - -CstyleBehaviour.$matchTokenType = function(token, types) { +CstyleBehaviour["$matchTokenType"] = function(token, types) { return types.indexOf(token.type || token) > -1; }; -CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) { +CstyleBehaviour["recordAutoInsert"] = function(editor, session, bracket) { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); // Reset previous state if text or context changed too much - if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0])) + if (!this["isAutoInsertedClosing"](cursor, line, context.autoInsertedLineEnd[0])) context.autoInsertedBrackets = 0; context.autoInsertedRow = cursor.row; context.autoInsertedLineEnd = bracket + line.substr(cursor.column); context.autoInsertedBrackets++; }; -CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) { +CstyleBehaviour["recordMaybeInsert"] = function(editor, session, bracket) { var cursor = editor.getCursorPosition(); var line = session.doc.getLine(cursor.row); - if (!this.isMaybeInsertedClosing(cursor, line)) + if (!this["isMaybeInsertedClosing"](cursor, line)) context.maybeInsertedBrackets = 0; context.maybeInsertedRow = cursor.row; context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket; @@ -384,26 +386,26 @@ CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) { context.maybeInsertedBrackets++; }; -CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) { +CstyleBehaviour["isAutoInsertedClosing"] = function(cursor, line, bracket) { return context.autoInsertedBrackets > 0 && cursor.row === context.autoInsertedRow && bracket === context.autoInsertedLineEnd[0] && line.substr(cursor.column) === context.autoInsertedLineEnd; }; -CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) { +CstyleBehaviour["isMaybeInsertedClosing"] = function(cursor, line) { return context.maybeInsertedBrackets > 0 && cursor.row === context.maybeInsertedRow && line.substr(cursor.column) === context.maybeInsertedLineEnd && line.substr(0, cursor.column) == context.maybeInsertedLineStart; }; -CstyleBehaviour.popAutoInsertedClosing = function() { +CstyleBehaviour["popAutoInsertedClosing"] = function() { context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1); context.autoInsertedBrackets--; }; -CstyleBehaviour.clearMaybeInsertedClosing = function() { +CstyleBehaviour["clearMaybeInsertedClosing"] = function() { if (context) { context.maybeInsertedBrackets = 0; context.maybeInsertedRow = -1; diff --git a/src/mode/text.js b/src/mode/text.js index ad50a0c3a39..5c5b4e9841e 100644 --- a/src/mode/text.js +++ b/src/mode/text.js @@ -80,6 +80,9 @@ Mode = function() { doc.removeInLine(i, m[1].length, m[0].length); }; + /** + * @type {any} + */ var testRemove = function(line, row) { if (regexpStart.test(line)) return true; @@ -127,6 +130,9 @@ Mode = function() { doc.insertInLine({row: i, column: minIndent}, lineCommentStart); } }; + /** + * @type {any} + */ var testRemove = function(line, i) { return regexpStart.test(line); }; @@ -284,9 +290,11 @@ Mode = function() { (function(scope) { var functionName = delegations[i]; var defaultHandler = scope[functionName]; - scope[delegations[i]] = function() { - return this.$delegator(functionName, arguments, defaultHandler); - }; + scope[delegations[i]] = + /** @this {import("../../ace").Ace.SyntaxMode} */ + function () { + return this.$delegator(functionName, arguments, defaultHandler); + }; }(this)); } }; @@ -343,7 +351,7 @@ Mode = function() { this.getKeywords = function(append) { // this is for autocompletion to pick up regexp'ed keywords if (!this.completionKeywords) { - var rules = this.$tokenizer.rules; + var rules = this.$tokenizer["rules"]; var completionKeywords = []; for (var rule in rules) { var ruleItr = rules[rule]; diff --git a/src/mode/text_highlight_rules.js b/src/mode/text_highlight_rules.js index e44f201f6fe..57cf5901392 100644 --- a/src/mode/text_highlight_rules.js +++ b/src/mode/text_highlight_rules.js @@ -2,7 +2,11 @@ var lang = require("../lib/lang"); -var TextHighlightRules = function() { +/** + * @type {(new() => Partial) & {prototype: import("../../ace").Ace.HighlightRules}} + */ +var TextHighlightRules; +TextHighlightRules = function() { // regexp must not have capturing parentheses // regexps are ordered -> the first match is used @@ -19,6 +23,11 @@ var TextHighlightRules = function() { (function() { + /** + * @param {import("../../ace").Ace.HighlightRulesMap} rules + * @param {string} [prefix] + * @this {import("../../ace").Ace.HighlightRules} + */ this.addRules = function(rules, prefix) { if (!prefix) { for (var key in rules) @@ -42,10 +51,22 @@ var TextHighlightRules = function() { } }; + /** + * @returns {import("../../ace").Ace.HighlightRulesMap} + * @this {import("../../ace").Ace.HighlightRules} + */ this.getRules = function() { return this.$rules; }; + /** + * @param HighlightRules + * @param prefix + * @param escapeRules + * @param states + * @param append + * @this {import("../../ace").Ace.HighlightRules} + */ this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) { var embedRules = typeof HighlightRules == "function" ? new HighlightRules().getRules() @@ -72,6 +93,9 @@ var TextHighlightRules = function() { this.$embeds.push(prefix); }; + /** + * @this {import("../../ace").Ace.HighlightRules} + */ this.getEmbeds = function() { return this.$embeds; }; @@ -87,17 +111,21 @@ var TextHighlightRules = function() { return stack.shift() || "start"; }; + /** + * @this {import("../../ace").Ace.HighlightRules} + */ this.normalizeRules = function() { var id = 0; var rules = this.$rules; function processState(key) { var state = rules[key]; - state.processed = true; + state["processed"] = true; for (var i = 0; i < state.length; i++) { var rule = state[i]; var toInsert = null; if (Array.isArray(rule)) { toInsert = rule; + // @ts-ignore rule = {}; } if (!rule.regex && rule.start) { @@ -158,6 +186,10 @@ var TextHighlightRules = function() { } if (toInsert) { + /** + * @type{any[]} + */ + // @ts-ignore var args = [i, 1].concat(toInsert); if (rule.noEscape) args = args.filter(function(x) {return !x.next;}); @@ -198,6 +230,9 @@ var TextHighlightRules = function() { : function(value) {return keywords[value] || defaultToken; }; }; + /** + * @this {import("../../ace").Ace.HighlightRules} + */ this.getKeywords = function() { return this.$keywords; }; diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index 18acc2c82d1..3eca9da43ef 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -28,8 +28,8 @@ class DefaultHandlers { mouseHandler[x] = this[x]; }, this); - mouseHandler.selectByLines = this.extendSelectionBy.bind(mouseHandler, "getLineRange"); - mouseHandler.selectByWords = this.extendSelectionBy.bind(mouseHandler, "getWordRange"); + mouseHandler["selectByLines"] = this.extendSelectionBy.bind(mouseHandler, "getLineRange"); + mouseHandler["selectByWords"] = this.extendSelectionBy.bind(mouseHandler, "getWordRange"); } /** diff --git a/src/mouse/dragdrop_handler.js b/src/mouse/dragdrop_handler.js index b49536866f5..e482a50c305 100644 --- a/src/mouse/dragdrop_handler.js +++ b/src/mouse/dragdrop_handler.js @@ -357,6 +357,7 @@ function DragdropHandler(mouseHandler) { // IE does not handle [draggable] attribute set after mousedown var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y); if (distance > 3) + // @ts-ignore target.dragDrop(); } if (this.state === "dragWait") { diff --git a/src/mouse/mouse_handler.js b/src/mouse/mouse_handler.js index 926624fa767..2ba9ccdf0be 100644 --- a/src/mouse/mouse_handler.js +++ b/src/mouse/mouse_handler.js @@ -1,6 +1,6 @@ "use strict"; /** - * @typedef {MouseHandler & import("./default_handlers").DefaultHandlers & import("./default_gutter_handler").GutterHandler & import("./dragdrop_handler").DragdropHandler} IMouseHandler + * @typedef {MouseHandler & import("./default_handlers").DefaultHandlers & import("./default_gutter_handler").GutterHandler & import("./dragdrop_handler").DragdropHandler & {cancelDrag?}} IMouseHandler * @export */ @@ -83,7 +83,9 @@ class MouseHandler { } else { renderer.setCursorStyle(""); } - }, editor); + + }, //@ts-expect-error TODO: seems mistyping - should be boolean + editor); } onMouseEvent(name, e) { @@ -102,6 +104,7 @@ class MouseHandler { onMouseWheel(name, e) { var mouseEvent = new MouseEvent(e, this.editor); + //@ts-expect-error TODO: couldn't find this property init in the ace codebase mouseEvent.speed = this.$scrollSpeed * 2; mouseEvent.wheelX = e.wheelX; mouseEvent.wheelY = e.wheelY; diff --git a/src/multi_select.js b/src/multi_select.js index 5146f83ed7e..69fc073cc10 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -759,7 +759,7 @@ var Editor = require("./editor").Editor; for (var i = all.length; i--; ) { var range = all[i]; if (range.isEmpty()) { - var tmp = session.getWordRange(range.start.row, range.start.column); + let tmp = session.getWordRange(range.start.row, range.start.column); range.start.row = tmp.start.row; range.start.column = tmp.start.column; range.end.row = tmp.end.row; diff --git a/src/range_list.js b/src/range_list.js index 22b626cfd97..2ea6d868275 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -143,7 +143,7 @@ class RangeList { var startIndex = this.pointIndex({row: startRow, column: 0}); if (startIndex < 0) startIndex = -startIndex - 1; - //TODO: seems mistake + //@ts-expect-error TODO: potential wrong argument var endIndex = this.pointIndex({row: endRow, column: 0}, startIndex); if (endIndex < 0) endIndex = -endIndex - 1; diff --git a/src/search.js b/src/search.js index 3751ba9a323..58a6ad594f3 100644 --- a/src/search.js +++ b/src/search.js @@ -81,8 +81,8 @@ class Search { var firstRange = null; iterator.forEach(function(sr, sc, er, ec) { firstRange = new Range(sr, sc, er, ec); - if (sc == ec && options.start && options.start.start - && options.skipCurrent != false && firstRange.isEqual(options.start) + if (sc == ec && options.start && /**@type{Range}*/(options.start).start + && options.skipCurrent != false && firstRange.isEqual(/**@type{Range}*/(options.start)) ) { firstRange = null; return false; diff --git a/src/selection.js b/src/selection.js index 0727b823d61..1c7ac6a4823 100644 --- a/src/selection.js +++ b/src/selection.js @@ -32,9 +32,6 @@ var Range = require("./range").Range; * * @event changeSelection **/ -/** - * @type {ISelection} - */ class Selection { /** * Creates a new `Selection` object. @@ -189,7 +186,7 @@ class Selection { /** * Sets the selection to the provided range. - * @param {Range} range The range of text to select + * @param {import("../ace").Ace.IRange} range The range of text to select * @param {Boolean} [reverse] Indicates if the range should go backwards (`true`) or not * @this {ISelection} **/ @@ -359,6 +356,7 @@ class Selection { /** * Selects an entire word boundary. + * @this {ISelection} **/ selectWord() { this.setSelectionRange(this.getWordRange()); @@ -367,6 +365,7 @@ class Selection { /** * Selects a word, including its right whitespace. * @related EditSession.getAWordRange + * @this {ISelection} **/ selectAWord() { var cursor = this.getCursor(); @@ -393,6 +392,7 @@ class Selection { /** * Selects the entire line. + * @this {ISelection} **/ selectLine() { this.setSelectionRange(this.getLineRange()); @@ -869,6 +869,7 @@ class Selection { /** * @param {Range & {desiredColumn?: number}} range + * @this {ISelection} */ fromOrientedRange(range) { this.setSelectionRange(range, range.cursor == range.start); diff --git a/src/snippets.js b/src/snippets.js index c1a06a8c2e4..63e8cb8bddc 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -120,7 +120,7 @@ class SnippetManager { * @return {Tokenizer} */ getTokenizer() { - return SnippetManager.$tokenizer || this.createTokenizer(); + return SnippetManager["$tokenizer"] || this.createTokenizer(); } createTokenizer() { @@ -145,7 +145,7 @@ class SnippetManager { next: "formatString" }; - SnippetManager.$tokenizer = new Tokenizer({ + SnippetManager["$tokenizer"] = new Tokenizer({ start: [ {regex: /\\./, onMatch: function(val, state, stack) { var ch = val[1]; @@ -241,7 +241,7 @@ class SnippetManager { {regex: "([^:}\\\\]|\\\\.)*:?", token: "", next: "formatString"} ] }); - return SnippetManager.$tokenizer; + return SnippetManager["$tokenizer"]; } tokenizeTmSnippet(str, startState) { @@ -384,6 +384,7 @@ class SnippetManager { var tabstopManager = new TabstopManager(editor); var selectionId = editor.inVirtualSelectionMode && editor.selection.index; + //@ts-expect-error TODO: potential wrong arguments tabstopManager.addTabstops(processedSnippet.tabstops, range.start, end, selectionId); } diff --git a/src/split.js b/src/split.js index c534c7dad88..11da0c7badd 100644 --- a/src/split.js +++ b/src/split.js @@ -229,6 +229,7 @@ Split = function(container, theme, splits) { s.setTabSize(session.getTabSize()); s.setUseSoftTabs(session.getUseSoftTabs()); s.setOverwrite(session.getOverwrite()); + // @ts-expect-error TODO: string[] != number[] s.setBreakpoints(session.getBreakpoints()); s.setUseWrapMode(session.getUseWrapMode()); s.setUseWorker(session.getUseWorker()); diff --git a/src/tokenizer.js b/src/tokenizer.js index 9c6b2a55e69..76b47d480f4 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -117,6 +117,7 @@ class Tokenizer { */ $applyToken(str) { var values = this.splitRegex.exec(str).slice(1); + //@ts-ignore var types = this.token.apply(this, values); // required for compatibility with old modes @@ -145,6 +146,7 @@ class Tokenizer { if (!values) return "text"; var tokens = []; + //@ts-ignore var types = this.tokenArray; for (var i = 0, l = types.length; i < l; i++) { if (values[i + 1]) @@ -219,6 +221,9 @@ class Tokenizer { */ getLineTokens(line, startState) { if (startState && typeof startState != "string") { + /** + * @type {any[]} + */ var stack = startState.slice(0); startState = stack[0]; if (startState === "#tmp") { @@ -228,7 +233,7 @@ class Tokenizer { } else var stack = []; - var currentState = startState || "start"; + var currentState = /**@type{string}*/(startState) || "start"; var state = this.states[currentState]; if (!state) { currentState = "start"; diff --git a/src/tokenizer_dev.js b/src/tokenizer_dev.js index 62f6bc62f97..1457f4d198e 100644 --- a/src/tokenizer_dev.js +++ b/src/tokenizer_dev.js @@ -16,6 +16,9 @@ class Tokenizer extends BaseTokenizer { **/ getLineTokens(line, startState) { if (startState && typeof startState != "string") { + /** + * @type {any[]} + */ var stack = startState.slice(0); startState = stack[0]; } else @@ -40,7 +43,10 @@ class Tokenizer extends BaseTokenizer { stateTransitions = []; onStateChange(); } - + + /** + * @type {any} + */ var token = { type: null, value: "", diff --git a/src/tooltip.js b/src/tooltip.js index 0f538f401ee..1ec0750b745 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -167,6 +167,10 @@ exports.Tooltip = Tooltip; class HoverTooltip extends Tooltip { + /** + * @type {number} + */ + row constructor(parentNode=document.body) { super(parentNode); diff --git a/src/undomanager.js b/src/undomanager.js index 7e932e3146c..29e9ddd31a7 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -59,7 +59,7 @@ class UndoManager { /** * - * @param {string} selection + * @param {any} selection * @param {number} [rev] */ addSelection(selection, rev) { diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 3475b6da266..23a5031ae1a 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -33,7 +33,6 @@ dom.importCssString(editorCss, "ace_editor.css", false); /** * The class that is responsible for drawing everything you see on the screen! * @related editor.renderer - * @type {IVirtualRenderer} **/ class VirtualRenderer { /** @@ -196,7 +195,9 @@ class VirtualRenderer { // }; updateCharacterSize() { + // @ts-expect-error TODO: missing property initialization anywhere in codebase if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) { + // @ts-expect-error TODO: missing property initialization anywhere in codebase this.$allowBoldFonts = this.$textLayer.allowBoldFonts; this.setStyle("ace_nobold", !this.$allowBoldFonts); } @@ -1839,12 +1840,15 @@ class VirtualRenderer { /** * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} - * @param {String} [theme] The path to a theme + * @param {String | import("../ace").Ace.Theme} [theme] The path to a theme * @param {() => void} [cb] optional callback * @this {IVirtualRenderer} **/ setTheme(theme, cb) { var _self = this; + /** + * @type {string} + */ this.$themeId = theme; _self._dispatchEvent('themeChange',{theme:theme}); @@ -1855,6 +1859,9 @@ class VirtualRenderer { afterLoad(theme); } + /** + * @param {import("../ace").Ace.Theme} module + */ function afterLoad(module) { if (_self.$themeId != theme) return cb && cb(); diff --git a/src/worker/worker_client.js b/src/worker/worker_client.js index fd4f9022d04..3166374734f 100644 --- a/src/worker/worker_client.js +++ b/src/worker/worker_client.js @@ -1,6 +1,9 @@ // not implemented -exports.WorkerClient = function() { +var WorkerClient; +WorkerClient = function() { this.attachToDocument = function() {}; this.on = function() {}; this.terminate = function() {}; }; + +exports.WorkerClient = WorkerClient; From 6cf736d6e8f0ad4b4af9ed6e5d4004c745fcb67c Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 17 Sep 2023 18:24:44 +0400 Subject: [PATCH 08/36] resolve merge conflicts with new version --- ace.d.ts | 2 +- package.json | 2 +- src/ace.js | 21 +++++++++++---------- src/ext/simple_tokenizer.js | 4 ++-- src/lib/deep_copy.js | 4 ++-- src/lib/report_error.js | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index ce41af09416..2f208b39a32 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -386,7 +386,7 @@ export namespace Ace { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; - exec?: (editor: Editor, args?: any) => void; + exec?: (editor?: Editor, args?: any) => void; isAvailable?: (editor: Editor) => boolean; description?: string, multiSelectAction?: "forEach"|"forEachLine"|Function, diff --git a/package.json b/package.json index 8964a53e280..8d4d34a61b1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "eslint": "^8.20.0", "istanbul": "^0.4.5", "standard-version": "^9.3.2", - "typescript": "^5.3.0-dev.20230817" + "typescript": "^5.2.2" }, "mappings": { "ace": "." diff --git a/src/ace.js b/src/ace.js index 1f594b0a462..053557001c9 100644 --- a/src/ace.js +++ b/src/ace.js @@ -4,14 +4,10 @@ * @namespace Ace **/ /** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").IEditSession} IEditSession */ /** - * - * @typedef IEditor - * @type {import("./editor").IEditor} + * @typedef {import("./editor").IEditor} IEditor */ "use strict"; "include loader_build"; @@ -19,7 +15,13 @@ var dom = require("./lib/dom"); var Range = require("./range").Range; +/** + * @type {any} + */ var EditSession = require("./edit_session").EditSession; +/** + * @type {any} + */ var Editor = require("./editor").Editor; var UndoManager = require("./undomanager").UndoManager; var Renderer = require("./virtual_renderer").VirtualRenderer; @@ -85,16 +87,15 @@ exports.edit = function(el, options) { /** * Creates a new [[EditSession]], and returns the associated [[Document]]. - * @param {import('./document').Document | String} text {:textParam} - * @param {import("./edit_session").TextMode} [mode] {:modeParam} + * @param {import('./document').IDocument | String} text {:textParam} + * @param {import("../ace").Ace.SyntaxMode} [mode] {:modeParam} * @returns {IEditSession} **/ exports.createEditSession = function(text, mode) { /** - * @type {any} + * @type {IEditSession} */ var doc = new EditSession(text, mode); - doc.setUndoManager(new UndoManager()); return doc; }; exports.Range = Range; diff --git a/src/ext/simple_tokenizer.js b/src/ext/simple_tokenizer.js index 04a384762a6..5592f326310 100644 --- a/src/ext/simple_tokenizer.js +++ b/src/ext/simple_tokenizer.js @@ -40,7 +40,7 @@ class SimpleTokenizer { * Result is a list of list of tokens, where each line from the provided content is a separate list of tokens. * * @param {string} content to tokenize - * @param {import("ace-code").Ace.HighlightRules} highlightRules defining the language grammar + * @param {import("../../ace").Ace.HighlightRules} highlightRules defining the language grammar * @returns {import("ace-code/src/ext/simple_tokenizer").TokenizeResult} tokenization result containing a list of token for each of the lines from content */ function tokenize(content, highlightRules) { @@ -59,4 +59,4 @@ function tokenize(content, highlightRules) { module.exports = { tokenize -}; \ No newline at end of file +}; diff --git a/src/lib/deep_copy.js b/src/lib/deep_copy.js index 897bbbdb5db..555b282454b 100644 --- a/src/lib/deep_copy.js +++ b/src/lib/deep_copy.js @@ -4,7 +4,7 @@ exports.deepCopy = function deepCopy(obj) { var copy; if (Array.isArray(obj)) { copy = []; - for (var key = 0; key < obj.length; key++) { + for (let key = 0; key < obj.length; key++) { copy[key] = deepCopy(obj[key]); } return copy; @@ -13,7 +13,7 @@ exports.deepCopy = function deepCopy(obj) { return obj; copy = {}; - for (var key in obj) + for (let key in obj) copy[key] = deepCopy(obj[key]); return copy; }; diff --git a/src/lib/report_error.js b/src/lib/report_error.js index 55f1372bd5b..43225b52fbd 100644 --- a/src/lib/report_error.js +++ b/src/lib/report_error.js @@ -1,7 +1,7 @@ exports.reportError = function reportError(msg, data) { var e = new Error(msg); - e.data = data; + e["data"] = data; if (typeof console == "object" && console.error) console.error(e); setTimeout(function() { throw e; }); From 5d05997c3507520015f0a8b070227a7e120af0df Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 17 Sep 2023 18:29:41 +0400 Subject: [PATCH 09/36] revert demo changes --- demo/webpack/demo.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/demo/webpack/demo.js b/demo/webpack/demo.js index a6a044047ff..c981adb354e 100644 --- a/demo/webpack/demo.js +++ b/demo/webpack/demo.js @@ -1,24 +1,25 @@ "use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -// import ace -var build_1 = require("../../build"); -// import Range from ace (it is also available as ace.Range) -var build_2 = require("../../build/"); -// import modes that you want to include into your main bundle -require("../../build/src-noconflict/mode-javascript"); -// import webpack resolver to dynamically load modes, you need to install file-loader for this to work! -require("../../build/webpack-resolver"); -// if you want to allow dynamic loading of only a few modules use setModuleUrl for each of them manually -/* + +import ace from '../../build' +import {Range} from '../../build/' + import jsWorkerUrl from "file-loader!../../build/src-noconflict/worker-javascript"; +import jsModeUrl from "file-loader!../../build/src-noconflict/worker-javascript"; ace.config.setModuleUrl("ace/mode/javascript_worker", jsWorkerUrl) -*/ -var editor = build_1.default.edit(null, { +ace.config.setModuleUrl("ace/mode/javascript", jsModeUrl) + +import {Mode as JSMode} from "../../build/src-noconflict/mode-javascript" + +console.log(Range.fromPoints({row: 0, column: 0}, {row: 0, column: 1})) +console.log(new Range(0,0,0,1)) + +var editor = ace.edit(null, { maxLines: 50, minLines: 10, value: "var hello = 'world'" + "\n", + // mode: new JSMode(), mode: "ace/mode/javascript", bug: 1 -}); -editor.selection.setRange(new build_2.Range(0, 0, 0, 3)); -document.body.appendChild(editor.container); +}) + +document.body.appendChild(editor.container) From 02c9a3c3b042e2b3ad76ce0e71b504bf0b4821c6 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 17 Sep 2023 19:57:43 +0400 Subject: [PATCH 10/36] fix eslint errors --- src/autocomplete.js | 9 +++++---- src/edit_session.js | 5 +---- src/edit_session/fold.js | 9 +++++---- src/editor.js | 9 ++++----- src/ext/searchbox.js | 5 ++++- src/ext/static_highlight.js | 2 +- src/keyboard/textinput.js | 2 +- src/layer/cursor.js | 2 +- src/line_widgets.js | 24 +++++++++++------------- src/mouse/mouse_event.js | 6 +++--- src/mouse/mouse_handler.js | 10 +++++----- src/range.js | 16 ++++++++-------- src/tokenizer.js | 8 ++++---- src/tooltip.js | 8 ++++---- src/undomanager.js | 9 ++++----- src/virtual_renderer.js | 8 ++++---- version.js | 2 +- 17 files changed, 66 insertions(+), 68 deletions(-) diff --git a/src/autocomplete.js b/src/autocomplete.js index b7cb7fc22ca..cdfc386bc75 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -64,12 +64,13 @@ var destroyCompleter = function(e, editor) { * There is an autocompletion popup, an optional inline ghost text renderer and a docuent tooltip popup inside. */ class Autocomplete { - /** - * @type {IAcePopup} - */ - popup; + constructor() { + /** + * @type {IAcePopup} + */ + this.popup; this.autoInsert = false; this.autoSelect = true; this.autoShown = false; diff --git a/src/edit_session.js b/src/edit_session.js index 76d36e5f811..ada7151613e 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -131,10 +131,7 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; **/ class EditSession { - /** - * @type {IDocument} - */ - doc; + /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index e6f8ff704bf..f65e93bdcb4 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -13,16 +13,17 @@ var RangeList = require("../range_list").RangeList; * Simple fold-data struct. **/ class Fold extends RangeList { - /** - * @type {number} - */ - collapseChildren; + /** * @param {Range} range * @param {any} placeholder */ constructor(range, placeholder) { super(); + /** + * @type {number} + */ + this.collapseChildren; this.foldLine = null; this.placeholder = placeholder; this.range = range; diff --git a/src/editor.js b/src/editor.js index 1a9f7d0f67b..ae1f2e6565c 100644 --- a/src/editor.js +++ b/src/editor.js @@ -55,11 +55,6 @@ var keys = require('./lib/keys'); * Event sessions dealing with the mouse and keyboard are bubbled up from `Document` to the `Editor`, which decides what to do with them. **/ class Editor { - /** - * @type {IEditSession} - */ - session; - /** * Creates a new `Editor` object. * @@ -69,6 +64,10 @@ class Editor { * @this {IEditor} **/ constructor(renderer, session, options) { + /** + * @type {IEditSession} + */ + this.session; this.$toDestroy = []; var container = renderer.getContainerElement(); diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index 9ebb2411fda..ab8cd2993a0 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -16,13 +16,16 @@ var MAX_COUNT = 999; dom.importCssString(searchboxCss, "ace_searchbox", false); class SearchBox { - activeInput; /** * @param {IEditor} editor * @param {undefined} [range] * @param {undefined} [showReplaceForm] */ constructor(editor, range, showReplaceForm) { + /** + * @type {any} + */ + this.activeInput; var div = dom.createElement("div"); dom.buildDom(["div", {class:"ace_search right"}, ["span", {action: "hide", class: "ace_searchbtn_close"}], diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index f3c2bf0fd98..c5b636d27d4 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -11,8 +11,8 @@ var dom = require("../lib/dom"); var escapeHTML = require("../lib/lang").escapeHTML; class Element { - /** @type{string} */className; constructor(type) { + /** @type{string} */this.className; this.type = type; this.style = {}; this.textContent = ""; diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index eb365b4db7d..3a31600e744 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -21,7 +21,7 @@ var isIOS = useragent.isIOS; var valueResetRegex = isIOS ? /\s/ : /\n/; var isMobile = useragent.isMobile; -var TextInput +var TextInput; TextInput= function(parentNode, host) { /** * @type {HTMLTextAreaElement & {msGetInputContext?: () => {compositionStartOffset: number}, getInputContext?: () => {compositionStartOffset: number}}} diff --git a/src/layer/cursor.js b/src/layer/cursor.js index 096dbf8095d..e9fa631c7f7 100644 --- a/src/layer/cursor.js +++ b/src/layer/cursor.js @@ -4,8 +4,8 @@ var dom = require("../lib/dom"); class Cursor { - /**@type{number}*/timeoutId; constructor(parentEl) { + /**@type{number}*/this.timeoutId; this.element = dom.createElement("div"); this.element.className = "ace_layer ace_cursor-layer"; parentEl.appendChild(this.element); diff --git a/src/line_widgets.js b/src/line_widgets.js index 3eababc087b..35b0ecdfdd7 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -13,21 +13,19 @@ var dom = require("./lib/dom"); class LineWidgets { - /** - * @type {import("../ace").Ace.LineWidget[]} - */ - lineWidgets; - /** - * @type {IEditor} - */ - editor; - $useWrapMode; - $wrapData; - /** * @param {IEditSession} session */ constructor(session) { + /** + * @type {import("../ace").Ace.LineWidget[]} + */ + this.lineWidgets; + /** + * @type {IEditor} + */ + this.editor; + this.session = session; this.session.widgetManager = this; this.session.getRowLength = this.getRowLength; @@ -53,10 +51,10 @@ class LineWidgets { h = this.lineWidgets[row] && this.lineWidgets[row].rowCount || 0; else h = 0; - if (!this.$useWrapMode || !this.$wrapData[row]) { + if (!this["$useWrapMode"] || !this["$wrapData"][row]) { return 1 + h; } else { - return this.$wrapData[row].length + 1 + h; + return this["$wrapData"][row].length + 1 + h; } } diff --git a/src/mouse/mouse_event.js b/src/mouse/mouse_event.js index 45daa75284e..21f9c0b8292 100644 --- a/src/mouse/mouse_event.js +++ b/src/mouse/mouse_event.js @@ -7,10 +7,10 @@ var useragent = require("../lib/useragent"); * Custom Ace mouse event */ class MouseEvent { - /** @type {number} */speed; - /** @type {number} */wheelX; - /** @type {number} */wheelY; constructor(domEvent, editor) { + /** @type {number} */this.speed; + /** @type {number} */this.wheelX; + /** @type {number} */this.wheelY; this.domEvent = domEvent; this.editor = editor; diff --git a/src/mouse/mouse_handler.js b/src/mouse/mouse_handler.js index 2ba9ccdf0be..d41dedaa959 100644 --- a/src/mouse/mouse_handler.js +++ b/src/mouse/mouse_handler.js @@ -14,16 +14,16 @@ var addTouchListeners = require("./touch_handler").addTouchListeners; var config = require("../config"); class MouseHandler { - /** @type {boolean} */$dragDelay; - /** @type {boolean} */$dragEnabled; - /** @type {boolean} */$mouseMoved; - /** @type {MouseEvent} */mouseEvent; - /** @type {number} */$focusTimeout; /** * @param {import("../editor").IEditor} editor * @this {IMouseHandler} */ constructor(editor) { + /** @type {boolean} */this.$dragDelay; + /** @type {boolean} */this.$dragEnabled; + /** @type {boolean} */this.$mouseMoved; + /** @type {MouseEvent} */this.mouseEvent; + /** @type {number} */this.$focusTimeout; var _self = this; this.editor = editor; diff --git a/src/range.js b/src/range.js index e11f0fd19ce..107d5816658 100644 --- a/src/range.js +++ b/src/range.js @@ -7,14 +7,6 @@ * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. **/ class Range { - /** - * @type {Number | undefined} - */ - id; - /** - * @type {import("../ace").Ace.Point | undefined} - */ - cursor; /** * Creates a new `Range` object with the given starting and ending rows and columns. * @param {Number} [startRow] The starting row @@ -24,6 +16,14 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { + /** + * @type {Number | undefined} + */ + this.id; + /** + * @type {import("../ace").Ace.Point | undefined} + */ + this.cursor; /** * @type {import("../ace").Ace.Point} */ diff --git a/src/tokenizer.js b/src/tokenizer.js index 6ed5fbd2ef7..400b10b4367 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -7,15 +7,15 @@ var MAX_TOKEN_COUNT = 2000; * This class takes a set of highlighting rules, and creates a tokenizer out of them. For more information, see [the wiki on extending highlighters](https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#wiki-extendingTheHighlighter). **/ class Tokenizer { - /** - * @type {RegExp} - */ - splitRegex; /** * Constructs a new tokenizer based on the given rules and flags. * @param {Object} rules The highlighting rules **/ constructor(rules) { + /** + * @type {RegExp} + */ + this.splitRegex; this.states = rules; this.regExps = {}; diff --git a/src/tooltip.js b/src/tooltip.js index 1ec0750b745..2fc4b2fe610 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -167,12 +167,12 @@ exports.Tooltip = Tooltip; class HoverTooltip extends Tooltip { - /** - * @type {number} - */ - row constructor(parentNode=document.body) { super(parentNode); + /** + * @type {number?} + */ + this.row; this.timeout = undefined; this.lastT = 0; diff --git a/src/undomanager.js b/src/undomanager.js index 29e9ddd31a7..98563cad52c 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -7,15 +7,14 @@ * This object maintains the undo stack for an [[EditSession `EditSession`]]. **/ class UndoManager { - /** - * @type {boolean} - */ - $keepRedoStack; - /** * Resets the current undo state and creates a new `UndoManager`. **/ constructor() { + /** + * @type {boolean} + */ + this.$keepRedoStack; this.$maxRev = 0; this.$fromUndo = false; this.$undoDepth = Infinity; diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 23a5031ae1a..f1365fc9400 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -35,10 +35,6 @@ dom.importCssString(editorCss, "ace_editor.css", false); * @related editor.renderer **/ class VirtualRenderer { - /** - * @type {IEditSession} - */ - session; /** * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`. * @param {Element} [container] The root element of the editor @@ -46,6 +42,10 @@ class VirtualRenderer { * @this {IVirtualRenderer} **/ constructor(container, theme) { + /** + * @type {IEditSession} + */ + this.session; var _self = this; /** * @type {HTMLElement} diff --git a/version.js b/version.js index eaf1e5feaf4..e8e425289c8 100755 --- a/version.js +++ b/version.js @@ -1,4 +1,4 @@ #!/usr/bin/env node var x; x = require('./package'); -console.log(x.version) +console.log(x.version); From 9eb7d72921874a5c5dcea726e488f824b1925416 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 17 Sep 2023 20:49:58 +0400 Subject: [PATCH 11/36] fix bugs --- src/ace.js | 1 + src/autocomplete.js | 9 +++++---- src/mode/text.js | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ace.js b/src/ace.js index 053557001c9..773f6682a0e 100644 --- a/src/ace.js +++ b/src/ace.js @@ -96,6 +96,7 @@ exports.createEditSession = function(text, mode) { * @type {IEditSession} */ var doc = new EditSession(text, mode); + doc.setUndoManager(new UndoManager()); return doc; }; exports.Range = Range; diff --git a/src/autocomplete.js b/src/autocomplete.js index cdfc386bc75..c5accf21711 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -643,15 +643,16 @@ Autocomplete.startCommand = { * This class is responsible for providing completions and inserting them to the editor */ class CompletionProvider { - /** - * @type {FilteredList} - */ - completions; + /** * @param {{pos: import("../ace").Ace.Position, prefix: string}} initialPosition */ constructor(initialPosition) { + /** + * @type {FilteredList} + */ + this.completions; this.initialPosition = initialPosition; this.active = true; } diff --git a/src/mode/text.js b/src/mode/text.js index 5c5b4e9841e..7e0fd1d7393 100644 --- a/src/mode/text.js +++ b/src/mode/text.js @@ -13,7 +13,6 @@ var Range = require("../range").Range; var Mode; Mode = function() { this.HighlightRules = TextHighlightRules; - new this.HighlightRules().getRules(); }; (function() { From d9e9a198726e17d399dec9ebfe3dac0cd0e5d5bc Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 17 Sep 2023 20:59:01 +0400 Subject: [PATCH 12/36] return demo --- demo/webpack/demo.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/demo/webpack/demo.js b/demo/webpack/demo.js index c981adb354e..6ff273d254d 100644 --- a/demo/webpack/demo.js +++ b/demo/webpack/demo.js @@ -1,25 +1,34 @@ "use strict"; +// import ace import ace from '../../build' -import {Range} from '../../build/' +// import Range from ace (it is also available as ace.Range) +import {Range, EditSession} from '../../build/' +// import modes that you want to include into your main bundle +import "../../build/src-noconflict/mode-javascript"; + +// import webpack resolver to dynamically load modes, you need to install file-loader for this to work! +import "../../build/webpack-resolver"; +// if you want to allow dynamic loading of only a few modules use setModuleUrl for each of them manually +/* import jsWorkerUrl from "file-loader!../../build/src-noconflict/worker-javascript"; -import jsModeUrl from "file-loader!../../build/src-noconflict/worker-javascript"; ace.config.setModuleUrl("ace/mode/javascript_worker", jsWorkerUrl) -ace.config.setModuleUrl("ace/mode/javascript", jsModeUrl) - -import {Mode as JSMode} from "../../build/src-noconflict/mode-javascript" - -console.log(Range.fromPoints({row: 0, column: 0}, {row: 0, column: 1})) -console.log(new Range(0,0,0,1)) +*/ var editor = ace.edit(null, { maxLines: 50, minLines: 10, value: "var hello = 'world'" + "\n", - // mode: new JSMode(), mode: "ace/mode/javascript", bug: 1 }) +editor.selection.setRange(new Range(0,0,0,3)) + document.body.appendChild(editor.container) + +/* +import {Mode as JSMode} from "../../build/src-noconflict/mode-javascript" +editor.setMode( new JSMode()) +*/ From cd5ce9a282c2bcea5bad377cf208d45fc26f38ae Mon Sep 17 00:00:00 2001 From: mkslanc Date: Mon, 18 Sep 2023 19:54:30 +0400 Subject: [PATCH 13/36] continue providing types --- src/keyboard/hash_handler.js | 15 ++++++++++++++- src/lib/event.js | 23 +++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index a244d19113b..d3b74707bf5 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -6,10 +6,19 @@ var useragent = require("../lib/useragent"); var KEY_MODS = keyUtil.KEY_MODS; class MultiHashHandler { + /** + * @param {Record | import("../../ace").Ace.Command[]} [config] + * @param {string} [platform] + */ constructor(config, platform) { this.$init(config, platform, false); } + /** + * @param {Record | import("../../ace").Ace.Command[]} config + * @param {string} [platform] + * @param {boolean} [$singleCommand] + */ $init(config, platform, $singleCommand) { this.platform = platform || (useragent.isMac ? "mac" : "win"); /** @@ -131,7 +140,7 @@ class MultiHashHandler { } /** - * @param {Record | import("../../ace").Ace.Command[]} commands + * @param {Record | import("../../ace").Ace.Command[]} [commands] */ addCommands(commands) { commands && Object.keys(commands).forEach(function(name) { @@ -268,6 +277,10 @@ function getPosition(command) { } class HashHandler extends MultiHashHandler { + /** + * @param {Record | import("../../ace").Ace.Command[]} [config] + * @param {string} [platform] + */ constructor(config, platform) { super(config, platform); this.$singleCommand = true; diff --git a/src/lib/event.js b/src/lib/event.js index 3a8bf6d509d..ecf7566cf21 100644 --- a/src/lib/event.js +++ b/src/lib/event.js @@ -35,7 +35,7 @@ EventListener.prototype.destroy = function() { this.elem = this.type = this.callback = undefined; }; -var addListener = exports.addListener = function(elem, type, callback, destroyer) { +var addListener = exports.addListener = function(elem, type, callback, /**@type{any?}*/destroyer) { elem.addEventListener(type, callback, getListenerOptions()); if (destroyer) destroyer.$toDestroy.push(new EventListener(elem, type, callback)); @@ -95,6 +95,12 @@ exports.capture = function(el, eventHandler, releaseCaptureHandler) { return onMouseUp; }; +/** + * + * @param el + * @param callback + * @param [destroyer] + */ exports.addMouseWheelListener = function(el, callback, destroyer) { addListener(el, "wheel", function(e) { var factor = 0.15; @@ -121,6 +127,14 @@ exports.addMouseWheelListener = function(el, callback, destroyer) { }, destroyer); }; +/** + * + * @param elements + * @param timeouts + * @param eventHandler + * @param callbackName + * @param [destroyer] + */ exports.addMultiMouseDownListener = function(elements, timeouts, eventHandler, callbackName, destroyer) { var clicks = 0; var startX, startY, timer; @@ -234,7 +248,12 @@ function normalizeCommandKeys(callback, e, keyCode) { return callback(e, hashId, keyCode); } - +/** + * + * @param el + * @param callback + * @param [destroyer] + */ exports.addCommandKeyListener = function(el, callback, destroyer) { // @ts-expect-error TODO: property is missing in useragent if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) { From 47027a1a3a8d7cfc4f23d94beaddc13c857dd589 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 21 Sep 2023 19:54:29 +0400 Subject: [PATCH 14/36] describe available events for different classes --- ace.d.ts | 154 ++++++++++++++++++++++++++++++++++-- src/ace.js | 2 +- src/anchor.js | 2 +- src/autocomplete/popup.js | 7 +- src/background_tokenizer.js | 2 +- src/document.js | 2 +- src/edit_session.js | 88 +-------------------- src/editor.js | 5 +- src/layer/gutter.js | 2 +- src/layer/text.js | 4 +- src/placeholder.js | 4 +- src/selection.js | 2 +- src/split.js | 10 +-- src/virtual_renderer.js | 51 ++++++++---- 14 files changed, 202 insertions(+), 133 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 2f208b39a32..ce666aba0fa 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -20,6 +20,7 @@ export namespace Ace { type AcePopup = import("./src/autocomplete/popup").IAcePopup; type Config = import("./src/config").IConfig; type AceInline = import("./src/autocomplete/inline").AceInline; + type MouseEvent = import("./src/mouse/mouse_event").MouseEvent; interface Theme { cssClass?: string; @@ -311,29 +312,168 @@ export namespace Ace { enableKeyboardAccessibility: boolean; enableCodeLens: boolean; } + + interface EventsBase { + [key: string]: any; + } + + interface EditSessionEvents { + /** + * Emitted when the document changes. + * @param delta + */ + "change": (delta: Delta) => void; + /** + * Emitted when the tab size changes, via [[EditSession.setTabSize]]. + * @param tabSize + */ + "changeTabSize": (tabSize: number) => void; + /** + * Emitted when the ability to overwrite text changes, via [[EditSession.setOverwrite]]. + * @param overwrite + */ + "changeOverwrite": (overwrite: boolean) => void; + /** + * Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change. + * @param e + */ + "changeBreakpoint": (e: { row: number, breakpoint: boolean }) => void; + /** + * Emitted when a front marker changes. + * @param e + */ + "changeFrontMarker": (e: { row: number, marker: boolean }) => void; + /** + * Emitted when a back marker changes. + * @param e + */ + "changeBackMarker": (e: { row: number, marker: boolean }) => void; + /** + * Emitted when an annotation changes, like through [[EditSession.setAnnotations]]. + * @param e + */ + "changeAnnotation": (e: { row: number, lines: string[] }) => void; + /** + * Emitted when a background tokenizer asynchronously processes new rows. + */ + "tokenizerUpdate": (e: {data: { first: string, last: string }}) => void; + /** + * Emitted when the current mode changes. + * @param e + */ + "changeMode": (e) => void; + /** + * Emitted when the wrap mode changes. + * @param e + */ + "changeWrapMode": (e) => void; + /** + * Emitted when the wrapping limit changes. + * @param e + */ + "changeWrapLimit": (e) => void; + /** + * Emitted when a code fold is added or removed. + * @param e + */ + "changeFold": (e, session: EditSession) => void; + /** + * Emitted when the scroll top changes. + * @param {Number} scrollTop The new scroll top value + **/ + "changeScrollTop": (scrollTop: number) => void; + /** + * Emitted when the scroll left changes. + * @param {Number} scrollLeft The new scroll left value + **/ + "changeScrollLeft": (scrollLeft: number) => void; + "changeEditor": (e: { editor: Editor }) => void; + } + + interface EditorEvents { + "change": () => void; + "changeSelection": () => void; + "input": () => void; + "changeSession": () => void; + "blur": () => void; + "mousedown": (e: MouseEvent) => void; + "mousemove": (e: MouseEvent & {scrollTop?}) => void; + "changeStatus": () => void; + "keyboardActivity": () => void; + "mousewheel": (e: MouseEvent) => void; + "mouseup": (e: MouseEvent) => void; + "beforeEndOperation": (e) => void; + "nativecontextmenu": (e) => void; + "destroy": () => void; + "focus": () => void; + } + + interface AcePopupEvents extends EditorEvents { + "click": (e: MouseEvent) => void; + "show": () => void; + "hide": () => void; + "select": (hide: boolean) => void; + "changeHoverMarker": (e) => void; + } + + interface DocumentEvents { + "change": (e: Delta) => void; + "changeNewLineMode": () => void; + } + + interface AnchorEvents { + "change": (e: { old, value }) => void; + } + + interface BackgroundTokenizerEvents { + "update": (e) => void; + } + + interface SelectionEvents { + "changeCursor": () => void; + "changeSelection": () => void; + } + + interface PlaceHolderEvents { + + } + + interface GutterEvents { + "changeGutterWidth": (width: number) => void; + } + + interface TextEvents { + "changeCharacterSize": (e) => void; + } + + interface VirtualRendererEvents { + "afterRender": (e, renderer: VirtualRenderer) => void; + "beforeRender": (e, renderer: VirtualRenderer) => void; + } - class EventEmitter { - once(name: string, callback: Function): void; + class EventEmitter { + once(name: K, callback: T[K]): void; setDefaultHandler(name: string, callback: Function): void; removeDefaultHandler(name: string, callback: Function): void; - on(name: string, callback: Function, capturing?: boolean): Function; + on(name: K, callback: T[K], capturing?: boolean): T[K]; - addEventListener(name: string, callback: Function, capturing?: boolean): Function; + addEventListener(name: K, callback: T[K], capturing?: boolean): T[K]; - off(name: string, callback: Function): void; + off(name: K, callback: T[K]): void; - removeListener(name: string, callback: Function): void; + removeListener(name: K, callback: T[K]): void; - removeEventListener(name: string, callback: Function): void; + removeEventListener(name: K, callback: T[K]): void; removeAllListeners(name?: string): void; _signal(eventName: string, e: any): void; _emit(eventName: string, e: any): void; + _dispatchEvent(eventName: string, e: any): void; } interface SearchOptions { diff --git a/src/ace.js b/src/ace.js index 773f6682a0e..fc829527afc 100644 --- a/src/ace.js +++ b/src/ace.js @@ -40,7 +40,7 @@ exports.config = require("./config"); /** * Embeds the Ace editor into the DOM, at the element provided by `el`. - * @param {String | Element & {env?, value?}} el Either the id of an element, or the element itself + * @param {String | HTMLElement & {env?, value?}} el Either the id of an element, or the element itself * @param {Object } [options] Options for the editor * @returns {IEditor} **/ diff --git a/src/anchor.js b/src/anchor.js index e90985cd882..eb41209c344 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -5,7 +5,7 @@ */ /** * @typedef IAnchor - * @type {Anchor & import("../ace").Ace.EventEmitter & {markerId?: number}} + * @type {Anchor & import("../ace").Ace.EventEmitter & {markerId?: number}} */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index a18911687ea..79927ed3236 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -6,7 +6,7 @@ */ /** * @typedef IAcePopup - * @type {IEditor & import("../../ace").Ace.AcePopupProperties} + * @type {IEditor & import("../../ace").Ace.AcePopupProperties & import("../../ace").Ace.EventEmitter} * @export */ var Renderer = require("../virtual_renderer").VirtualRenderer; @@ -91,7 +91,7 @@ class AcePopup { popup.$isFocused = true; popup.renderer.$cursorLayer.restartTimer = noop; - popup.renderer.$cursorLayer.element.style.opacity = 0; + popup.renderer.$cursorLayer.element.style.opacity = "0"; popup.renderer.$maxLines = 8; popup.renderer.$keepTextAreaAtCursor = false; @@ -149,6 +149,9 @@ class AcePopup { }); popup.renderer.on("afterRender", function () { var row = popup.getRow(); + /** + * @type {any} + */ var t = popup.renderer.$textLayer; var selected = t.element.childNodes[row - t.config.firstRow]; var el = document.activeElement; // Active element is textarea of main editor diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 5263c6f0c6d..c0e61cc89a9 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -13,7 +13,7 @@ */ /** * @typedef IBackgroundTokenizer - * @type {BackgroundTokenizer & import("../ace").Ace.EventEmitter} + * @type {BackgroundTokenizer & import("../ace").Ace.EventEmitter} */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; diff --git a/src/document.js b/src/document.js index 496a4e781f3..1315a853742 100644 --- a/src/document.js +++ b/src/document.js @@ -1,6 +1,6 @@ "use strict"; /** - * @typedef {Document & import("../ace").Ace.EventEmitter} IDocument + * @typedef {Document & import("../ace").Ace.EventEmitter} IDocument * @export */ /** diff --git a/src/edit_session.js b/src/edit_session.js index ada7151613e..7ea3785bb1b 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IEditSession - * @type {EditSession & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EventEmitter & import("../ace").Ace.EditSessionProperties & import("./edit_session/folding").IFolding & import("./edit_session/bracket_match").BracketMatch} + * @type {EditSession & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EventEmitter & import("../ace").Ace.EditSessionProperties & import("./edit_session/folding").IFolding & import("./edit_session/bracket_match").BracketMatch} * @export */ /** @@ -35,101 +35,16 @@ var Range = require("./range").Range; /** @type {any} */var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer; var SearchHighlight = require("./search_highlight").SearchHighlight; -//{ events -/** - * - * Emitted when the document changes. - * @event change - * @param {Object} e An object containing a `delta` of information about the change. - **/ -/** - * Emitted when the tab size changes, via [[EditSession.setTabSize]]. - * - * @event changeTabSize - **/ -/** - * Emitted when the ability to overwrite text changes, via [[EditSession.setOverwrite]]. - * - * @event changeOverwrite - **/ -/** - * Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change. - * - * @event changeBreakpoint - **/ -/** - * Emitted when a front marker changes. - * - * @event changeFrontMarker - **/ -/** - * Emitted when a back marker changes. - * - * @event changeBackMarker - **/ -/** - * Emitted when an annotation changes, like through [[EditSession.setAnnotations]]. - * - * @event changeAnnotation - **/ -/** - * Emitted when a background tokenizer asynchronously processes new rows. - * @event tokenizerUpdate - * - * @param {Object} e An object containing one property, `"data"`, that contains information about the changing rows - * - **/ -/** - * Emitted when the current mode changes. - * - * @event changeMode - * - **/ -/** - * Emitted when the wrap mode changes. - * - * @event changeWrapMode - * - **/ -/** - * Emitted when the wrapping limit changes. - * - * @event changeWrapLimit - * - **/ -/** - * Emitted when a code fold is added or removed. - * - * @event changeFold - * - **/ - /** - * Emitted when the scroll top changes. - * @event changeScrollTop - * - * @param {Number} scrollTop The new scroll top value - **/ -/** - * Emitted when the scroll left changes. - * @event changeScrollLeft - * - * @param {Number} scrollLeft The new scroll left value - **/ -//} - /** * @typedef TextMode * @type {import("../ace").Ace.SyntaxMode} */ - - /** * Stores all the data about [[Editor `Editor`]] state providing easy way to change editors state. * * `EditSession` can be attached to only one [[Document `Document`]]. Same `Document` can be attached to several `EditSession`s. **/ - class EditSession { @@ -1607,7 +1522,6 @@ class EditSession { * @param [$printMargin] * @returns {Boolean} * @this {IEditSession} - * @private **/ adjustWrapLimit(desiredLimit, $printMargin) { var limits = this.$wrapLimitRange; diff --git a/src/editor.js b/src/editor.js index ae1f2e6565c..a302cc7cde8 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IEditor - * @type {Editor & import("../ace").Ace.EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EditorProperties & import("../ace").Ace.EditorMultiSelectProperties} + * @type {Editor & import("../ace").Ace.EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EditorProperties & import("../ace").Ace.EditorMultiSelectProperties} * @export */ /** @@ -17,7 +17,6 @@ * @typedef ISelection * @type {import("./selection").ISelection} */ - /** * @typedef ICommandManager * @type {import("./commands/command_manager").ICommandManager} @@ -3020,6 +3019,7 @@ config.defineOptions(Editor.prototype, "editor", { this.renderer.placeholderNode.textContent = this.$placeholder || ""; } }.bind(this); + // @ts-ignore this.on("input", this.$updatePlaceholder); } this.$updatePlaceholder(); @@ -3196,5 +3196,4 @@ var relativeNumberRenderer = { this.update(null, editor); } }; - exports.Editor = Editor; diff --git a/src/layer/gutter.js b/src/layer/gutter.js index c6ecb82ffc7..1c8aed85f41 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IGutter - * @type {Gutter & import("../../ace").Ace.EventEmitter & {[key: string]: any}}} + * @type {Gutter & import("../../ace").Ace.EventEmitter & {[key: string]: any}}} */ var dom = require("../lib/dom"); var oop = require("../lib/oop"); diff --git a/src/layer/text.js b/src/layer/text.js index 45a15ac3559..085743c5cc4 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -7,7 +7,7 @@ /** * * @typedef IText - * @type {Text & import("../../ace").Ace.EventEmitter} + * @type {Text & import("../../ace").Ace.EventEmitter} * @export */ var oop = require("../lib/oop"); @@ -45,7 +45,7 @@ class Text { } /** - * @param {string | number} padding + * @param {number} padding */ setPadding(padding) { this.$padding = padding; diff --git a/src/placeholder.js b/src/placeholder.js index 32d0421b5aa..b4777a9fa21 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -3,13 +3,13 @@ * @typedef {import("./edit_session").IEditSession} IEditSession */ /** - * @typedef {PlaceHolder & import("../ace").Ace.EventEmitter} IPlaceHolder + * @typedef {PlaceHolder & import("../ace").Ace.EventEmitter} IPlaceHolder */ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var oop = require("./lib/oop"); -class PlaceHolder { +class PlaceHolder { /** * @param {IEditSession} session * @param {Number} length diff --git a/src/selection.js b/src/selection.js index 1c7ac6a4823..fdd2c53b427 100644 --- a/src/selection.js +++ b/src/selection.js @@ -6,7 +6,7 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; /** * @typedef ISelection - * @type {Selection & import("../ace").Ace.ISelection & import("../ace").Ace.EventEmitter} + * @type {Selection & import("../ace").Ace.ISelection & import("../ace").Ace.EventEmitter} * @export */ /** diff --git a/src/split.js b/src/split.js index 11da0c7badd..dd5940685d5 100644 --- a/src/split.js +++ b/src/split.js @@ -9,19 +9,15 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; /** * @typedef {import("./editor").IEditor} IEditor */ -var Editor = require("./editor").Editor; +/**@type{any}*/var Editor = require("./editor").Editor; var Renderer = require("./virtual_renderer").VirtualRenderer; -/** - * @type {any} - */ -var EditSession = require("./edit_session").EditSession; +/**@type{any}*/var EditSession = require("./edit_session").EditSession; /** * @typedef ISplit * @type {import("../ace").Ace.EventEmitter & {[key: string]: any}} */ - var Split; /** * @constructor @@ -61,7 +57,7 @@ Split = function(container, theme, splits) { el.style.cssText = "position: absolute; top:0px; bottom:0px"; this.$container.appendChild(el); /** - * @type {any} + * @type {IEditor} */ var editor = new Editor(new Renderer(el, this.$theme)); diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index f1365fc9400..564edd87f5a 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1,7 +1,7 @@ "use strict"; /** * @typedef IVirtualRenderer - * @type {VirtualRenderer & EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.VirtualRendererProperties} + * @type {VirtualRenderer & import("../ace").Ace.EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.VirtualRendererProperties} */ /** * @@ -12,9 +12,9 @@ var oop = require("./lib/oop"); var dom = require("./lib/dom"); var lang = require("./lib/lang"); var config = require("./config"); -var GutterLayer = require("./layer/gutter").Gutter; +/**@type{any}*/var GutterLayer = require("./layer/gutter").Gutter; var MarkerLayer = require("./layer/marker").Marker; -var TextLayer = require("./layer/text").Text; +/**@type{any}*/var TextLayer = require("./layer/text").Text; var CursorLayer = require("./layer/cursor").Cursor; var HScrollBar = require("./scrollbar").HScrollBar; var VScrollBar = require("./scrollbar").VScrollBar; @@ -37,7 +37,7 @@ dom.importCssString(editorCss, "ace_editor.css", false); class VirtualRenderer { /** * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`. - * @param {Element} [container] The root element of the editor + * @param {HTMLElement} [container] The root element of the editor * @param {String} [theme] The starting theme * @this {IVirtualRenderer} **/ @@ -47,9 +47,6 @@ class VirtualRenderer { */ this.session; var _self = this; - /** - * @type {HTMLElement} - */ this.container = container || dom.createElement("div"); dom.addCssClass(this.container, "ace_editor"); @@ -62,7 +59,7 @@ class VirtualRenderer { this.$gutter = dom.createElement("div"); this.$gutter.className = "ace_gutter"; this.container.appendChild(this.$gutter); - this.$gutter.setAttribute("aria-hidden", true); + this.$gutter.setAttribute("aria-hidden", "true"); /** * @type {HTMLElement} */ @@ -77,11 +74,16 @@ class VirtualRenderer { this.content.className = "ace_content"; this.scroller.appendChild(this.content); + /** + * @type {import("./layer/gutter").IGutter} + */ this.$gutterLayer = new GutterLayer(this.$gutter); this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this)); this.$markerBack = new MarkerLayer(this.content); - + /** + * @type {import("./layer/text").IText} + */ var textLayer = this.$textLayer = new TextLayer(this.content); this.canvas = textLayer.element; @@ -194,6 +196,9 @@ class VirtualRenderer { // console.log(a.trim()) // }; + /** + * @this {IVirtualRenderer} + */ updateCharacterSize() { // @ts-expect-error TODO: missing property initialization anywhere in codebase if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) { @@ -301,6 +306,7 @@ class VirtualRenderer { /** * Triggers a full update of all the layers, for all the rows. * @param {Boolean} [force] If `true`, forces the changes through + * @this {IVirtualRenderer} **/ updateFull(force) { if (force) @@ -316,6 +322,9 @@ class VirtualRenderer { this.$textLayer.checkForSizeChanges(); } + /** + * @this {IVirtualRenderer} + */ $updateSizeAsync() { if (this.$loop.pending) this.$size.$dirty = true; @@ -552,11 +561,11 @@ class VirtualRenderer { } /** * Identifies whether you want to show the print margin column or not. - * @param {Boolean} showPrintMargin Set to `true` to show the print margin column + * @param {number} printMarginColumn Set to `true` to show the print margin column * @this {IVirtualRenderer} **/ - setPrintMarginColumn(showPrintMargin) { - this.setOption("printMarginColumn", showPrintMargin); + setPrintMarginColumn(printMarginColumn) { + this.setOption("printMarginColumn", printMarginColumn); } /** @@ -768,7 +777,7 @@ class VirtualRenderer { /** * Sets the padding for all the layers. * @param {Number} padding A new padding value (in pixels) - * + * @this {IVirtualRenderer} **/ setPadding(padding) { this.$padding = padding; @@ -786,6 +795,7 @@ class VirtualRenderer { * @param {number} [bottom] * @param {number} [left] * @param {number} [right] + * @this {IVirtualRenderer} */ setScrollMargin(top, bottom, left, right) { var sm = this.scrollMargin; @@ -806,6 +816,7 @@ class VirtualRenderer { * @param {number} [bottom] * @param {number} [left] * @param {number} [right] + * @this {IVirtualRenderer} */ setMargin(top, bottom, left, right) { var sm = this.margin; @@ -1027,6 +1038,7 @@ class VirtualRenderer { } else if (changes & this.CHANGE_CURSOR) { if (this.$highlightGutterLine) + // @ts-expect-error TODO: potential wrong param this.$gutterLayer.updateLineHighlight(config); if (this.$customScrollbar) { this.$scrollDecorator.$updateDecorators(config); @@ -1332,7 +1344,7 @@ class VirtualRenderer { * Scrolls the cursor into the first visibile area of the editor * @param {import("../ace").Ace.Point} [cursor] * @param {number} [offset] - * @param {{ top: any; bottom: any; }} [$viewMargin] + * @param {{ top?: any; bottom?: any; }} [$viewMargin] */ scrollCursorIntoView(cursor, offset, $viewMargin) { // the editor is not visible @@ -1474,7 +1486,7 @@ class VirtualRenderer { * @param {Boolean} center If `true`, centers the editor the to indicated line * @param {Boolean} animate If `true` animates scrolling * @param {() => void} [callback] Function to be called after the animation has finished - * + * @this {IVirtualRenderer} **/ scrollToLine(line, center, animate, callback) { var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); @@ -1522,6 +1534,7 @@ class VirtualRenderer { _self.session.$scrollTop = toValue; function endAnimation() { + // @ts-ignore _self.$timer = clearInterval(_self.$timer); _self.$scrollAnimation = null; _self.$stopAnimation = false; @@ -1732,6 +1745,7 @@ class VirtualRenderer { * @param {String} text A string of text to use * * Sets the inner text of the current composition to `text`. + * @this {IVirtualRenderer} **/ setCompositionText(text) { var cursor = this.session.selection.cursor; @@ -1847,12 +1861,13 @@ class VirtualRenderer { setTheme(theme, cb) { var _self = this; /** - * @type {string} + * @type {any} */ this.$themeId = theme; _self._dispatchEvent('themeChange',{theme:theme}); if (!theme || typeof theme == "string") { + // @ts-ignore var moduleName = theme || this.$options.theme.initialValue; config.loadModule(["theme", moduleName], afterLoad); } else { @@ -1876,7 +1891,9 @@ class VirtualRenderer { ); if (_self.theme) dom.removeCssClass(_self.container, _self.theme.cssClass); - + /** + * @type {any} + */ var padding = "padding" in module ? module.padding : "padding" in (_self.theme || {}) ? 4 : _self.$padding; if (_self.$padding && padding != _self.$padding) From ba40d17acd543942d75a292b3206c9680714b699 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Fri, 22 Sep 2023 17:55:33 +0400 Subject: [PATCH 15/36] improvements in types --- ace.d.ts | 108 ++++++++++++++++++++++++++---------- src/anchor.js | 13 ----- src/autocomplete/popup.js | 2 +- src/background_tokenizer.js | 8 +-- src/document.js | 17 ------ src/edit_session.js | 1 - src/editor.js | 31 ++--------- src/selection.js | 10 ---- 8 files changed, 84 insertions(+), 106 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index ce666aba0fa..a06667e265c 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -90,27 +90,27 @@ export namespace Ace { } interface AcePopupProperties { - setSelectOnHover?: (val: boolean) => void, - setRow?: (line: number) => void, - getRow?: () => number, - getHoveredRow?: () => number, - filterText?: string, - isOpen?: boolean, - isTopdown?: boolean, - autoSelect?: boolean, - data?: Completion[], - setData?: (data: Completion[], filterText: string) => void, - getData?: (row: number) => Completion, - hide?: () => void, - anchor?: "top" | "bottom", - anchorPosition?: Point, - tryShow?: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, - $borderSize?: number, - show?: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, - goTo?: (where: AcePopupNavigation) => void, - getTextLeftOffset?: () => number, - $imageSize?: number, - anchorPos?: any + setSelectOnHover: (val: boolean) => void, + setRow: (line: number) => void, + getRow: () => number, + getHoveredRow: () => number, + filterText: string, + isOpen: boolean, + isTopdown: boolean, + autoSelect: boolean, + data: Completion[], + setData: (data: Completion[], filterText: string) => void, + getData: (row: number) => Completion, + hide: () => void, + anchor: "top" | "bottom", + anchorPosition: Point, + tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, + $borderSize: number, + show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, + goTo: (where: AcePopupNavigation) => void, + getTextLeftOffset: () => number, + $imageSize: number, + anchorPos: any } interface ISelection { [key: string]: any; @@ -165,6 +165,7 @@ export namespace Ace { } interface EditSessionProperties { + doc: Document, $highlightLineMarker?: { start: Point, end: Point, @@ -212,7 +213,7 @@ export namespace Ace { textarea?: HTMLTextAreaElement, $hScrollBarAlwaysVisible?: boolean, $vScrollBarAlwaysVisible?: boolean - $maxLines?: number, + $maxLines?: number | null, $scrollPastEnd?: number, enableKeyboardAccessibility?: boolean, keyboardFocusClassName?: string, @@ -379,23 +380,27 @@ export namespace Ace { "changeFold": (e, session: EditSession) => void; /** * Emitted when the scroll top changes. - * @param {Number} scrollTop The new scroll top value + * @param scrollTop The new scroll top value **/ "changeScrollTop": (scrollTop: number) => void; /** * Emitted when the scroll left changes. - * @param {Number} scrollLeft The new scroll left value + * @param scrollLeft The new scroll left value **/ "changeScrollLeft": (scrollLeft: number) => void; "changeEditor": (e: { editor: Editor }) => void; } interface EditorEvents { - "change": () => void; + "change": (delta: Delta) => void; "changeSelection": () => void; "input": () => void; - "changeSession": () => void; - "blur": () => void; + /** + * Emitted whenever the [[EditSession]] changes. + * @param e An object with two properties, `oldSession` and `session`, that represent the old and new [[EditSession]]s. + **/ + "changeSession": (e: {oldSession: EditSession, session: EditSession}) => void; + "blur": (e) => void; "mousedown": (e: MouseEvent) => void; "mousemove": (e: MouseEvent & {scrollTop?}) => void; "changeStatus": () => void; @@ -406,6 +411,20 @@ export namespace Ace { "nativecontextmenu": (e) => void; "destroy": () => void; "focus": () => void; + /** + * Emitted when text is copied. + * @param text The copied text + **/ + "copy": (text: string) => void; + /** + * Emitted when text is pasted. + **/ + "paste": (text: string, event) => void; + /** + * Emitted when the selection style changes, via [[Editor.setSelectionStyle]]. + * @param data Contains one property, `data`, which indicates the new selection style + **/ + "changeSelectionStyle": (data: "fullLine" | "screenLine" | "text" | "line") => void; } interface AcePopupEvents extends EditorEvents { @@ -417,20 +436,49 @@ export namespace Ace { } interface DocumentEvents { + /** + * Fires whenever the document changes. + * Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available: + * * `"insert"` + * * `range`: the [[Range]] of the change within the document + * * `lines`: the lines being added + * * `"remove"` + * * `range`: the [[Range]] of the change within the document + * * `lines`: the lines being removed + * + **/ "change": (e: Delta) => void; "changeNewLineMode": () => void; } interface AnchorEvents { - "change": (e: { old, value }) => void; + /** + * Fires whenever the anchor position changes. + * Both of these objects have a `row` and `column` property corresponding to the position. + * Events that can trigger this function include [[Anchor.setPosition `setPosition()`]]. + * @param {Object} e An object containing information about the anchor position. It has two properties: + * - `old`: An object describing the old Anchor position + * - `value`: An object describing the new Anchor position + **/ + "change": (e: { old: Point, value: Point }) => void; } interface BackgroundTokenizerEvents { - "update": (e) => void; + /** + * Fires whenever the background tokeniziers between a range of rows are going to be updated. + * @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated. + **/ + "update": (e: {first:number, last:number}) => void; } interface SelectionEvents { + /** + * Emitted when the cursor position changes. + **/ "changeCursor": () => void; + /** + * Emitted when the cursor selection changes. + **/ "changeSelection": () => void; } @@ -526,7 +574,7 @@ export namespace Ace { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; - exec?: (editor?: Editor, args?: any) => void; + exec?: (editor: Editor, args?: any) => void; isAvailable?: (editor: Editor) => boolean; description?: string, multiSelectAction?: "forEach"|"forEachLine"|Function, diff --git a/src/anchor.js b/src/anchor.js index eb41209c344..8c2a9e8056e 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -50,19 +50,6 @@ class Anchor { return this.document; } - /** - * Fires whenever the anchor position changes. - * - * Both of these objects have a `row` and `column` property corresponding to the position. - * - * Events that can trigger this function include [[Anchor.setPosition `setPosition()`]]. - * - * @event change - * @param {Object} e An object containing information about the anchor position. It has two properties: - * - `old`: An object describing the old Anchor position - * - `value`: An object describing the new Anchor position - * - **/ /** * Internal function called when `"change"` event fired. * @param {import("../ace").Ace.Delta} delta diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 79927ed3236..65bfe0f3d73 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -64,9 +64,9 @@ class AcePopup { constructor(parentNode) { var el = dom.createElement("div"); /** - * * @type {IAcePopup} */ + // @ts-ignore var popup = $singleLineEditor(el); if (parentNode) { diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index c0e61cc89a9..c69bf53d957 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -108,13 +108,7 @@ class BackgroundTokenizer { this.stop(); } - /** - * Fires whenever the background tokeniziers between a range of rows are going to be updated. - * - * @event update - * @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated. - * - **/ + /** * Emits the `'update'` event. `firstRow` and `lastRow` are used to define the boundaries of the region to be updated. * @param {Number} firstRow The starting row region diff --git a/src/document.js b/src/document.js index 1315a853742..08a630c787f 100644 --- a/src/document.js +++ b/src/document.js @@ -334,23 +334,6 @@ class Document { } return position; } - - /** - * Fires whenever the document changes. - * - * Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available: - * - * * `"insert"` - * * `range`: the [[Range]] of the change within the document - * * `lines`: the lines being added - * * `"remove"` - * * `range`: the [[Range]] of the change within the document - * * `lines`: the lines being removed - * - * @event change - * @param {Object} e Contains at least one property called `"action"`. `"action"` indicates the action that triggered the change. Each action also has a set of additional properties. - * - **/ /** * Inserts the elements in `lines` into the document as full lines (does not merge with existing line), starting at the row index given by `row`. This method also triggers the `"change"` event. diff --git a/src/edit_session.js b/src/edit_session.js index 7ea3785bb1b..79c0727ef0c 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -112,7 +112,6 @@ class EditSession { setDocument(doc) { if (this.doc) this.doc.off("change", this.$onChange); - this.doc = doc; doc.on("change", this.$onChange, true); diff --git a/src/editor.js b/src/editor.js index a302cc7cde8..5f33f67de33 100644 --- a/src/editor.js +++ b/src/editor.js @@ -302,12 +302,7 @@ class Editor { } - /** - * Emitted whenever the [[EditSession]] changes. - * @event changeSession - * @param {Object} e An object with two properties, `oldSession` and `session`, that represent the old and new [[EditSession]]s. - * - **/ + /** * Sets a new editsession to use. This method also emits the `'changeSession'` event. * @param {IEditSession} [session] The new session to use @@ -629,7 +624,6 @@ class Editor { /** * Emitted once the editor comes into focus. - * @event focus * @this {IEditor} **/ onFocus(e) { @@ -643,7 +637,6 @@ class Editor { /** * Emitted once the editor has been blurred. - * @event blur * @this {IEditor} **/ onBlur(e) { @@ -666,7 +659,6 @@ class Editor { /** * Emitted whenever the document is changed. - * @event change * @param {import("../ace").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes * @this {IEditor} **/ @@ -852,12 +844,7 @@ class Editor { return this.session.getTextRange(this.getSelectionRange()); } - /** - * Emitted when text is copied. - * @event copy - * @param {String} text The copied text - * - **/ + /** * Returns the string of text currently highlighted. * @this {IEditor} @@ -899,13 +886,7 @@ class Editor { this.commands.exec("cut", this); } - /** - * Emitted when text is pasted. - * @event paste - * @param {Object} an object which contains one property, `text`, that represents the text to be pasted. Editing this property will alter the text that is pasted. - * - * - **/ + /** * Called whenever a text "paste" happens. * @param {String} text The pasted text @@ -1208,11 +1189,7 @@ class Editor { return this.getOption("dragDelay"); } - /** - * Emitted when the selection style changes, via [[Editor.setSelectionStyle]]. - * @event changeSelectionStyle - * @param {Object} data Contains one property, `data`, which indicates the new selection style - **/ + /** * Draw selection markers spanning whole line, or only over selected text. Default value is "line" * @param {"fullLine" | "screenLine" | "text" | "line"} val The new selection style "line"|"text" diff --git a/src/selection.js b/src/selection.js index fdd2c53b427..5308b8e1e06 100644 --- a/src/selection.js +++ b/src/selection.js @@ -22,16 +22,6 @@ var Range = require("./range").Range; * @type {import("./anchor").IAnchor} */ -/** - * Emitted when the cursor position changes. - * @event changeCursor - * - **/ -/** - * Emitted when the cursor selection changes. - * - * @event changeSelection - **/ class Selection { /** * Creates a new `Selection` object. From caaa69ed32643ab05da7512959e2a410bbbe423f Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 26 Sep 2023 04:25:39 +0400 Subject: [PATCH 16/36] better way to merge interfaces --- ace.d.ts | 13 +++++++++ src/ace.js | 2 +- src/editor.js | 75 +++------------------------------------------------ 3 files changed, 18 insertions(+), 72 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index a06667e265c..7db6f96e504 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -899,3 +899,16 @@ export interface TooltipCommand extends Ace.Command { export type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; + + +declare module "./src/editor" { + export interface Editor extends + Ace.EventEmitter, + Ace.OptionsProvider, + Ace.EditorProperties, + Ace.EditorMultiSelectProperties + { + + } + export type IEditor = Editor +} \ No newline at end of file diff --git a/src/ace.js b/src/ace.js index fc829527afc..ec4bd4940f6 100644 --- a/src/ace.js +++ b/src/ace.js @@ -7,7 +7,7 @@ * @typedef {import("./edit_session").IEditSession} IEditSession */ /** - * @typedef {import("./editor").IEditor} IEditor + * @typedef {import("./editor").Editor} IEditor */ "use strict"; "include loader_build"; diff --git a/src/editor.js b/src/editor.js index 5f33f67de33..9da7983f1cd 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,9 +1,5 @@ "use strict"; -/** - * @typedef IEditor - * @type {Editor & import("../ace").Ace.EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EditorProperties & import("../ace").Ace.EditorMultiSelectProperties} - * @export - */ + /** * * @typedef IEditSession @@ -60,7 +56,6 @@ class Editor { * @param {IVirtualRenderer} renderer Associated `VirtualRenderer` that draws everything * @param {IEditSession} [session] The `EditSession` to refer to * @param {Object} [options] The default options - * @this {IEditor} **/ constructor(renderer, session, options) { /** @@ -129,9 +124,6 @@ class Editor { config._signal("editor", this); } - /** - * @this {IEditor} - */ $initOperationListeners() { this.commands.on("exec", this.startOperation.bind(this), true); this.commands.on("afterExec", this.endOperation.bind(this), true); @@ -179,10 +171,8 @@ class Editor { this.curOp.selectionBefore = this.selection.toJSON(); } - /** - * - * @param e - * @this {IEditor} + /** + * @arg e */ endOperation(e) { if (this.curOp && this.session) { @@ -230,10 +220,8 @@ class Editor { } } - /** - * + /** * @param e - * @this {IEditor} */ $historyTracker(e) { if (!this.$mergeUndoDeltas) @@ -306,7 +294,6 @@ class Editor { /** * Sets a new editsession to use. This method also emits the `'changeSession'` event. * @param {IEditSession} [session] The new session to use - * @this {IEditor} **/ setSession(session) { if (this.session == session) @@ -517,7 +504,6 @@ class Editor { /** * Gets the current font size of the editor text. - * @this {IEditor} * @return {string} */ getFontSize() { @@ -528,7 +514,6 @@ class Editor { /** * Set a new font size (in pixels) for the editor text. * @param {String} size A font size ( _e.g._ "12px") - * @this {IEditor} **/ setFontSize(size) { this.setOption("fontSize", size); @@ -624,7 +609,6 @@ class Editor { /** * Emitted once the editor comes into focus. - * @this {IEditor} **/ onFocus(e) { if (this.$isFocused) @@ -637,7 +621,6 @@ class Editor { /** * Emitted once the editor has been blurred. - * @this {IEditor} **/ onBlur(e) { if (!this.$isFocused) @@ -649,7 +632,6 @@ class Editor { } /** - * @this {IEditor} */ $cursorChange() { this.renderer.updateCursor(); @@ -660,7 +642,6 @@ class Editor { /** * Emitted whenever the document is changed. * @param {import("../ace").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes - * @this {IEditor} **/ onDocumentChange(delta) { // Rerender and emit "change" event. @@ -690,7 +671,6 @@ class Editor { /** * Emitted when the selection changes. - * @this {IEditor} **/ onCursorChange() { this.$cursorChange(); @@ -698,7 +678,6 @@ class Editor { } /** - * @this {IEditor} */ $updateHighlightActiveLine() { var session = this.getSession(); @@ -733,7 +712,6 @@ class Editor { /** * * @param e - * @this {IEditor} */ onSelectionChange(e) { var session = this.session; @@ -806,7 +784,6 @@ class Editor { } /** - * @this {IEditor} * @param e */ onChangeMode (e) { @@ -825,7 +802,6 @@ class Editor { /** - * @this {IEditor} */ onChangeFold() { // Update the active line marker as due to folding changes the current @@ -847,7 +823,6 @@ class Editor { /** * Returns the string of text currently highlighted. - * @this {IEditor} * @returns {String} **/ getCopyText () { @@ -872,7 +847,6 @@ class Editor { /** * Called whenever a text "copy" happens. - * @this {IEditor} **/ onCopy() { this.commands.exec("copy", this); @@ -880,7 +854,6 @@ class Editor { /** * Called whenever a text "cut" happens. - * @this {IEditor} **/ onCut() { this.commands.exec("cut", this); @@ -891,7 +864,6 @@ class Editor { * Called whenever a text "paste" happens. * @param {String} text The pasted text * @param {any} event - * @this {IEditor} **/ onPaste(text, event) { var e = {text: text, event: event}; @@ -901,7 +873,6 @@ class Editor { /** * * @param e - * @this {IEditor} * @returns {boolean} */ $handlePaste(e) { @@ -944,7 +915,6 @@ class Editor { * @param {string | string[]} command * @param [args] * @return {boolean} - * @this {IEditor} */ execCommand(command, args) { return this.commands.exec(command, this, args); @@ -954,7 +924,6 @@ class Editor { * Inserts `text` into wherever the cursor is pointing. * @param {String} text The new text to add * @param {boolean} [pasted] - * @this {IEditor} **/ insert(text, pasted) { var session = this.session; @@ -1079,7 +1048,6 @@ class Editor { * * @param text * @param composition - * @this {IEditor} * @returns {*} */ onTextInput(text, composition) { @@ -1098,7 +1066,6 @@ class Editor { /** * @param {string} [text] * @param {any} [composition] - * @this {IEditor} */ applyComposition(text, composition) { if (composition.extendLeft || composition.extendRight) { @@ -1156,7 +1123,6 @@ class Editor { /** * Sets how fast the mouse scrolling should do. * @param {Number} speed A value indicating the new speed (in milliseconds) - * @this {IEditor} **/ setScrollSpeed(speed) { this.setOption("scrollSpeed", speed); @@ -1164,7 +1130,6 @@ class Editor { /** * Returns the value indicating how fast the mouse scroll speed is (in milliseconds). - * @this {IEditor} * @returns {Number} **/ getScrollSpeed() { @@ -1173,7 +1138,6 @@ class Editor { /** * Sets the delay (in milliseconds) of the mouse drag. - * @this {IEditor} * @param {Number} dragDelay A value indicating the new delay **/ setDragDelay(dragDelay) { @@ -1182,7 +1146,6 @@ class Editor { /** * Returns the current mouse drag delay. - * @this {IEditor} * @returns {Number} **/ getDragDelay() { @@ -1193,7 +1156,6 @@ class Editor { /** * Draw selection markers spanning whole line, or only over selected text. Default value is "line" * @param {"fullLine" | "screenLine" | "text" | "line"} val The new selection style "line"|"text" - * @this {IEditor} **/ setSelectionStyle(val) { this.setOption("selectionStyle", val); @@ -1201,7 +1163,6 @@ class Editor { /** * Returns the current selection style. - * @this {IEditor} * @returns {import("../ace").Ace.EditorOptions["selectionStyle"]} **/ getSelectionStyle() { @@ -1211,14 +1172,12 @@ class Editor { /** * Determines whether or not the current line should be highlighted. * @param {Boolean} shouldHighlight Set to `true` to highlight the current line - * @this {IEditor} **/ setHighlightActiveLine(shouldHighlight) { this.setOption("highlightActiveLine", shouldHighlight); } /** * Returns `true` if current lines are always highlighted. - * @this {IEditor} * @return {Boolean} **/ getHighlightActiveLine() { @@ -1226,7 +1185,6 @@ class Editor { } /** - * @this {IEditor} * @param {boolean} shouldHighlight */ setHighlightGutterLine(shouldHighlight) { @@ -1234,7 +1192,6 @@ class Editor { } /** - * @this {IEditor} * @returns {Boolean} */ getHighlightGutterLine() { @@ -1244,7 +1201,6 @@ class Editor { /** * Determines if the currently selected word should be highlighted. * @param {Boolean} shouldHighlight Set to `true` to highlight the currently selected word - * @this {IEditor} **/ setHighlightSelectedWord(shouldHighlight) { this.setOption("highlightSelectedWord", shouldHighlight); @@ -1252,7 +1208,6 @@ class Editor { /** * Returns `true` if currently highlighted words are to be highlighted. - * @this {IEditor} * @returns {Boolean} **/ getHighlightSelectedWord() { @@ -1354,7 +1309,6 @@ class Editor { /** * If `readOnly` is true, then the editor is set to read-only mode, and none of the content can change. * @param {Boolean} readOnly Specifies whether the editor can be modified or not - * @this {IEditor} **/ setReadOnly(readOnly) { this.setOption("readOnly", readOnly); @@ -1362,7 +1316,6 @@ class Editor { /** * Returns `true` if the editor is set to read-only mode. - * @this {IEditor} * @returns {Boolean} **/ getReadOnly() { @@ -1372,7 +1325,6 @@ class Editor { /** * Specifies whether to use behaviors or not. ["Behaviors" in this case is the auto-pairing of special characters, like quotation marks, parenthesis, or brackets.]{: #BehaviorsDef} * @param {Boolean} enabled Enables or disables behaviors - * @this {IEditor} **/ setBehavioursEnabled(enabled) { this.setOption("behavioursEnabled", enabled); @@ -1380,7 +1332,6 @@ class Editor { /** * Returns `true` if the behaviors are currently enabled. {:BehaviorsDef} - * @this {IEditor} * @returns {Boolean} **/ getBehavioursEnabled() { @@ -1391,7 +1342,6 @@ class Editor { * Specifies whether to use wrapping behaviors or not, i.e. automatically wrapping the selection with characters such as brackets * when such a character is typed in. * @param {Boolean} enabled Enables or disables wrapping behaviors - * @this {IEditor} **/ setWrapBehavioursEnabled(enabled) { this.setOption("wrapBehavioursEnabled", enabled); @@ -1399,7 +1349,6 @@ class Editor { /** * Returns `true` if the wrapping behaviors are currently enabled. - * @this {IEditor} * @returns {boolean} **/ getWrapBehavioursEnabled() { @@ -1409,7 +1358,6 @@ class Editor { /** * Indicates whether the fold widgets should be shown or not. * @param {Boolean} show Specifies whether the fold widgets are shown - * @this {IEditor} **/ setShowFoldWidgets(show) { this.setOption("showFoldWidgets", show); @@ -1417,7 +1365,6 @@ class Editor { } /** * Returns `true` if the fold widgets are shown. - * @this {IEditor} * @return {Boolean} **/ getShowFoldWidgets() { @@ -1425,7 +1372,6 @@ class Editor { } /** - * @this {IEditor} * @param {boolean} fade */ setFadeFoldWidgets(fade) { @@ -1433,7 +1379,6 @@ class Editor { } /** - * @this {IEditor} * @returns {boolean} */ getFadeFoldWidgets() { @@ -1443,7 +1388,6 @@ class Editor { /** * Removes the current selection or one character. * @param {'left' | 'right'} [dir] The direction of the deletion to occur, either "left" or "right" - * @this {IEditor} **/ remove(dir) { if (this.selection.isEmpty()){ @@ -1530,7 +1474,6 @@ class Editor { /** * Splits the line at the current selection (by inserting an `'\n'`). - * @this {IEditor} **/ splitLine() { if (!this.selection.isEmpty()) { @@ -1629,7 +1572,6 @@ class Editor { * Inserts an indentation into the current cursor position or indents the selected lines. * * @related EditSession.indentRows - * @this {IEditor} **/ indent() { var session = this.session; @@ -1753,7 +1695,6 @@ class Editor { /** * If the character before the cursor is a number, this functions changes its value by `amount`. * @param {Number} amount The value to change the numeral by (can be negative to decrease value) - * @this {IEditor} **/ modifyNumber(amount) { var row = this.selection.getCursor().row; @@ -1801,7 +1742,6 @@ class Editor { } /** - * @this {IEditor} */ toggleWord() { var row = this.selection.getCursor().row; @@ -2422,7 +2362,6 @@ class Editor { * @param {Number} lineNumber The line number to go to * @param {Number} [column] A column number to go to * @param {Boolean} [animate] If `true` animates scolling - * @this {IEditor} **/ gotoLine(lineNumber, column, animate) { this.selection.clearSelection(); @@ -2750,7 +2689,6 @@ class Editor { /** * * Cleans up the entire editor. - * @this {IEditor} **/ destroy() { if (this.$toDestroy) { @@ -2773,7 +2711,6 @@ class Editor { /** * Enables automatic scrolling of the cursor into view when editor itself is inside scrollable element * @param {Boolean} enable default true - * @this {IEditor} **/ setAutoScrollEditorIntoView(enable) { if (!enable) @@ -2829,9 +2766,6 @@ class Editor { }; } - /** - * @this {IEditor} - */ $resetCursorStyle() { var style = this.$cursorStyle || "ace"; var cursorLayer = this.renderer.$cursorLayer; @@ -2971,7 +2905,6 @@ config.defineOptions(Editor.prototype, "editor", { }, placeholder: { /** - * @this {IEditor} * @param message */ set: function(message) { From 5402ec96d666d1598e3953e3a3aef4eabeea981a Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 28 Sep 2023 16:58:01 +0400 Subject: [PATCH 17/36] use declare module instead of hackish typedef's --- ace.d.ts | 750 ++++++++++++++---- src/ace.js | 24 +- src/anchor.js | 16 +- src/autocomplete.js | 35 +- src/autocomplete/inline.js | 2 +- src/autocomplete/popup.js | 24 +- src/background_tokenizer.js | 28 +- src/bidihandler.js | 6 +- src/commands/command_manager.js | 21 +- src/config.js | 4 +- src/document.js | 55 +- src/edit_session.js | 116 +-- src/edit_session/bracket_match.js | 13 +- src/edit_session/fold.js | 10 +- src/edit_session/fold_line.js | 3 +- src/edit_session/folding.js | 34 +- src/editor.js | 40 +- src/ext/beautify.js | 2 +- src/ext/code_lens.js | 10 +- src/ext/command_bar.js | 33 +- src/ext/elastic_tabstops_lite.js | 4 +- src/ext/emmet.js | 2 +- src/ext/error_marker.js | 2 +- src/ext/hardwrap.js | 2 +- src/ext/inline_autocomplete.js | 15 +- src/ext/keybinding_menu.js | 12 +- .../get_editor_keyboard_shortcuts.js | 2 +- src/ext/options.js | 9 +- src/ext/prompt.js | 17 +- src/ext/searchbox.js | 13 +- src/ext/settings_menu.js | 9 +- src/ext/static_highlight.js | 6 - src/ext/statusbar.js | 7 +- src/ext/whitespace.js | 9 +- src/keyboard/keybinding.js | 2 +- src/layer/cursor.js | 33 +- src/layer/font_metrics.js | 7 - src/layer/gutter.js | 11 +- src/layer/lines.js | 36 +- src/layer/marker.js | 9 +- src/layer/text.js | 26 +- src/lib/app_config.js | 11 +- src/line_widgets.js | 25 +- src/marker_group.js | 9 +- src/mouse/default_gutter_handler.js | 3 + src/mouse/default_handlers.js | 24 +- src/mouse/dragdrop_handler.js | 20 +- src/mouse/mouse_handler.js | 8 +- src/multi_select.js | 115 ++- src/occur.js | 26 +- src/placeholder.js | 10 +- src/range.js | 14 +- src/scrollbar.js | 9 - src/scrollbar_custom.js | 6 - src/search.js | 8 +- src/selection.js | 71 +- src/snippets.js | 7 +- src/split.js | 22 +- src/token_iterator.js | 7 +- src/undomanager.js | 10 +- src/virtual_renderer.js | 136 ++-- tsconfig.json | 1 + 62 files changed, 992 insertions(+), 1009 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 7db6f96e504..717d7e897dd 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -2,26 +2,26 @@ /// export namespace Ace { - type Anchor = import("./src/anchor").IAnchor; - type Editor = import("./src/editor").IEditor; - type EditSession = import("./src/edit_session").IEditSession; - type Document = import("./src/document").IDocument; - type Folding = import("./src/edit_session/folding").IFolding; + type Anchor = import("./src/anchor").Anchor; + type Editor = import("./src/editor").Editor; + type EditSession = import("./src/edit_session").EditSession; + type Document = import("./src/document").Document; type Fold = import("./src/edit_session/fold").Fold; type FoldLine = import("./src/edit_session/fold_line").FoldLine; type Range = import("./src/range").Range; - type VirtualRenderer = import("./src/virtual_renderer").IVirtualRenderer; + type VirtualRenderer = import("./src/virtual_renderer").VirtualRenderer; type UndoManager = import("./src/undomanager").UndoManager; type Tokenizer = import("./src/tokenizer").Tokenizer; type TokenIterator = import("./src/token_iterator").TokenIterator; - type Selection = import("./src/selection").ISelection; + type Selection = import("./src/selection").Selection; type Autocomplete = import("./src/autocomplete").Autocomplete; type CompletionProvider = import("./src/autocomplete").CompletionProvider; - type AcePopup = import("./src/autocomplete/popup").IAcePopup; - type Config = import("./src/config").IConfig; + type AcePopup = import("./src/autocomplete/popup").AcePopup; + type Config = import("./src/config").Config; type AceInline = import("./src/autocomplete/inline").AceInline; type MouseEvent = import("./src/mouse/mouse_event").MouseEvent; - + type RangeList = import("./src/range_list").RangeList; + type FilteredList = import("./src/autocomplete").FilteredList; interface Theme { cssClass?: string; cssText?: string; @@ -72,48 +72,155 @@ export namespace Ace { interface ScreenCoordinates { row: number, column: number, - side: 1 | -1, - offsetX: number - } - interface FoldingProperties { - $foldMode: FoldMode, - foldWidgets: FoldWidget[], - getFoldWidget: Function, - getFoldWidgetRange: Function, - $updateFoldWidgets(delta: Delta): void, - $tokenizerUpdateFoldWidgets(e): void, - addFold(placeholder: Fold|String, range?: Range): Fold, - removeFold(fold: Fold): void, - removeFolds(folds: Fold[]): void, - setFoldStyle(style: string): void, - $setFolding(foldMode: FoldMode): void, - } - - interface AcePopupProperties { - setSelectOnHover: (val: boolean) => void, - setRow: (line: number) => void, - getRow: () => number, - getHoveredRow: () => number, - filterText: string, - isOpen: boolean, - isTopdown: boolean, - autoSelect: boolean, - data: Completion[], - setData: (data: Completion[], filterText: string) => void, - getData: (row: number) => Completion, - hide: () => void, - anchor: "top" | "bottom", - anchorPosition: Point, - tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, - $borderSize: number, - show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, - goTo: (where: AcePopupNavigation) => void, - getTextLeftOffset: () => number, - $imageSize: number, - anchorPos: any + side?: 1 | -1, + offsetX?: number } - interface ISelection { - [key: string]: any; + + interface Folding { + $foldData: FoldLine[]; + /** + * Looks up a fold at a given row/column. Possible values for side: + * -1: ignore a fold if fold.start = row/column + * +1: ignore a fold if fold.end = row/column + **/ + getFoldAt(row: number, column: number, side?: number): Ace.Fold; + /** + * Returns all folds in the given range. Note, that this will return folds + **/ + getFoldsInRange(range: Ace.Range | Ace.Delta): Ace.Fold[]; + getFoldsInRangeList(ranges: Ace.Range[] | Ace.Range): Ace.Fold[]; + /** + * Returns all folds in the document + */ + getAllFolds(): Ace.Fold[]; + /** + * Returns the string between folds at the given position. + * E.g. + * foob|arwolrd -> "bar" + * foobarwol|rd -> "world" + * foobarwolrd -> + * + * where | means the position of row/column + * + * The trim option determs if the return string should be trimed according + * to the "side" passed with the trim value: + * + * E.g. + * foob|arwolrd -trim=-1> "b" + * foobarwol|rd -trim=+1> "rld" + * fo|obarwolrd -trim=00> "foo" + */ + getFoldStringAt(row: number, column: number, trim?: number, foldLine?: Ace.FoldLine): string | null; + getFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; + /** + * Returns the fold which starts after or contains docRow + */ + getNextFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; + getFoldedRowCount(first: number, last: number): number; + $addFoldLine(foldLine: FoldLine): Ace.FoldLine; + /** + * Adds a new fold. + * @returns {Ace.Fold} + * The new created Fold object or an existing fold object in case the + * passed in range fits an existing fold exactly. + */ + addFold(placeholder: Ace.Fold | string, range?: Ace.Range): Ace.Fold; + $modified: boolean; + addFolds(folds: Ace.Fold[]): void; + removeFold(fold: Ace.Fold): void; + removeFolds(folds: Ace.Fold[]): void; + expandFold(fold: Ace.Fold): void; + expandFolds(folds: Ace.Fold[]): void; + unfold(location?: number | null | Ace.Point | Ace.Range | Ace.Range[], expandInner?: boolean): Ace.Fold[] | undefined; + /** + * Checks if a given documentRow is folded. This is true if there are some + * folded parts such that some parts of the line is still visible. + **/ + isRowFolded(docRow: number, startFoldRow?: Ace.FoldLine): boolean; + getRowFoldEnd(docRow: number, startFoldRow?: Ace.FoldLine): number; + getRowFoldStart(docRow: number, startFoldRow?: Ace.FoldLine): number; + getFoldDisplayLine(foldLine: Ace.FoldLine, endRow?: number | null, endColumn?: number | null, startRow?: number | null, startColumn?: number | null): string; + getDisplayLine(row: number, endColumn: number | null, startRow: number | null, startColumn: number | null): string; + $cloneFoldData(): Ace.FoldLine[]; + toggleFold(tryToUnfold?: boolean): void; + getCommentFoldRange(row: number, column: number, dir?: number): Ace.Range | undefined; + foldAll(startRow?: number | null, endRow?: number | null, depth?: number | null, test?: Function): void; + foldToLevel(level: number): void; + foldAllComments(): void; + $foldStyles: { + manual: number; + markbegin: number; + markbeginend: number; + }; + $foldStyle: string; + setFoldStyle(style: string): void; + $setFolding(foldMode: Ace.FoldMode): void; + $foldMode: any; + foldWidgets: any[]; + getFoldWidget: any; + getFoldWidgetRange: any; + $updateFoldWidgets: any; + $tokenizerUpdateFoldWidgets: any; + getParentFoldRangeData(row: number, ignoreCurrent?: boolean): { + range?: Ace.Range; + firstRange?: Ace.Range; + }; + onFoldWidgetClick(row: number, e: any): void; + $toggleFoldWidget(row: number, options: any): Fold | any; + /** + * + * @param {boolean} [toggleParent] + */ + toggleFoldWidget(toggleParent?: boolean): void; + updateFoldWidgets(delta: Ace.Delta): void; + tokenizerUpdateFoldWidgets(e: any): void; + } + + interface BracketMatch { + findMatchingBracket: (position: Point, chr?: string) => Point; + + getBracketRange: (pos: Point) => null | Range; + /** + * Returns: + * * null if there is no any bracket at `pos`; + * * two Ranges if there is opening and closing brackets; + * * one Range if there is only one bracket + */ + getMatchingBracketRanges: (pos: Point, isBackwards?: boolean) => null | Range[]; + $brackets: { + ")": string; + "(": string; + "]": string; + "[": string; + "{": string; + "}": string; + "<": string; + ">": string; + }; + $findOpeningBracket: (bracket: string, position: Point, typeRe?: RegExp) => Point | null; + $findClosingBracket: (bracket: string, position: Point, typeRe?: RegExp) => Point | null; + /** + * Returns [[Range]]'s for matching tags and tag names, if there are any + */ + getMatchingTags: (pos: Point) => { + closeTag: Range; + closeTagName: Range; + openTag: Range; + openTagName: Range; + }; + $findTagName: (iterator: any) => any; + $findClosingTag: (iterator: any, token: any) => { + openTag: Range; + closeTag: Range; + openTagName: Range; + closeTagName: Range; + }; + $findOpeningTag: (iterator: any, token: any) => { + openTag: Range; + closeTag: Range; + openTagName: Range; + closeTagName: Range; + }; } interface IRange { start: Point; @@ -143,93 +250,6 @@ export namespace Ace { lenses?: any[], } - interface EditorProperties { - $mergeUndoDeltas?: any, - $highlightSelectedWord?: boolean, - $updatePlaceholder?: Function, - $cursorStyle?: string, - $readOnly?: any, - $highlightActiveLine?: any, - $enableAutoIndent?: any, - $copyWithEmptySelection?: any - $selectionStyle?: string, - env?: any; - widgetManager?: import("./src/line_widgets").LineWidgets, - completer?: import("./src/autocomplete").Autocomplete | import("./src/ext/inline_autocomplete").InlineAutocomplete, - completers: Completer[], - $highlightTagPending?: boolean, - showKeyboardShortcuts?: () => void, - showSettingsMenu?: () => void, - searchBox?: import("./src/ext/searchbox").SearchBox - [key: string]: any; - } - - interface EditSessionProperties { - doc: Document, - $highlightLineMarker?: { - start: Point, - end: Point, - id?: number - } - $useSoftTabs?: boolean, - $tabSize?: number, - $useWorker?: boolean, - $wrapAsCode?: boolean, - $indentedSoftWrap?: boolean, - widgetManager?: any, - $bracketHighlight?: any, - $selectionMarker?: number, - curOp?: { - command: {}, - args: string, - scrollTop: number, - [key: string]: any; - }, - lineWidgetsWidth?: number, - $getWidgetScreenLength?: () => number, - _changedWidgets?: any, - $options:any, - $wrapMethod?: any, - $enableVarChar?: any, - $wrap?:any, - $navigateWithinSoftTabs?: boolean - [key: string]: any; - } - - interface EditorMultiSelectProperties { - inMultiSelectMode?: boolean, - forEachSelection?: Function, - exitMultiSelectMode?: Function, - } - - interface VirtualRendererProperties { - $customScrollbar?: boolean, - $extraHeight?: number, - $showGutter?: boolean, - $showPrintMargin?: boolean, - $printMarginColumn?: number, - $animatedScroll?: boolean, - $isMousePressed?: boolean, - textarea?: HTMLTextAreaElement, - $hScrollBarAlwaysVisible?: boolean, - $vScrollBarAlwaysVisible?: boolean - $maxLines?: number | null, - $scrollPastEnd?: number, - enableKeyboardAccessibility?: boolean, - keyboardFocusClassName?: string, - $highlightGutterLine?: boolean, - $minLines?: number, - $maxPixelHeight?: number, - $gutterWidth?: number, - showInvisibles?: boolean, - $hasCssTransforms?: boolean, - $blockCursor?: boolean, - $useTextareaForIME?: boolean, - theme?: any, - $theme?: any, - destroyed?: boolean, - } - type NewLineMode = 'auto' | 'unix' | 'windows'; interface EditSessionOptions { @@ -313,11 +333,11 @@ export namespace Ace { enableKeyboardAccessibility: boolean; enableCodeLens: boolean; } - + interface EventsBase { [key: string]: any; } - + interface EditSessionEvents { /** * Emitted when the document changes. @@ -390,8 +410,8 @@ export namespace Ace { "changeScrollLeft": (scrollLeft: number) => void; "changeEditor": (e: { editor: Editor }) => void; } - - interface EditorEvents { + + interface EditorEvents{ "change": (delta: Delta) => void; "changeSelection": () => void; "input": () => void; @@ -426,15 +446,18 @@ export namespace Ace { **/ "changeSelectionStyle": (data: "fullLine" | "screenLine" | "text" | "line") => void; } - - interface AcePopupEvents extends EditorEvents { + + interface AcePopupEvents{ "click": (e: MouseEvent) => void; + "dblclick": (e: MouseEvent) => void; + "tripleclick": (e: MouseEvent) => void; + "quadclick": (e: MouseEvent) => void; "show": () => void; "hide": () => void; "select": (hide: boolean) => void; "changeHoverMarker": (e) => void; } - + interface DocumentEvents { /** * Fires whenever the document changes. @@ -462,15 +485,15 @@ export namespace Ace { **/ "change": (e: { old: Point, value: Point }) => void; } - + interface BackgroundTokenizerEvents { /** * Fires whenever the background tokeniziers between a range of rows are going to be updated. * @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated. **/ - "update": (e: {first:number, last:number}) => void; + "update": (e: {first:number, last:number}) => void; } - + interface SelectionEvents { /** * Emitted when the cursor position changes. @@ -481,15 +504,15 @@ export namespace Ace { **/ "changeSelection": () => void; } - + interface PlaceHolderEvents { - + } - + interface GutterEvents { "changeGutterWidth": (width: number) => void; } - + interface TextEvents { "changeCharacterSize": (e) => void; } @@ -574,7 +597,7 @@ export namespace Ace { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; - exec?: (editor: Editor, args?: any) => void; + exec?: (editor?: Editor | any, args?: any) => void; isAvailable?: (editor: Editor) => boolean; description?: string, multiSelectAction?: "forEach"|"forEachLine"|Function, @@ -586,7 +609,7 @@ export namespace Ace { } type CommandLike = Command | ((editor: Editor) => void); - + type KeyboardHandler = import("./src/keyboard/hash_handler").HashHandler & { attach?: (editor: Editor) => void; detach?: (editor: Editor) => void; @@ -797,7 +820,7 @@ export namespace Ace { on(name: 'exec', callback: execEventHandler): Function; on(name: 'afterExec', callback: execEventHandler): Function; } - type CommandManager = import("./src/commands/command_manager").ICommandManager & CommandManagerEvents; + type CommandManager = import("./src/commands/command_manager").CommandManager; interface SavedSelection { @@ -901,14 +924,411 @@ export type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineA export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; +declare module "./src/anchor" { + export interface Anchor extends Ace.EventEmitter { + markerId?: number; + } + + +} + +declare module "./src/autocomplete" { + export interface Autocomplete { + popup: Ace.AcePopup + } + + export interface CompletionProvider { + completions: Ace.FilteredList; + } +} + + +declare module "./src/background_tokenizer" { + export interface BackgroundTokenizer extends Ace.EventEmitter { + + } +} + +declare module "./src/document" { + export interface Document extends + Ace.EventEmitter { + + } + +} + declare module "./src/editor" { - export interface Editor extends - Ace.EventEmitter, - Ace.OptionsProvider, - Ace.EditorProperties, - Ace.EditorMultiSelectProperties - { - - } - export type IEditor = Editor -} \ No newline at end of file + export interface Editor extends + Ace.EventEmitter, + Ace.OptionsProvider, + EditorMultiSelectProperties + { + session: Ace.EditSession; + $mergeUndoDeltas?: any, + $highlightSelectedWord?: boolean, + $updatePlaceholder?: Function, + $cursorStyle?: string, + $readOnly?: any, + $highlightActiveLine?: any, + $enableAutoIndent?: any, + $copyWithEmptySelection?: any + $selectionStyle?: string, + env?: any; + widgetManager?: import("./src/line_widgets").LineWidgets, + completer?: import("./src/autocomplete").Autocomplete | import("./src/ext/inline_autocomplete").InlineAutocomplete, + completers: Ace.Completer[], + $highlightTagPending?: boolean, + showKeyboardShortcuts?: () => void, + showSettingsMenu?: () => void, + searchBox?: import("./src/ext/searchbox").SearchBox, + [key: string]: any; + } + + interface EditorMultiSelectProperties { + inMultiSelectMode?: boolean, + /** + * Updates the cursor and marker layers. + **/ + updateSelectionMarkers: () => void, + /** + * Adds the selection and cursor. + * @param orientedRange A range containing a cursor + **/ + addSelectionMarker: (orientedRange: Ace.Range & {marker?}) => Ace.Range & {marker?}, + /** + * Removes the selection marker. + * @param range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. + **/ + removeSelectionMarker: (range: Ace.Range & {marker?}) => void, + removeSelectionMarkers: (ranges: (Ace.Range & {marker?})[]) => void, + $onAddRange: (e) => void, + $onRemoveRange: (e) => void, + $onMultiSelect: (e) => void, + $onSingleSelect: (e) => void, + $onMultiSelectExec: (e) => void, + /** + * Executes a command for each selection range. + * @param cmd The command to execute + * @param [args] Any arguments for the command + **/ + forEachSelection: (cmd: Object, args?: string, options?: Object) => void, + /** + * Removes all the selections except the last added one. + **/ + exitMultiSelectMode: () => void, + getSelectedText: () => string, + $checkMultiselectChange: (e, anchor: Ace.Anchor) => void, + /** + * Finds and selects all the occurrences of `needle`. + * @param needle The text to find + * @param options The search options + * @param additive keeps + * @returns {Number} The cumulative count of all found matches + **/ + findAll: (needle?: string, options?: Partial, additive?: boolean) => number, + /** + * Adds a cursor above or below the active cursor. + * @param dir The direction of lines to select: -1 for up, 1 for down + * @param [skip] If `true`, removes the active selection range + */ + selectMoreLines: (dir: number, skip?: boolean) => void, + /** + * Transposes the selected ranges. + * @param {Number} dir The direction to rotate selections + **/ + transposeSelections: (dir: number) => void, + /** + * Finds the next occurrence of text in an active selection and adds it to the selections. + * @param {Number} dir The direction of lines to select: -1 for up, 1 for down + * @param {Boolean} [skip] If `true`, removes the active selection range + * @param {Boolean} [stopAtFirst] + **/ + selectMore: (dir: number, skip?: boolean, stopAtFirst?: boolean) => void, + /** + * Aligns the cursors or selected text. + **/ + alignCursors: () => void, + $reAlignText: (lines: string[], forceLeft: boolean) => string[], + } +} + +declare module "./src/edit_session" { + export interface EditSession extends + Ace.EventEmitter, + Ace.OptionsProvider, + Ace.Folding, Ace.BracketMatch + { + doc: Ace.Document, + $highlightLineMarker?: { + start: Ace.Point, + end: Ace.Point, + id?: number + } + $useSoftTabs?: boolean, + $tabSize?: number, + $useWorker?: boolean, + $wrapAsCode?: boolean, + $indentedSoftWrap?: boolean, + widgetManager?: any, + $bracketHighlight?: any, + $selectionMarker?: number, + curOp?: { + command: {}, + args: string, + scrollTop: number, + [key: string]: any; + }, + lineWidgetsWidth?: number, + $getWidgetScreenLength?: () => number, + _changedWidgets?: any, + $options:any, + + $wrapMethod?: any, + $enableVarChar?: any, + $wrap?:any, + $navigateWithinSoftTabs?: boolean, + getSelectionMarkers(): any[], + [key: string]: any; + } +} + +declare module "./src/edit_session/fold" { + export interface Fold { + collapseChildren?: number; + } +} + +// @ts-expect-error +declare module "./src/placeholder" { + export interface PlaceHolder extends Ace.EventEmitter { + } +} + +declare module "./src/scrollbar" { + export interface Scrollbar extends Ace.EventEmitter { + } + export interface VScrollBar extends Scrollbar { + } + export interface HScrollBar extends Scrollbar { + } +} + +declare module "./src/scrollbar_custom" { + export interface Scrollbar extends Ace.EventEmitter { + } + export interface VScrollBar extends Scrollbar { + } + export interface HScrollBar extends Scrollbar { + } +} + +declare module "./src/line_widgets" { + export interface LineWidgets { + lineWidgets: Ace.LineWidget[]; + editor: Ace.Editor; + } +} + +declare module "./src/selection" { + export interface Selection extends Ace.EventEmitter, MultiSelectProperties { + } + + interface MultiSelectProperties { + ranges: Ace.Range[] | null; + rangeList: Ace.RangeList | null; + /** + * Adds a range to a selection by entering multiselect mode, if necessary. + * @param {Ace.Range} range The new range to add + * @param {Boolean} [$blockChangeEvents] Whether or not to block changing events + **/ + addRange(range: Ace.Range, $blockChangeEvents?: boolean): any; + inMultiSelectMode: boolean; + /** + * @param {Ace.Range} [range] + **/ + toSingleRange(range?: Ace.Range): void; + /** + * Removes a Range containing pos (if it exists). + * @param {Ace.Point} pos The position to remove, as a `{row, column}` object + **/ + substractPoint(pos: Ace.Point): any; + /** + * Merges overlapping ranges ensuring consistency after changes + **/ + mergeOverlappingRanges(): void; + /** + * @param {Ace.Range} range + */ + $onAddRange(range: Ace.Range): void; + rangeCount: number; + /** + * + * @param {Ace.Range[]} removed + */ + $onRemoveRange(removed: Ace.Range[]): void; + /** + * adds multicursor support to selection + */ + $initRangeList(): void; + /** + * Returns a concatenation of all the ranges. + * @returns {Ace.Range[]} + **/ + getAllRanges(): Ace.Range[]; + /** + * Splits all the ranges into lines. + **/ + splitIntoLines(): void; + /** + */ + joinSelections(): void; + /** + **/ + toggleBlockSelection(): void; + /** + * + * Gets list of ranges composing rectangular block on the screen + * + * @param {Ace.ScreenCoordinates} screenCursor The cursor to use + * @param {Ace.ScreenCoordinates} screenAnchor The anchor to use + * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping + * @returns {Ace.Range[]} + **/ + rectangularRangeBlock(screenCursor: Ace.ScreenCoordinates, screenAnchor: Ace.ScreenCoordinates, includeEmptyLines?: boolean): Ace.Range[]; + + _eventRegistry?: any; + index?: number; + } +} + +declare module "./src/range" { + export interface Range { + id?: number; + cursor?: Ace.Point; + isBackwards?: boolean; + } +} + +declare module "./src/virtual_renderer" { + export interface VirtualRenderer extends + Ace.EventEmitter, Ace.OptionsProvider { + $customScrollbar?: boolean, + $extraHeight?: number, + $showGutter?: boolean, + $showPrintMargin?: boolean, + $printMarginColumn?: number, + $animatedScroll?: boolean, + $isMousePressed?: boolean, + textarea?: HTMLTextAreaElement, + $hScrollBarAlwaysVisible?: boolean, + $vScrollBarAlwaysVisible?: boolean + $maxLines?: number | null, + $scrollPastEnd?: number, + enableKeyboardAccessibility?: boolean, + keyboardFocusClassName?: string, + $highlightGutterLine?: boolean, + $minLines?: number, + $maxPixelHeight?: number, + $gutterWidth?: number, + showInvisibles?: boolean, + $hasCssTransforms?: boolean, + $blockCursor?: boolean, + $useTextareaForIME?: boolean, + theme?: any, + $theme?: any, + destroyed?: boolean, + session: Ace.EditSession, + } + +} + +declare module "./src/snippets" { + export interface SnippetManager extends Ace.EventEmitter { + } +} + +declare module "./src/ext/command_bar" { + export interface CommandBarTooltip extends Ace.EventEmitter { + $shouldHideMoreOptions?: boolean, + } +} + +declare module "./src/commands/command_manager" { + export interface CommandManager extends Ace.EventEmitter { + $checkCommandState?: boolean + } +} + +declare module "./src/autocomplete/popup" { + type AcePopupEventsCombined = Ace.EditorEvents & Ace.AcePopupEvents; + type AcePopupWithEditor = Ace.EventEmitter & Ace.Editor; + export interface AcePopup extends AcePopupWithEditor { + setSelectOnHover: (val: boolean) => void, + setRow: (line: number) => void, + getRow: () => number, + getHoveredRow: () => number, + filterText: string, + isOpen: boolean, + isTopdown: boolean, + autoSelect: boolean, + data: Ace.Completion[], + setData: (data: Ace.Completion[], filterText: string) => void, + getData: (row: number) => Ace.Completion, + hide: () => void, + anchor: "top" | "bottom", + anchorPosition: Ace.Point, + tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, + $borderSize: number, + show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, + goTo: (where: Ace.AcePopupNavigation) => void, + getTextLeftOffset: () => number, + $imageSize: number, + anchorPos: any + } +} + +declare module "./src/layer/cursor" { + export interface Cursor { + timeoutId?: number; + } +} + +declare module "./src/layer/gutter" { + export interface Gutter extends Ace.EventEmitter { + $useSvgGutterIcons?: boolean, + $showFoldedAnnotations?: boolean, + } +} + +declare module "./src/layer/text" { + export interface Text extends Ace.EventEmitter { + } +} + +declare module "./src/lib/app_config" { + export interface AppConfig extends Ace.EventEmitter { + } +} + +declare module "./src/mouse/mouse_handler" { + type DefaultHandlers = import("./src/mouse/default_handlers").DefaultHandlers; + //@ts-ignore + type GutterHandler = import("./src/mouse/default_gutter_handler").GutterHandler; + type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; + + export interface MouseHandler extends DefaultHandlers, GutterHandler, DragdropHandler { + $tooltipFollowsMouse?: boolean, + cancelDrag?: boolean + } +} + +// @ts-expect-error +declare module "./src/ext/options" { + export interface OptionPanel extends Ace.EventEmitter { + } +} + +declare module "./src/layer/font_metrics" { + export interface FontMetrics extends Ace.EventEmitter { + } +} diff --git a/src/ace.js b/src/ace.js index ec4bd4940f6..7556f15d384 100644 --- a/src/ace.js +++ b/src/ace.js @@ -3,25 +3,13 @@ * * @namespace Ace **/ -/** - * @typedef {import("./edit_session").IEditSession} IEditSession - */ -/** - * @typedef {import("./editor").Editor} IEditor - */ "use strict"; "include loader_build"; var dom = require("./lib/dom"); var Range = require("./range").Range; -/** - * @type {any} - */ var EditSession = require("./edit_session").EditSession; -/** - * @type {any} - */ var Editor = require("./editor").Editor; var UndoManager = require("./undomanager").UndoManager; var Renderer = require("./virtual_renderer").VirtualRenderer; @@ -42,7 +30,7 @@ exports.config = require("./config"); * Embeds the Ace editor into the DOM, at the element provided by `el`. * @param {String | HTMLElement & {env?, value?}} el Either the id of an element, or the element itself * @param {Object } [options] Options for the editor - * @returns {IEditor} + * @returns {Editor} **/ exports.edit = function(el, options) { if (typeof el == "string") { @@ -67,9 +55,6 @@ exports.edit = function(el, options) { } var doc = exports.createEditSession(value); - /** - * @type {IEditor} - */ var editor = new Editor(new Renderer(el), doc, options); var env = { @@ -87,14 +72,11 @@ exports.edit = function(el, options) { /** * Creates a new [[EditSession]], and returns the associated [[Document]]. - * @param {import('./document').IDocument | String} text {:textParam} + * @param {import('./document').Document | String} text {:textParam} * @param {import("../ace").Ace.SyntaxMode} [mode] {:modeParam} - * @returns {IEditSession} + * @returns {EditSession} **/ exports.createEditSession = function(text, mode) { - /** - * @type {IEditSession} - */ var doc = new EditSession(text, mode); doc.setUndoManager(new UndoManager()); return doc; diff --git a/src/anchor.js b/src/anchor.js index 8c2a9e8056e..d884e19766f 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -1,27 +1,21 @@ "use strict"; /** - * @typedef IDocument + * @typedef Document * @type {import("./document").Document} */ -/** - * @typedef IAnchor - * @type {Anchor & import("../ace").Ace.EventEmitter & {markerId?: number}} - */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; /** * Defines a floating pointer in the document. Whenever text is inserted or deleted before the cursor, the position of the anchor is updated. - * @this {IAnchor} **/ class Anchor { /** * Creates a new `Anchor` and associates it with a document. * - * @param {IDocument} doc The document to associate with the anchor + * @param {Document} doc The document to associate with the anchor * @param {Number|import("../ace").Ace.Point} row The starting row position * @param {Number} [column] The starting column position - * @this {IAnchor} **/ constructor(doc, row, column) { this.$onChange = this.onChange.bind(this); @@ -44,7 +38,7 @@ class Anchor { /** * * Returns the current document. - * @returns {IDocument} + * @returns {Document} **/ getDocument() { return this.document; @@ -53,7 +47,6 @@ class Anchor { /** * Internal function called when `"change"` event fired. * @param {import("../ace").Ace.Delta} delta - * @this {IAnchor} */ onChange(delta) { if (delta.start.row == delta.end.row && delta.start.row != this.row) @@ -71,7 +64,6 @@ class Anchor { * @param {Number} row The row index to move the anchor to * @param {Number} column The column index to move the anchor to * @param {Boolean} [noClip] Identifies if you want the position to be clipped - * @this {IAnchor} **/ setPosition(row, column, noClip) { var pos; @@ -110,7 +102,7 @@ class Anchor { /** * When called, the `"change"` event listener is appended. - * @param {IDocument} doc The document to associate with + * @param {Document} doc The document to associate with * **/ attach(doc) { diff --git a/src/autocomplete.js b/src/autocomplete.js index c5accf21711..7d102d3904d 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -1,12 +1,9 @@ "use strict"; /** - * @typedef {import("./autocomplete/popup").IAcePopup} IAcePopup - */ -/** - * @typedef {import("./editor").IEditor} IEditor + * @typedef {import("./editor").Editor} Editor */ var HashHandler = require("./keyboard/hash_handler").HashHandler; -/**@type{any}*/var AcePopup = require("./autocomplete/popup").AcePopup; +var AcePopup = require("./autocomplete/popup").AcePopup; var AceInline = require("./autocomplete/inline").AceInline; var getAriaId = require("./autocomplete/popup").getAriaId; var util = require("./autocomplete/util"); @@ -30,7 +27,7 @@ var config = require("./config"); * @property {string} [command] - A command to be executed after the completion is inserted (experimental) * @property {string} [snippet] - a text snippet that would be inserted when the completion is selected * @property {string} [value] - The text that would be inserted when selecting this completion. - * @property {{insertMatch:(editor: IEditor, data: Completion) => void}} [completer] + * @property {{insertMatch:(editor: Editor, data: Completion) => void}} [completer] * @export */ @@ -67,10 +64,6 @@ class Autocomplete { constructor() { - /** - * @type {IAcePopup} - */ - this.popup; this.autoInsert = false; this.autoSelect = true; this.autoShown = false; @@ -96,7 +89,7 @@ class Autocomplete { $init() { /** - * @type {IAcePopup} + * @type {AcePopup} */ this.popup = new AcePopup(this.parentNode || document.body || document.documentElement); this.popup.on("click", function(e) { @@ -120,7 +113,7 @@ class Autocomplete { /** * - * @return {IAcePopup} + * @return {AcePopup} */ getPopup() { return this.popup || this.$init(); @@ -213,7 +206,7 @@ class Autocomplete { } /** - * @param {IEditor} editor + * @param {Editor} editor * @param {string} prefix * @param {boolean} [keepPopupPosition] */ @@ -341,7 +334,7 @@ class Autocomplete { /** * This is the entry point for the autocompletion class, triggers the actions which collect and display suggestions - * @param {IEditor} editor + * @param {Editor} editor * @param {import("../ace").Ace.CompletionOptions} options */ showPopup(editor, options) { @@ -649,16 +642,12 @@ class CompletionProvider { * @param {{pos: import("../ace").Ace.Position, prefix: string}} initialPosition */ constructor(initialPosition) { - /** - * @type {FilteredList} - */ - this.completions; this.initialPosition = initialPosition; this.active = true; } /** - * @param {IEditor} editor + * @param {Editor} editor * @param {number} index * @param {import("../ace").Ace.CompletionProviderOptions} [options] * @returns {boolean} @@ -671,7 +660,7 @@ class CompletionProvider { } /** - * @param {IEditor} editor + * @param {Editor} editor * @param {Completion} data * @param {import("../ace").Ace.CompletionProviderOptions} [options] * @returns {boolean} @@ -727,7 +716,7 @@ class CompletionProvider { } /** - * @param {IEditor} editor + * @param {Editor} editor * @param {Completion} data */ $insertString(editor, data) { @@ -736,7 +725,7 @@ class CompletionProvider { } /** - * @param {IEditor} editor + * @param {Editor} editor * @param {import("../ace").Ace.CompletionCallbackFunction} callback */ gatherCompletions(editor, callback) { @@ -766,7 +755,7 @@ class CompletionProvider { /** * This is the entry point to the class, it gathers, then provides the completions asynchronously via callback. * The callback function may be called multiple times, the last invokation is marked with a `finished` flag - * @param {IEditor} editor + * @param {Editor} editor * @param {import("../ace").Ace.CompletionProviderOptions} options * @param {(err: Error | undefined, completions: FilteredList | [], finished: boolean) => void} callback */ diff --git a/src/autocomplete/inline.js b/src/autocomplete/inline.js index e0fabe2fd27..64aad92b8fc 100644 --- a/src/autocomplete/inline.js +++ b/src/autocomplete/inline.js @@ -15,7 +15,7 @@ class AceInline { /** * Renders the completion as ghost text to the current cursor position - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor * @param {import("../../ace").Ace.Completion} completion * @param {string} prefix * @returns {boolean} True if the completion could be rendered to the editor, false otherwise diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 65bfe0f3d73..82c327dd355 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -1,18 +1,5 @@ "use strict"; -/** - * - * @typedef IEditor - * @type {import("../editor").IEditor} - */ -/** - * @typedef IAcePopup - * @type {IEditor & import("../../ace").Ace.AcePopupProperties & import("../../ace").Ace.EventEmitter} - * @export - */ var Renderer = require("../virtual_renderer").VirtualRenderer; -/** - * @type {any} - */ var Editor = require("../editor").Editor; var Range = require("../range").Range; var event = require("../lib/event"); @@ -27,18 +14,12 @@ var getAriaId = function (index) { /** * * @param {HTMLElement} [el] - * @return {IEditor} + * @return {Editor} */ var $singleLineEditor = function (el) { - /** - * @type {Renderer & {$maxLines?: number}}} - */ var renderer = new Renderer(el); renderer.$maxLines = 4; - /** - * @type {IEditor} - */ var editor = new Editor(renderer); editor.setHighlightActiveLine(false); @@ -54,7 +35,6 @@ var $singleLineEditor = function (el) { /** * This object is used in some places where needed to show popups - like prompt; autocomplete etc. - * @type {IAcePopup} */ class AcePopup { /** @@ -64,7 +44,7 @@ class AcePopup { constructor(parentNode) { var el = dom.createElement("div"); /** - * @type {IAcePopup} + * @type {AcePopup} */ // @ts-ignore var popup = $singleLineEditor(el); diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index c69bf53d957..5ac357408a3 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -1,24 +1,13 @@ "use strict"; /** - * @typedef IDocument - * @type {import("./document").IDocument} + * @typedef {import("./document").Document} Document */ /** - * @typedef IEditor - * @type {import("./editor").IEditor} - */ -/** - * @typedef ITokenizer - * @type {import("./tokenizer").Tokenizer} - */ -/** - * @typedef IBackgroundTokenizer - * @type {BackgroundTokenizer & import("../ace").Ace.EventEmitter} + * @typedef {import("./editor").Editor} Editor */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; - /** * Tokenizes the current [[Document `Document`]] in the background, and caches the tokenized rows for future use. * @@ -28,9 +17,8 @@ class BackgroundTokenizer { /** * Creates a new `BackgroundTokenizer` object. - * @param {ITokenizer} tokenizer The tokenizer to use - * @param {IEditor} [editor] The editor to associate with - * @this {IBackgroundTokenizer} + * @param {import("./tokenizer").Tokenizer} tokenizer The tokenizer to use + * @param {any} [editor] The editor to associate with **/ constructor(tokenizer, editor) { /** @@ -86,7 +74,7 @@ class BackgroundTokenizer { /** * Sets a new tokenizer for this object. - * @param {ITokenizer} tokenizer The new tokenizer to use + * @param {import("./tokenizer").Tokenizer} tokenizer The new tokenizer to use **/ setTokenizer(tokenizer) { this.tokenizer = tokenizer; @@ -98,7 +86,7 @@ class BackgroundTokenizer { /** * Sets a new document to associate with this object. - * @param {IDocument} doc The new document to associate with + * @param {Document} doc The new document to associate with **/ setDocument(doc) { this.doc = doc; @@ -113,7 +101,6 @@ class BackgroundTokenizer { * Emits the `'update'` event. `firstRow` and `lastRow` are used to define the boundaries of the region to be updated. * @param {Number} firstRow The starting row region * @param {Number} lastRow The final row region - * @this {IBackgroundTokenizer} **/ fireUpdateEvent(firstRow, lastRow) { var data = { @@ -221,9 +208,6 @@ class BackgroundTokenizer { return this.lines[row] = data.tokens; } - /** - * @this {IBackgroundTokenizer} - */ cleanup() { this.running = false; this.lines = []; diff --git a/src/bidihandler.js b/src/bidihandler.js index ae3fc576074..9fd5bdfb7b4 100644 --- a/src/bidihandler.js +++ b/src/bidihandler.js @@ -1,8 +1,4 @@ "use strict"; -/** - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} - */ var bidiUtil = require("./lib/bidiutil"); var lang = require("./lib/lang"); var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/; @@ -14,7 +10,7 @@ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/; class BidiHandler { /** * Creates a new `BidiHandler` object - * @param {IEditSession} session The session to use + * @param {import("./edit_session").EditSession} session The session to use **/ constructor(session) { this.session = session; diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index c5e554afa58..104c7f08d66 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -1,27 +1,17 @@ "use strict"; -/** - * @typedef ICommandManager - * @type {CommandManager & import("../../ace").Ace.EventEmitter & {$checkCommandState?: boolean}} - * @export - */ /** * - * @typedef IEditor - * @type {import("../editor").IEditor} + * @typedef {import("../editor").Editor} Editor */ var oop = require("../lib/oop"); var MultiHashHandler = require("../keyboard/hash_handler").MultiHashHandler; var EventEmitter = require("../lib/event_emitter").EventEmitter; -/** - * @type {ICommandManager} - */ class CommandManager extends MultiHashHandler{ /** * new CommandManager(platform, commands) * @param {String} platform Identifier for the platform; must be either `"mac"` or `"win"` * @param {any[]} commands A list of commands - * @this {ICommandManager} **/ constructor(platform, commands) { super(commands, platform); @@ -37,10 +27,9 @@ class CommandManager extends MultiHashHandler{ /** * * @param {string | string[] | import("../../ace").Ace.Command} command - * @param {IEditor} editor + * @param {Editor} editor * @param {any} args * @returns {boolean} - * @this {ICommandManager} */ exec(command, editor, args) { if (Array.isArray(command)) { @@ -70,9 +59,8 @@ class CommandManager extends MultiHashHandler{ } /** - * @param {IEditor} editor + * @param {Editor} editor * @returns {boolean} - * @this {ICommandManager} */ toggleRecording(editor) { if (this.$inReplay) @@ -101,8 +89,7 @@ class CommandManager extends MultiHashHandler{ } /** - * @param {IEditor} editor - * @this {ICommandManager} + * @param {Editor} editor */ replay(editor) { if (this.$inReplay || !this.macro) diff --git a/src/config.js b/src/config.js index 1bd0327563b..fed086fbfa8 100644 --- a/src/config.js +++ b/src/config.js @@ -1,9 +1,9 @@ "no use strict"; /** - * @typedef {import("./lib/app_config").IAppConfig} IAppConfig + * @typedef {import("./lib/app_config").AppConfig} AppConfig */ /** - * @typedef {IAppConfig & Config} IConfig + * @typedef {AppConfig & Config} IConfig * @export */ diff --git a/src/document.js b/src/document.js index 08a630c787f..46f22d7b347 100644 --- a/src/document.js +++ b/src/document.js @@ -1,18 +1,8 @@ "use strict"; -/** - * @typedef {Document & import("../ace").Ace.EventEmitter} IDocument - * @export - */ -/** - * @typedef {import("./anchor").IAnchor} IAnchor - */ var oop = require("./lib/oop"); var applyDelta = require("./apply_delta").applyDelta; var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; -/** - * @type {any} - */ var Anchor = require("./anchor").Anchor; /** @@ -24,7 +14,6 @@ class Document { * * Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty. * @param {String | String[]} textOrLines text The starting text - * @this {IDocument} **/ constructor(textOrLines) { /** @@ -47,7 +36,7 @@ class Document { * Replaces all the lines in the current `Document` with the value of `text`. * * @param {String} text The text to use - * @this {IDocument} + **/ setValue(text) { var len = this.getLength() - 1; @@ -67,7 +56,7 @@ class Document { * Creates a new `Anchor` to define a floating point in the document. * @param {Number} row The row number to use * @param {Number} column The column number to use - * @returns {IAnchor} + * @returns {Anchor} **/ createAnchor(row, column) { return new Anchor(this, row, column); @@ -75,7 +64,7 @@ class Document { /** * @param {string} text - * @this {IDocument} + */ $detectNewLine(text) { var match = text.match(/^.*?(\r\n|\r|\n)/m); @@ -104,7 +93,7 @@ class Document { /** * [Sets the new line mode.]{: #Document.setNewLineMode.desc} * @param {import("../ace").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} - * @this {IDocument} + **/ setNewLineMode(newLineMode) { if (this.$newLineMode === newLineMode) @@ -202,7 +191,7 @@ class Document { /** * @param row * @param lines - * @this {IDocument} + * @deprecated */ insertLines(row, lines) { @@ -215,7 +204,7 @@ class Document { * @param firstRow * @param lastRow * @returns {String[]} - * @this {IDocument} + * @deprecated */ removeLines(firstRow, lastRow) { @@ -226,7 +215,7 @@ class Document { /** * @param position * @returns {import("../ace").Ace.Point} - * @this {IDocument} + * @deprecated */ insertNewLine(position) { @@ -239,7 +228,7 @@ class Document { * @param {import("../ace").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text to insert * @returns {import("../ace").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. - * @this {IDocument} + **/ insert(position, text) { // Only detect new lines if the document has no line break yet. @@ -262,7 +251,7 @@ class Document { * ``` * {row: endRow, column: 0} * ``` - * @this {IDocument} + **/ insertInLine(position, text) { var start = this.clippedPos(position.row, position.column); @@ -339,7 +328,7 @@ class Document { * Inserts the elements in `lines` into the document as full lines (does not merge with existing line), starting at the row index given by `row`. This method also triggers the `"change"` event. * @param {Number} row The index of the row to insert at * @param {string[]} lines An array of strings - * @this {IDocument} + **/ insertFullLines(row, lines) { // Clip to document. @@ -375,7 +364,7 @@ class Document { * ``` * {row: row, column: 0} * ``` - * @this {IDocument} + **/ insertMergedLines(position, lines) { var start = this.clippedPos(position.row, position.column); @@ -398,7 +387,7 @@ class Document { * Removes the `range` from the document. * @param {import("../ace").Ace.IRange} range A specified Range to remove * @returns {import("../ace").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. - * @this {IDocument} + **/ remove(range) { var start = this.clippedPos(range.start.row, range.start.column); @@ -418,7 +407,7 @@ class Document { * @param {Number} startColumn The column to start removing at * @param {Number} endColumn The column to stop removing at * @returns {import("../ace").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. - * @this {IDocument} + **/ removeInLine(row, startColumn, endColumn) { var start = this.clippedPos(row, startColumn); @@ -439,7 +428,7 @@ class Document { * @param {Number} firstRow The first row to be removed * @param {Number} lastRow The last row to be removed * @returns {String[]} Returns all the removed lines. - * @this {IDocument} + **/ removeFullLines(firstRow, lastRow) { // Clip to document. @@ -474,7 +463,7 @@ class Document { /** * Removes the new line between `row` and the row immediately following it. This method also triggers the `"change"` event. * @param {Number} row The row to check - * @this {IDocument} + **/ removeNewLine(row) { if (row < this.getLength() - 1 && row >= 0) { @@ -495,7 +484,7 @@ class Document { * {row: endRow, column: 0} * If the text and range are empty, this function returns an object containing the current `range.start` value. * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value. - * @this {IDocument} + **/ replace(range, text) { if (!(range instanceof Range)) @@ -524,7 +513,7 @@ class Document { /** * Applies all changes in `deltas` to the document. * @param {import("../ace").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) - * @this {IDocument} + **/ applyDeltas(deltas) { for (var i=0; i=0; i--) { @@ -547,7 +536,7 @@ class Document { * Applies `delta` to the document. * @param {import("../ace").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) * @param {boolean} [doNotValidate] - * @this {IDocument} + **/ applyDelta(delta, doNotValidate) { var isInsert = delta.action == "insert"; @@ -568,7 +557,7 @@ class Document { /** * @param {import("../ace").Ace.Delta} delta - * @this {IDocument} + */ $safeApplyDelta(delta) { var docLength = this.$lines.length; @@ -585,7 +574,7 @@ class Document { * * @param {import("../ace").Ace.Delta} delta * @param {number} MAX - * @this {IDocument} + */ $splitAndapplyLargeDelta(delta, MAX) { // Split large insert deltas. This is necessary because: @@ -622,7 +611,7 @@ class Document { /** * Reverts `delta` from the document. * @param {import("../ace").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) - * @this {IDocument} + **/ revertDelta(delta) { this.$safeApplyDelta({ diff --git a/src/edit_session.js b/src/edit_session.js index 79c0727ef0c..e70d0ff8346 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,21 +1,10 @@ "use strict"; -/** - * @typedef IEditSession - * @type {EditSession & import("../ace").Ace.OptionsProvider & import("../ace").Ace.EventEmitter & import("../ace").Ace.EditSessionProperties & import("./edit_session/folding").IFolding & import("./edit_session/bracket_match").BracketMatch} - * @export - */ /** * @typedef {import("./undomanager").UndoManager} UndoManager */ /** * @typedef {import("./edit_session/fold_line").FoldLine} FoldLine */ -/** - * @typedef {import("./selection").ISelection} ISelection - */ -/** - * @typedef {import("./document").IDocument} IDocument - */ /** * @typedef {import("../ace").Ace.Point} Point */ @@ -25,14 +14,11 @@ var lang = require("./lib/lang"); var BidiHandler = require("./bidihandler").BidiHandler; var config = require("./config"); var EventEmitter = require("./lib/event_emitter").EventEmitter; -/** - * @type {any} - */ var Selection = require("./selection").Selection; var TextMode = require("./mode/text").Mode; var Range = require("./range").Range; -/** @type {any} */var Document = require("./document").Document; -/** @type {any} */var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer; +var Document = require("./document").Document; +var BackgroundTokenizer = require("./background_tokenizer").BackgroundTokenizer; var SearchHighlight = require("./search_highlight").SearchHighlight; /** @@ -46,15 +32,13 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; * `EditSession` can be attached to only one [[Document `Document`]]. Same `Document` can be attached to several `EditSession`s. **/ class EditSession { - - /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. - * @param {IDocument | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} + * @param {Document | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} * @param {import("../ace").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} - * @this {IEditSession} **/ constructor(text, mode) { + /**@type {Document}*/this.doc; this.$breakpoints = []; this.$decorations = []; this.$frontMarkers = {}; @@ -72,9 +56,6 @@ class EditSession { }; // Set default background tokenizer with Text mode until editor session mode is set - /** - * @type {import("./background_tokenizer").IBackgroundTokenizer} - */ this.bgTokenizer = new BackgroundTokenizer((new TextMode()).getTokenizer(), this); @@ -87,12 +68,9 @@ class EditSession { this.$onChange = this.onChange.bind(this); if (typeof text != "object" || !text.getLine) - text = new Document(text); + text = new Document(/**@type{string}*/(text)); - this.setDocument(/**@type{IDocument}*/(text)); - /** - * @type {ISelection}} - */ + this.setDocument(text); this.selection = new Selection(this); this.$bidiHandler = new BidiHandler(this); @@ -106,7 +84,7 @@ class EditSession { /** * Sets the `EditSession` to point to a new `Document`. If a `BackgroundTokenizer` exists, it also points to `doc`. * - * @param {IDocument} doc The new `Document` to use + * @param {Document} doc The new `Document` to use * **/ setDocument(doc) { @@ -122,7 +100,7 @@ class EditSession { /** * Returns the `Document` associated with this session. - * @return {IDocument} + * @return {Document} **/ getDocument() { return this.doc; @@ -188,7 +166,6 @@ class EditSession { /** * * @param {import("../ace").Ace.Delta} delta - * @this {IEditSession} */ onChange(delta) { this.$modified = true; @@ -218,7 +195,6 @@ class EditSession { /** * Sets the session text. * @param {String} text The new text to place - * @this {IEditSession} **/ setValue(text) { this.doc.setValue(text); @@ -242,7 +218,7 @@ class EditSession { /** * Returns selection object. - * @returns {ISelection} + * @returns {Selection} **/ getSelection() { return this.selection; @@ -298,7 +274,6 @@ class EditSession { /** * Sets the undo manager. * @param {UndoManager} undoManager The new undo manager - * @this {IEditSession} **/ setUndoManager(undoManager) { this.$undoManager = undoManager; @@ -339,7 +314,6 @@ class EditSession { /** * Returns the current value for tabs. If the user is using soft tabs, this will be a series of spaces (defined by [[EditSession.getTabSize `getTabSize()`]]); otherwise it's simply `'\t'`. * @returns {String} - * @this {IEditSession} **/ getTabString() { if (this.getUseSoftTabs()) { @@ -352,7 +326,6 @@ class EditSession { /** * Pass `true` to enable the use of soft tabs. Soft tabs means you're using spaces instead of the tab character (`'\t'`). * @param {Boolean} val Value indicating whether or not to use soft tabs - * @this {IEditSession} **/ setUseSoftTabs(val) { this.setOption("useSoftTabs", val); @@ -361,7 +334,6 @@ class EditSession { /** * Returns `true` if soft tabs are being used, `false` otherwise. * @returns {Boolean} - * @this {IEditSession} **/ getUseSoftTabs() { // todo might need more general way for changing settings from mode, but this is ok for now @@ -370,14 +342,12 @@ class EditSession { /** * Set the number of spaces that define a soft tab; for example, passing in `4` transforms the soft tabs to be equivalent to four spaces. This function also emits the `changeTabSize` event. * @param {Number} tabSize The new tab size - * @this {IEditSession} **/ setTabSize(tabSize) { this.setOption("tabSize", tabSize); } /** * Returns the current tab size. - * @this {IEditSession} * @return {number} **/ getTabSize() { @@ -387,7 +357,6 @@ class EditSession { /** * Returns `true` if the character at the position is a soft tab. * @param {Point} position The position to check - * @this {IEditSession} **/ isTabStop(position) { return this.$useSoftTabs && (position.column % this.$tabSize === 0); @@ -396,7 +365,6 @@ class EditSession { /** * Set whether keyboard navigation of soft tabs moves the cursor within the soft tab, rather than over * @param {Boolean} navigateWithinSoftTabs Value indicating whether or not to navigate within soft tabs - * @this {IEditSession} **/ setNavigateWithinSoftTabs(navigateWithinSoftTabs) { this.setOption("navigateWithinSoftTabs", navigateWithinSoftTabs); @@ -404,7 +372,6 @@ class EditSession { /** * Returns `true` if keyboard navigation moves the cursor within soft tabs, `false` if it moves the cursor over soft tabs. * @returns {Boolean} - * @this {IEditSession} **/ getNavigateWithinSoftTabs() { return this.$navigateWithinSoftTabs; @@ -417,7 +384,6 @@ class EditSession { * * @param {Boolean} overwrite Defines whether or not to set overwrites * - * @this {IEditSession} **/ setOverwrite(overwrite) { this.setOption("overwrite", overwrite); @@ -432,7 +398,6 @@ class EditSession { /** * Sets the value of overwrite to the opposite of whatever it currently is. - * @this {IEditSession} **/ toggleOverwrite() { this.setOverwrite(!this.$overwrite); @@ -442,7 +407,6 @@ class EditSession { * Adds `className` to the `row`, to be used for CSS stylings and whatnot. * @param {Number} row The row number * @param {String} className The class to add - * @this {IEditSession} **/ addGutterDecoration(row, className) { if (!this.$decorations[row]) @@ -455,7 +419,6 @@ class EditSession { * Removes `className` from the `row`. * @param {Number} row The row number * @param {String} className The class to add - * @this {IEditSession} **/ removeGutterDecoration(row, className) { this.$decorations[row] = (this.$decorations[row] || "").replace(" " + className, ""); @@ -473,7 +436,6 @@ class EditSession { /** * Sets a breakpoint on every row number given by `rows`. This function also emites the `'changeBreakpoint'` event. * @param {number[]} rows An array of row indices - * @this {IEditSession} **/ setBreakpoints(rows) { this.$breakpoints = []; @@ -485,7 +447,6 @@ class EditSession { /** * Removes all breakpoints on the rows. This function also emits the `'changeBreakpoint'` event. - * @this {IEditSession} **/ clearBreakpoints() { this.$breakpoints = []; @@ -496,7 +457,6 @@ class EditSession { * Sets a breakpoint on the row number given by `row`. This function also emits the `'changeBreakpoint'` event. * @param {Number} row A row index * @param {String} className Class of the breakpoint - * @this {IEditSession} **/ setBreakpoint(row, className) { if (className === undefined) @@ -511,7 +471,6 @@ class EditSession { /** * Removes a breakpoint on the row number given by `row`. This function also emits the `'changeBreakpoint'` event. * @param {Number} row A row index - * @this {IEditSession} **/ clearBreakpoint(row) { delete this.$breakpoints[row]; @@ -526,7 +485,6 @@ class EditSession { * @param {Boolean} [inFront] Set to `true` to establish a front marker * * @return {Number} The new marker id - * @this {IEditSession} **/ addMarker(range, clazz, type, inFront) { var id = this.$markerId++; @@ -557,7 +515,6 @@ class EditSession { * @param {Boolean} [inFront] Set to `true` to establish a front marker * * @return {import("../ace").Ace.MarkerLike} The added marker - * @this {IEditSession} **/ addDynamicMarker(marker, inFront) { if (!marker.update) @@ -580,7 +537,6 @@ class EditSession { /** * Removes the marker with the specified ID. If this marker was in front, the `'changeFrontMarker'` event is emitted. If the marker was in the back, the `'changeBackMarker'` event is emitted. * @param {Number} markerId A number representing a marker - * @this {IEditSession} **/ removeMarker(markerId) { var marker = this.$frontMarkers[markerId] || this.$backMarkers[markerId]; @@ -605,7 +561,6 @@ class EditSession { /** * * @param {RegExp} re - * @this {IEditSession} */ highlight(re) { if (!this.$searchHighlight) { @@ -622,7 +577,6 @@ class EditSession { * @param {string} clazz * @param {boolean} [inFront] * @return {Range} - * @this {IEditSession} */ highlightLines(startRow, endRow, clazz, inFront) { if (typeof endRow != "number") { @@ -649,7 +603,6 @@ class EditSession { /** * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event. * @param {import("../ace").Ace.Annotation[]} annotations A list of annotations - * @this {IEditSession} **/ setAnnotations(annotations) { this.$annotations = annotations; @@ -666,7 +619,6 @@ class EditSession { /** * Clears all the annotations for this session. This function also triggers the `'changeAnnotation'` event. - * @this {IEditSession} **/ clearAnnotations() { this.setAnnotations([]); @@ -768,19 +720,16 @@ class EditSession { /** * Identifies if you want to use a worker for the `EditSession`. * @param {Boolean} useWorker Set to `true` to use a worker - * @this {IEditSession} **/ setUseWorker(useWorker) { this.setOption("useWorker", useWorker); } /** * Returns `true` if workers are being used. - * @this {IEditSession} **/ getUseWorker() { return this.$useWorker; } /** * Reloads all the tokens on the current session. This function calls [[BackgroundTokenizer.start `BackgroundTokenizer.start ()`]] to all the rows; it also emits the `'tokenizerUpdate'` event. - * @this {IEditSession} **/ onReloadTokenizer(e) { var rows = e.data; @@ -792,7 +741,6 @@ class EditSession { * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. * @param {import("../ace").Ace.SyntaxMode | string} mode Set a new text mode * @param {() => void} [cb] optional callback - * @this {IEditSession} **/ setMode(mode, cb) { if (mode && typeof mode === "object") { @@ -840,7 +788,6 @@ class EditSession { * * @param mode * @param [$isPlaceholder] - * @this {IEditSession} */ $onChangeMode(mode, $isPlaceholder) { if (!$isPlaceholder) @@ -914,7 +861,6 @@ class EditSession { /** * This function sets the scroll top value. It also emits the `'changeScrollTop'` event. * @param {Number} scrollTop The new scroll top value - * @this {IEditSession} **/ setScrollTop(scrollTop) { // TODO: should we force integer lineheight instead? scrollTop = Math.round(scrollTop); @@ -935,7 +881,6 @@ class EditSession { /** * [Sets the value of the distance between the left of the editor and the leftmost part of the visible content.]{: #EditSession.setScrollLeft} - * @this {IEditSession} * @param {number} scrollLeft */ setScrollLeft(scrollLeft) { @@ -958,7 +903,6 @@ class EditSession { /** * Returns the width of the screen. * @returns {Number} - * @this {IEditSession} **/ getScreenWidth() { this.$computeWidth(); @@ -969,7 +913,6 @@ class EditSession { /** * @return {number} - * @this {IEditSession} */ getLineWidgetMaxWidth() { if (this.lineWidgetsWidth != null) return this.lineWidgetsWidth; @@ -983,7 +926,6 @@ class EditSession { /** * @param {boolean} [force] - * @this {IEditSession} */ $computeWidth(force) { if (this.$modified || force) { @@ -1094,7 +1036,6 @@ class EditSession { * Reverts previous changes to your document. * @param {import("../ace").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] [If `true`, doesn't select the range of where the change occured]{: #dontSelect} - * @this {IEditSession} **/ undoChanges(deltas, dontSelect) { if (!deltas.length) @@ -1228,7 +1169,6 @@ class EditSession { * @param {Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * @returns {Range} The new range where the text was moved to. - * @this {IEditSession} **/ moveText(fromRange, toPosition, copy) { var text = this.getTextRange(fromRange); @@ -1279,7 +1219,6 @@ class EditSession { * @param {Number} startRow Starting row * @param {Number} endRow Ending row * @param {String} indentString The indent token - * @this {IEditSession} **/ indentRows(startRow, endRow, indentString) { indentString = indentString.replace(/\t/g, this.getTabString()); @@ -1290,7 +1229,6 @@ class EditSession { /** * Outdents all the rows defined by the `start` and `end` properties of `range`. * @param {Range} range A range of rows - * @this {IEditSession} **/ outdentRows(range) { var rowRange = range.collapseRows(); @@ -1322,7 +1260,6 @@ class EditSession { * @param {number} lastRow * @param [dir] * @returns {number} - * @this {IEditSession} */ $moveLines(firstRow, lastRow, dir) { firstRow = this.getRowFoldStart(firstRow); @@ -1361,7 +1298,6 @@ class EditSession { * @param {Number} firstRow The starting row to move up * @param {Number} lastRow The final row to move up * @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1. - * @this {IEditSession} **/ moveLinesUp(firstRow, lastRow) { return this.$moveLines(firstRow, lastRow, -1); @@ -1372,7 +1308,6 @@ class EditSession { * @param {Number} firstRow The starting row to move down * @param {Number} lastRow The final row to move down * @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1. - * @this {IEditSession} **/ moveLinesDown(firstRow, lastRow) { return this.$moveLines(firstRow, lastRow, 1); @@ -1383,7 +1318,6 @@ class EditSession { * @param {Number} firstRow The starting row to duplicate * @param {Number} lastRow The final row to duplicate * @returns {Number} Returns the number of new rows added; in other words, `lastRow - firstRow + 1`. - * @this {IEditSession} **/ duplicateLines(firstRow, lastRow) { return this.$moveLines(firstRow, lastRow, 0); @@ -1466,7 +1400,6 @@ class EditSession { /** * Sets whether or not line wrapping is enabled. If `useWrapMode` is different than the current value, the `'changeWrapMode'` event is emitted. * @param {Boolean} useWrapMode Enable (or disable) wrap mode - * @this {IEditSession} **/ setUseWrapMode(useWrapMode) { if (useWrapMode != this.$useWrapMode) { @@ -1501,7 +1434,6 @@ class EditSession { * Sets the boundaries of wrap. Either value can be `null` to have an unconstrained wrap, or, they can be the same number to pin the limit. If the wrap limits for `min` or `max` are different, this method also emits the `'changeWrapMode'` event. * @param {Number} min The minimum wrap value (the left side wrap) * @param {Number} max The maximum wrap value (the right side wrap) - * @this {IEditSession} **/ setWrapLimitRange(min, max) { if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) { @@ -1520,7 +1452,6 @@ class EditSession { * @param {Number} desiredLimit The new wrap limit * @param [$printMargin] * @returns {Boolean} - * @this {IEditSession} **/ adjustWrapLimit(desiredLimit, $printMargin) { var limits = this.$wrapLimitRange; @@ -1570,7 +1501,6 @@ class EditSession { * at a minimum of the given length minus 20 chars and at a maximum * of the given number of chars. * @param {number} limit The maximum line length in chars, for soft wrapping lines. - * @this {IEditSession} */ setWrapLimit(limit) { this.setWrapLimitRange(limit, limit); @@ -1594,7 +1524,6 @@ class EditSession { /** * * @param {import("../ace").Ace.Delta} delta - * @this {IEditSession} */ $updateInternalDataOnChange(delta) { var useWrapMode = this.$useWrapMode; @@ -1718,7 +1647,6 @@ class EditSession { * * @param {number} firstRow * @param {number} lastRow - * @this {IEditSession} */ $updateWrapData(firstRow, lastRow) { var lines = this.doc.getAllLines(); @@ -1770,7 +1698,6 @@ class EditSession { * @param {number} wrapLimit * @param {number} tabSize * @returns {*[]} - * @this {IEditSession} */ $computeWrapSplits(tokens, wrapLimit, tabSize) { if (tokens.length == 0) { @@ -1927,7 +1854,6 @@ class EditSession { * @param {String} str The string to check * @param {Number} [offset] The value to start at * @returns {number[]} - * @this {IEditSession} **/ $getDisplayTokens(str, offset) { var arr = []; @@ -1968,7 +1894,6 @@ class EditSession { * @returns {Number[]} Returns an `int[]` array with two elements:
* The first position indicates the number of columns for `str` on screen.
* The second value contains the position of the document column that this function read until. - * @this {IEditSession} **/ $getStringScreenWidth(str, maxScreenColumn, screenColumn) { if (maxScreenColumn == 0) @@ -2029,7 +1954,6 @@ class EditSession { /** * @param {Number} screenRow * @returns {Number} - * @this {IEditSession} **/ getRowWrapIndent(screenRow) { if (this.$useWrapMode) { @@ -2047,7 +1971,6 @@ class EditSession { * @returns {Number} * * @related EditSession.documentToScreenColumn - * @this {IEditSession} **/ getScreenLastRowColumn(screenRow) { var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE); @@ -2059,7 +1982,6 @@ class EditSession { * @param {Number} docRow * @param {Number} docColumn * @returns {number} - * @this {IEditSession} **/ getDocumentLastRowColumn(docRow, docColumn) { var screenRow = this.documentToScreenRow(docRow, docColumn); @@ -2071,7 +1993,6 @@ class EditSession { * @param {Number} docRow * @param {Number} docColumn * @returns {Point} - * @this {IEditSession} **/ getDocumentLastRowColumnPosition(docRow, docColumn) { var screenRow = this.documentToScreenRow(docRow, docColumn); @@ -2096,7 +2017,6 @@ class EditSession { * @param {Number} screenColumn The screen column to check * * @returns {Number} - * @this {IEditSession} **/ getScreenTabSize(screenColumn) { return this.$tabSize - (screenColumn % this.$tabSize | 0); @@ -2106,7 +2026,6 @@ class EditSession { * @param {number} screenRow * @param {number} screenColumn * @returns {number} - * @this {IEditSession} */ screenToDocumentRow(screenRow, screenColumn) { return this.screenToDocumentPosition(screenRow, screenColumn).row; @@ -2116,7 +2035,6 @@ class EditSession { * @param {number} screenRow * @param {number} screenColumn * @returns {number} - * @this {IEditSession} */ screenToDocumentColumn(screenRow, screenColumn) { return this.screenToDocumentPosition(screenRow, screenColumn).column; @@ -2131,7 +2049,6 @@ class EditSession { * @returns {Point} The object returned has two properties: `row` and `column`. * * @related EditSession.documentToScreenPosition - * @this {IEditSession} **/ screenToDocumentPosition(screenRow, screenColumn, offsetX) { if (screenRow < 0) @@ -2228,7 +2145,6 @@ class EditSession { * @returns {Point} The object returned by this method has two properties: `row` and `column`. * * @related EditSession.screenToDocumentPosition - * @this {IEditSession} **/ documentToScreenPosition(docRow, docColumn) { // Normalize the passed in arguments. @@ -2329,7 +2245,6 @@ class EditSession { * @param {Number} row * @param {Number} docColumn * @returns {Number} - * @this {IEditSession} **/ documentToScreenColumn(row, docColumn) { return this.documentToScreenPosition(row, docColumn).column; @@ -2340,7 +2255,6 @@ class EditSession { * @param {Number} docRow * @param {Number} docColumn * @returns {number} - * @this {IEditSession} **/ documentToScreenRow(docRow, docColumn) { return this.documentToScreenPosition(docRow, docColumn).row; @@ -2349,7 +2263,6 @@ class EditSession { /** * Returns the length of the screen. * @returns {Number} - * @this {IEditSession} **/ getScreenLength() { var screenRows = 0; @@ -2392,7 +2305,6 @@ class EditSession { } /** - * @this {IEditSession} * @param {import("./layer/font_metrics").FontMetrics} fm */ $setFontMetrics(fm) { @@ -2422,9 +2334,6 @@ class EditSession { }; } - /** - * @this {IEditSession} - */ destroy() { if (!this.destroyed) { this.bgTokenizer.setDocument(null); @@ -2537,7 +2446,6 @@ require("./edit_session/bracket_match").BracketMatch.call(EditSession.prototype) config.defineOptions(EditSession.prototype, "session", { wrap: { /** - * @this {IEditSession} * @param {string | boolean | number} value */ set: function(value) { @@ -2575,7 +2483,6 @@ config.defineOptions(EditSession.prototype, "session", { }, wrapMethod: { /** - * @this {IEditSession} * @param {"code"|"text"|"auto"|boolean} val */ set: function(val) { @@ -2593,9 +2500,6 @@ config.defineOptions(EditSession.prototype, "session", { initialValue: "auto" }, indentedSoftWrap: { - /** - * @this {IEditSession} - */ set: function() { if (this.$useWrapMode) { this.$useWrapMode = false; @@ -2610,7 +2514,6 @@ config.defineOptions(EditSession.prototype, "session", { }, useWorker: { /** - * @this {IEditSession} * @param {boolean} useWorker */ set: function(useWorker) { @@ -2625,7 +2528,6 @@ config.defineOptions(EditSession.prototype, "session", { useSoftTabs: {initialValue: true}, tabSize: { /** - * @this {IEditSession} * @param tabSize */ set: function(tabSize) { diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index 05700a5aaa6..ebbf2c9a714 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -1,21 +1,17 @@ "use strict"; /** - * @typedef {import("../edit_session").IEditSession} IEditSession + * @typedef {import("../edit_session").EditSession} EditSession */ - var TokenIterator = require("../token_iterator").TokenIterator; var Range = require("../range").Range; -/** - * @export - * @this {IEditSession} - */ function BracketMatch() { /** * * @param {import("../../ace").Ace.Point} position * @param {string} [chr] + * @this {EditSession} */ this.findMatchingBracket = function(position, chr) { if (position.column == 0) return null; @@ -36,6 +32,7 @@ function BracketMatch() { /** * @param {import("../../ace").Ace.Point} pos * @return {null|Range} + * @this {EditSession} */ this.getBracketRange = function(pos) { var line = this.getLine(pos.row); @@ -86,6 +83,7 @@ function BracketMatch() { * @param {import("../../ace").Ace.Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} + * @this {EditSession} */ this.getMatchingBracketRanges = function(pos, isBackwards) { var line = this.getLine(pos.row); @@ -131,6 +129,7 @@ function BracketMatch() { * @param {import("../../ace").Ace.Point} position * @param {RegExp} [typeRe] * @return {import("../../ace").Ace.Point|null} + * @this {EditSession} */ this.$findOpeningBracket = function(bracket, position, typeRe) { var openBracket = this.$brackets[bracket]; @@ -196,6 +195,7 @@ function BracketMatch() { * @param {import("../../ace").Ace.Point} position * @param {RegExp} [typeRe] * @return {import("../../ace").Ace.Point|null} + * @this {EditSession} */ this.$findClosingBracket = function(bracket, position, typeRe) { var closingBracket = this.$brackets[bracket]; @@ -259,6 +259,7 @@ function BracketMatch() { * Returns [[Range]]'s for matching tags and tag names, if there are any * @param {import("../../ace").Ace.Point} pos * @returns {{closeTag: Range, closeTagName: Range, openTag: Range, openTagName: Range} | undefined} + * @this {EditSession} */ this.getMatchingTags = function (pos) { var iterator = new TokenIterator(this, pos.row, pos.column); diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index f65e93bdcb4..ddbb767365f 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -1,11 +1,9 @@ "use strict"; /** - * @typedef FoldLine - * @type {import("./fold_line").FoldLine} + * @typedef {import("./fold_line").FoldLine} FoldLine */ /** - * @typedef Range - * @type {import("../range").Range} + * @typedef {import("../range").Range} Range */ var RangeList = require("../range_list").RangeList; @@ -20,10 +18,6 @@ class Fold extends RangeList { */ constructor(range, placeholder) { super(); - /** - * @type {number} - */ - this.collapseChildren; this.foldLine = null; this.placeholder = placeholder; this.range = range; diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index 131c235e899..bf0bb5d7476 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -1,7 +1,6 @@ "use strict"; /** - * @typedef Fold - * @type {import("./fold").Fold} + * @typedef {import("./fold").Fold} Fold */ var Range = require("../range").Range; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 1999572a9c7..5f9f21c3854 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -1,13 +1,6 @@ +// @ts-nocheck "use strict"; -/** - * @typedef {Folding & import("../../ace").Ace.FoldingProperties} IFolding - * @export - */ - -/** - * @typedef {import("../edit_session").IEditSession} IEditSession - */ var Range = require("../range").Range; var FoldLine = require("./fold_line").FoldLine; var Fold = require("./fold").Fold; @@ -15,8 +8,13 @@ var TokenIterator = require("../token_iterator").TokenIterator; var MouseEvent = require("../mouse/mouse_event").MouseEvent; /** - * @export - * @this {IEditSession} + * @typedef IFolding + * @type {import("../edit_session").EditSession & import("../../ace").Ace.Folding} + */ + +/** + * @this {IFolding} + * @type {IFolding} */ function Folding() { /** @@ -27,7 +25,6 @@ function Folding() { * @param {number} column * @param {number} [side] * @return {Fold} - * @this {IEditSession} **/ this.getFoldAt = function(row, column, side) { var foldLine = this.getFoldLine(row); @@ -281,16 +278,19 @@ function Folding() { /** * Adds a new fold. * - * @param {Fold|String} placeholder + * @param {Fold|string} placeholder * @param {Range} [range] * @returns {Fold} * The new created Fold object or an existing fold object in case the * passed in range fits an existing fold exactly. - * @this {IEditSession} + * @this {IFolding} */ this.addFold = function(placeholder, range) { var foldData = this.$foldData; var added = false; + /** + * @type {Fold} + */ var fold; if (placeholder instanceof Fold) @@ -382,7 +382,6 @@ function Folding() { /** * * @param {Fold} fold - * @this {IEditSession} */ this.removeFold = function(fold) { var foldLine = fold.foldLine; @@ -829,7 +828,6 @@ function Folding() { /** * @param {string} style - * @this {IEditSession} */ this.setFoldStyle = function(style) { if (!this.$foldStyles[style]) @@ -851,7 +849,6 @@ function Folding() { /** * @param {import("../../ace").Ace.FoldMode} foldMode - * @this {IEditSession} */ this.$setFolding = function(foldMode) { if (this.$foldMode == foldMode) @@ -882,7 +879,6 @@ function Folding() { * @param {number} row * @param {boolean} [ignoreCurrent] * @return {{range?: Range, firstRange?: Range}} - * @this {IEditSession} */ this.getParentFoldRangeData = function (row, ignoreCurrent) { var fw = this.foldWidgets; @@ -939,7 +935,6 @@ function Folding() { * @param {number} row * @param options * @return {Fold|*} - * @this {IEditSession} */ this.$toggleFoldWidget = function(row, options) { if (!this.getFoldWidget) @@ -990,7 +985,6 @@ function Folding() { /** * * @param {boolean} [toggleParent] - * @this {IEditSession} */ this.toggleFoldWidget = function(toggleParent) { var row = this.selection.getCursor().row; @@ -1017,7 +1011,6 @@ function Folding() { /** * @param {import("../../ace").Ace.Delta} delta - * @this {IEditSession} */ this.updateFoldWidgets = function(delta) { var firstRow = delta.start.row; @@ -1035,7 +1028,6 @@ function Folding() { }; /** * @param e - * @this {IEditSession} */ this.tokenizerUpdateFoldWidgets = function(e) { var rows = e.data; diff --git a/src/editor.js b/src/editor.js index 9da7983f1cd..c116fff1075 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,21 +1,11 @@ "use strict"; /** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef VirtualRenderer + * @type {import("./virtual_renderer").VirtualRenderer} */ /** - * @typedef IVirtualRenderer - * @type {import("./virtual_renderer").IVirtualRenderer} - */ -/** - * @typedef ISelection - * @type {import("./selection").ISelection} - */ -/** - * @typedef ICommandManager - * @type {import("./commands/command_manager").ICommandManager} + * @typedef {import("./selection").Selection} Selection */ var oop = require("./lib/oop"); @@ -30,7 +20,7 @@ var EditSession = require("./edit_session").EditSession; var Search = require("./search").Search; var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; -/** @type {any} */var CommandManager = require("./commands/command_manager").CommandManager; +var CommandManager = require("./commands/command_manager").CommandManager; var defaultCommands = require("./commands/default_commands").commands; var config = require("./config"); var TokenIterator = require("./token_iterator").TokenIterator; @@ -53,15 +43,13 @@ class Editor { /** * Creates a new `Editor` object. * - * @param {IVirtualRenderer} renderer Associated `VirtualRenderer` that draws everything - * @param {IEditSession} [session] The `EditSession` to refer to + * @param {VirtualRenderer} renderer Associated `VirtualRenderer` that draws everything + * @param {EditSession} [session] The `EditSession` to refer to * @param {Object} [options] The default options **/ constructor(renderer, session, options) { - /** - * @type {IEditSession} - */ - this.session; + /**@type{EditSession}*/this.session; + this.$toDestroy = []; var container = renderer.getContainerElement(); @@ -70,16 +58,13 @@ class Editor { */ this.container = container; /** - * @type {IVirtualRenderer} + * @type {VirtualRenderer} */ this.renderer = renderer; /** * @type {string} */ this.id = "editor" + (++Editor.$uid); - /** - * @type {ICommandManager} - */ this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands); if (typeof document == "object") { this.textInput = new TextInput(renderer.getTextAreaContainer(), this); @@ -293,7 +278,7 @@ class Editor { /** * Sets a new editsession to use. This method also emits the `'changeSession'` event. - * @param {IEditSession} [session] The new session to use + * @param {EditSession} [session] The new session to use **/ setSession(session) { if (this.session == session) @@ -410,7 +395,7 @@ class Editor { /** * Returns the current session being used. - * @returns {IEditSession} + * @returns {EditSession} **/ getSession() { return this.session; @@ -450,7 +435,7 @@ class Editor { /** * * Returns the currently highlighted selection. - * @returns {ISelection} The selection object + * @returns {Selection} The selection object **/ getSelection() { return this.selection; @@ -1924,6 +1909,7 @@ class Editor { selection.fromOrientedRange(range); } else { var ranges = selection.rangeList.ranges; + // @ts-expect-error TODO: possible bug, no args in parameters selection.rangeList.detach(this.session); this.inVirtualSelectionMode = true; diff --git a/src/ext/beautify.js b/src/ext/beautify.js index ee22f4ec049..be367fb4e21 100644 --- a/src/ext/beautify.js +++ b/src/ext/beautify.js @@ -23,7 +23,7 @@ exports.formatOptions = { /** * - * @param {import("../edit_session").IEditSession} session + * @param {import("../edit_session").EditSession} session */ exports.beautify = function(session) { var iterator = new TokenIterator(session, 0, 0); diff --git a/src/ext/code_lens.js b/src/ext/code_lens.js index 36ba3688e51..6623e828d5a 100644 --- a/src/ext/code_lens.js +++ b/src/ext/code_lens.js @@ -1,7 +1,6 @@ "use strict"; /** - * @typedef IEditSession - * @type {import("../edit_session").IEditSession} + * @typedef {import("../edit_session").EditSession} EditSession */ var LineWidgets = require("../line_widgets").LineWidgets; @@ -99,7 +98,7 @@ function clearCodeLensWidgets(session) { /** * - * @param {IEditSession} session + * @param {EditSession} session * @param lenses * @return {number} */ @@ -199,7 +198,7 @@ function detachFromEditor(editor) { /** * - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor * @param codeLensProvider */ exports.registerCodeLensProvider = function(editor, codeLensProvider) { @@ -209,8 +208,7 @@ exports.registerCodeLensProvider = function(editor, codeLensProvider) { }; /** - * - * @param {IEditSession} session + * @param {EditSession} session */ exports.clear = function(session) { exports.setLenses(session, null); diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 72aa5f766ba..8c0e9077fb5 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -1,13 +1,3 @@ -/** - * @typedef ICommandBarTooltip - * @type {CommandBarTooltip & import("../../ace").Ace.EventEmitter & {[key: string]: any}} - */ - -/** - * @typedef IEditor - * @type {import("../editor").IEditor} - */ - var Tooltip = require("../tooltip").Tooltip; var EventEmitter = require("../lib/event_emitter").EventEmitter; var lang = require("../lib/lang"); @@ -56,12 +46,9 @@ var keyDisplayMap = { * When attached to an editor, it is either always shown or only when the active line is hovered * with mouse, depending on the alwaysShow property. */ -/** - * @type {ICommandBarTooltip} - */ class CommandBarTooltip { /** - * @param {Element} parentNode + * @param {HTMLElement} parentNode * @param {Partial} [options] */ constructor(parentNode, options) { @@ -101,7 +88,6 @@ class CommandBarTooltip { * * @param {string} id * @param {import("../../ace").TooltipCommand} command - * @this {ICommandBarTooltip} */ registerCommand(id, command) { var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip; @@ -110,7 +96,7 @@ class CommandBarTooltip { name: "···", exec: /** - * @this {ICommandBarTooltip} + * @this {CommandBarTooltip} */ function() { this.$shouldHideMoreOptions = false; @@ -148,7 +134,6 @@ class CommandBarTooltip { * When false, the tooltip is displayed only when the mouse hovers over the active editor line. * * @param {boolean} alwaysShow - * @this {ICommandBarTooltip} */ setAlwaysShow(alwaysShow) { this.$alwaysShow = alwaysShow; @@ -162,8 +147,7 @@ class CommandBarTooltip { * Depending on the alwaysShow parameter it either displays the tooltip immediately, * or subscribes to the necessary events to display the tooltip on hover. * - * @param {IEditor} editor - * @this {ICommandBarTooltip} + * @param {import("../editor").Editor} editor */ attach(editor) { if (!editor || (this.isShown() && this.editor === editor)) { @@ -188,7 +172,6 @@ class CommandBarTooltip { /** * Updates the position of the command bar tooltip. It aligns itself above the active line in the editor. - * @this {ICommandBarTooltip} */ updatePosition() { if (!this.editor) { @@ -359,12 +342,13 @@ class CommandBarTooltip { } } + // @ts-ignore dom.buildDom(['div', { class: [BUTTON_CLASS_NAME, command.cssClass || ""].join(" "), ref: id }, buttonNode], parentEl, this.elements); this.commands[id] = command; var eventListener = /** - * @this {ICommandBarTooltip} + * @this {CommandBarTooltip} */ function(e) { if (this.editor) { @@ -388,7 +372,6 @@ class CommandBarTooltip { /** * @param {boolean} visible - * @this {ICommandBarTooltip} */ $setMoreOptionsVisibility(visible) { if (visible) { @@ -493,9 +476,6 @@ class CommandBarTooltip { } } - /** - * @this {ICommandBarTooltip} - */ $showTooltip() { if (this.isShown()) { return; @@ -507,9 +487,6 @@ class CommandBarTooltip { this.updatePosition(); this._signal("show"); } - /** - * @this {ICommandBarTooltip} - */ $hideTooltip() { this.$mouseInTooltip = false; if (!this.isShown()) { diff --git a/src/ext/elastic_tabstops_lite.js b/src/ext/elastic_tabstops_lite.js index 68d0a0d1ed8..5cb6dd341e8 100644 --- a/src/ext/elastic_tabstops_lite.js +++ b/src/ext/elastic_tabstops_lite.js @@ -2,7 +2,7 @@ class ElasticTabstopsLite { /** - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor */ constructor(editor) { this.$editor = editor; @@ -310,7 +310,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { useElasticTabstops: { /** * @param {boolean} val - * @this {import("../editor").IEditor} + * @this {import("../editor").Editor} */ set: function(val) { if (val) { diff --git a/src/ext/emmet.js b/src/ext/emmet.js index 8be9d945bcc..1e82cc61ac6 100644 --- a/src/ext/emmet.js +++ b/src/ext/emmet.js @@ -12,7 +12,7 @@ var emmet, emmetPath; class AceEmmetEditor { /** - * @param {import("../editor").IEditor} editor + * @param {Editor} editor */ setupContext(editor) { this.ace = editor; diff --git a/src/ext/error_marker.js b/src/ext/error_marker.js index e388b14c0ef..84f185b3520 100644 --- a/src/ext/error_marker.js +++ b/src/ext/error_marker.js @@ -60,7 +60,7 @@ function findAnnotations(session, row, dir) { } /** - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor * @param {number} dir */ exports.showErrorMarker = function(editor, dir) { diff --git a/src/ext/hardwrap.js b/src/ext/hardwrap.js index 634d63d1c62..1db3fb15499 100644 --- a/src/ext/hardwrap.js +++ b/src/ext/hardwrap.js @@ -3,7 +3,7 @@ var Range = require("../range").Range; /** - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor * @param {import("../../ace").Ace.HardWrapOptions} options */ function hardWrap(editor, options) { diff --git a/src/ext/inline_autocomplete.js b/src/ext/inline_autocomplete.js index 6ba683a02d7..ef46e622cdf 100644 --- a/src/ext/inline_autocomplete.js +++ b/src/ext/inline_autocomplete.js @@ -1,7 +1,5 @@ "use strict"; -/** - * @typedef {import("./command_bar").ICommandBarTooltip} ICommandBarTooltip - */ + var HashHandler = require("../keyboard/hash_handler").HashHandler; var AceInline = require("../autocomplete/inline").AceInline; var FilteredList = require("../autocomplete").FilteredList; @@ -10,7 +8,7 @@ var Editor = require("../editor").Editor; var util = require("../autocomplete/util"); var dom = require("../lib/dom"); var lang = require("../lib/lang"); -/**@type{any}*/var CommandBarTooltip = require("./command_bar").CommandBarTooltip; +var CommandBarTooltip = require("./command_bar").CommandBarTooltip; var BUTTON_CLASS_NAME = require("./command_bar").BUTTON_CLASS_NAME; var snippetCompleter = require("./language_tools").snippetCompleter; @@ -28,7 +26,7 @@ var destroyCompleter = function(e, editor) { */ class InlineAutocomplete { /** - * @param {import("../editor").IEditor} editor + * @param {Editor} editor */ constructor(editor) { this.editor = editor; @@ -55,8 +53,7 @@ class InlineAutocomplete { } /** - * - * @return {ICommandBarTooltip} + * @return {CommandBarTooltip} */ getInlineTooltip() { if (!this.inlineTooltip) { @@ -408,11 +405,11 @@ require("../config").defineOptions(Editor.prototype, "editor", { * Factory method to create a command bar tooltip for inline autocomplete. * * @param {HTMLElement} parentEl The parent element where the tooltip HTML elements will be added. - * @returns {ICommandBarTooltip} The command bar tooltip for inline autocomplete + * @returns {CommandBarTooltip} The command bar tooltip for inline autocomplete */ InlineAutocomplete.createInlineTooltip = function(parentEl) { /** - * @type {ICommandBarTooltip} + * @type {CommandBarTooltip} */ var inlineTooltip = new CommandBarTooltip(parentEl); inlineTooltip.registerCommand("Previous", diff --git a/src/ext/keybinding_menu.js b/src/ext/keybinding_menu.js index 57de93c7c16..26ebbefa601 100644 --- a/src/ext/keybinding_menu.js +++ b/src/ext/keybinding_menu.js @@ -11,19 +11,15 @@ */ "use strict"; -/** - * @typedef IEditor - * @type {import("../editor").IEditor} - */ -/** @type {any} */var Editor = require("../editor").Editor; +var Editor = require("../editor").Editor; /** * Generates a menu which displays the keyboard shortcuts. * @author * Matthew Christopher Kastor-Inare III
* ☭ Hial Atropa!! ☭ - * @param {IEditor} editor An instance of the ace editor. + * @param {Editor} editor An instance of the ace editor. */ function showKeyboardShortcuts(editor) { // make sure the menu isn't open already. @@ -45,7 +41,7 @@ function showKeyboardShortcuts(editor) { } /** - * @param {IEditor} editor + * @param {Editor} editor */ module.exports.init = function (editor) { Editor.prototype.showKeyboardShortcuts = function () { @@ -60,7 +56,7 @@ module.exports.init = function (editor) { exec: /** * - * @param {IEditor} editor + * @param {Editor} editor * @param [line] */ function (editor, line) { diff --git a/src/ext/menu_tools/get_editor_keyboard_shortcuts.js b/src/ext/menu_tools/get_editor_keyboard_shortcuts.js index a000e5a914d..c87320e61fc 100644 --- a/src/ext/menu_tools/get_editor_keyboard_shortcuts.js +++ b/src/ext/menu_tools/get_editor_keyboard_shortcuts.js @@ -19,7 +19,7 @@ * @author * Matthew Christopher Kastor-Inare III
* ☭ Hial Atropa!! ☭ - * @param {import("../../editor").IEditor} editor An editor instance. + * @param {import("../../editor").Editor} editor An editor instance. * @returns {Array} Returns an array of objects representing the keyboard * shortcuts for the given editor. * @example diff --git a/src/ext/options.js b/src/ext/options.js index d46c51dd5f0..4dab474c435 100644 --- a/src/ext/options.js +++ b/src/ext/options.js @@ -211,14 +211,10 @@ var optionGroups = { } }; -/** - * @typedef IOptionPanel - * @type {OptionPanel & import("../../ace").Ace.EventEmitter} - */ class OptionPanel { /** * - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor * @param {HTMLElement} [element] */ constructor(editor, element) { @@ -267,7 +263,6 @@ class OptionPanel { /** * @param {string} key * @param {Object} option - * @this {IOptionPanel} */ renderOptionControl(key, option) { var self = this; @@ -362,7 +357,6 @@ class OptionPanel { * * @param key * @param option - * @this {IOptionPanel} */ renderOption(key, option) { if (option.path && !option.onchange && !this.editor.$options[option.path]) @@ -380,7 +374,6 @@ class OptionPanel { /** * @param {string | number | Object} option * @param {string | number | boolean} value - * @this {IOptionPanel} */ setOption(option, value) { if (typeof option == "string") diff --git a/src/ext/prompt.js b/src/ext/prompt.js index 32aeee130b4..6bb754d0940 100644 --- a/src/ext/prompt.js +++ b/src/ext/prompt.js @@ -1,6 +1,5 @@ /** - * @typedef IEditor - * @type {import("../editor").IEditor} + * @typedef {import("../editor").Editor} Editor */ @@ -10,9 +9,6 @@ var nls = require("../config").nls; var Range = require("../range").Range; var dom = require("../lib/dom"); var FilteredList= require("../autocomplete").FilteredList; -/** - * @type {any} - */ var AcePopup = require('../autocomplete/popup').AcePopup; var $singleLineEditor = require('../autocomplete/popup').$singleLineEditor; var UndoManager = require("../undomanager").UndoManager; @@ -44,7 +40,7 @@ var openPrompt; /** * Prompt plugin is used for getting input from user. * - * @param {IEditor} editor Ouside editor related to this prompt. Will be blurred when prompt is open. + * @param {Editor} editor Ouside editor related to this prompt. Will be blurred when prompt is open. * @param {String | Partial} message Predefined value of prompt input box. * @param {Partial} options Cusomizable options for this prompt. * @param {Function} [callback] Function called after done. @@ -89,9 +85,6 @@ function prompt(editor, message, options, callback) { } if (options.getCompletions) { - /** - * @type {import("../autocomplete/popup").IAcePopup} - */ var popup = new AcePopup(); popup.renderer.setStyle("ace_autocomplete_inline"); popup.container.style.display = "block"; @@ -220,7 +213,7 @@ function prompt(editor, message, options, callback) { /** * - * @param {IEditor} editor + * @param {Editor} editor * @param {Function} [callback] */ prompt.gotoLine = function(editor, callback) { @@ -332,7 +325,7 @@ prompt.gotoLine = function(editor, callback) { /** * - * @param {IEditor} editor + * @param {Editor} editor * @param {Function} [callback] */ prompt.commands = function(editor, callback) { @@ -467,7 +460,7 @@ prompt.commands = function(editor, callback) { /** * - * @param {IEditor} editor + * @param {Editor} editor * @param {Function} [callback] */ prompt.modes = function(editor, callback) { diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index ab8cd2993a0..1d62a4f418b 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -1,7 +1,6 @@ "use strict"; /** - * @typedef IEditor - * @type {import("../editor").IEditor} + * @typedef {import("../editor").Editor} Editor */ var dom = require("../lib/dom"); var lang = require("../lib/lang"); @@ -17,7 +16,7 @@ dom.importCssString(searchboxCss, "ace_searchbox", false); class SearchBox { /** - * @param {IEditor} editor + * @param {Editor} editor * @param {undefined} [range] * @param {undefined} [showReplaceForm] */ @@ -63,13 +62,13 @@ class SearchBox { } /** - * @param {IEditor} editor + * @param {Editor} editor */ setEditor(editor) { editor.searchBox = this; editor.renderer.scroller.appendChild(this.element); /** - * @type {IEditor} + * @type {Editor} */ this.editor = editor; } @@ -143,7 +142,6 @@ class SearchBox { if (action && _this[action]) _this[action](); else if (_this.$searchBarKb.commands[action]) - // @ts-expect-error this could be different command type _this.$searchBarKb.commands[action].exec(_this); event.stopPropagation(e); }); @@ -152,7 +150,6 @@ class SearchBox { var keyString = keyUtil.keyCodeToString(keyCode); var command = _this.$searchBarKb.findKeyCommand(hashId, keyString); if (command && command.exec) { - // @ts-expect-error this could be different command type command.exec(_this); event.stopEvent(e); } @@ -437,7 +434,7 @@ exports.SearchBox = SearchBox; /** * - * @param {IEditor} editor + * @param {Editor} editor * @param {boolean} [isReplace] */ exports.Search = function(editor, isReplace) { diff --git a/src/ext/settings_menu.js b/src/ext/settings_menu.js index a839cc3a31d..f6e600f551f 100644 --- a/src/ext/settings_menu.js +++ b/src/ext/settings_menu.js @@ -15,16 +15,12 @@ var OptionPanel = require("./options").OptionPanel; var overlayPage = require('./menu_tools/overlay_page').overlayPage; -/** - * @typedef IEditor - * @type {import("../editor").IEditor} - */ /** * This displays the settings menu if it is not already being shown. * @author * Matthew Christopher Kastor-Inare III
* ☭ Hial Atropa!! ☭ - * @param {IEditor} editor An instance of the ace editor. + * @param {import("../editor").Editor} editor An instance of the ace editor. */ function showSettingsMenu(editor) { // show if the menu isn't open already. @@ -44,9 +40,6 @@ function showSettingsMenu(editor) { * to the editor with appropriate keyboard shortcuts. */ module.exports.init = function() { - /** - * @type {any} - */ var Editor = require("../editor").Editor; Editor.prototype.showSettingsMenu = function() { showSettingsMenu(this); diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index c5b636d27d4..acdf3911a3c 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -1,8 +1,5 @@ "use strict"; -/** - * @type {any} - */ var EditSession = require("../edit_session").EditSession; var TextLayer = require("../layer/text").Text; var baseStyles = require("./static-css"); @@ -199,9 +196,6 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) { lineStart = parseInt(lineStart || 1, 10); - /** - * @type {import("../edit_session").IEditSession} - */ var session = new EditSession(""); session.setUseWorker(false); session.setMode(mode); diff --git a/src/ext/statusbar.js b/src/ext/statusbar.js index 61d97d1ff66..a9e649b018a 100644 --- a/src/ext/statusbar.js +++ b/src/ext/statusbar.js @@ -1,8 +1,7 @@ "use strict"; /** * - * @typedef IEditor - * @type {import("../editor").IEditor} + * @typedef {import("../editor").Editor} Editor */ var dom = require("../lib/dom"); var lang = require("../lib/lang"); @@ -10,7 +9,7 @@ var lang = require("../lib/lang"); /** simple statusbar **/ class StatusBar{ /** - * @param {IEditor} editor + * @param {Editor} editor * @param {HTMLElement} parentNode */ constructor(editor, parentNode) { @@ -29,7 +28,7 @@ class StatusBar{ } /** - * @param {IEditor} editor + * @param {Editor} editor */ updateStatus(editor) { var status = []; diff --git a/src/ext/whitespace.js b/src/ext/whitespace.js index 153c1dbade8..3a42fcde289 100644 --- a/src/ext/whitespace.js +++ b/src/ext/whitespace.js @@ -2,8 +2,7 @@ /** * - * @typedef IEditSession - * @type {import("../edit_session").IEditSession} + * @typedef {import("../edit_session").EditSession} EditSession */ var lang = require("../lib/lang"); @@ -87,7 +86,7 @@ exports.$detectIndentation = function(lines, fallback) { }; /** - * @param {IEditSession} session + * @param {EditSession} session * @returns {{ch?: string, length?: number}|{}} */ exports.detectIndentation = function(session) { @@ -103,7 +102,7 @@ exports.detectIndentation = function(session) { }; /** - * @param {IEditSession} session + * @param {EditSession} session * @param {Object} options * @param {boolean} [options.trimEmpty] trim empty lines too * @param {boolean} [options.keepCursorPosition] do not trim whitespace before the cursor @@ -146,7 +145,7 @@ exports.trimTrailingSpace = function(session, options) { }; /** - * @param {IEditSession} session + * @param {EditSession} session * @param {string} ch * @param {number} len */ diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 48a4945c507..3296ba58116 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -6,7 +6,7 @@ var event = require("../lib/event"); class KeyBinding { /** - * @param {import("../editor").IEditor} editor + * @param {import("../editor").Editor} editor */ constructor(editor) { this.$editor = editor; diff --git a/src/layer/cursor.js b/src/layer/cursor.js index e9fa631c7f7..5e56a781d55 100644 --- a/src/layer/cursor.js +++ b/src/layer/cursor.js @@ -4,8 +4,10 @@ var dom = require("../lib/dom"); class Cursor { + /** + * @param {HTMLElement} parentEl + */ constructor(parentEl) { - /**@type{number}*/this.timeoutId; this.element = dom.createElement("div"); this.element.className = "ace_layer ace_cursor-layer"; parentEl.appendChild(this.element); @@ -20,7 +22,10 @@ class Cursor { dom.addCssClass(this.element, "ace_hidden-cursors"); this.$updateCursors = this.$updateOpacity.bind(this); } - + + /** + * @param {boolean} [val] + */ $updateOpacity(val) { var cursors = this.cursors; for (var i = cursors.length; i--; ) @@ -44,15 +49,24 @@ class Cursor { this.$isAnimating = false; dom.removeCssClass(this.element, "ace_animate-blinking"); } - + + /** + * @param {number} padding + */ setPadding(padding) { this.$padding = padding; } + /** + * @param {import("../edit_session").EditSession} session + */ setSession(session) { this.session = session; } + /** + * @param {boolean} blinking + */ setBlinking(blinking) { if (blinking != this.isBlinking) { this.isBlinking = blinking; @@ -60,6 +74,9 @@ class Cursor { } } + /** + * @param {number} blinkInterval + */ setBlinkInterval(blinkInterval) { if (blinkInterval != this.blinkInterval) { this.blinkInterval = blinkInterval; @@ -67,6 +84,9 @@ class Cursor { } } + /** + * @param {boolean} smoothBlinking + */ setSmoothBlinking(smoothBlinking) { if (smoothBlinking != this.smoothBlinking) { this.smoothBlinking = smoothBlinking; @@ -148,6 +168,10 @@ class Cursor { } } + /** + * @param {import("../../ace").Ace.Point} [position] + * @param {boolean} [onScreen] + */ getPixelPosition(position, onScreen) { if (!this.config || !this.session) return {left : 0, top : 0}; @@ -213,6 +237,9 @@ class Cursor { this.restartTimer(); } + /** + * @param {boolean} overwrite + */ $setOverwrite(overwrite) { if (overwrite != this.overwrite) { this.overwrite = overwrite; diff --git a/src/layer/font_metrics.js b/src/layer/font_metrics.js index e9583e0f8ce..3ffafed5942 100644 --- a/src/layer/font_metrics.js +++ b/src/layer/font_metrics.js @@ -13,7 +13,6 @@ class FontMetrics { /** * @param {HTMLElement} parentEl - * @this {FontMetrics & import("../../ace").Ace.EventEmitter} */ constructor(parentEl) { this.el = dom.createElement("div"); @@ -58,7 +57,6 @@ class FontMetrics { /** * @param size - * @this {FontMetrics & import("../../ace").Ace.EventEmitter} */ checkForSizeChanges(size) { if (size === undefined) @@ -74,9 +72,6 @@ class FontMetrics { } } - /** - * @this {FontMetrics & import("../../ace").Ace.EventEmitter} - */ $addObserver() { var self = this; this.$observer = new window.ResizeObserver(function(e) { @@ -87,7 +82,6 @@ class FontMetrics { } /** - * @this {FontMetrics & import("../../ace").Ace.EventEmitter} * @return {number} */ $pollSizeChanges() { @@ -103,7 +97,6 @@ class FontMetrics { /** * @param {boolean} val - * @this {FontMetrics & import("../../ace").Ace.EventEmitter} */ setPolling(val) { if (val) { diff --git a/src/layer/gutter.js b/src/layer/gutter.js index 1c8aed85f41..6eb656b4299 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -1,8 +1,4 @@ "use strict"; -/** - * @typedef IGutter - * @type {Gutter & import("../../ace").Ace.EventEmitter & {[key: string]: any}}} - */ var dom = require("../lib/dom"); var oop = require("../lib/oop"); var lang = require("../lib/lang"); @@ -30,7 +26,7 @@ class Gutter{ } /** - * @param {import("../edit_session").IEditSession} session + * @param {import("../edit_session").EditSession} session */ setSession(session) { if (this.session) @@ -115,7 +111,6 @@ class Gutter{ /** * @param {import("../../ace").Ace.LayerConfig} config - * @this {IGutter} */ update(config) { this.config = config; @@ -169,7 +164,6 @@ class Gutter{ /** * @param {import("../../ace").Ace.LayerConfig} config - * @this {IGutter} */ $updateGutterWidth(config) { var session = this.session; @@ -238,7 +232,6 @@ class Gutter{ /** * @param {import("../../ace").Ace.LayerConfig} config - * @this {IGutter} */ scrollLines(config) { var oldConfig = this.config; @@ -287,7 +280,6 @@ class Gutter{ * @param {import("../../ace").Ace.LayerConfig} config * @param {number} firstRow * @param {number} lastRow - * @this {IGutter} */ $renderLines(config, firstRow, lastRow) { var fragment = []; @@ -319,7 +311,6 @@ class Gutter{ * @param {import("../../ace").Ace.LayerConfig} config * @param {import("../../ace").Ace.IRange | undefined} fold * @param {number} row - * @this {IGutter} */ $renderCell(cell, config, fold, row) { var element = cell.element; diff --git a/src/layer/lines.js b/src/layer/lines.js index e2f9a1e808d..354362cda5d 100644 --- a/src/layer/lines.js +++ b/src/layer/lines.js @@ -3,6 +3,10 @@ var dom = require("../lib/dom"); class Lines { + /** + * @param {HTMLElement} element + * @param {number} [canvasHeight] + */ constructor(element, canvasHeight) { this.element = element; this.canvasHeight = canvasHeight || 500000; @@ -12,25 +16,42 @@ class Lines { this.cellCache = []; this.$offsetCoefficient = 0; } - + + /** + * @param {import("../../ace").Ace.LayerConfig} config + */ moveContainer(config) { dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient); - } - + } + + /** + * @param {import("../../ace").Ace.LayerConfig} oldConfig + * @param {import("../../ace").Ace.LayerConfig} newConfig + */ pageChanged(oldConfig, newConfig) { return ( Math.floor((oldConfig.firstRowScreen * oldConfig.lineHeight) / this.canvasHeight) !== Math.floor((newConfig.firstRowScreen * newConfig.lineHeight) / this.canvasHeight) ); } - + + /** + * @param {number} row + * @param {Partial} config + * @param {import("../edit_session").EditSession} session + */ computeLineTop(row, config, session) { var screenTop = config.firstRowScreen * config.lineHeight; var screenPage = Math.floor(screenTop / this.canvasHeight); var lineTop = session.documentToScreenRow(row, 0) * config.lineHeight; return lineTop - (screenPage * this.canvasHeight); } - + + /** + * @param {number} row + * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../edit_session").EditSession} session + */ computeLineHeight(row, config, session) { return config.lineHeight * session.getRowLineCount(row); } @@ -38,7 +59,10 @@ class Lines { getLength() { return this.cells.length; } - + + /** + * @param {number} index + */ get(index) { return this.cells[index]; } diff --git a/src/layer/marker.js b/src/layer/marker.js index 3c683ce42fd..e937eb9c852 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -22,7 +22,7 @@ class Marker { } /** - * @param {import("../edit_session").IEditSession} session + * @param {import("../edit_session").EditSession} session */ setSession(session) { this.session = session; @@ -55,6 +55,9 @@ class Marker { x.className = className; } + /** + * @param {import("../../ace").Ace.LayerConfig} config + */ update(config) { if (!config) return; @@ -97,6 +100,10 @@ class Marker { } } + /** + * @param {number} row + * @param {import("../../ace").Ace.LayerConfig} layerConfig + */ $getTop(row, layerConfig) { return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; } diff --git a/src/layer/text.js b/src/layer/text.js index 085743c5cc4..877e58c76d4 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -1,14 +1,7 @@ "use strict"; /** * - * @typedef IEditSession - * @type {import("../edit_session").IEditSession} - */ -/** - * - * @typedef IText - * @type {Text & import("../../ace").Ace.EventEmitter} - * @export + * @typedef {import("../edit_session").EditSession} EditSession */ var oop = require("../lib/oop"); var dom = require("../lib/dom"); @@ -18,9 +11,6 @@ var EventEmitter = require("../lib/event_emitter").EventEmitter; var nls = require("../config").nls; const isTextToken = require("./text_util").isTextToken; -/** - * @type {IText} - */ class Text { /** * @param {HTMLElement} parentEl @@ -73,7 +63,7 @@ class Text { this.$fontMetrics = measure; this.$fontMetrics.on("changeCharacterSize", /** - * @this {IText} + * @this {Text} */ function (e) { this._signal("changeCharacterSize", e); @@ -89,11 +79,11 @@ class Text { } /** - * @param {IEditSession} session + * @param {EditSession} session */ setSession(session) { /** - * @type {IEditSession} + * @type {EditSession} */ this.session = session; if (session) @@ -144,7 +134,7 @@ class Text { $computeTabString() { var tabSize = this.session.getTabSize(); this.tabSize = tabSize; - var tabStr = this.$tabStrings = [0]; + /**@type{any}*/var tabStr = this.$tabStrings = [0]; for (var i = 1; i < tabSize + 1; i++) { if (this.showTabs) { var span = this.dom.createElement("span"); @@ -228,7 +218,7 @@ class Text { if (row > last) break; - var lineElement = lineElements[lineElementsIdx++]; + /**@type{any}*/var lineElement = lineElements[lineElementsIdx++]; if (lineElement) { this.dom.removeChildren(lineElement); this.$renderLine( @@ -459,7 +449,9 @@ class Text { $highlightIndentGuide() { if (!this.$highlightIndentGuides || !this.displayIndentGuides) return; - + /** + * @type {{ indentLevel?: number; start?: number; end?: number; dir?: number; }} + **/ this.$highlightIndentGuideMarker = { indentLevel: undefined, start: undefined, diff --git a/src/lib/app_config.js b/src/lib/app_config.js index da7204e7785..fe624dc146c 100644 --- a/src/lib/app_config.js +++ b/src/lib/app_config.js @@ -1,9 +1,4 @@ "no use strict"; -/** - * @typedef IAppConfig - * @type {AppConfig & import("../../ace").Ace.EventEmitter} - * @export - */ var oop = require("./oop"); var EventEmitter = require("./event_emitter").EventEmitter; const reportError = require("./report_error").reportError; @@ -63,9 +58,6 @@ function warn(message) { var messages; -/** - * @type {IAppConfig} - */ class AppConfig { constructor() { this.$defaultOptions = {}; @@ -75,8 +67,7 @@ class AppConfig { * @param {Object} obj * @param {string} path * @param {{ [key: string]: any }} options - * @returns {IAppConfig} - * @this {IAppConfig} + * @returns {AppConfig} */ defineOptions(obj, path, options) { if (!obj.$options) diff --git a/src/line_widgets.js b/src/line_widgets.js index 35b0ecdfdd7..94f3a045d7c 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -1,12 +1,12 @@ "use strict"; /** - * @typedef {import("./edit_session").IEditSession} IEditSession + * @typedef {import("./edit_session").EditSession} EditSession */ /** - * @typedef {import("./editor").IEditor} IEditor + * @typedef {import("./editor").Editor} Editor */ /** - * @typedef {import("./virtual_renderer").IVirtualRenderer} IVirtualRenderer + * @typedef {import("./virtual_renderer").VirtualRenderer} VirtualRenderer */ var dom = require("./lib/dom"); @@ -14,18 +14,9 @@ var dom = require("./lib/dom"); class LineWidgets { /** - * @param {IEditSession} session + * @param {EditSession} session */ constructor(session) { - /** - * @type {import("../ace").Ace.LineWidget[]} - */ - this.lineWidgets; - /** - * @type {IEditor} - */ - this.editor; - this.session = session; this.session.widgetManager = this; this.session.getRowLength = this.getRowLength; @@ -76,7 +67,7 @@ class LineWidgets { /** * - * @param {IEditor} editor + * @param {Editor} editor */ attach(editor) { if (editor && editor.widgetManager && editor.widgetManager != this) @@ -116,7 +107,7 @@ class LineWidgets { /** * * @param e - * @param {IEditSession} session + * @param {EditSession} session */ updateOnFold(e, session) { var lineWidgets = session.lineWidgets; @@ -334,7 +325,7 @@ class LineWidgets { /** * @param {any} e - * @param {IVirtualRenderer} renderer + * @param {VirtualRenderer} renderer */ measureWidgets(e, renderer) { var changedWidgets = this.session._changedWidgets; @@ -381,7 +372,7 @@ class LineWidgets { /** * @param {any} e - * @param {IVirtualRenderer} renderer + * @param {VirtualRenderer} renderer */ renderWidgets(e, renderer) { var config = renderer.layerConfig; diff --git a/src/marker_group.js b/src/marker_group.js index 14679f1bb01..396e87d97c0 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -1,8 +1,7 @@ "use strict"; /** * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").EditSession} EditSession */ /** * @typedef MarkerGroupItem @@ -17,12 +16,12 @@ Potential improvements: class MarkerGroup { /** - * @param {IEditSession} session + * @param {EditSession} session */ constructor(session) { this.markers = []; /** - * @type {IEditSession} + * @type {EditSession} */ this.session = session; // @ts-expect-error TODO: could potential error here, or most likely missing checks in other places @@ -63,7 +62,7 @@ class MarkerGroup { /** * @param {any} html * @param {import("./layer/marker").Marker} markerLayer - * @param {IEditSession} session + * @param {EditSession} session * @param {{ firstRow: any; lastRow: any; }} config */ update(html, markerLayer, session, config) { diff --git a/src/mouse/default_gutter_handler.js b/src/mouse/default_gutter_handler.js index ce2498741fc..32c148f7dc6 100644 --- a/src/mouse/default_gutter_handler.js +++ b/src/mouse/default_gutter_handler.js @@ -4,6 +4,9 @@ var event = require("../lib/event"); var Tooltip = require("../tooltip").Tooltip; var nls = require("../config").nls; +/** + * @param {import("../mouse/mouse_handler").MouseHandler} mouseHandler + */ function GutterHandler(mouseHandler) { var editor = mouseHandler.editor; var gutter = editor.renderer.$gutterLayer; diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index 3eca9da43ef..64775239d59 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -1,6 +1,6 @@ "use strict"; /** - * @typedef {import("./mouse_handler").IMouseHandler} IMouseHandler + * @typedef {import("./mouse_handler").MouseHandler} MouseHandler */ var useragent = require("../lib/useragent"); @@ -9,7 +9,7 @@ var SCROLL_COOLDOWN_T = 550; // milliseconds class DefaultHandlers { /** - * @param {IMouseHandler} mouseHandler + * @param {MouseHandler} mouseHandler */ constructor(mouseHandler) { mouseHandler.$clickSelection = null; @@ -34,7 +34,7 @@ class DefaultHandlers { /** * @param ev - * @this {IMouseHandler} + * @this {MouseHandler} */ onMouseDown(ev) { var inSelection = ev.inSelection(); @@ -80,7 +80,7 @@ class DefaultHandlers { * * @param {import("../../ace").Ace.Position} [pos] * @param {boolean} [waitForClickSelection] - * @this {IMouseHandler} + * @this {MouseHandler} */ startSelect(pos, waitForClickSelection) { pos = pos || this.editor.renderer.screenToTextCoordinates(this.x, this.y); @@ -98,7 +98,7 @@ class DefaultHandlers { } /** - * @this {IMouseHandler} + * @this {MouseHandler} */ select() { var anchor, editor = this.editor; @@ -123,7 +123,7 @@ class DefaultHandlers { /** * @param {string | number} unitName - * @this {IMouseHandler} + * @this {MouseHandler} */ extendSelectionBy(unitName) { var anchor, editor = this.editor; @@ -156,7 +156,7 @@ class DefaultHandlers { } /** - * @this {IMouseHandler} + * @this {MouseHandler} */ selectByLinesEnd() { this.$clickSelection = null; @@ -164,7 +164,7 @@ class DefaultHandlers { } /** - * @this {IMouseHandler} + * @this {MouseHandler} */ focusWait() { var distance = calcDistance(this.mousedownEvent.x, this.mousedownEvent.y, this.x, this.y); @@ -176,7 +176,7 @@ class DefaultHandlers { /** * @param {import("./mouse_event").MouseEvent} ev - * @this {IMouseHandler} + * @this {MouseHandler} */ onDoubleClick(ev) { var pos = ev.getDocumentPosition(); @@ -200,7 +200,7 @@ class DefaultHandlers { /** * @param {import("./mouse_event").MouseEvent} ev - * @this {IMouseHandler} + * @this {MouseHandler} */ onTripleClick(ev) { var pos = ev.getDocumentPosition(); @@ -219,7 +219,7 @@ class DefaultHandlers { /** * @param {import("./mouse_event").MouseEvent} ev - * @this {IMouseHandler} + * @this {MouseHandler} */ onQuadClick(ev) { var editor = this.editor; @@ -231,7 +231,7 @@ class DefaultHandlers { /** * @param {import("./mouse_event").MouseEvent} ev - * @this {IMouseHandler} + * @this {MouseHandler} */ onMouseWheel(ev) { if (ev.getAccelKey()) diff --git a/src/mouse/dragdrop_handler.js b/src/mouse/dragdrop_handler.js index e482a50c305..a10e514f5e1 100644 --- a/src/mouse/dragdrop_handler.js +++ b/src/mouse/dragdrop_handler.js @@ -1,6 +1,6 @@ "use strict"; /** - * @typedef {import("./mouse_handler").IMouseHandler} IMouseHandler + * @typedef {import("./mouse_handler").MouseHandler} MouseHandler */ var dom = require("../lib/dom"); var event = require("../lib/event"); @@ -12,9 +12,9 @@ var SCROLL_CURSOR_HYSTERESIS = 5; /** * - * @param {IMouseHandler} mouseHandler + * @param {MouseHandler} mouseHandler * @constructor - * @this {IMouseHandler} + * @this {MouseHandler} */ function DragdropHandler(mouseHandler) { @@ -300,12 +300,12 @@ function DragdropHandler(mouseHandler) { } /** - * @this {IMouseHandler} + * @this {MouseHandler} */ (function() { /** - * @this {IMouseHandler & this} + * @this {MouseHandler & this} */ this.dragWait = function() { var interval = Date.now() - this.mousedownEvent.time; @@ -314,7 +314,7 @@ function DragdropHandler(mouseHandler) { }; /** - * @this {IMouseHandler & this} + * @this {MouseHandler & this} */ this.dragWaitEnd = function() { var target = this.editor.container; @@ -324,7 +324,7 @@ function DragdropHandler(mouseHandler) { }; /** - * @this {IMouseHandler & this} + * @this {MouseHandler & this} */ this.dragReadyEnd = function(e) { this.editor.$resetCursorStyle(); @@ -334,7 +334,7 @@ function DragdropHandler(mouseHandler) { }; /** - * @this {IMouseHandler & this} + * @this {MouseHandler & this} */ this.startDrag = function(){ this.cancelDrag = false; @@ -349,7 +349,7 @@ function DragdropHandler(mouseHandler) { }; /** - * @this {IMouseHandler & this} + * @this {MouseHandler & this} */ this.onMouseDrag = function(e) { var target = this.editor.container; @@ -370,7 +370,7 @@ function DragdropHandler(mouseHandler) { }; /** - * @this {IMouseHandler & this} + * @this {MouseHandler & this} */ this.onMouseDown = function(e) { if (!this.$dragEnabled) diff --git a/src/mouse/mouse_handler.js b/src/mouse/mouse_handler.js index d41dedaa959..aada8b7bb27 100644 --- a/src/mouse/mouse_handler.js +++ b/src/mouse/mouse_handler.js @@ -1,9 +1,4 @@ "use strict"; -/** - * @typedef {MouseHandler & import("./default_handlers").DefaultHandlers & import("./default_gutter_handler").GutterHandler & import("./dragdrop_handler").DragdropHandler & {cancelDrag?}} IMouseHandler - * @export - */ - var event = require("../lib/event"); var useragent = require("../lib/useragent"); var DefaultHandlers = require("./default_handlers").DefaultHandlers; @@ -15,8 +10,7 @@ var config = require("../config"); class MouseHandler { /** - * @param {import("../editor").IEditor} editor - * @this {IMouseHandler} + * @param {import("../editor").Editor} editor */ constructor(editor) { /** @type {boolean} */this.$dragDelay; diff --git a/src/multi_select.js b/src/multi_select.js index 69fc073cc10..dd49174a3ab 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -1,21 +1,9 @@ -/** - * @typedef {import("./selection").ISelection} ISelection - */ -/** - * @typedef {import("./editor").IEditor} IEditor - */ -/** - * @typedef {import("./edit_session").IEditSession} IEditSession - */ /** * @typedef {import("./anchor").Anchor} Anchor */ var RangeList = require("./range_list").RangeList; var Range = require("./range").Range; -/** - * @type {any} - */ var Selection = require("./selection").Selection; var onMouseDown = require("./mouse/multi_select_handler").onMouseDown; var event = require("./lib/event"); @@ -38,7 +26,7 @@ function find(session, needle, dir) { var EditSession = require("./edit_session").EditSession; (function() { /** - * @this {IEditSession} + * @this {EditSession} */ this.getSelectionMarkers = function() { return this.$selectionMarkers; @@ -52,12 +40,7 @@ var EditSession = require("./edit_session").EditSession; * @type {RangeList|null} */ Selection.prototype.rangeList = null; -/** - * - * @param {Range} range - * @param {boolean} [$blockChangeEvents] - * @this {ISelection} - */ + Selection.prototype.addRange = function(range, $blockChangeEvents) { if (!range) return; @@ -96,14 +79,8 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { }; // extend Selection -/** - */ (function() { // list of ranges in reverse addition order - /** - * @this {ISelection} - * @type {Range[]|null} - */ this.ranges = null; // automatically sorted list of ranges @@ -116,8 +93,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { * Adds a range to a selection by entering multiselect mode, if necessary. * @param {Range} range The new range to add * @param {Boolean} $blockChangeEvents Whether or not to block changing events - * @method Selection.addRange - * @this {ISelection} + * @this {Selection} **/ this.addRange = function(range, $blockChangeEvents) { if (!range) @@ -158,7 +134,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * @param {Range} [range] - * @this {ISelection} + * @this {Selection} **/ this.toSingleRange = function(range) { range = range || this.ranges[0]; @@ -172,7 +148,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Removes a Range containing pos (if it exists). * @param {import("../ace").Ace.Point} pos The position to remove, as a `{row, column}` object - * @this {ISelection} + * @this {Selection} **/ this.substractPoint = function(pos) { var removed = this.rangeList.substractPoint(pos); @@ -184,7 +160,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Merges overlapping ranges ensuring consistency after changes - * @this {ISelection} + * @this {Selection} **/ this.mergeOverlappingRanges = function() { var removed = this.rangeList.merge(); @@ -194,7 +170,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * @param {Range} range - * @this {ISelection} + * @this {Selection} */ this.$onAddRange = function(range) { this.rangeCount = this.rangeList.ranges.length; @@ -205,7 +181,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * * @param {Range[]} removed - * @this {ISelection} + * @this {Selection} */ this.$onRemoveRange = function(removed) { this.rangeCount = this.rangeList.ranges.length; @@ -226,6 +202,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { this.inMultiSelectMode = false; this._signal("singleSelect"); this.session.$undoSelect = true; + // @ts-expect-error TODO: possible bug, no args in parameters this.rangeList.detach(this.session); } @@ -236,7 +213,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * adds multicursor support to selection - * @this {ISelection} + * @this {Selection} */ this.$initRangeList = function() { if (this.rangeList) @@ -250,7 +227,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Returns a concatenation of all the ranges. * @returns {Range[]} - * @this {ISelection} + * @this {Selection} **/ this.getAllRanges = function() { return this.rangeCount ? this.rangeList.ranges.concat() : [this.getRange()]; @@ -258,7 +235,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Splits all the ranges into lines. - * @this {ISelection} + * @this {Selection} **/ this.splitIntoLines = function () { var ranges = this.ranges.length ? this.ranges : [this.getRange()]; @@ -284,7 +261,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { }; /** - * @this {ISelection} + * @this {Selection} */ this.joinSelections = function () { var ranges = this.rangeList.ranges; @@ -296,7 +273,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { }; /** - * @this {ISelection} + * @this {Selection} **/ this.toggleBlockSelection = function () { if (this.rangeCount > 1) { @@ -311,6 +288,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { var anchor = this.session.documentToScreenPosition(this.anchor); var rectSel = this.rectangularRangeBlock(cursor, anchor); + // @ts-expect-error TODO: possible bug rectSel.forEach(this.addRange, this); } }; @@ -321,9 +299,9 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { * * @param {import("../ace").Ace.ScreenCoordinates} screenCursor The cursor to use * @param {import("../ace").Ace.ScreenCoordinates} screenAnchor The anchor to use - * @param {Boolean} includeEmptyLines If true, this includes ranges inside the block which are empty due to clipping + * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping * @returns {Range[]} - * @this {ISelection} + * @this {Selection} **/ this.rectangularRangeBlock = function(screenCursor, screenAnchor, includeEmptyLines) { var rectSel = []; @@ -403,7 +381,7 @@ var Editor = require("./editor").Editor; * * Updates the cursor and marker layers. * @method Editor.updateSelectionMarkers - * @this {IEditor} + * @this {Editor} **/ this.updateSelectionMarkers = function() { this.renderer.updateCursor(); @@ -414,7 +392,7 @@ var Editor = require("./editor").Editor; * Adds the selection and cursor. * @param {Range & {marker?}} orientedRange A range containing a cursor * @returns {Range & {marker?}} - * @this {IEditor} + * @this {Editor} **/ this.addSelectionMarker = function(orientedRange) { if (!orientedRange.cursor) @@ -431,7 +409,7 @@ var Editor = require("./editor").Editor; /** * Removes the selection marker. * @param {Range & {marker?}} range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. - * @this {IEditor} + * @this {Editor} **/ this.removeSelectionMarker = function(range) { if (!range.marker) @@ -446,7 +424,7 @@ var Editor = require("./editor").Editor; /** * * @param {(Range & {marker?})[]} ranges - * @this {IEditor} + * @this {Editor} */ this.removeSelectionMarkers = function(ranges) { var markerList = this.session.$selectionMarkers; @@ -464,7 +442,7 @@ var Editor = require("./editor").Editor; /** * @param e - * @this {IEditor} + * @this {Editor} */ this.$onAddRange = function(e) { this.addSelectionMarker(e.range); @@ -474,7 +452,7 @@ var Editor = require("./editor").Editor; /** * @param e - * @this {IEditor} + * @this {Editor} */ this.$onRemoveRange = function(e) { this.removeSelectionMarkers(e.ranges); @@ -484,7 +462,7 @@ var Editor = require("./editor").Editor; /** * @param e - * @this {IEditor} + * @this {Editor} */ this.$onMultiSelect = function(e) { if (this.inMultiSelectMode) @@ -501,7 +479,7 @@ var Editor = require("./editor").Editor; /** * @param e - * @this {IEditor} + * @this {Editor} */ this.$onSingleSelect = function(e) { if (this.session.multiSelect.inVirtualMode) @@ -519,7 +497,7 @@ var Editor = require("./editor").Editor; /** * @param e - * @this {IEditor} + * @this {Editor} */ this.$onMultiSelectExec = function(e) { var command = e.command; @@ -546,8 +524,9 @@ var Editor = require("./editor").Editor; /** * Executes a command for each selection range. * @param {Object} cmd The command to execute - * @param {String} args Any arguments for the command - * @this {IEditor} + * @param {String} [args] Any arguments for the command + * @param {Object} [options] + * @this {Editor} **/ this.forEachSelection = function(cmd, args, options) { if (this.inVirtualSelectionMode) @@ -566,7 +545,7 @@ var Editor = require("./editor").Editor; var reg = selection._eventRegistry; selection._eventRegistry = {}; /** - * @type {ISelection} + * @type {Selection} */ var tmpSel = new Selection(session); this.inVirtualSelectionMode = true; @@ -603,7 +582,7 @@ var Editor = require("./editor").Editor; /** * Removes all the selections except the last added one. - * @this {IEditor} + * @this {Editor} **/ this.exitMultiSelectMode = function() { if (!this.inMultiSelectMode || this.inVirtualSelectionMode) @@ -612,7 +591,7 @@ var Editor = require("./editor").Editor; }; /** - * @this {IEditor} + * @this {Editor} * @return {string} */ this.getSelectedText = function() { @@ -637,7 +616,7 @@ var Editor = require("./editor").Editor; * * @param e * @param {Anchor} anchor - * @this {IEditor} + * @this {Editor} */ this.$checkMultiselectChange = function(e, anchor) { if (this.inMultiSelectMode && !this.inVirtualSelectionMode) { @@ -657,12 +636,12 @@ var Editor = require("./editor").Editor; /** * Finds and selects all the occurrences of `needle`. - * @param {String} needle The text to find - * @param {Partial} options The search options - * @param {Boolean} additive keeps + * @param {String} [needle] The text to find + * @param {Partial} [options] The search options + * @param {Boolean} [additive] keeps * * @returns {Number} The cumulative count of all found matches - * @this {IEditor} + * @this {Editor} **/ this.findAll = function(needle, options, additive) { options = options || {}; @@ -700,7 +679,7 @@ var Editor = require("./editor").Editor; * @param {Number} dir The direction of lines to select: -1 for up, 1 for down * @param {Boolean} [skip] If `true`, removes the active selection range * - * @this {IEditor} + * @this {Editor} */ this.selectMoreLines = function(dir, skip) { var range = this.selection.toOrientedRange(); @@ -749,7 +728,7 @@ var Editor = require("./editor").Editor; /** * Transposes the selected ranges. * @param {Number} dir The direction to rotate selections - * @this {IEditor} + * @this {Editor} **/ this.transposeSelections = function(dir) { var session = this.session; @@ -792,9 +771,9 @@ var Editor = require("./editor").Editor; /** * Finds the next occurrence of text in an active selection and adds it to the selections. * @param {Number} dir The direction of lines to select: -1 for up, 1 for down - * @param {Boolean} skip If `true`, removes the active selection range + * @param {Boolean} [skip] If `true`, removes the active selection range * @param {Boolean} [stopAtFirst] - * @this {IEditor} + * @this {Editor} **/ this.selectMore = function(dir, skip, stopAtFirst) { var session = this.session; @@ -823,7 +802,7 @@ var Editor = require("./editor").Editor; /** * Aligns the cursors or selected text. - * @this {IEditor} + * @this {Editor} **/ this.alignCursors = function() { var session = this.session; @@ -906,7 +885,7 @@ var Editor = require("./editor").Editor; * @param {string[]} lines * @param {boolean} [forceLeft] * @return {*} - * @this {IEditor} + * @this {Editor} */ this.$reAlignText = function(lines, forceLeft) { var isLeftAligned = true, isRightAligned = true; @@ -975,7 +954,7 @@ function isSamePoint(p1, p2) { /** * patch * adds multicursor support to a session - * @this {IEditor} + * @this {Editor} * @type {(e) => void} */ exports.onSessionChange = function(e) { @@ -1018,7 +997,7 @@ exports.onSessionChange = function(e) { // adds multiple selection support to the editor // (note: should be called only once for each editor instance) /** - * @param {IEditor} editor + * @param {Editor} editor */ function MultiSelect(editor) { if (editor.$multiselectOnSessionChange) @@ -1040,7 +1019,7 @@ function MultiSelect(editor) { } /** - * @param {IEditor} editor + * @param {Editor} editor */ function addAltCursorListeners(editor){ if (!editor.textInput) return; @@ -1077,7 +1056,7 @@ require("./config").defineOptions(Editor.prototype, "editor", { enableMultiselect: { /** * @param {boolean} val - * @this {IEditor} + * @this {Editor} */ set: function(val) { MultiSelect(this); diff --git a/src/occur.js b/src/occur.js index 270a0fd8375..7098bca3a77 100644 --- a/src/occur.js +++ b/src/occur.js @@ -1,16 +1,10 @@ "use strict"; /** - * @typedef {import("./editor").IEditor} IEditor - */ -/** - * @typedef {import("./edit_session").IEditSession} IEditSession + * @typedef {import("./editor").Editor} Editor */ var oop = require("./lib/oop"); var Search = require("./search").Search; -/** - * @type {any} - */ var EditSession = require("./edit_session").EditSession; var SearchHighlight = require("./search_highlight").SearchHighlight; @@ -27,7 +21,7 @@ class Occur extends Search { * and these are then used as the content of a new [[Document * `Document`]]. The current cursor position of editor will be translated * so that the cursor is on the matching row/column as it was before. - * @param {IEditor} editor + * @param {Editor} editor * @param {Object} options options.needle should be a String * @return {Boolean} Whether occur activation was successful * @@ -45,7 +39,7 @@ class Occur extends Search { * Disables occur mode. Resets the [[Sessions `EditSession`]] [[Document * `Document`]] back to the original doc. If options.translatePosition is * truthy also maps the [[Editors `Editor`]] cursor position accordingly. - * @param {IEditor} editor + * @param {Editor} editor * @param {Object} options options.translatePosition * @return {Boolean} Whether occur deactivation was successful * @@ -60,7 +54,7 @@ class Occur extends Search { } /** - * @param {IEditSession} sess + * @param {EditSession} sess * @param {RegExp} regexp */ highlight(sess, regexp) { @@ -71,7 +65,7 @@ class Occur extends Search { } /** - * @param {IEditor} editor + * @param {Editor} editor * @param {Partial} options */ displayOccurContent(editor, options) { @@ -80,7 +74,7 @@ class Occur extends Search { var found = this.matchingLines(editor.session, options); var lines = found.map(function(foundLine) { return foundLine.content; }); /** - * @type {IEditSession} + * @type {EditSession} */ var occurSession = new EditSession(lines.join('\n')); occurSession.$occur = this; @@ -93,7 +87,7 @@ class Occur extends Search { } /** - * @param {IEditor} editor + * @param {Editor} editor */ displayOriginalContent(editor) { editor.setSession(this.$originalSession); @@ -104,7 +98,7 @@ class Occur extends Search { * Translates the position from the original document to the occur lines in * the document or the beginning if the doc {row: 0, column: 0} if not * found. - * @param {IEditSession} session The occur session + * @param {EditSession} session The occur session * @param {import("../ace").Ace.Point} pos The position in the original document * @return {import("../ace").Ace.Point} position in occur doc **/ @@ -122,7 +116,7 @@ class Occur extends Search { /** * Translates the position from the occur document to the original document * or `pos` if not found. - * @param {IEditSession} session The occur session + * @param {EditSession} session The occur session * @param {import("../ace").Ace.Point} pos The position in the occur session document * @return {import("../ace").Ace.Point} position **/ @@ -134,7 +128,7 @@ class Occur extends Search { } /** - * @param {IEditSession} session + * @param {EditSession} session * @param {Partial} options */ matchingLines(session, options) { diff --git a/src/placeholder.js b/src/placeholder.js index b4777a9fa21..78846cc005d 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -1,23 +1,16 @@ "use strict"; -/** - * @typedef {import("./edit_session").IEditSession} IEditSession - */ -/** - * @typedef {PlaceHolder & import("../ace").Ace.EventEmitter} IPlaceHolder - */ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var oop = require("./lib/oop"); class PlaceHolder { /** - * @param {IEditSession} session + * @param {import("./edit_session").EditSession} session * @param {Number} length * @param {import("../ace").Ace.Point} pos * @param {any[]} others * @param {String} mainClass * @param {String} othersClass - * @this {IPlaceHolder} **/ constructor(session, length, pos, others, mainClass, othersClass) { var _self = this; @@ -178,7 +171,6 @@ class PlaceHolder { * * Emitted when the cursor changes. * @param {any} [event] - * @this {IPlaceHolder} */ onCursorChange(event) { if (this.$updating || !this.session) return; diff --git a/src/range.js b/src/range.js index 107d5816658..2504dd38767 100644 --- a/src/range.js +++ b/src/range.js @@ -1,8 +1,4 @@ "use strict"; -/** - * @typedef {import("./edit_session").IEditSession} IEditSession - */ - /** * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. **/ @@ -16,14 +12,6 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { - /** - * @type {Number | undefined} - */ - this.id; - /** - * @type {import("../ace").Ace.Point | undefined} - */ - this.cursor; /** * @type {import("../ace").Ace.Point} */ @@ -424,7 +412,7 @@ class Range { /** * Given the current `Range`, this function converts those starting and ending [[Point]]'s into screen positions, and then returns a new `Range` object. - * @param {IEditSession} session The `EditSession` to retrieve coordinates from + * @param {import("./edit_session").EditSession} session The `EditSession` to retrieve coordinates from * @returns {Range} **/ toScreenRange(session) { diff --git a/src/scrollbar.js b/src/scrollbar.js index c1a89b4ce33..70cc2cc02af 100644 --- a/src/scrollbar.js +++ b/src/scrollbar.js @@ -76,12 +76,8 @@ class VScrollBar extends Scrollbar { /** * Emitted when the scroll bar, well, scrolls. * @event scroll - * @param {Object} e Contains one property, `"data"`, which indicates the current scroll top position **/ - /** - * @this {VScrollBar & import("../ace").Ace.EventEmitter} - */ onScroll() { if (!this.skipEvent) { this.scrollTop = this.element.scrollTop; @@ -175,12 +171,7 @@ class HScrollBar extends Scrollbar { /** * Emitted when the scroll bar, well, scrolls. * @event scroll - * @param {Object} e Contains one property, `"data"`, which indicates the current scroll left position **/ - - /** - * @this {HScrollBar & import("../ace").Ace.EventEmitter} - */ onScroll() { if (!this.skipEvent) { this.scrollLeft = this.element.scrollLeft; diff --git a/src/scrollbar_custom.js b/src/scrollbar_custom.js index 408f71758dc..095d2038ba8 100644 --- a/src/scrollbar_custom.js +++ b/src/scrollbar_custom.js @@ -105,7 +105,6 @@ class VScrollBar extends ScrollBar { /** * Emitted when the scroll thumb dragged or scrollbar canvas clicked. - * @this {VScrollBar & import("../ace").Ace.EventEmitter} **/ onMouseDown(eType, e) { if (eType !== "mousedown") return; @@ -176,7 +175,6 @@ class VScrollBar extends ScrollBar { /** * Sets the height of the scroll bar, in pixels. * @param {Number} height The new height - * @this {VScrollBar & import("../ace").Ace.EventEmitter} **/ setHeight(height) { this.height = Math.max(0, height); @@ -191,7 +189,6 @@ class VScrollBar extends ScrollBar { * @param {Number} height The new inner height * * @param {boolean} force Forcely update height - * @this {VScrollBar & import("../ace").Ace.EventEmitter} **/ setScrollHeight(height, force) { if (this.pageHeight === height && !force) return; @@ -244,7 +241,6 @@ class HScrollBar extends ScrollBar { /** * Emitted when the scroll thumb dragged or scrollbar canvas clicked. - * @this {HScrollBar & import("../ace").Ace.EventEmitter} **/ onMouseDown(eType, e) { if (eType !== "mousedown") return; @@ -313,7 +309,6 @@ class HScrollBar extends ScrollBar { /** * Sets the width of the scroll bar, in pixels. * @param {Number} width The new width - * @this {HScrollBar & import("../ace").Ace.EventEmitter} **/ setWidth(width) { this.width = Math.max(0, width); @@ -328,7 +323,6 @@ class HScrollBar extends ScrollBar { * Sets the inner and scroll width of the scroll bar, in pixels. * @param {Number} width The new inner width * @param {boolean} force Forcely update width - * @this {HScrollBar & import("../ace").Ace.EventEmitter} **/ setScrollWidth(width, force) { if (this.pageWidth === width && !force) return; diff --git a/src/search.js b/src/search.js index 58a6ad594f3..ad73163a381 100644 --- a/src/search.js +++ b/src/search.js @@ -1,8 +1,6 @@ "use strict"; /** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").EditSession} EditSession */ var lang = require("./lib/lang"); var oop = require("./lib/oop"); @@ -69,7 +67,7 @@ class Search { /** * Searches for `options.needle`. If found, this method returns the [[Range `Range`]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session. - * @param {IEditSession} session The session to search with + * @param {EditSession} session The session to search with * @returns {Range|false} **/ find(session) { @@ -96,7 +94,7 @@ class Search { /** * Searches for all occurrances `options.needle`. If found, this method returns an array of [[Range `Range`s]] where the text first occurs. If `options.backwards` is `true`, the search goes backwards in the session. - * @param {IEditSession} session The session to search with + * @param {EditSession} session The session to search with * @returns {Range[]} **/ findAll(session) { diff --git a/src/selection.js b/src/selection.js index 5308b8e1e06..6aa519c1ca1 100644 --- a/src/selection.js +++ b/src/selection.js @@ -5,47 +5,35 @@ var lang = require("./lib/lang"); var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; /** - * @typedef ISelection - * @type {Selection & import("../ace").Ace.ISelection & import("../ace").Ace.EventEmitter} - * @export + * @typedef {import("./edit_session").EditSession} EditSession */ /** - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} - */ -/** - * @typedef IDocument - * @type {import("./document").IDocument} - */ -/** - * @typedef IAnchor - * @type {import("./anchor").IAnchor} + * @typedef {import("./anchor").Anchor} Anchor */ class Selection { /** * Creates a new `Selection` object. - * @param {IEditSession} session The session to use - * @this {ISelection} + * @param {EditSession} session The session to use * @constructor **/ constructor(session) { /** - * @type {IEditSession} + * @type {EditSession} */ this.session = session; /** - * @type {IDocument} + * @type {import("./document").Document} */ this.doc = session.getDocument(); this.clearSelection(); /** - * @type {IAnchor} + * @type {Anchor} */ this.cursor = this.lead = this.doc.createAnchor(0, 0); /** - * @type {IAnchor} + * @type {Anchor} */ this.anchor = this.doc.createAnchor(0, 0); this.$silent = false; @@ -157,7 +145,6 @@ class Selection { /** * [Empties the selection (by de-selecting it). This function also emits the `'changeSelection'` event.]{: #Selection.clearSelection} - * @this {ISelection} **/ clearSelection() { if (!this.$isEmpty) { @@ -168,7 +155,6 @@ class Selection { /** * Selects all the text in the document. - * @this {ISelection} **/ selectAll() { this.$setSelection(0, 0, Number.MAX_VALUE, Number.MAX_VALUE); @@ -178,7 +164,6 @@ class Selection { * Sets the selection to the provided range. * @param {import("../ace").Ace.IRange} range The range of text to select * @param {Boolean} [reverse] Indicates if the range should go backwards (`true`) or not - * @this {ISelection} **/ setRange(range, reverse) { var start = reverse ? range.end : range.start; @@ -191,7 +176,6 @@ class Selection { * @param {number} anchorColumn * @param {number} cursorRow * @param {number} cursorColumn - * @this {ISelection} */ $setSelection(anchorRow, anchorColumn, cursorRow, cursorColumn) { if (this.$silent) @@ -243,7 +227,6 @@ class Selection { * Moves the selection cursor to the indicated row and column. * @param {Number} row The row to select to * @param {Number} column The column to select to - * @this {ISelection} **/ moveTo(row, column) { this.clearSelection(); @@ -253,7 +236,6 @@ class Selection { /** * Moves the selection cursor to the row and column indicated by `pos`. * @param {Object} pos An object containing the row and column - * @this {ISelection} **/ moveToPosition(pos) { this.clearSelection(); @@ -346,7 +328,6 @@ class Selection { /** * Selects an entire word boundary. - * @this {ISelection} **/ selectWord() { this.setSelectionRange(this.getWordRange()); @@ -355,7 +336,6 @@ class Selection { /** * Selects a word, including its right whitespace. * @related EditSession.getAWordRange - * @this {ISelection} **/ selectAWord() { var cursor = this.getCursor(); @@ -382,7 +362,6 @@ class Selection { /** * Selects the entire line. - * @this {ISelection} **/ selectLine() { this.setSelectionRange(this.getLineRange()); @@ -390,7 +369,6 @@ class Selection { /** * Moves the cursor up one row. - * @this {ISelection} **/ moveCursorUp() { this.moveCursorBy(-1, 0); @@ -398,7 +376,6 @@ class Selection { /** * Moves the cursor down one row. - * @this {ISelection} **/ moveCursorDown() { this.moveCursorBy(1, 0); @@ -424,7 +401,6 @@ class Selection { /** * Moves the cursor left one column. - * @this {ISelection} **/ moveCursorLeft() { var cursor = this.lead.getPosition(), @@ -450,7 +426,6 @@ class Selection { /** * Moves the cursor right one column. - * @this {ISelection} **/ moveCursorRight() { var cursor = this.lead.getPosition(), @@ -479,7 +454,6 @@ class Selection { /** * Moves the cursor to the start of the line. - * @this {ISelection} **/ moveCursorLineStart() { var row = this.lead.row; @@ -504,7 +478,6 @@ class Selection { /** * Moves the cursor to the end of the line. - * @this {ISelection} **/ moveCursorLineEnd() { var lead = this.lead; @@ -523,7 +496,6 @@ class Selection { /** * Moves the cursor to the end of the file. - * @this {ISelection} **/ moveCursorFileEnd() { var row = this.doc.getLength() - 1; @@ -533,7 +505,6 @@ class Selection { /** * Moves the cursor to the start of the file. - * @this {ISelection} **/ moveCursorFileStart() { this.moveCursorTo(0, 0); @@ -541,7 +512,6 @@ class Selection { /** * Moves the cursor to the word on the right. - * @this {ISelection} **/ moveCursorLongWordRight() { var row = this.lead.row; @@ -587,7 +557,6 @@ class Selection { /** * * Moves the cursor to the word on the left. - * @this {ISelection} **/ moveCursorLongWordLeft() { var row = this.lead.row; @@ -670,9 +639,6 @@ class Selection { return index; } - /** - * @this {ISelection} - */ moveCursorShortWordRight() { var row = this.lead.row; var column = this.lead.column; @@ -700,9 +666,6 @@ class Selection { this.moveCursorTo(row, column + index); } - /** - * @this {ISelection} - */ moveCursorShortWordLeft() { var row = this.lead.row; var column = this.lead.column; @@ -729,9 +692,6 @@ class Selection { return this.moveCursorTo(row, column - index); } - /** - * @this {ISelection} - */ moveCursorWordRight() { if (this.session.$selectLongWords) this.moveCursorLongWordRight(); @@ -739,9 +699,6 @@ class Selection { this.moveCursorShortWordRight(); } - /** - * @this {ISelection} - */ moveCursorWordLeft() { if (this.session.$selectLongWords) this.moveCursorLongWordLeft(); @@ -755,7 +712,6 @@ class Selection { * @param {Number} chars The number of characters to move by * * @related EditSession.documentToScreenPosition - * @this {ISelection} **/ moveCursorBy(rows, chars) { var screenPos = this.session.documentToScreenPosition( @@ -802,7 +758,6 @@ class Selection { /** * Moves the selection to the position indicated by its `row` and `column`. * @param {import("../ace").Ace.Point} position The position to move to - * @this {ISelection} **/ moveCursorToPosition(position) { this.moveCursorTo(position.row, position.column); @@ -813,7 +768,6 @@ class Selection { * @param {Number} row The row to move to * @param {Number} column The column to move to * @param {Boolean} [keepDesiredColumn] [If `true`, the cursor move does not respect the previous column]{: #preventUpdateBool} - * @this {ISelection} **/ moveCursorTo(row, column, keepDesiredColumn) { // Ensure the row/column is not inside of a fold. @@ -844,7 +798,6 @@ class Selection { * @param {Number} row The row to move to * @param {Number} column The column to move to * @param {Boolean} keepDesiredColumn {:preventUpdateBool} - * @this {ISelection} **/ moveCursorToScreen(row, column, keepDesiredColumn) { var pos = this.session.screenToDocumentPosition(row, column); @@ -859,7 +812,6 @@ class Selection { /** * @param {Range & {desiredColumn?: number}} range - * @this {ISelection} */ fromOrientedRange(range) { this.setSelectionRange(range, range.cursor == range.start); @@ -891,7 +843,6 @@ class Selection { * Will reset the cursor position. * @param {Function} func The callback that should change the cursor position * @returns {Range} - * @this {ISelection} **/ getRangeOfMovements(func) { var start = this.getCursor(); @@ -909,18 +860,16 @@ class Selection { /** * * @returns {Range|Range[]} - * @this {ISelection} */ toJSON() { if (this.rangeCount) { - var data = this.ranges.map(function(r) { + /**@type{Range|Range[]}*/var data = this.ranges.map(function(r) { var r1 = r.clone(); r1.isBackwards = r.cursor == r.start; return r1; }); } else { - // @ts-ignore - var data = this.getRange(); + /**@type{Range|Range[]}*/var data = this.getRange(); data.isBackwards = this.isBackwards(); } return data; @@ -929,7 +878,6 @@ class Selection { /** * * @param data - * @this {ISelection} */ fromJSON(data) { if (data.start == undefined) { @@ -955,7 +903,6 @@ class Selection { * * @param data * @return {Boolean|boolean|*|boolean} - * @this {ISelection} */ isEqual(data) { if ((data.length || this.rangeCount) && data.length != this.rangeCount) diff --git a/src/snippets.js b/src/snippets.js index 63e8cb8bddc..027058ef069 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -1,7 +1,4 @@ "use strict"; -/** - * @typedef {SnippetManager & import("../ace").Ace.EventEmitter} ISnippetManager - */ /** * @typedef Snippet * @property {string} [content] @@ -510,7 +507,6 @@ class SnippetManager { /** * @param {any[]} snippets * @param {string} scope - * @this {ISnippetManager} */ register(snippets, scope) { var snippetMap = this.snippetMap; @@ -588,7 +584,8 @@ class SnippetManager { addSnippet(snippets[key]); }); } - + + // @ts-ignore this._signal("registerSnippets", {scope: scope}); } unregister(snippets, scope) { diff --git a/src/split.js b/src/split.js index dd5940685d5..b2cd6c5e34e 100644 --- a/src/split.js +++ b/src/split.js @@ -3,15 +3,9 @@ var oop = require("./lib/oop"); var lang = require("./lib/lang"); var EventEmitter = require("./lib/event_emitter").EventEmitter; -/** - * @typedef {import("./edit_session").IEditSession} IEditSession - */ -/** - * @typedef {import("./editor").IEditor} IEditor - */ -/**@type{any}*/var Editor = require("./editor").Editor; +var Editor = require("./editor").Editor; var Renderer = require("./virtual_renderer").VirtualRenderer; -/**@type{any}*/var EditSession = require("./edit_session").EditSession; +var EditSession = require("./edit_session").EditSession; /** * @typedef ISplit @@ -48,7 +42,7 @@ Split = function(container, theme, splits) { oop.implement(this, EventEmitter); /** - * @returns {IEditor} + * @returns {Editor} * @this {ISplit} */ this.$createEditor = function() { @@ -56,9 +50,6 @@ Split = function(container, theme, splits) { el.className = this.$editorCSS; el.style.cssText = "position: absolute; top:0px; bottom:0px"; this.$container.appendChild(el); - /** - * @type {IEditor} - */ var editor = new Editor(new Renderer(el, this.$theme)); editor.on("focus", function() { @@ -209,13 +200,10 @@ Split = function(container, theme, splits) { /** * - * @param {IEditSession} session - * @return {IEditSession} + * @param {EditSession} session + * @return {EditSession} */ this.$cloneSession = function(session) { - /** - * @type {IEditSession} - */ var s = new EditSession(session.getDocument(), session.getMode()); var undoManager = session.getUndoManager(); diff --git a/src/token_iterator.js b/src/token_iterator.js index 347fdda2195..fb887e8c8eb 100644 --- a/src/token_iterator.js +++ b/src/token_iterator.js @@ -1,9 +1,4 @@ "use strict"; -/** - * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} - */ var Range = require("./range").Range; /** @@ -12,7 +7,7 @@ var Range = require("./range").Range; class TokenIterator { /** * Creates a new token iterator object. The inital token index is set to the provided row and column coordinates. - * @param {IEditSession} session The session to associate with + * @param {import("./edit_session").EditSession} session The session to associate with * @param {Number} initialRow The row to start the tokenizing at * @param {Number} initialColumn The column to start the tokenizing at **/ diff --git a/src/undomanager.js b/src/undomanager.js index 98563cad52c..dc17782378d 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -1,6 +1,6 @@ "use strict"; /** - * @typedef {import("./edit_session").IEditSession} IEditSession + * @typedef {import("./edit_session").EditSession} EditSession */ /** @@ -23,7 +23,7 @@ class UndoManager { /** * - * @param {IEditSession} session + * @param {EditSession} session */ addSession(session) { this.$session = session; @@ -36,7 +36,7 @@ class UndoManager { * * @param {import("../ace").Ace.Delta} delta * @param {boolean} allowMerge - * @param {IEditSession} [session] + * @param {EditSession} [session] **/ add(delta, allowMerge, session) { if (this.$fromUndo) return; @@ -159,7 +159,7 @@ class UndoManager { /** * [Perform an undo operation on the document, reverting the last change.]{: #UndoManager.undo} - * @param {IEditSession} session + * @param {EditSession} session * @param {Boolean} [dontSelect] {:dontSelect} **/ undo(session, dontSelect) { @@ -192,7 +192,7 @@ class UndoManager { /** * [Perform a redo operation on the document, reimplementing the last change.]{: #UndoManager.redo} - * @param {IEditSession} session + * @param {EditSession} session * @param {Boolean} [dontSelect] {:dontSelect} * **/ diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 564edd87f5a..1dc53eb4085 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1,20 +1,15 @@ "use strict"; -/** - * @typedef IVirtualRenderer - * @type {VirtualRenderer & import("../ace").Ace.EventEmitter & import("../ace").Ace.OptionsProvider & import("../ace").Ace.VirtualRendererProperties} - */ /** * - * @typedef IEditSession - * @type {import("./edit_session").IEditSession} + * @typedef {import("./edit_session").EditSession} EditSession */ var oop = require("./lib/oop"); var dom = require("./lib/dom"); var lang = require("./lib/lang"); var config = require("./config"); -/**@type{any}*/var GutterLayer = require("./layer/gutter").Gutter; +var GutterLayer = require("./layer/gutter").Gutter; var MarkerLayer = require("./layer/marker").Marker; -/**@type{any}*/var TextLayer = require("./layer/text").Text; +var TextLayer = require("./layer/text").Text; var CursorLayer = require("./layer/cursor").Cursor; var HScrollBar = require("./scrollbar").HScrollBar; var VScrollBar = require("./scrollbar").VScrollBar; @@ -37,15 +32,11 @@ dom.importCssString(editorCss, "ace_editor.css", false); class VirtualRenderer { /** * Constructs a new `VirtualRenderer` within the `container` specified, applying the given `theme`. - * @param {HTMLElement} [container] The root element of the editor + * @param {HTMLElement | null} [container] The root element of the editor * @param {String} [theme] The starting theme - * @this {IVirtualRenderer} + **/ constructor(container, theme) { - /** - * @type {IEditSession} - */ - this.session; var _self = this; this.container = container || dom.createElement("div"); @@ -74,16 +65,10 @@ class VirtualRenderer { this.content.className = "ace_content"; this.scroller.appendChild(this.content); - /** - * @type {import("./layer/gutter").IGutter} - */ this.$gutterLayer = new GutterLayer(this.$gutter); this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this)); this.$markerBack = new MarkerLayer(this.content); - /** - * @type {import("./layer/text").IText} - */ var textLayer = this.$textLayer = new TextLayer(this.content); this.canvas = textLayer.element; @@ -196,9 +181,6 @@ class VirtualRenderer { // console.log(a.trim()) // }; - /** - * @this {IVirtualRenderer} - */ updateCharacterSize() { // @ts-expect-error TODO: missing property initialization anywhere in codebase if (this.$textLayer.allowBoldFonts != this.$allowBoldFonts) { @@ -219,7 +201,7 @@ class VirtualRenderer { /** * * Associates the renderer with an [[EditSession `EditSession`]]. - * @param {IEditSession} session The session to associate with + * @param {EditSession} session The session to associate with **/ setSession(session) { if (this.session) @@ -306,7 +288,7 @@ class VirtualRenderer { /** * Triggers a full update of all the layers, for all the rows. * @param {Boolean} [force] If `true`, forces the changes through - * @this {IVirtualRenderer} + **/ updateFull(force) { if (force) @@ -322,9 +304,6 @@ class VirtualRenderer { this.$textLayer.checkForSizeChanges(); } - /** - * @this {IVirtualRenderer} - */ $updateSizeAsync() { if (this.$loop.pending) this.$size.$dirty = true; @@ -337,7 +316,7 @@ class VirtualRenderer { * @param {Number} [gutterWidth] The width of the gutter in pixels * @param {Number} [width] The width of the editor in pixels * @param {Number} [height] The hiehgt of the editor, in pixels - * @this {IVirtualRenderer} + **/ onResize(force, gutterWidth, width, height) { if (this.resizing > 2) @@ -384,7 +363,7 @@ class VirtualRenderer { * @param [width] * @param [height] * @return {number} - * @this {IVirtualRenderer} + */ $updateCachedSize(force, gutterWidth, width, height) { height -= (this.$extraHeight || 0); @@ -447,7 +426,7 @@ class VirtualRenderer { /** * * @param {number} width - * @this {IVirtualRenderer} + */ onGutterResize(width) { var gutterWidth = this.$showGutter ? width : 0; @@ -465,7 +444,7 @@ class VirtualRenderer { /** * Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen. - * @this {IVirtualRenderer} + **/ adjustWrapLimit() { var availableWidth = this.$size.scrollerWidth - this.$padding * 2; @@ -476,7 +455,7 @@ class VirtualRenderer { /** * Identifies whether you want to have an animated scroll or not. * @param {Boolean} shouldAnimate Set to `true` to show animated scrolls - * @this {IVirtualRenderer} + **/ setAnimatedScroll(shouldAnimate){ this.setOption("animatedScroll", shouldAnimate); @@ -485,7 +464,7 @@ class VirtualRenderer { /** * Returns whether an animated scroll happens or not. * @returns {Boolean} - * @this {IVirtualRenderer} + **/ getAnimatedScroll() { return this.$animatedScroll; @@ -494,7 +473,7 @@ class VirtualRenderer { /** * Identifies whether you want to show invisible characters or not. * @param {Boolean} showInvisibles Set to `true` to show invisibles - * @this {IVirtualRenderer} + **/ setShowInvisibles(showInvisibles) { this.setOption("showInvisibles", showInvisibles); @@ -504,7 +483,7 @@ class VirtualRenderer { /** * Returns whether invisible characters are being shown or not. * @returns {Boolean} - * @this {IVirtualRenderer} + **/ getShowInvisibles() { return this.getOption("showInvisibles"); @@ -512,7 +491,7 @@ class VirtualRenderer { /** * @return {boolean} - * @this {IVirtualRenderer} + */ getDisplayIndentGuides() { return this.getOption("displayIndentGuides"); @@ -520,14 +499,14 @@ class VirtualRenderer { /** * @param {boolean} display - * @this {IVirtualRenderer} + */ setDisplayIndentGuides(display) { this.setOption("displayIndentGuides", display); } /** - * @this {IVirtualRenderer} + * @return {boolean} */ getHighlightIndentGuides() { @@ -535,7 +514,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + * @param {boolean} highlight */ setHighlightIndentGuides(highlight) { @@ -545,7 +524,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the print margin or not. * @param {Boolean} showPrintMargin Set to `true` to show the print margin - * @this {IVirtualRenderer} + **/ setShowPrintMargin(showPrintMargin) { this.setOption("showPrintMargin", showPrintMargin); @@ -554,7 +533,7 @@ class VirtualRenderer { /** * Returns whether the print margin is being shown or not. * @returns {Boolean} - * @this {IVirtualRenderer} + **/ getShowPrintMargin() { return this.getOption("showPrintMargin"); @@ -562,7 +541,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the print margin column or not. * @param {number} printMarginColumn Set to `true` to show the print margin column - * @this {IVirtualRenderer} + **/ setPrintMarginColumn(printMarginColumn) { this.setOption("printMarginColumn", printMarginColumn); @@ -571,7 +550,7 @@ class VirtualRenderer { /** * Returns whether the print margin column is being shown or not. * @returns {number} - * @this {IVirtualRenderer} + **/ getPrintMarginColumn() { return this.getOption("printMarginColumn"); @@ -580,7 +559,7 @@ class VirtualRenderer { /** * Returns `true` if the gutter is being shown. * @returns {Boolean} - * @this {IVirtualRenderer} + **/ getShowGutter(){ return this.getOption("showGutter"); @@ -589,14 +568,14 @@ class VirtualRenderer { /** * Identifies whether you want to show the gutter or not. * @param {Boolean} show Set to `true` to show the gutter - * @this {IVirtualRenderer} + **/ setShowGutter(show){ return this.setOption("showGutter", show); } /** - * @this {IVirtualRenderer} + * @returns {boolean} */ getFadeFoldWidgets(){ @@ -604,7 +583,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + * @param {boolean} show */ setFadeFoldWidgets(show) { @@ -612,7 +591,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} * + * * @param {boolean} shouldHighlight */ setHighlightGutterLine(shouldHighlight) { @@ -620,7 +599,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + * @returns {boolean} */ getHighlightGutterLine() { @@ -628,7 +607,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + */ $updatePrintMargin() { if (!this.$showPrintMargin && !this.$printMarginEl) @@ -681,7 +660,7 @@ class VirtualRenderer { // move text input over the cursor // this is required for IME /** - * @this {IVirtualRenderer} + */ $moveTextAreaToCursor() { if (this.$isMousePressed) return; @@ -777,7 +756,7 @@ class VirtualRenderer { /** * Sets the padding for all the layers. * @param {Number} padding A new padding value (in pixels) - * @this {IVirtualRenderer} + **/ setPadding(padding) { this.$padding = padding; @@ -795,7 +774,7 @@ class VirtualRenderer { * @param {number} [bottom] * @param {number} [left] * @param {number} [right] - * @this {IVirtualRenderer} + */ setScrollMargin(top, bottom, left, right) { var sm = this.scrollMargin; @@ -816,7 +795,7 @@ class VirtualRenderer { * @param {number} [bottom] * @param {number} [left] * @param {number} [right] - * @this {IVirtualRenderer} + */ setMargin(top, bottom, left, right) { var sm = this.margin; @@ -833,7 +812,7 @@ class VirtualRenderer { /** * Returns whether the horizontal scrollbar is set to be always visible. * @returns {Boolean} - * @this {IVirtualRenderer} + **/ getHScrollBarAlwaysVisible() { return this.$hScrollBarAlwaysVisible; @@ -842,7 +821,7 @@ class VirtualRenderer { /** * Identifies whether you want to show the horizontal scrollbar or not. * @param {Boolean} alwaysVisible Set to `true` to make the horizontal scroll bar visible - * @this {IVirtualRenderer} + **/ setHScrollBarAlwaysVisible(alwaysVisible) { this.setOption("hScrollBarAlwaysVisible", alwaysVisible); @@ -850,7 +829,7 @@ class VirtualRenderer { /** * Returns whether the horizontal scrollbar is set to be always visible. * @returns {Boolean} - * @this {IVirtualRenderer} + **/ getVScrollBarAlwaysVisible() { return this.$vScrollBarAlwaysVisible; @@ -859,14 +838,13 @@ class VirtualRenderer { /** * Identifies whether you want to show the horizontal scrollbar or not. * @param {Boolean} alwaysVisible Set to `true` to make the horizontal scroll bar visible - @this {IVirtualRenderer} **/ setVScrollBarAlwaysVisible(alwaysVisible) { this.setOption("vScrollBarAlwaysVisible", alwaysVisible); } /** - * @this {IVirtualRenderer} + */ $updateScrollBarV() { var scrollHeight = this.layerConfig.maxHeight; @@ -899,7 +877,7 @@ class VirtualRenderer { * @param {number} changes * @param {boolean} [force] * @returns {number} - * @this {IVirtualRenderer} + */ $renderChanges(changes, force) { if (this.$changes) { @@ -1062,7 +1040,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + */ $autosize() { var height = this.session.getScreenLength() * this.lineHeight; @@ -1096,7 +1074,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + * @returns {number} */ $computeLayerConfig() { @@ -1207,7 +1185,7 @@ class VirtualRenderer { /** * @returns {boolean | undefined} - * @this {IVirtualRenderer} + */ $updateLines() { if (!this.$changedLines) return; @@ -1236,7 +1214,7 @@ class VirtualRenderer { /** * * @returns {number} - * @this {IVirtualRenderer} + */ $getLongestLine() { var charCount = this.session.getScreenWidth(); @@ -1486,7 +1464,7 @@ class VirtualRenderer { * @param {Boolean} center If `true`, centers the editor the to indicated line * @param {Boolean} animate If `true` animates scrolling * @param {() => void} [callback] Function to be called after the animation has finished - * @this {IVirtualRenderer} + **/ scrollToLine(line, center, animate, callback) { var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); @@ -1504,7 +1482,7 @@ class VirtualRenderer { * * @param fromValue * @param [callback] - * @this {IVirtualRenderer} + */ animateScrolling(fromValue, callback) { var toValue = this.scrollTop; @@ -1631,7 +1609,7 @@ class VirtualRenderer { * @param {number} x * @param {number} y * @returns {import("../ace").Ace.ScreenCoordinates} - * @this {IVirtualRenderer} + */ pixelToScreenCoordinates(x, y) { var canvasPos; @@ -1657,7 +1635,7 @@ class VirtualRenderer { * @param {number} x * @param {number} y * @returns {import("../ace").Ace.Point} - * @this {IVirtualRenderer} + */ screenToTextCoordinates(x, y) { var canvasPos; @@ -1720,7 +1698,7 @@ class VirtualRenderer { /** * @param {Object} composition - * @this {IVirtualRenderer} + **/ showComposition(composition) { this.$composition = composition; @@ -1745,7 +1723,7 @@ class VirtualRenderer { * @param {String} text A string of text to use * * Sets the inner text of the current composition to `text`. - * @this {IVirtualRenderer} + **/ setCompositionText(text) { var cursor = this.session.selection.cursor; @@ -1756,7 +1734,7 @@ class VirtualRenderer { /** * * Hides the current composition. - * @this {IVirtualRenderer} + **/ hideComposition() { if (!this.$composition) @@ -1856,7 +1834,7 @@ class VirtualRenderer { * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} * @param {String | import("../ace").Ace.Theme} [theme] The path to a theme * @param {() => void} [cb] optional callback - * @this {IVirtualRenderer} + **/ setTheme(theme, cb) { var _self = this; @@ -1967,7 +1945,7 @@ class VirtualRenderer { /** * Destroys the text and cursor layers for this renderer. - * @this {IVirtualRenderer} + **/ destroy() { this.freeze(); @@ -2024,7 +2002,7 @@ class VirtualRenderer { } /** - * @this {IVirtualRenderer} + */ $addResizeObserver() { if (!window.ResizeObserver || this.$resizeObserver) return; @@ -2071,7 +2049,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { useResizeObserver: { /** * @param value - * @this {IVirtualRenderer} + */ set: function(value) { if (!value && this.$resizeObserver) { @@ -2102,7 +2080,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { printMargin: { /** * @param val - * @this {IVirtualRenderer} + */ set: function(val) { if (typeof val == "number") @@ -2209,7 +2187,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { minLines: { /** * @param val - * @this {IVirtualRenderer} + */ set: function(val) { if (!(this.$minLines < 0x1ffffffffffff)) @@ -2226,7 +2204,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { scrollPastEnd: { /** * @param val - * @this {IVirtualRenderer} + */ set: function(val) { val = +val || 0; diff --git a/tsconfig.json b/tsconfig.json index 7cfa9abac4e..c0d20c8ac69 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,5 +28,6 @@ "include": [ "./src/**/*", "./ace.d.ts", + "./ace-extensions.d.ts" ] } From 43901dcf10618c309d8d357bd1df0f1bba7c9f8d Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 28 Sep 2023 17:17:02 +0400 Subject: [PATCH 18/36] resolve merge conflicts --- ace.d.ts | 33 +++------------------------------ src/autocomplete.js | 1 + 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 500bcd38403..758a456f863 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -875,35 +875,6 @@ export namespace Ace { } type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; - type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; - - export class CompletionProvider { - insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; - insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; - completions: CompletionRecord; - gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; - provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; - detach(): void; - } - - export class Autocomplete { - constructor(); - autoInsert?: boolean; - autoSelect?: boolean; - autoShown?: boolean; - exactMatch?: boolean; - setSelectOnHover?: Boolean; - stickySelectionDelay?: Number; - inlineEnabled?: boolean; - parentNode?: HTMLElement; - setSelectOnHover?: Boolean; - stickySelectionDelay?: Number; - emptyMessage?(prefix: String): String; - getPopup(): AcePopup; - showPopup(editor: Editor, options: CompletionOptions): void; - detach(): void; - destroy(): void; - } type CompletionProviderCallback = (this: import("./src/autocomplete").Autocomplete, err: Error | undefined, completions: import("./src/autocomplete").FilteredList, finished: boolean) => void; type AcePopupNavigation = "up" | "down" | "start" | "end"; @@ -964,7 +935,9 @@ declare module "./src/anchor" { declare module "./src/autocomplete" { export interface Autocomplete { - popup: Ace.AcePopup + popup: Ace.AcePopup; + setSelectOnHover: boolean; + stickySelectionDelay: number; } export interface CompletionProvider { diff --git a/src/autocomplete.js b/src/autocomplete.js index b36c6e82544..9e200118761 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -28,6 +28,7 @@ var config = require("./config"); * @property {string} [snippet] - a text snippet that would be inserted when the completion is selected * @property {string} [value] - The text that would be inserted when selecting this completion. * @property {{insertMatch:(editor: Editor, data: Completion) => void}} [completer] + * @property {boolean} [hideInlinePreview] * @export */ From 06bc8c88f5feb3caf70db990b457ea250f09b3fd Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 28 Sep 2023 18:58:49 +0400 Subject: [PATCH 19/36] fix multiline jsdoc types definitions --- ace.d.ts | 9 +++-- src/anchor.js | 3 +- src/autocomplete.js | 7 ++-- src/autocomplete/popup.js | 12 ++----- src/background_tokenizer.js | 4 +-- src/commands/default_commands.js | 4 +-- src/document.js | 4 +-- src/edit_session.js | 24 ++++--------- src/edit_session/fold.js | 4 +-- src/edit_session/fold_line.js | 4 +-- src/edit_session/folding.js | 11 ++---- src/editor.js | 35 +++++-------------- src/ext/command_bar.js | 4 +-- src/ext/emmet.js | 4 +-- src/ext/inline_autocomplete.js | 4 +-- src/ext/language_tools.js | 8 ++--- src/ext/options.js | 4 +-- src/ext/prompt.js | 12 ++----- src/ext/searchbox.js | 60 ++++++++------------------------ src/ext/static_highlight.js | 12 ++----- src/keyboard/hash_handler.js | 4 +-- src/keyboard/keybinding.js | 4 +-- src/keyboard/textinput.js | 9 ++--- src/layer/marker.js | 4 +-- src/layer/text.js | 8 ++--- src/lib/event_emitter.js | 8 ++--- src/lib/net.js | 4 +-- src/marker_group.js | 9 ++--- src/mode/behaviour.js | 4 +-- src/mode/text.js | 28 ++++----------- src/mode/text_highlight_rules.js | 4 +-- src/multi_select.js | 16 +++------ src/occur.js | 4 +-- src/range.js | 8 ++--- src/search.js | 8 ++--- src/selection.js | 16 +++------ src/snippets.js | 12 ++----- src/split.js | 3 +- src/tokenizer.js | 8 ++--- src/tokenizer_dev.js | 8 ++--- src/tooltip.js | 4 --- src/undomanager.js | 4 +-- src/virtual_renderer.js | 24 ++++--------- 43 files changed, 112 insertions(+), 318 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 758a456f863..eaad4f7b155 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -936,8 +936,7 @@ declare module "./src/anchor" { declare module "./src/autocomplete" { export interface Autocomplete { popup: Ace.AcePopup; - setSelectOnHover: boolean; - stickySelectionDelay: number; + emptyMessage?: Function } export interface CompletionProvider { @@ -1335,3 +1334,9 @@ declare module "./src/layer/font_metrics" { export interface FontMetrics extends Ace.EventEmitter { } } + +declare module "./src/tooltip" { + export interface HoverTooltip { + row: number; + } +} diff --git a/src/anchor.js b/src/anchor.js index d884e19766f..fb04e87cef2 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -1,7 +1,6 @@ "use strict"; /** - * @typedef Document - * @type {import("./document").Document} + * @typedef {import("./document").Document} Document */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; diff --git a/src/autocomplete.js b/src/autocomplete.js index 9e200118761..ca71ab39d87 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -100,9 +100,7 @@ class Autocomplete { } $init() { - /** - * @type {AcePopup} - */ + /**@type {AcePopup}**/ this.popup = new AcePopup(this.parentNode || document.body || document.documentElement); this.popup.on("click", function(e) { this.insertMatch(); @@ -124,7 +122,6 @@ class Autocomplete { } /** - * * @return {AcePopup} */ getPopup() { @@ -443,7 +440,7 @@ class Autocomplete { }).provideCompletions(this.editor, completionOptions, /** * @type {(err: any, completions: FilteredList, finished: boolean) => void | boolean} - * @this {Autocomplete & {emptyMessage}} + * @this {Autocomplete} */ function (err, completions, finished) { var filtered = completions.filtered; diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 82c327dd355..99896bb0957 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -43,9 +43,7 @@ class AcePopup { */ constructor(parentNode) { var el = dom.createElement("div"); - /** - * @type {AcePopup} - */ + /**@type {AcePopup}*/ // @ts-ignore var popup = $singleLineEditor(el); @@ -129,9 +127,7 @@ class AcePopup { }); popup.renderer.on("afterRender", function () { var row = popup.getRow(); - /** - * @type {any} - */ + /**@type {any}*/ var t = popup.renderer.$textLayer; var selected = t.element.childNodes[row - t.config.firstRow]; var el = document.activeElement; // Active element is textarea of main editor @@ -183,9 +179,7 @@ class AcePopup { var bgTokenizer = popup.session.bgTokenizer; bgTokenizer.$tokenizeRow = function (row) { - /** - * @type {import("../../ace").Ace.Completion &{name?, className?, matchMask?, message?}} - */ + /**@type {import("../../ace").Ace.Completion &{name?, className?, matchMask?, message?}}*/ var data = popup.data[row]; var tokens = []; if (!data) return tokens; diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 5ac357408a3..3ab6c89339f 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -21,9 +21,7 @@ class BackgroundTokenizer { * @param {any} [editor] The editor to associate with **/ constructor(tokenizer, editor) { - /** - * @type {false|number} - */ + /**@type {false|number}*/ this.running = false; this.lines = []; this.states = []; diff --git a/src/commands/default_commands.js b/src/commands/default_commands.js index 0dbbd148042..d963851d763 100644 --- a/src/commands/default_commands.js +++ b/src/commands/default_commands.js @@ -12,9 +12,7 @@ function bindKey(win, mac) { multiSelectAction: "forEach"|"forEachLine"|function|undefined, scrollIntoView: true|"cursor"|"center"|"selectionPart" */ -/** - * @type {import("../../ace").Ace.Command[]} - */ +/**@type {import("../../ace").Ace.Command[]} */ exports.commands = [{ name: "showSettingsMenu", description: "Show settings menu", diff --git a/src/document.js b/src/document.js index 46f22d7b347..43e7ff3a519 100644 --- a/src/document.js +++ b/src/document.js @@ -16,9 +16,7 @@ class Document { * @param {String | String[]} textOrLines text The starting text **/ constructor(textOrLines) { - /** - * @type {string[]} - */ + /**@type {string[]}*/ this.$lines = [""]; // There has to be one line at least in the document. If you pass an empty diff --git a/src/edit_session.js b/src/edit_session.js index e70d0ff8346..136d6b531b5 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -46,9 +46,7 @@ class EditSession { this.$markerId = 1; this.$undoSelect = true; - /** - * @type {FoldLine[]} - */ + /** @type {FoldLine[]} */ this.$foldData = []; this.id = "session" + (++EditSession.$uid); this.$foldData.toString = function() { @@ -112,13 +110,9 @@ class EditSession { **/ $resetRowCache(docRow) { if (!docRow) { - /** - * @type {number[]} - */ + /** @type {number[]} */ this.$docRowCache = []; - /** - * @type {number[]} - */ + /** @type {number[]} */ this.$screenRowCache = []; return; } @@ -813,13 +807,9 @@ class EditSession { this.bgTokenizer.setTokenizer(tokenizer); this.bgTokenizer.setDocument(this.getDocument()); - /** - * @type {RegExp} - */ + /**@type {RegExp}*/ this.tokenRe = mode.tokenRe; - /** - * @type {RegExp} - */ + /**@type {RegExp}*/ this.nonTokenRe = mode.nonTokenRe; @@ -2266,9 +2256,7 @@ class EditSession { **/ getScreenLength() { var screenRows = 0; - /** - * @type {FoldLine} - */ + /**@type {FoldLine}*/ var fold = null; if (!this.$useWrapMode) { screenRows = this.getLength(); diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index ddbb767365f..ff65f3c3c4a 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -25,9 +25,7 @@ class Fold extends RangeList { this.end = range.end; this.sameRow = range.start.row == range.end.row; - /** - * @type {Fold[]} - */ + /**@type {Fold[]}*/ this.subFolds = this.ranges = []; } diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index bf0bb5d7476..f8775dcfd71 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -13,9 +13,7 @@ class FoldLine { constructor(foldData, folds) { this.foldData = foldData; if (Array.isArray(folds)) { - /** - * @type {Fold[]} - */ + /**@type {Fold[]} */ this.folds = folds; } else { folds = this.folds = [ folds ]; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 5f9f21c3854..0554e2e5c09 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -8,8 +8,7 @@ var TokenIterator = require("../token_iterator").TokenIterator; var MouseEvent = require("../mouse/mouse_event").MouseEvent; /** - * @typedef IFolding - * @type {import("../edit_session").EditSession & import("../../ace").Ace.Folding} + * @typedef {import("../edit_session").EditSession & import("../../ace").Ace.Folding} IFolding */ /** @@ -101,9 +100,7 @@ function Folding() { */ this.getFoldsInRangeList = function(ranges) { if (Array.isArray(ranges)) { - /** - * @type {Fold[]} - */ + /**@type {Fold[]} */ var folds = []; ranges.forEach(function(range) { folds = folds.concat(this.getFoldsInRange(range)); @@ -288,9 +285,7 @@ function Folding() { this.addFold = function(placeholder, range) { var foldData = this.$foldData; var added = false; - /** - * @type {Fold} - */ + /**@type {Fold}*/ var fold; if (placeholder instanceof Fold) diff --git a/src/editor.js b/src/editor.js index c116fff1075..749ba39e356 100644 --- a/src/editor.js +++ b/src/editor.js @@ -1,8 +1,7 @@ "use strict"; /** - * @typedef VirtualRenderer - * @type {import("./virtual_renderer").VirtualRenderer} + * @typedef {import("./virtual_renderer").VirtualRenderer} VirtualRenderer */ /** * @typedef {import("./selection").Selection} Selection @@ -53,36 +52,24 @@ class Editor { this.$toDestroy = []; var container = renderer.getContainerElement(); - /** - * @type {HTMLElement & {env?, value?}} - */ + /**@type {HTMLElement & {env?, value?}}*/ this.container = container; - /** - * @type {VirtualRenderer} - */ + /**@type {VirtualRenderer}*/ this.renderer = renderer; - /** - * @type {string} - */ + /**@type {string}*/ this.id = "editor" + (++Editor.$uid); this.commands = new CommandManager(useragent.isMac ? "mac" : "win", defaultCommands); if (typeof document == "object") { this.textInput = new TextInput(renderer.getTextAreaContainer(), this); this.renderer.textarea = this.textInput.getElement(); // TODO detect touch event support - /** - * @type {MouseHandler} - */ + /**@type {MouseHandler}*/ this.$mouseHandler = new MouseHandler(this); new FoldHandler(this); } - /** - * @type {KeyBinding} - */ + /**@type {KeyBinding}*/ this.keyBinding = new KeyBinding(this); - /** - * @type {Search} - */ + /**@type {Search}*/ this.$search = new Search().set({ wrap: true }); @@ -666,9 +653,7 @@ class Editor { */ $updateHighlightActiveLine() { var session = this.getSession(); - /** - * @type {import("../ace").Ace.Point|false} - */ + /**@type {import("../ace").Ace.Point|false}*/ var highlight; if (this.$highlightActiveLine) { if (this.$selectionStyle != "line" || !this.selection.isMultiLine()) @@ -2945,9 +2930,7 @@ config.defineOptions(Editor.prototype, "editor", { this.focus(); } }; - /** - * @type {GutterKeyboardHandler} - */ + /**@type {GutterKeyboardHandler}*/ var gutterKeyboardHandler; // If keyboard a11y mode is enabled we: diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 8c0e9077fb5..8bbbbf9fbbc 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -311,9 +311,7 @@ class CommandBarTooltip { }); } - /** - * @type {any[]} - */ + /**@type {any[]} */ var buttonNode; if (forMainTooltip && command.iconCssClass) { //Only support icon button for main tooltip, otherwise fall back to text button diff --git a/src/ext/emmet.js b/src/ext/emmet.js index 1e82cc61ac6..d75eb3f0891 100644 --- a/src/ext/emmet.js +++ b/src/ext/emmet.js @@ -166,9 +166,7 @@ class AceEmmetEditor { var syntax = this.ace.session.$modeId.split("/").pop(); if (syntax == "html" || syntax == "php") { var cursor = this.ace.getCursorPosition(); - /** - * @type {string | string[]} - */ + /**@type {string | string[]} */ var state = this.ace.session.getState(cursor.row); if (typeof state != "string") state = state[0]; diff --git a/src/ext/inline_autocomplete.js b/src/ext/inline_autocomplete.js index ef46e622cdf..c78b5c764b5 100644 --- a/src/ext/inline_autocomplete.js +++ b/src/ext/inline_autocomplete.js @@ -408,9 +408,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { * @returns {CommandBarTooltip} The command bar tooltip for inline autocomplete */ InlineAutocomplete.createInlineTooltip = function(parentEl) { - /** - * @type {CommandBarTooltip} - */ + /**@type {CommandBarTooltip}*/ var inlineTooltip = new CommandBarTooltip(parentEl); inlineTooltip.registerCommand("Previous", // @ts-expect-error diff --git a/src/ext/language_tools.js b/src/ext/language_tools.js index b6d7ba35e50..ab23e7752f3 100644 --- a/src/ext/language_tools.js +++ b/src/ext/language_tools.js @@ -7,9 +7,7 @@ var lang = require("../lib/lang"); var util = require("../autocomplete/util"); var textCompleter = require("../autocomplete/text_completer"); -/** - * @type {import("../../ace").Ace.Completer} - */ +/**@type {import("../../ace").Ace.Completer}*/ var keyWordCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { if (session.$mode.completer) { @@ -34,9 +32,7 @@ var transformSnippetTooltip = function(str) { return record[p1]; }); }; -/** - * @type {import("../../ace").Ace.Completer} - */ +/**@type {import("../../ace").Ace.Completer} */ var snippetCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { var scopes = []; diff --git a/src/ext/options.js b/src/ext/options.js index 4dab474c435..7e7ab9b27fd 100644 --- a/src/ext/options.js +++ b/src/ext/options.js @@ -271,9 +271,7 @@ class OptionPanel { return self.renderOptionControl(key, x); }); } - /** - * @type {any} - */ + /**@type {any}*/ var control; var value = self.getOption(option); diff --git a/src/ext/prompt.js b/src/ext/prompt.js index 6bb754d0940..54ba7d8bfae 100644 --- a/src/ext/prompt.js +++ b/src/ext/prompt.js @@ -63,9 +63,7 @@ function prompt(editor, message, options, callback) { var cmdLine = $singleLineEditor(); cmdLine.session.setUndoManager(new UndoManager()); - /** - * @type {any} - */ + /**@type {any}*/ var el = dom.buildDom(["div", {class: "ace_prompt_container" + (options.hasDescription ? " input-box-with-description" : "")}]); var overlay = overlayPage(editor, el, done); el.appendChild(cmdLine.container); @@ -117,9 +115,7 @@ function prompt(editor, message, options, callback) { } if (options.hasDescription) { - /** - * @type {any} - */ + /**@type {any}*/ var promptTextContainer = dom.buildDom(["div", {class: "ace_prompt_text_container"}]); dom.buildDom(options.prompt || "Press 'Enter' to confirm or 'Escape' to cancel", promptTextContainer); el.appendChild(promptTextContainer); @@ -464,9 +460,7 @@ prompt.commands = function(editor, callback) { * @param {Function} [callback] */ prompt.modes = function(editor, callback) { - /** - * @type {any[]} - */ + /**@type {any[]}*/ var modesArray = modelist.modes; modesArray = modesArray.map(function(item) { return {value: item.caption, mode: item.name}; diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index 1d62a4f418b..9c2669a8495 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -21,9 +21,7 @@ class SearchBox { * @param {undefined} [showReplaceForm] */ constructor(editor, range, showReplaceForm) { - /** - * @type {any} - */ + /**@type {any}*/ this.activeInput; var div = dom.createElement("div"); dom.buildDom(["div", {class:"ace_search right"}, @@ -49,9 +47,7 @@ class SearchBox { ["span", {action: "searchInSelection", class: "ace_button", title: nls("Search In Selection")}, "S"] ] ], div); - /** - * @type {any} - */ + /**@type {any}*/ this.element = div.firstChild; this.setSession = this.setSession.bind(this); @@ -67,9 +63,7 @@ class SearchBox { setEditor(editor) { editor.searchBox = this; editor.renderer.scroller.appendChild(this.element); - /** - * @type {Editor} - */ + /**@type {Editor}*/ this.editor = editor; } @@ -82,45 +76,25 @@ class SearchBox { * @param {HTMLElement} sb */ $initElements(sb) { - /** - * @type {HTMLElement} - */ + /**@type {HTMLElement}*/ this.searchBox = sb.querySelector(".ace_search_form"); - /** - * @type {HTMLElement} - */ + /**@type {HTMLElement}*/ this.replaceBox = sb.querySelector(".ace_replace_form"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.searchOption = sb.querySelector("[action=searchInSelection]"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.replaceOption = sb.querySelector("[action=toggleReplace]"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.regExpOption = sb.querySelector("[action=toggleRegexpMode]"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.caseSensitiveOption = sb.querySelector("[action=toggleCaseSensitive]"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.wholeWordOption = sb.querySelector("[action=toggleWholeWords]"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.searchInput = this.searchBox.querySelector(".ace_search_field"); - /** - * @type {HTMLInputElement} - */ + /**@type {HTMLInputElement}*/ this.replaceInput = this.replaceBox.querySelector(".ace_search_field"); - /** - * @type {HTMLElement} - */ + /**@type {HTMLElement}*/ this.searchCounter = sb.querySelector(".ace_search_counter"); } @@ -222,9 +196,7 @@ class SearchBox { preventScroll: preventScroll, range: this.searchRange }); - /** - * @type {any} - */ + /**@type {any}*/ var noMatch = !range && this.searchInput.value; dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); this.editor._emit("findSearchBox", { match: !noMatch }); @@ -275,9 +247,7 @@ class SearchBox { caseSensitive: this.caseSensitiveOption.checked, wholeWord: this.wholeWordOption.checked }); - /** - * @type {any} - */ + /**@type {any}*/ var noMatch = !range && this.searchInput.value; dom.setCssClass(this.searchBox, "ace_nomatch", noMatch); this.editor._emit("findSearchBox", { match: !noMatch }); diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index acdf3911a3c..6d1f9dbe68c 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -64,9 +64,7 @@ var simpleDom = { }; -/** - * @type {any} - */ +/**@type {any}*/ var SimpleTextLayer = function() { this.config = {}; this.dom = simpleDom; @@ -93,9 +91,7 @@ var highlight = function(el, opts, callback) { if (el.firstElementChild) { var textLen = 0; for (var i = 0; i < el.childNodes.length; i++) { - /** - * @type {any} - */ + /**@type {any}*/ var ch = el.childNodes[i]; if (ch.nodeType == 3) { textLen += ch.data.length; @@ -200,9 +196,7 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) { session.setUseWorker(false); session.setMode(mode); - /** - * @type {TextLayer} - */ + /**@type {TextLayer}*/ var textLayer = new SimpleTextLayer(); textLayer.setSession(session); Object.keys(textLayer.$tabStrings).forEach(function(k) { diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index d3b74707bf5..b4f6c0a4802 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -21,9 +21,7 @@ class MultiHashHandler { */ $init(config, platform, $singleCommand) { this.platform = platform || (useragent.isMac ? "mac" : "win"); - /** - * @type {Record} - */ + /**@type {Record}*/ this.commands = {}; this.commandKeyBinding = {}; this.addCommands(config); diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 3296ba58116..6a8a21db3e0 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -11,9 +11,7 @@ class KeyBinding { constructor(editor) { this.$editor = editor; this.$data = {editor: editor}; - /** - * @type {(import("../../ace").Ace.KeyboardHandler)[]} - */ + /**@type {(import("../../ace").Ace.KeyboardHandler)[]}*/ this.$handlers = []; this.setDefaultHandler(editor.commands); } diff --git a/src/keyboard/textinput.js b/src/keyboard/textinput.js index 3a31600e744..9c04c22e64f 100644 --- a/src/keyboard/textinput.js +++ b/src/keyboard/textinput.js @@ -23,9 +23,7 @@ var isMobile = useragent.isMobile; var TextInput; TextInput= function(parentNode, host) { - /** - * @type {HTMLTextAreaElement & {msGetInputContext?: () => {compositionStartOffset: number}, getInputContext?: () => {compositionStartOffset: number}}} - */ + /**@type {HTMLTextAreaElement & {msGetInputContext?: () => {compositionStartOffset: number}, getInputContext?: () => {compositionStartOffset: number}}}*/ var text = dom.createElement("textarea"); text.className = "ace_text-input"; @@ -39,10 +37,7 @@ TextInput= function(parentNode, host) { var copied = false; var pasted = false; - /** - * - * @type {false | {[key: string]: any}}} - */ + /**@type {false | {[key: string]: any}}} */ var inComposition = false; var sendingText = false; var tempStyle = ''; diff --git a/src/layer/marker.js b/src/layer/marker.js index e937eb9c852..49d1db1def5 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -40,9 +40,7 @@ class Marker { * @param {string} css */ elt(className, css) { - /** - * @type {any} - */ + /**@type {any}*/ var x = this.i != -1 && this.element.childNodes[this.i]; if (!x) { x = document.createElement("div"); diff --git a/src/layer/text.js b/src/layer/text.js index 877e58c76d4..0ef36e7cb3a 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -82,9 +82,7 @@ class Text { * @param {EditSession} session */ setSession(session) { - /** - * @type {EditSession} - */ + /**@type {EditSession}*/ this.session = session; if (session) this.$computeTabString(); @@ -449,9 +447,7 @@ class Text { $highlightIndentGuide() { if (!this.$highlightIndentGuides || !this.displayIndentGuides) return; - /** - * @type {{ indentLevel?: number; start?: number; end?: number; dir?: number; }} - **/ + /**@type {{ indentLevel?: number; start?: number; end?: number; dir?: number; }}*/ this.$highlightIndentGuideMarker = { indentLevel: undefined, start: undefined, diff --git a/src/lib/event_emitter.js b/src/lib/event_emitter.js index 1169d9ff461..aac6f3d70c0 100644 --- a/src/lib/event_emitter.js +++ b/src/lib/event_emitter.js @@ -1,7 +1,5 @@ "use strict"; -/** - * @type {any} - */ +/**@type {any}*/ var EventEmitter = {}; var stopPropagation = function() { this.propagationStopped = true; }; var preventDefault = function() { this.defaultPrevented = true; }; @@ -63,9 +61,7 @@ EventEmitter.once = function(eventName, callback) { EventEmitter.setDefaultHandler = function(eventName, callback) { - /** - * @type {any} - */ + /**@type {any}*/ var handlers = this._defaultHandlers; if (!handlers) handlers = this._defaultHandlers = {_disabled_: {}}; diff --git a/src/lib/net.js b/src/lib/net.js index 0f3670a24d8..d8103ba82a0 100644 --- a/src/lib/net.js +++ b/src/lib/net.js @@ -24,9 +24,7 @@ exports.get = function (url, callback) { exports.loadScript = function(path, callback) { var head = dom.getDocumentHead(); - /** - * @type {HTMLScriptElement & {onload?: Function, onreadystatechange?: Function, readyState?: string}} - */ + /**@type {HTMLScriptElement & {onload?: Function, onreadystatechange?: Function, readyState?: string}}*/ var s = document.createElement('script'); s.src = path; diff --git a/src/marker_group.js b/src/marker_group.js index 396e87d97c0..48ed2fed3c3 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -1,12 +1,9 @@ "use strict"; /** - * * @typedef {import("./edit_session").EditSession} EditSession */ /** - * @typedef MarkerGroupItem - * @type {{range: import("./range").Range, className: string}} - * @export + * @typedef {{range: import("./range").Range, className: string}} MarkerGroupItem */ /* @@ -20,9 +17,7 @@ class MarkerGroup { */ constructor(session) { this.markers = []; - /** - * @type {EditSession} - */ + /**@type {EditSession}*/ this.session = session; // @ts-expect-error TODO: could potential error here, or most likely missing checks in other places session.addDynamicMarker(this); diff --git a/src/mode/behaviour.js b/src/mode/behaviour.js index d32ca895625..764843849e3 100644 --- a/src/mode/behaviour.js +++ b/src/mode/behaviour.js @@ -3,9 +3,7 @@ * @typedef {Behaviour & {[key: string]: any}} IBehaviour */ -/** - * @type {any} - */ +/**@type {any}*/ var Behaviour; Behaviour = function() { this.$behaviours = {}; diff --git a/src/mode/text.js b/src/mode/text.js index 7e0fd1d7393..c4e06434d2b 100644 --- a/src/mode/text.js +++ b/src/mode/text.js @@ -51,14 +51,10 @@ Mode = function() { if (!this.lineCommentStart) { if (!this.blockComment) return false; - /** - * @type {any} - */ + /**@type {any}*/ var lineCommentStart = this.blockComment.start; var lineCommentEnd = this.blockComment.end; - /** - * @type {any} - */ + /**@type {any}*/ var regexpStart = new RegExp("^(\\s*)(?:" + lang.escapeRegExp(lineCommentStart) + ")"); var regexpEnd = new RegExp("(?:" + lang.escapeRegExp(lineCommentEnd) + ")\\s*$"); @@ -79,9 +75,7 @@ Mode = function() { doc.removeInLine(i, m[1].length, m[0].length); }; - /** - * @type {any} - */ + /**@type {any}*/ var testRemove = function(line, row) { if (regexpStart.test(line)) return true; @@ -93,19 +87,13 @@ Mode = function() { }; } else { if (Array.isArray(this.lineCommentStart)) { - /** - * @type {any} - */ + /**@type {any}*/ var regexpStart = this.lineCommentStart.map(lang.escapeRegExp).join("|"); - /** - * @type {any} - */ + /**@type {any}*/ var lineCommentStart = this.lineCommentStart[0]; } else { var regexpStart = lang.escapeRegExp(this.lineCommentStart); - /** - * @type {any} - */ + /**@type {any}*/ var lineCommentStart = this.lineCommentStart; } regexpStart = new RegExp("^(\\s*)(?:" + regexpStart + ") ?"); @@ -129,9 +117,7 @@ Mode = function() { doc.insertInLine({row: i, column: minIndent}, lineCommentStart); } }; - /** - * @type {any} - */ + /**@type {any}*/ var testRemove = function(line, i) { return regexpStart.test(line); }; diff --git a/src/mode/text_highlight_rules.js b/src/mode/text_highlight_rules.js index bd9f5081391..212b80687fa 100644 --- a/src/mode/text_highlight_rules.js +++ b/src/mode/text_highlight_rules.js @@ -2,9 +2,7 @@ const deepCopy = require("../lib/deep_copy").deepCopy; -/** - * @type {(new() => Partial) & {prototype: import("../../ace").Ace.HighlightRules}} - */ +/**@type {(new() => Partial) & {prototype: import("../../ace").Ace.HighlightRules}}*/ var TextHighlightRules; TextHighlightRules = function() { diff --git a/src/multi_select.js b/src/multi_select.js index dd49174a3ab..d2b6012245b 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -84,9 +84,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { this.ranges = null; // automatically sorted list of ranges - /** - * @type {RangeList | null} - */ + /**@type {RangeList | null} */ this.rangeList = null; /** @@ -544,9 +542,7 @@ var Editor = require("./editor").Editor; var reg = selection._eventRegistry; selection._eventRegistry = {}; - /** - * @type {Selection} - */ + /**@type {Selection}*/ var tmpSel = new Selection(session); this.inVirtualSelectionMode = true; for (var i = ranges.length; i--;) { @@ -699,15 +695,11 @@ var Editor = require("./editor").Editor; } if (isBackwards) { - /** - * @type {Range & {desiredColumn?: number}} - */ + /**@type {Range & {desiredColumn?: number}}*/ var newRange = Range.fromPoints(lead, anchor); newRange.cursor = newRange.start; } else { - /** - * @type {Range & {desiredColumn?: number}} - */ + /**@type {Range & {desiredColumn?: number}}*/ var newRange = Range.fromPoints(anchor, lead); newRange.cursor = newRange.end; } diff --git a/src/occur.js b/src/occur.js index 7098bca3a77..df1b894ce5e 100644 --- a/src/occur.js +++ b/src/occur.js @@ -73,9 +73,7 @@ class Occur extends Search { this.$originalSession = editor.session; var found = this.matchingLines(editor.session, options); var lines = found.map(function(foundLine) { return foundLine.content; }); - /** - * @type {EditSession} - */ + /**@type {EditSession}*/ var occurSession = new EditSession(lines.join('\n')); occurSession.$occur = this; occurSession.$occurMatchingLines = found; diff --git a/src/range.js b/src/range.js index 2504dd38767..50f3b42fcf4 100644 --- a/src/range.js +++ b/src/range.js @@ -12,16 +12,12 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { - /** - * @type {import("../ace").Ace.Point} - */ + /**@type {import("../ace").Ace.Point}*/ this.start = { row: startRow, column: startColumn }; - /** - * @type {import("../ace").Ace.Point} - */ + /**@type {import("../ace").Ace.Point}*/ this.end = { row: endRow, column: endColumn diff --git a/src/search.js b/src/search.js index ad73163a381..7c212299841 100644 --- a/src/search.js +++ b/src/search.js @@ -31,9 +31,7 @@ class Search { **/ constructor() { - /** - * @type {SearchOptions} - */ + /**@type {SearchOptions}*/ this.$options = {}; } @@ -247,9 +245,7 @@ class Search { return options.re = this.$assembleMultilineRegExp(needle, modifier); try { - /** - * @type {RegExp|false} - */ + /**@type {RegExp|false}*/ var re = new RegExp(needle, modifier); } catch(e) { re = false; diff --git a/src/selection.js b/src/selection.js index 6aa519c1ca1..7bf8f0fac93 100644 --- a/src/selection.js +++ b/src/selection.js @@ -18,23 +18,15 @@ class Selection { * @constructor **/ constructor(session) { - /** - * @type {EditSession} - */ + /**@type {EditSession}*/ this.session = session; - /** - * @type {import("./document").Document} - */ + /**@type {import("./document").Document}*/ this.doc = session.getDocument(); this.clearSelection(); - /** - * @type {Anchor} - */ + /**@type {Anchor}*/ this.cursor = this.lead = this.doc.createAnchor(0, 0); - /** - * @type {Anchor} - */ + /**@type {Anchor}*/ this.anchor = this.doc.createAnchor(0, 0); this.$silent = false; diff --git a/src/snippets.js b/src/snippets.js index 027058ef069..2563f561f06 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -452,9 +452,7 @@ class SnippetManager { var after = line.substr(cursor.column); var snippetMap = this.snippetMap; - /** - * @type {Snippet} - */ + /**@type {Snippet}*/ var snippet; this.getActiveScopes(editor).some(function(scope) { var snippets = snippetMap[scope]; @@ -950,9 +948,7 @@ class TabstopManager { for (var i = 0; i < ts.length; i++) { var p = ts[i]; - /** - * @type {Range & {original?: Range, tabstop?: any, linked?: boolean}}} - */ + /**@type {Range & {original?: Range, tabstop?: any, linked?: boolean}}}*/ var range = Range.fromPoints(p.start, p.end || p.start); movePoint(range.start, start); movePoint(range.end, start); @@ -1062,9 +1058,7 @@ dom.importCssString(` position: absolute; }`, "snippets.css", false); -/** - * @type {any} - */ +/**@type {any}*/ exports.snippetManager = new SnippetManager(); diff --git a/src/split.js b/src/split.js index b2cd6c5e34e..ba07e9c3f40 100644 --- a/src/split.js +++ b/src/split.js @@ -8,8 +8,7 @@ var Renderer = require("./virtual_renderer").VirtualRenderer; var EditSession = require("./edit_session").EditSession; /** - * @typedef ISplit - * @type {import("../ace").Ace.EventEmitter & {[key: string]: any}} + * @typedef {import("../ace").Ace.EventEmitter & {[key: string]: any}} ISplit */ var Split; diff --git a/src/tokenizer.js b/src/tokenizer.js index 400b10b4367..070b6612410 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -12,9 +12,7 @@ class Tokenizer { * @param {Object} rules The highlighting rules **/ constructor(rules) { - /** - * @type {RegExp} - */ + /**@type {RegExp}*/ this.splitRegex; this.states = rules; @@ -221,9 +219,7 @@ class Tokenizer { */ getLineTokens(line, startState) { if (startState && typeof startState != "string") { - /** - * @type {any[]} - */ + /**@type {any[]}*/ var stack = startState.slice(0); startState = stack[0]; if (startState === "#tmp") { diff --git a/src/tokenizer_dev.js b/src/tokenizer_dev.js index 1457f4d198e..a005882bd9c 100644 --- a/src/tokenizer_dev.js +++ b/src/tokenizer_dev.js @@ -16,9 +16,7 @@ class Tokenizer extends BaseTokenizer { **/ getLineTokens(line, startState) { if (startState && typeof startState != "string") { - /** - * @type {any[]} - */ + /**@type {any[]}*/ var stack = startState.slice(0); startState = stack[0]; } else @@ -44,9 +42,7 @@ class Tokenizer extends BaseTokenizer { onStateChange(); } - /** - * @type {any} - */ + /**@type {any}*/ var token = { type: null, value: "", diff --git a/src/tooltip.js b/src/tooltip.js index cdbfe3dabfc..d0d44885bb0 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -169,10 +169,6 @@ exports.Tooltip = Tooltip; class HoverTooltip extends Tooltip { constructor(parentNode=document.body) { super(parentNode); - /** - * @type {number?} - */ - this.row; this.timeout = undefined; this.lastT = 0; diff --git a/src/undomanager.js b/src/undomanager.js index dc17782378d..cac4c618d58 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -11,9 +11,7 @@ class UndoManager { * Resets the current undo state and creates a new `UndoManager`. **/ constructor() { - /** - * @type {boolean} - */ + /**@type {boolean}*/ this.$keepRedoStack; this.$maxRev = 0; this.$fromUndo = false; diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 1dc53eb4085..ee36b434bf7 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -51,16 +51,12 @@ class VirtualRenderer { this.$gutter.className = "ace_gutter"; this.container.appendChild(this.$gutter); this.$gutter.setAttribute("aria-hidden", "true"); - /** - * @type {HTMLElement} - */ + /**@type {HTMLElement}*/ this.scroller = dom.createElement("div"); this.scroller.className = "ace_scroller"; this.container.appendChild(this.scroller); - /** - * @type {HTMLElement} - */ + /**@type {HTMLElement}*/ this.content = dom.createElement("div"); this.content.className = "ace_content"; this.scroller.appendChild(this.content); @@ -1838,9 +1834,7 @@ class VirtualRenderer { **/ setTheme(theme, cb) { var _self = this; - /** - * @type {any} - */ + /**@type {any}*/ this.$themeId = theme; _self._dispatchEvent('themeChange',{theme:theme}); @@ -1869,9 +1863,7 @@ class VirtualRenderer { ); if (_self.theme) dom.removeCssClass(_self.container, _self.theme.cssClass); - /** - * @type {any} - */ + /**@type {any}*/ var padding = "padding" in module ? module.padding : "padding" in (_self.theme || {}) ? 4 : _self.$padding; if (_self.$padding && padding != _self.$padding) @@ -1969,13 +1961,9 @@ class VirtualRenderer { delete this.$scrollDecorator; } if (val === true) { - /** - * @type {import("../ace").Ace.VScrollbar} - */ + /**@type {import("../ace").Ace.VScrollbar}*/ this.scrollBarV = new VScrollBarCustom(this.container, this); - /** - * @type {import("../ace").Ace.HScrollbar} - */ + /**@type {import("../ace").Ace.HScrollbar}*/ this.scrollBarH = new HScrollBarCustom(this.container, this); this.scrollBarV.setHeight(this.$size.scrollerHeight); this.scrollBarH.setWidth(this.$size.scrollerWidth); From ad589bd21071d514dbf228f8664950be5dcb35f8 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sat, 30 Sep 2023 21:00:44 +0400 Subject: [PATCH 20/36] continue providing types --- ace.d.ts | 4 ++-- src/edit_session.js | 8 ++++---- src/ext/code_lens.js | 20 +++++++++++++++++++- src/ext/emmet.js | 13 +++++++++++++ src/ext/error_marker.js | 5 +++++ src/ext/hardwrap.js | 5 +++++ src/ext/modelist.js | 8 ++++++++ src/ext/rtl.js | 15 +++++++++++++-- src/ext/static_highlight.js | 7 +++++-- src/ext/textarea.js | 10 +++++++++- 10 files changed, 83 insertions(+), 12 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index eaad4f7b155..db215113ba5 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -579,8 +579,8 @@ export namespace Ace { } interface Annotation { - row?: number; - column?: number; + row: number; + column: number; text: string; type: string; } diff --git a/src/edit_session.js b/src/edit_session.js index 136d6b531b5..0a8f83852e3 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -2232,8 +2232,8 @@ class EditSession { /** * For the given document row and column, returns the screen column. - * @param {Number} row - * @param {Number} docColumn + * @param {Number|Point} row + * @param {Number} [docColumn] * @returns {Number} **/ documentToScreenColumn(row, docColumn) { @@ -2242,8 +2242,8 @@ class EditSession { /** * For the given document row and column, returns the screen row. - * @param {Number} docRow - * @param {Number} docColumn + * @param {Number|Point} docRow + * @param {Number} [docColumn] * @returns {number} **/ documentToScreenRow(docRow, docColumn) { diff --git a/src/ext/code_lens.js b/src/ext/code_lens.js index 6623e828d5a..b6fee2355a1 100644 --- a/src/ext/code_lens.js +++ b/src/ext/code_lens.js @@ -2,12 +2,18 @@ /** * @typedef {import("../edit_session").EditSession} EditSession */ +/** + * @typedef {import("../virtual_renderer").VirtualRenderer & {$textLayer: import("../layer/text").Text &{$lenses}}} VirtualRenderer + */ var LineWidgets = require("../line_widgets").LineWidgets; var event = require("../lib/event"); var lang = require("../lib/lang"); var dom = require("../lib/dom"); +/** + * @param {VirtualRenderer} renderer + */ function clearLensElements(renderer) { var textLayer = renderer.$textLayer; var lensElements = textLayer.$lenses; @@ -16,6 +22,10 @@ function clearLensElements(renderer) { textLayer.$lenses = null; } +/** + * @param {number} changes + * @param {VirtualRenderer} renderer + */ function renderWidgets(changes, renderer) { var changed = changes & renderer.CHANGE_LINES || changes & renderer.CHANGE_FULL @@ -87,6 +97,9 @@ function renderWidgets(changes, renderer) { lensElements.pop().remove(); } +/** + * @param {EditSession} session + */ function clearCodeLensWidgets(session) { if (!session.lineWidgets) return; var widgetManager = session.widgetManager; @@ -127,6 +140,9 @@ exports.setLenses = function(session, lenses) { return firstRow; }; +/** + * @param {import("../editor").Editor} editor + */ function attachToEditor(editor) { editor.codeLensProviders = []; editor.renderer.on("afterRender", renderWidgets); @@ -189,6 +205,9 @@ function attachToEditor(editor) { editor.on("input", editor.$updateLensesOnInput); } +/** + * @param {import("../editor").Editor} editor + */ function detachFromEditor(editor) { editor.off("input", editor.$updateLensesOnInput); editor.renderer.off("afterRender", renderWidgets); @@ -197,7 +216,6 @@ function detachFromEditor(editor) { } /** - * * @param {import("../editor").Editor} editor * @param codeLensProvider */ diff --git a/src/ext/emmet.js b/src/ext/emmet.js index d75eb3f0891..073e3baf31e 100644 --- a/src/ext/emmet.js +++ b/src/ext/emmet.js @@ -322,6 +322,10 @@ var keymap = { var editorProxy = new AceEmmetEditor(); exports.commands = new HashHandler(); +/** + * @param {Editor} editor + * @return {number|boolean} + */ exports.runEmmetCommand = function runEmmetCommand(editor) { if (this.action == "expand_abbreviation_with_tab") { if (!editor.selection.isEmpty()) @@ -367,6 +371,10 @@ for (var command in keymap) { }); } +/** + * @param {Editor} editor + * @param {boolean} [enabled] + */ exports.updateCommands = function(editor, enabled) { if (enabled) { editor.keyBinding.addKeyboardHandler(exports.commands); @@ -382,6 +390,11 @@ exports.isSupportedMode = function(mode) { return /css|less|scss|sass|stylus|html|php|twig|ejs|handlebars/.test(id); }; +/** + * @param {Editor} editor + * @param {string} command + * @return {boolean} + */ exports.isAvailable = function(editor, command) { if (/(evaluate_math_expression|expand_abbreviation)$/.test(command)) return true; diff --git a/src/ext/error_marker.js b/src/ext/error_marker.js index 84f185b3520..0fb5705bfe3 100644 --- a/src/ext/error_marker.js +++ b/src/ext/error_marker.js @@ -23,6 +23,11 @@ function binarySearch(array, needle, comparator) { return -(first + 1); } +/** + * @param {import("../edit_session").EditSession} session + * @param {number} row + * @param {number} dir + */ function findAnnotations(session, row, dir) { var annotations = session.getAnnotations().sort(Range.comparePoints); if (!annotations.length) diff --git a/src/ext/hardwrap.js b/src/ext/hardwrap.js index 1db3fb15499..2efac5c171d 100644 --- a/src/ext/hardwrap.js +++ b/src/ext/hardwrap.js @@ -45,6 +45,11 @@ function hardWrap(editor, options) { row++; } + /** + * @param {string} line + * @param {number} max + * @param {number} min + */ function findSpace(line, max, min) { if (line.length < max) return; diff --git a/src/ext/modelist.js b/src/ext/modelist.js index 26617f81d49..d7d4eb6243b 100644 --- a/src/ext/modelist.js +++ b/src/ext/modelist.js @@ -20,6 +20,11 @@ function getModeForPath(path) { } class Mode { + /** + * @param {string} name + * @param {string} caption + * @param {string} extensions + */ constructor(name, caption, extensions) { this.name = name; this.caption = caption; @@ -38,6 +43,9 @@ class Mode { this.extRe = new RegExp(re, "gi"); } + /** + * @param {string} filename + */ supportsFile(filename) { return filename.match(this.extRe); } diff --git a/src/ext/rtl.js b/src/ext/rtl.js index 4be16acf43a..dc7f93deb24 100644 --- a/src/ext/rtl.js +++ b/src/ext/rtl.js @@ -66,7 +66,9 @@ require("../config").defineOptions(Editor.prototype, "editor", { * - ensures RLE mark removal on line merge, when 'delete' is pressed and cursor stays * at last position of previous line and when 'backspace' is pressed and cursor stays at * first position of current line. This is achived by hacking range boundaries on 'remove' operation. - **/ + * @param {any} e + * @param {Editor} editor + */ function onChangeSelection(e, editor) { var lead = editor.getSelection().lead; if (editor.session.$bidiHandler.isRtlLine(lead.row)) { @@ -91,7 +93,9 @@ function onCommandEmitted(commadEvent) { * Whenever the document is changed make sure that line break operatin * on right-to-left line (like pressing Enter or pasting multi-line text) * produces new right-to-left lines - **/ + * @param {import("../../ace").Ace.Delta} delta + * @param {Editor} editor + */ function onChange(delta, editor) { var session = editor.session; session.$bidiHandler.currentRow = null; @@ -103,6 +107,10 @@ function onChange(delta, editor) { } } +/** + * @param {any} e + * @param {import("../virtual_renderer").VirtualRenderer} renderer + */ function updateLineDirection(e, renderer) { var session = renderer.session; var $bidiHandler = session.$bidiHandler; @@ -122,6 +130,9 @@ function updateLineDirection(e, renderer) { }); } +/** + * @param {import("../virtual_renderer").VirtualRenderer} renderer + */ function clearTextLayer(renderer) { var lines = renderer.$textLayer.$lines; lines.cells.forEach(clear); diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index 6d1f9dbe68c..6e532018317 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -8,6 +8,9 @@ var dom = require("../lib/dom"); var escapeHTML = require("../lib/lang").escapeHTML; class Element { + /** + * @param {string} type + */ constructor(type) { /** @type{string} */this.className; this.type = type; @@ -52,10 +55,10 @@ class Element { var simpleDom = { - createTextNode: function(textContent, element) { + createTextNode: function(/** @type {string} */ textContent, /** @type {any} */ element) { return escapeHTML(textContent); }, - createElement: function(type) { + createElement: function(/** @type {string} */ type) { return new Element(type); }, createFragment: function() { diff --git a/src/ext/textarea.js b/src/ext/textarea.js index 1d11901f9e3..fb883f7b6e3 100644 --- a/src/ext/textarea.js +++ b/src/ext/textarea.js @@ -6,7 +6,7 @@ var ace = require("../ace"); module.exports = exports = ace; -/* +/** * Returns the CSS property of element. * 1) If the CSS property is on the style object of the element, use it, OR * 2) Compute the CSS property @@ -14,6 +14,9 @@ module.exports = exports = ace; * If the property can't get computed, is 'auto' or 'intrinsic', the former * calculated property is used (this can happen in cases where the textarea * is hidden and has no dimension styles). + * @param {HTMLElement} element + * @param {HTMLElement} container + * @param {string} property */ var getCSSProperty = function(element, container, property) { var ret = element.style[property]; @@ -22,6 +25,7 @@ var getCSSProperty = function(element, container, property) { if (window.getComputedStyle) { ret = window.getComputedStyle(element, '').getPropertyValue(property); } else { + // @ts-ignore ret = element.currentStyle[property]; } } @@ -32,6 +36,10 @@ var getCSSProperty = function(element, container, property) { return ret; }; +/** + * @param {HTMLElement} elm + * @param {Object} styles + */ function applyStyles(elm, styles) { for (var style in styles) { elm.style[style] = styles[style]; From 18069d519ead77a67e8195b90fd8822aea9798dc Mon Sep 17 00:00:00 2001 From: mkslanc Date: Wed, 4 Oct 2023 19:31:06 +0400 Subject: [PATCH 21/36] continue providing types --- ace.d.ts | 4 +-- src/editor.js | 10 +++--- src/incremental_search.js | 38 ++++++++++++++++++++- src/layer/marker.js | 48 +++++++++++++++++++++++++-- src/multi_select.js | 5 +++ src/range_list.js | 5 ++- src/search.js | 7 ++++ src/search_highlight.js | 10 ++++++ src/selection.js | 2 +- src/tooltip.js | 58 +++++++++++++++++++++++++++++--- src/undomanager.js | 69 +++++++++++++++++++++++++++++++++++++-- 11 files changed, 237 insertions(+), 19 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index db215113ba5..8aeb3b742a6 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -422,7 +422,7 @@ export namespace Ace { "changeSession": (e: {oldSession: EditSession, session: EditSession}) => void; "blur": (e) => void; "mousedown": (e: MouseEvent) => void; - "mousemove": (e: MouseEvent & {scrollTop?}) => void; + "mousemove": (e: MouseEvent & {scrollTop?}, editor?: Editor) => void; "changeStatus": () => void; "keyboardActivity": () => void; "mousewheel": (e: MouseEvent) => void; @@ -610,7 +610,7 @@ export namespace Ace { type CommandLike = Command | ((editor: Editor) => void); - type KeyboardHandler = import("./src/keyboard/hash_handler").HashHandler & { + type KeyboardHandler = Partial & { attach?: (editor: Editor) => void; detach?: (editor: Editor) => void; getStatusText?: (editor?: any, data?) => string; diff --git a/src/editor.js b/src/editor.js index 749ba39e356..9cc588dd54b 100644 --- a/src/editor.js +++ b/src/editor.js @@ -3050,25 +3050,25 @@ config.defineOptions(Editor.prototype, "editor", { var relativeNumberRenderer = { - getText: function(session, row) { + getText: function(/**@type{EditSession}*/session, /**@type{number}*/row) { return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9 ? "\xb7" : ""))) + ""; }, - getWidth: function(session, lastLineNumber, config) { + getWidth: function(session, /**@type{number}*/lastLineNumber, config) { return Math.max( lastLineNumber.toString().length, (config.lastRow + 1).toString().length, 2 ) * config.characterWidth; }, - update: function(e, editor) { + update: function(e, /**@type{Editor}*/editor) { editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER); }, - attach: function(editor) { + attach: function(/**@type{Editor}*/editor) { editor.renderer.$gutterLayer.$renderer = this; editor.on("changeSelection", this.update); this.update(null, editor); }, - detach: function(editor) { + detach: function(/**@type{Editor}*/editor) { if (editor.renderer.$gutterLayer.$renderer == this) editor.renderer.$gutterLayer.$renderer = null; editor.off("changeSelection", this.update); diff --git a/src/incremental_search.js b/src/incremental_search.js index f9b5e428abb..58ba6725414 100644 --- a/src/incremental_search.js +++ b/src/incremental_search.js @@ -12,6 +12,9 @@ function isRegExp(obj) { return obj instanceof RegExp; } +/** + * @param {RegExp} re + */ function regExpToObject(re) { var string = String(re), start = string.indexOf('/'), @@ -22,6 +25,11 @@ function regExpToObject(re) { }; } +/** + * @param {string} string + * @param {string} flags + * @return {RegExp|string} + */ function stringToRegExp(string, flags) { try { return new RegExp(string, flags); @@ -49,7 +57,10 @@ class IncrementalSearch extends Search { this.$options = {wrap: false, skipCurrent: false}; this.$keyboardHandler = new ISearchKbd(this); } - + + /** + * @param {boolean} backwards + */ activate(editor, backwards) { this.$editor = editor; this.$startPos = this.$currentPos = editor.getCursorPosition(); @@ -64,6 +75,9 @@ class IncrementalSearch extends Search { this.statusMessage(true); } + /** + * @param {boolean} [reset] + */ deactivate(reset) { this.cancelSearch(reset); var editor = this.$editor; @@ -76,6 +90,9 @@ class IncrementalSearch extends Search { this.message(''); } + /** + * @param {Editor} editor + */ selectionFix(editor) { // Fix selection bug: When clicked inside the editor // editor.selection.$isEmpty is false even if the mouse click did not @@ -87,6 +104,9 @@ class IncrementalSearch extends Search { } } + /** + * @param {RegExp} regexp + */ highlight(regexp) { var sess = this.$editor.session, hl = sess.$isearchHighlight = sess.$isearchHighlight || sess.addDynamicMarker( @@ -95,6 +115,9 @@ class IncrementalSearch extends Search { sess._emit("changeBackMarker"); // force highlight layer redraw } + /** + * @param {boolean} [reset] + */ cancelSearch(reset) { var e = this.$editor; this.$prevNeedle = this.$options.needle; @@ -109,6 +132,10 @@ class IncrementalSearch extends Search { return Range.fromPoints(this.$currentPos, this.$currentPos); } + /** + * @param {boolean} moveToNext + * @param {Function} needleUpdateFunc + */ highlightAndFindWithNeedle(moveToNext, needleUpdateFunc) { if (!this.$editor) return null; var options = this.$options; @@ -141,6 +168,9 @@ class IncrementalSearch extends Search { return found; } + /** + * @param {string} s + */ addString(s) { return this.highlightAndFindWithNeedle(false, function(needle) { if (!isRegExp(needle)) @@ -151,6 +181,9 @@ class IncrementalSearch extends Search { }); } + /** + * @param {any} c + */ removeChar(c) { return this.highlightAndFindWithNeedle(false, function(needle) { if (!isRegExp(needle)) @@ -180,6 +213,9 @@ class IncrementalSearch extends Search { return true; } + /** + * @param {string} text + */ onPaste(text) { this.addString(text); } diff --git a/src/layer/marker.js b/src/layer/marker.js index 49d1db1def5..b44da5e1005 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -100,7 +100,7 @@ class Marker { /** * @param {number} row - * @param {import("../../ace").Ace.LayerConfig} layerConfig + * @param {Partial} layerConfig */ $getTop(row, layerConfig) { return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; @@ -108,6 +108,13 @@ class Marker { // Draws a marker, which spans a range of text on multiple lines + /** + * @param {undefined} stringBuilder + * @param {Range} range + * @param {string} clazz + * @param {Partial} layerConfig + * @param {string} [extraStyle] + */ drawTextMarker(stringBuilder, range, clazz, layerConfig, extraStyle) { var session = this.session; var start = range.start.row; @@ -132,6 +139,13 @@ class Marker { } // Draws a multi line marker, where lines span the full width + /** + * @param {undefined} stringBuilder + * @param {Range} range + * @param {string} clazz + * @param {import("../../ace").Ace.LayerConfig} config + * @param {string} [extraStyle] + */ drawMultiLineMarker(stringBuilder, range, clazz, config, extraStyle) { // from selection start to the end of the line var padding = this.$padding; @@ -187,6 +201,14 @@ class Marker { } // Draws a marker which covers part or whole width of a single screen line + /** + * @param {undefined} stringBuilder + * @param {Range} range + * @param {string} clazz + * @param {Partial} config + * @param {number} [extraLength] + * @param {string} [extraStyle] + */ drawSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle) { if (this.session.$bidiHandler.isBidiRow(range.start.row)) return this.drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle); @@ -206,6 +228,14 @@ class Marker { } // Draws Bidi marker which covers part or whole width of a single screen line + /** + * @param {undefined} stringBuilder + * @param {Range} range + * @param {string} clazz + * @param {Partial} config + * @param {number} extraLength + * @param {string} extraStyle + */ drawBidiSingleLineMarker(stringBuilder, range, clazz, config, extraLength, extraStyle) { var height = config.lineHeight, top = this.$getTop(range.start.row, config), padding = this.$padding; var selections = this.session.$bidiHandler.getSelections(range.start.column, range.end.column); @@ -221,6 +251,13 @@ class Marker { }, this); } + /** + * @param {undefined} stringBuilder + * @param {Range} range + * @param {string} clazz + * @param {Partial} config + * @param {undefined} [extraStyle] + */ drawFullLineMarker(stringBuilder, range, clazz, config, extraStyle) { var top = this.$getTop(range.start.row, config); var height = config.lineHeight; @@ -234,7 +271,14 @@ class Marker { "left:0;right:0;"+ (extraStyle || "") ); } - + + /** + * @param {undefined} stringBuilder + * @param {Range} range + * @param {string} clazz + * @param {Partial} config + * @param {undefined} [extraStyle] + */ drawScreenLineMarker(stringBuilder, range, clazz, config, extraStyle) { var top = this.$getTop(range.start.row, config); var height = config.lineHeight; diff --git a/src/multi_select.js b/src/multi_select.js index d2b6012245b..1ad26587466 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -15,6 +15,11 @@ exports.commands = commands.defaultCommands.concat(commands.multiSelectCommands) var Search = require("./search").Search; var search = new Search(); +/** + * @param {EditSession} session + * @param {string | RegExp} needle + * @param {number} dir + */ function find(session, needle, dir) { search.$options.wrap = true; search.$options.needle = needle; diff --git a/src/range_list.js b/src/range_list.js index 2ea6d868275..14a9337ad65 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -52,6 +52,9 @@ class RangeList { return this.ranges.splice(startIndex, endIndex - startIndex, range); } + /** + * @param {Range[]} list + */ addList(list) { var removed = []; for (var i = list.length; i--; ) { @@ -160,7 +163,7 @@ class RangeList { } /** - * @param {any} session + * @param {import("./edit_session").EditSession} session */ attach(session) { if (this.session) diff --git a/src/search.js b/src/search.js index 7c212299841..4b72fc35103 100644 --- a/src/search.js +++ b/src/search.js @@ -253,6 +253,10 @@ class Search { return options.re = re; } + /** + * @param {string} needle + * @param {string} modifier + */ $assembleMultilineRegExp(needle, modifier) { var parts = needle.replace(/\r\n|\r|\n/g, "$\n^").split("\n"); var re = []; @@ -264,6 +268,9 @@ class Search { return re; } + /** + * @param {import("./edit_session").EditSession} session + */ $matchIterator(session, options) { var re = this.$assembleRegExp(options); if (!re) diff --git a/src/search_highlight.js b/src/search_highlight.js index 8c941e82a51..bc9f0273c27 100644 --- a/src/search_highlight.js +++ b/src/search_highlight.js @@ -4,6 +4,10 @@ var lang = require("./lib/lang"); var Range = require("./range").Range; class SearchHighlight { + /** + * @param {any} regExp + * @param {string} clazz + */ constructor(regExp, clazz, type = "text") { this.setRegexp(regExp); this.clazz = clazz; @@ -17,6 +21,12 @@ class SearchHighlight { this.cache = []; } + /** + * @param {any} html + * @param {import("./layer/marker").Marker} markerLayer + * @param {import("./edit_session").EditSession} session + * @param {Partial} config + */ update(html, markerLayer, session, config) { if (!this.regExp) return; diff --git a/src/selection.js b/src/selection.js index 7bf8f0fac93..91f06e742d5 100644 --- a/src/selection.js +++ b/src/selection.js @@ -894,7 +894,7 @@ class Selection { /** * * @param data - * @return {Boolean|boolean|*|boolean} + * @return {boolean} */ isEqual(data) { if ((data.length || this.rangeCount) && data.length != this.rangeCount) diff --git a/src/tooltip.js b/src/tooltip.js index d0d44885bb0..f2cde4fd2f1 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -1,4 +1,10 @@ "use strict"; +/** + * @typedef {import("./editor").Editor} Editor + */ +/** + * @typedef {import("./mouse/mouse_event").MouseEvent} MouseEvent + */ var dom = require("./lib/dom"); var Range = require("./range").Range; @@ -60,6 +66,9 @@ class Tooltip { dom.addCssClass(this.getElement(), className); } + /** + * @param {import("../ace").Ace.Theme} theme + */ setTheme(theme) { this.$element.className = CLASSNAME + " " + (theme.isDark? "ace_dark " : "") + (theme.cssClass || ""); @@ -114,14 +123,21 @@ class Tooltip { class PopupManager { constructor () { + /**@type{Tooltip[]} */ this.popups = []; } - + + /** + * @param {Tooltip} popup + */ addPopup(popup) { this.popups.push(popup); this.updatePopups(); } + /** + * @param {Tooltip} popup + */ removePopup(popup) { const index = this.popups.indexOf(popup); if (index !== -1) { @@ -131,6 +147,7 @@ class PopupManager { } updatePopups() { + // @ts-expect-error TODO: could be actually an error this.popups.sort((a, b) => b.priority - a.priority); let visiblepopups = []; @@ -151,6 +168,11 @@ class PopupManager { } } + /** + * @param {Tooltip} popupA + * @param {Tooltip} popupB + * @return {boolean} + */ doPopupsOverlap (popupA, popupB) { const rectA = popupA.getElement().getBoundingClientRect(); const rectB = popupB.getElement().getBoundingClientRect(); @@ -190,13 +212,19 @@ class HoverTooltip extends Tooltip { if (!el.contains(document.activeElement)) this.hide(); }.bind(this)); } - + + /** + * @param {Editor} editor + */ addToEditor(editor) { editor.on("mousemove", this.onMouseMove); editor.on("mousedown", this.hide); editor.renderer.getMouseEventTarget().addEventListener("mouseout", this.onMouseOut, true); } + /** + * @param {Editor} editor + */ removeFromEditor(editor) { editor.off("mousemove", this.onMouseMove); editor.off("mousedown", this.hide); @@ -207,6 +235,10 @@ class HoverTooltip extends Tooltip { } } + /** + * @param {MouseEvent} e + * @param {Editor} editor + */ onMouseMove(e, editor) { this.lastEvent = e; this.lastT = Date.now(); @@ -240,6 +272,9 @@ class HoverTooltip extends Tooltip { } } + /** + * @param {MouseEvent} e + */ isOutsideOfText(e) { var editor = e.editor; var docPos = e.getDocumentPosition(); @@ -256,11 +291,20 @@ class HoverTooltip extends Tooltip { } return false; } - + + /** + * @param {any} value + */ setDataProvider(value) { this.$gatherData = value; } - + + /** + * @param {Editor} editor + * @param {Range} range + * @param {any} domNode + * @param {MouseEvent} startingEvent + */ showForRange(editor, range, domNode, startingEvent) { if (startingEvent && startingEvent != this.lastEvent) return; if (this.isOpen && document.activeElement == this.getElement()) return; @@ -301,7 +345,11 @@ class HoverTooltip extends Tooltip { this.setPosition(position.pageX, position.pageY); } - + + /** + * @param {Range} range + * @param {import("./edit_session").EditSession} [session] + */ addMarker(range, session) { if (this.marker) { this.$markerSession.removeMarker(this.marker); diff --git a/src/undomanager.js b/src/undomanager.js index cac4c618d58..928dd76470f 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -3,6 +3,14 @@ * @typedef {import("./edit_session").EditSession} EditSession */ +/** + * @typedef {import("../ace").Ace.Delta} Delta + */ + +/** + * @typedef {import("../ace").Ace.Point} Point + */ + /** * This object maintains the undo stack for an [[EditSession `EditSession`]]. **/ @@ -287,7 +295,10 @@ class UndoManager { } - + + /** + * @param {Delta} delta + */ $prettyPrint(delta) { if (delta) return stringifyDelta(delta); return stringifyDelta(this.$undoStack) + "\n---\n" + stringifyDelta(this.$redoStack); @@ -300,6 +311,10 @@ UndoManager.prototype.hasRedo = UndoManager.prototype.canRedo; UndoManager.prototype.isClean = UndoManager.prototype.isAtBookmark; UndoManager.prototype.markClean = UndoManager.prototype.bookmark; +/** + * @param {any[]} stack + * @param {number} pos + */ function rearrangeUndoStack(stack, pos) { for (var i = pos; i--; ) { var deltaSet = stack[i]; @@ -319,6 +334,9 @@ var Range = require("./range").Range; var cmp = Range.comparePoints; var comparePoints = Range.comparePoints; +/** + * @param {Delta} delta + */ function $updateMarkers(delta) { var isInsert = delta.action == "insert"; var start = delta.start; @@ -359,9 +377,16 @@ function $updateMarkers(delta) { } } +/** + * @param {Point} pos + */ function clonePos(pos) { return {row: pos.row,column: pos.column}; } + +/** + * @param {Delta} d + */ function cloneDelta(d) { return { start: clonePos(d.start), @@ -394,6 +419,11 @@ function stringifyDelta(d) { } return type; } + +/** + * @param {Range} r + * @return {string} + */ function stringifyRange(r) { return r.start.row + ":" + r.start.column + "=>" + r.end.row + ":" + r.end.column; @@ -420,6 +450,10 @@ function stringifyRange(r) { * d2.s < d1.s < d2.e // can split */ +/** + * @param {Delta} d1 + * @param {Delta} d2 + */ function swap(d1, d2) { var i1 = d1.action == "insert"; var i2 = d2.action == "insert"; @@ -487,6 +521,11 @@ function swapGroups(ds1, ds2) { o<---o c1 */ +/** + * + * @param {Delta} d1 + * @param {Delta} c1 + */ function xform(d1, c1) { var i1 = d1.action == "insert"; var i2 = c1.action == "insert"; @@ -543,17 +582,38 @@ function xform(d1, c1) { } return [c1, d1]; } - + +/** + * + * @param {import("../ace").Ace.IRange} d1 + * @param {import("../ace").Ace.IRange} d2 + * @param {number} dir + */ function shift(d1, d2, dir) { shiftPos(d1.start, d2.start, d2.end, dir); shiftPos(d1.end, d2.start, d2.end, dir); } + +/** + * + * @param {Point} pos + * @param {Point} start + * @param {Point} end + * @param {number} dir + */ function shiftPos(pos, start, end, dir) { if (pos.row == (dir == 1 ? start : end).row) { pos.column += dir * (end.column - start.column); } pos.row += dir * (end.row - start.row); } + +/** + * + * @param {Delta} c + * @param {Point} pos + * @return {Delta} + */ function splitDelta(c, pos) { var lines = c.lines; var end = c.end; @@ -573,6 +633,10 @@ function splitDelta(c, pos) { return rest; } +/** + * @param {any[]} redoStack + * @param {Delta} d + */ function moveDeltasByOne(redoStack, d) { d = cloneDelta(d); for (var j = redoStack.length; j--;) { @@ -597,6 +661,7 @@ function moveDeltasByOne(redoStack, d) { } return redoStack; } + function rebaseRedoStack(redoStack, deltaSets) { for (var i = 0; i < deltaSets.length; i++) { var deltas = deltaSets[i]; From b729b7472dbd8c8c23d279c72e0c902a703a5140 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sat, 7 Oct 2023 16:47:05 +0400 Subject: [PATCH 22/36] move some inline typedef imports to separate typedefs --- src/autocomplete/inline.js | 6 ++++-- src/background_tokenizer.js | 7 +++++-- src/bidihandler.js | 6 +++++- src/edit_session.js | 5 ++++- src/ext/command_bar.js | 5 ++++- src/ext/elastic_tabstops_lite.js | 5 ++--- src/ext/options.js | 5 ++++- src/keyboard/keybinding.js | 6 ++++-- src/layer/cursor.js | 6 ++++-- src/layer/gutter.js | 5 ++++- src/layer/lines.js | 8 +++++--- src/layer/marker.js | 6 ++++-- src/marker_group.js | 5 ++++- src/mouse/default_handlers.js | 11 +++++++---- src/mouse/mouse_handler.js | 5 ++++- src/placeholder.js | 5 ++++- src/range.js | 6 +++++- src/range_list.js | 5 ++++- src/search.js | 2 +- src/search_highlight.js | 11 ++++++++--- src/token_iterator.js | 6 +++++- src/tooltip.js | 7 +++++-- 22 files changed, 96 insertions(+), 37 deletions(-) diff --git a/src/autocomplete/inline.js b/src/autocomplete/inline.js index eb4b6165855..614760204b4 100644 --- a/src/autocomplete/inline.js +++ b/src/autocomplete/inline.js @@ -1,5 +1,7 @@ "use strict"; - +/** + * @typedef {import("../editor").Editor} Editor + */ var snippetManager = require("../snippets").snippetManager; /** @@ -15,7 +17,7 @@ class AceInline { /** * Renders the completion as ghost text to the current cursor position - * @param {import("../editor").Editor} editor + * @param {Editor} editor * @param {import("../../ace").Ace.Completion} completion * @param {string} prefix * @returns {boolean} True if the completion could be rendered to the editor, false otherwise diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 3ab6c89339f..a0e494a16ba 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -5,6 +5,9 @@ /** * @typedef {import("./editor").Editor} Editor */ +/** + * @typedef {import("./tokenizer").Tokenizer} Tokenizer + */ var oop = require("./lib/oop"); var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -17,7 +20,7 @@ class BackgroundTokenizer { /** * Creates a new `BackgroundTokenizer` object. - * @param {import("./tokenizer").Tokenizer} tokenizer The tokenizer to use + * @param {Tokenizer} tokenizer The tokenizer to use * @param {any} [editor] The editor to associate with **/ constructor(tokenizer, editor) { @@ -72,7 +75,7 @@ class BackgroundTokenizer { /** * Sets a new tokenizer for this object. - * @param {import("./tokenizer").Tokenizer} tokenizer The new tokenizer to use + * @param {Tokenizer} tokenizer The new tokenizer to use **/ setTokenizer(tokenizer) { this.tokenizer = tokenizer; diff --git a/src/bidihandler.js b/src/bidihandler.js index 9fd5bdfb7b4..003822fcafd 100644 --- a/src/bidihandler.js +++ b/src/bidihandler.js @@ -1,4 +1,8 @@ "use strict"; +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ + var bidiUtil = require("./lib/bidiutil"); var lang = require("./lib/lang"); var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/; @@ -10,7 +14,7 @@ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\u202B]/; class BidiHandler { /** * Creates a new `BidiHandler` object - * @param {import("./edit_session").EditSession} session The session to use + * @param {EditSession} session The session to use **/ constructor(session) { this.session = session; diff --git a/src/edit_session.js b/src/edit_session.js index 0a8f83852e3..875978e4646 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -8,6 +8,9 @@ /** * @typedef {import("../ace").Ace.Point} Point */ +/** + * @typedef {import("./layer/font_metrics").FontMetrics} FontMetrics + */ var oop = require("./lib/oop"); var lang = require("./lib/lang"); @@ -2293,7 +2296,7 @@ class EditSession { } /** - * @param {import("./layer/font_metrics").FontMetrics} fm + * @param {FontMetrics} fm */ $setFontMetrics(fm) { if (!this.$enableVarChar) return; diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 8bbbbf9fbbc..7395eab53f2 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -1,3 +1,6 @@ +/** + * @typedef {import("../editor").Editor} Editor + */ var Tooltip = require("../tooltip").Tooltip; var EventEmitter = require("../lib/event_emitter").EventEmitter; var lang = require("../lib/lang"); @@ -147,7 +150,7 @@ class CommandBarTooltip { * Depending on the alwaysShow parameter it either displays the tooltip immediately, * or subscribes to the necessary events to display the tooltip on hover. * - * @param {import("../editor").Editor} editor + * @param {Editor} editor */ attach(editor) { if (!editor || (this.isShown() && this.editor === editor)) { diff --git a/src/ext/elastic_tabstops_lite.js b/src/ext/elastic_tabstops_lite.js index 5cb6dd341e8..66ce76e8c03 100644 --- a/src/ext/elastic_tabstops_lite.js +++ b/src/ext/elastic_tabstops_lite.js @@ -1,8 +1,7 @@ "use strict"; - class ElasticTabstopsLite { /** - * @param {import("../editor").Editor} editor + * @param {Editor} editor */ constructor(editor) { this.$editor = editor; @@ -310,7 +309,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { useElasticTabstops: { /** * @param {boolean} val - * @this {import("../editor").Editor} + * @this {Editor} */ set: function(val) { if (val) { diff --git a/src/ext/options.js b/src/ext/options.js index 7e7ab9b27fd..f30f83f2af9 100644 --- a/src/ext/options.js +++ b/src/ext/options.js @@ -1,4 +1,7 @@ "use strict"; +/** + * @typedef {import("../editor").Editor} Editor + */ require("./menu_tools/overlay_page"); @@ -214,7 +217,7 @@ var optionGroups = { class OptionPanel { /** * - * @param {import("../editor").Editor} editor + * @param {Editor} editor * @param {HTMLElement} [element] */ constructor(editor, element) { diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 6a8a21db3e0..06be9ff4a07 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -1,12 +1,14 @@ "use strict"; - +/** + * @typedef {import("../editor").Editor} Editor + */ var keyUtil = require("../lib/keys"); var event = require("../lib/event"); class KeyBinding { /** - * @param {import("../editor").Editor} editor + * @param {Editor} editor */ constructor(editor) { this.$editor = editor; diff --git a/src/layer/cursor.js b/src/layer/cursor.js index 5e56a781d55..7be358ca137 100644 --- a/src/layer/cursor.js +++ b/src/layer/cursor.js @@ -1,5 +1,7 @@ "use strict"; - +/** + * @typedef {import("../edit_session").EditSession} EditSession + */ var dom = require("../lib/dom"); @@ -58,7 +60,7 @@ class Cursor { } /** - * @param {import("../edit_session").EditSession} session + * @param {EditSession} session */ setSession(session) { this.session = session; diff --git a/src/layer/gutter.js b/src/layer/gutter.js index 6eb656b4299..6d3e9b1f24d 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -1,4 +1,7 @@ "use strict"; +/** + * @typedef {import("../edit_session").EditSession} EditSession + */ var dom = require("../lib/dom"); var oop = require("../lib/oop"); var lang = require("../lib/lang"); @@ -26,7 +29,7 @@ class Gutter{ } /** - * @param {import("../edit_session").EditSession} session + * @param {EditSession} session */ setSession(session) { if (this.session) diff --git a/src/layer/lines.js b/src/layer/lines.js index 354362cda5d..c30f806b3ac 100644 --- a/src/layer/lines.js +++ b/src/layer/lines.js @@ -1,5 +1,7 @@ "use strict"; - +/** + * @typedef {import("../edit_session").EditSession} EditSession + */ var dom = require("../lib/dom"); class Lines { @@ -38,7 +40,7 @@ class Lines { /** * @param {number} row * @param {Partial} config - * @param {import("../edit_session").EditSession} session + * @param {EditSession} session */ computeLineTop(row, config, session) { var screenTop = config.firstRowScreen * config.lineHeight; @@ -50,7 +52,7 @@ class Lines { /** * @param {number} row * @param {import("../../ace").Ace.LayerConfig} config - * @param {import("../edit_session").EditSession} session + * @param {EditSession} session */ computeLineHeight(row, config, session) { return config.lineHeight * session.getRowLineCount(row); diff --git a/src/layer/marker.js b/src/layer/marker.js index b44da5e1005..a7e30a85ab2 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -1,5 +1,7 @@ "use strict"; - +/** + * @typedef {import("../edit_session").EditSession} EditSession + */ var Range = require("../range").Range; var dom = require("../lib/dom"); @@ -22,7 +24,7 @@ class Marker { } /** - * @param {import("../edit_session").EditSession} session + * @param {EditSession} session */ setSession(session) { this.session = session; diff --git a/src/marker_group.js b/src/marker_group.js index 48ed2fed3c3..36482db28e7 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -5,6 +5,9 @@ /** * @typedef {{range: import("./range").Range, className: string}} MarkerGroupItem */ +/** + * @typedef {import("./layer/marker").Marker} Marker + */ /* Potential improvements: @@ -56,7 +59,7 @@ class MarkerGroup { /** * @param {any} html - * @param {import("./layer/marker").Marker} markerLayer + * @param {Marker} markerLayer * @param {EditSession} session * @param {{ firstRow: any; lastRow: any; }} config */ diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index 64775239d59..bed8dc5dca6 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -2,6 +2,9 @@ /** * @typedef {import("./mouse_handler").MouseHandler} MouseHandler */ +/** + * @typedef {import("./mouse_event").MouseEvent} MouseEvent + */ var useragent = require("../lib/useragent"); var DRAG_OFFSET = 0; // pixels @@ -175,7 +178,7 @@ class DefaultHandlers { } /** - * @param {import("./mouse_event").MouseEvent} ev + * @param {MouseEvent} ev * @this {MouseHandler} */ onDoubleClick(ev) { @@ -199,7 +202,7 @@ class DefaultHandlers { } /** - * @param {import("./mouse_event").MouseEvent} ev + * @param {MouseEvent} ev * @this {MouseHandler} */ onTripleClick(ev) { @@ -218,7 +221,7 @@ class DefaultHandlers { } /** - * @param {import("./mouse_event").MouseEvent} ev + * @param {MouseEvent} ev * @this {MouseHandler} */ onQuadClick(ev) { @@ -230,7 +233,7 @@ class DefaultHandlers { } /** - * @param {import("./mouse_event").MouseEvent} ev + * @param {MouseEvent} ev * @this {MouseHandler} */ onMouseWheel(ev) { diff --git a/src/mouse/mouse_handler.js b/src/mouse/mouse_handler.js index aada8b7bb27..bb2a25b3f90 100644 --- a/src/mouse/mouse_handler.js +++ b/src/mouse/mouse_handler.js @@ -1,4 +1,7 @@ "use strict"; +/** + * @typedef {import("../editor").Editor} Editor + */ var event = require("../lib/event"); var useragent = require("../lib/useragent"); var DefaultHandlers = require("./default_handlers").DefaultHandlers; @@ -10,7 +13,7 @@ var config = require("../config"); class MouseHandler { /** - * @param {import("../editor").Editor} editor + * @param {Editor} editor */ constructor(editor) { /** @type {boolean} */this.$dragDelay; diff --git a/src/placeholder.js b/src/placeholder.js index 78846cc005d..7b7cf385789 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -1,11 +1,14 @@ "use strict"; +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ var Range = require("./range").Range; var EventEmitter = require("./lib/event_emitter").EventEmitter; var oop = require("./lib/oop"); class PlaceHolder { /** - * @param {import("./edit_session").EditSession} session + * @param {EditSession} session * @param {Number} length * @param {import("../ace").Ace.Point} pos * @param {any[]} others diff --git a/src/range.js b/src/range.js index 50f3b42fcf4..158ef59c8a3 100644 --- a/src/range.js +++ b/src/range.js @@ -1,4 +1,8 @@ "use strict"; + +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ /** * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. **/ @@ -408,7 +412,7 @@ class Range { /** * Given the current `Range`, this function converts those starting and ending [[Point]]'s into screen positions, and then returns a new `Range` object. - * @param {import("./edit_session").EditSession} session The `EditSession` to retrieve coordinates from + * @param {EditSession} session The `EditSession` to retrieve coordinates from * @returns {Range} **/ toScreenRange(session) { diff --git a/src/range_list.js b/src/range_list.js index 14a9337ad65..dc79200a2c1 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -1,4 +1,7 @@ "use strict"; +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ var Range = require("./range").Range; var comparePoints = Range.comparePoints; @@ -163,7 +166,7 @@ class RangeList { } /** - * @param {import("./edit_session").EditSession} session + * @param {EditSession} session */ attach(session) { if (this.session) diff --git a/src/search.js b/src/search.js index 4b72fc35103..0be5d046862 100644 --- a/src/search.js +++ b/src/search.js @@ -269,7 +269,7 @@ class Search { } /** - * @param {import("./edit_session").EditSession} session + * @param {EditSession} session */ $matchIterator(session, options) { var re = this.$assembleRegExp(options); diff --git a/src/search_highlight.js b/src/search_highlight.js index bc9f0273c27..8a0522950df 100644 --- a/src/search_highlight.js +++ b/src/search_highlight.js @@ -1,5 +1,10 @@ "use strict"; - +/** + * @typedef {import("./layer/marker").Marker} Marker + */ +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ var lang = require("./lib/lang"); var Range = require("./range").Range; @@ -23,8 +28,8 @@ class SearchHighlight { /** * @param {any} html - * @param {import("./layer/marker").Marker} markerLayer - * @param {import("./edit_session").EditSession} session + * @param {Marker} markerLayer + * @param {EditSession} session * @param {Partial} config */ update(html, markerLayer, session, config) { diff --git a/src/token_iterator.js b/src/token_iterator.js index fb887e8c8eb..cd7831a02d5 100644 --- a/src/token_iterator.js +++ b/src/token_iterator.js @@ -1,4 +1,8 @@ "use strict"; +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ + var Range = require("./range").Range; /** @@ -7,7 +11,7 @@ var Range = require("./range").Range; class TokenIterator { /** * Creates a new token iterator object. The inital token index is set to the provided row and column coordinates. - * @param {import("./edit_session").EditSession} session The session to associate with + * @param {EditSession} session The session to associate with * @param {Number} initialRow The row to start the tokenizing at * @param {Number} initialColumn The column to start the tokenizing at **/ diff --git a/src/tooltip.js b/src/tooltip.js index f2cde4fd2f1..5428777b66b 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -5,6 +5,9 @@ /** * @typedef {import("./mouse/mouse_event").MouseEvent} MouseEvent */ +/** + * @typedef {import("./edit_session").EditSession} EditSession + */ var dom = require("./lib/dom"); var Range = require("./range").Range; @@ -90,7 +93,7 @@ class Tooltip { } } - hide() { + hide(e) { if (this.isOpen) { this.getElement().style.display = "none"; this.getElement().className = CLASSNAME; @@ -348,7 +351,7 @@ class HoverTooltip extends Tooltip { /** * @param {Range} range - * @param {import("./edit_session").EditSession} [session] + * @param {EditSession} [session] */ addMarker(range, session) { if (this.marker) { From 79de75198ef62fc91de8a6fb5390d3b019c5c566 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 15 Oct 2023 18:08:54 +0400 Subject: [PATCH 23/36] correct declarations --- ace.d.ts | 378 +++++++++++++++------------- src/config.js | 32 +-- src/ext/searchbox.js | 2 +- src/mouse/default_gutter_handler.js | 6 +- src/mouse/dragdrop_handler.js | 2 - src/snippets.js | 1 - tsconfig.json | 6 +- 7 files changed, 217 insertions(+), 210 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index 8aeb3b742a6..dbef21f52aa 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -15,6 +15,7 @@ export namespace Ace { type TokenIterator = import("./src/token_iterator").TokenIterator; type Selection = import("./src/selection").Selection; type Autocomplete = import("./src/autocomplete").Autocomplete; + type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; type CompletionProvider = import("./src/autocomplete").CompletionProvider; type AcePopup = import("./src/autocomplete/popup").AcePopup; type Config = import("./src/config").Config; @@ -22,6 +23,14 @@ export namespace Ace { type MouseEvent = import("./src/mouse/mouse_event").MouseEvent; type RangeList = import("./src/range_list").RangeList; type FilteredList = import("./src/autocomplete").FilteredList; + type LineWidgets = import("./src/line_widgets").LineWidgets; + type SearchBox = import("./src/ext/searchbox").SearchBox; + type Occur = import("./src/occur").Occur; + type DefaultHandlers = import("./src/mouse/default_handlers").DefaultHandlers; + type GutterHandler = import("./src/mouse/default_gutter_handler").GutterHandler; + type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; + type AppConfig = import("./src/config").AppConfig; + interface Theme { cssClass?: string; cssText?: string; @@ -522,7 +531,7 @@ export namespace Ace { "beforeRender": (e, renderer: VirtualRenderer) => void; } - class EventEmitter { + class EventEmitter { once(name: K, callback: T[K]): void; setDefaultHandler(name: string, callback: Function): void; @@ -608,7 +617,7 @@ export namespace Ace { action?: string, } - type CommandLike = Command | ((editor: Editor) => void); + type CommandLike = Command | ((editor: Editor) => void) | ((sb: SearchBox) => void); type KeyboardHandler = Partial & { attach?: (editor: Editor) => void; @@ -879,6 +888,169 @@ export namespace Ace { type AcePopupNavigation = "up" | "down" | "start" | "end"; + interface EditorMultiSelectProperties { + inMultiSelectMode?: boolean, + /** + * Updates the cursor and marker layers. + **/ + updateSelectionMarkers: () => void, + /** + * Adds the selection and cursor. + * @param orientedRange A range containing a cursor + **/ + addSelectionMarker: (orientedRange: Ace.Range & {marker?}) => Ace.Range & {marker?}, + /** + * Removes the selection marker. + * @param range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. + **/ + removeSelectionMarker: (range: Ace.Range & {marker?}) => void, + removeSelectionMarkers: (ranges: (Ace.Range & {marker?})[]) => void, + $onAddRange: (e) => void, + $onRemoveRange: (e) => void, + $onMultiSelect: (e) => void, + $onSingleSelect: (e) => void, + $onMultiSelectExec: (e) => void, + /** + * Executes a command for each selection range. + * @param cmd The command to execute + * @param [args] Any arguments for the command + **/ + forEachSelection: (cmd: Object, args?: string, options?: Object) => void, + /** + * Removes all the selections except the last added one. + **/ + exitMultiSelectMode: () => void, + getSelectedText: () => string, + $checkMultiselectChange: (e, anchor: Ace.Anchor) => void, + /** + * Finds and selects all the occurrences of `needle`. + * @param needle The text to find + * @param options The search options + * @param additive keeps + * @returns {Number} The cumulative count of all found matches + **/ + findAll: (needle?: string, options?: Partial, additive?: boolean) => number, + /** + * Adds a cursor above or below the active cursor. + * @param dir The direction of lines to select: -1 for up, 1 for down + * @param [skip] If `true`, removes the active selection range + */ + selectMoreLines: (dir: number, skip?: boolean) => void, + /** + * Transposes the selected ranges. + * @param {Number} dir The direction to rotate selections + **/ + transposeSelections: (dir: number) => void, + /** + * Finds the next occurrence of text in an active selection and adds it to the selections. + * @param {Number} dir The direction of lines to select: -1 for up, 1 for down + * @param {Boolean} [skip] If `true`, removes the active selection range + * @param {Boolean} [stopAtFirst] + **/ + selectMore: (dir: number, skip?: boolean, stopAtFirst?: boolean) => void, + /** + * Aligns the cursors or selected text. + **/ + alignCursors: () => void, + $reAlignText: (lines: string[], forceLeft: boolean) => string[], + multiSelect?: any, + $multiselectOnSessionChange?: any, + $blockSelectEnabled?: boolean, + } + + interface CodeLenseEditorExtension{ + codeLensProviders?: any[]; + $codeLensClickHandler?: any; + $updateLenses?: () => void; + $updateLensesOnInput?: () => void; + } + + interface ElasticTabstopsEditorExtension { + elasticTabstops?: import("./src/ext/elastic_tabstops_lite").ElasticTabstopsLite; + } + + interface TextareaEditorExtension { + setDisplaySettings?: (settings: any) => void; + } + + interface PromptEditorExtension { + cmdLine?: Editor; + } + + interface OptionsEditorExtension { + $options?: any; + } + + interface MultiSelectProperties { + ranges: Ace.Range[] | null; + rangeList: Ace.RangeList | null; + /** + * Adds a range to a selection by entering multiselect mode, if necessary. + * @param {Ace.Range} range The new range to add + * @param {Boolean} [$blockChangeEvents] Whether or not to block changing events + **/ + addRange(range: Ace.Range, $blockChangeEvents?: boolean): any; + inMultiSelectMode: boolean; + /** + * @param {Ace.Range} [range] + **/ + toSingleRange(range?: Ace.Range): void; + /** + * Removes a Range containing pos (if it exists). + * @param {Ace.Point} pos The position to remove, as a `{row, column}` object + **/ + substractPoint(pos: Ace.Point): any; + /** + * Merges overlapping ranges ensuring consistency after changes + **/ + mergeOverlappingRanges(): void; + /** + * @param {Ace.Range} range + */ + $onAddRange(range: Ace.Range): void; + rangeCount: number; + /** + * + * @param {Ace.Range[]} removed + */ + $onRemoveRange(removed: Ace.Range[]): void; + /** + * adds multicursor support to selection + */ + $initRangeList(): void; + /** + * Returns a concatenation of all the ranges. + * @returns {Ace.Range[]} + **/ + getAllRanges(): Ace.Range[]; + /** + * Splits all the ranges into lines. + **/ + splitIntoLines(): void; + /** + */ + joinSelections(): void; + /** + **/ + toggleBlockSelection(): void; + /** + * + * Gets list of ranges composing rectangular block on the screen + * + * @param {Ace.ScreenCoordinates} screenCursor The cursor to use + * @param {Ace.ScreenCoordinates} screenAnchor The anchor to use + * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping + * @returns {Ace.Range[]} + **/ + rectangularRangeBlock(screenCursor: Ace.ScreenCoordinates, screenAnchor: Ace.ScreenCoordinates, includeEmptyLines?: boolean): Ace.Range[]; + + _eventRegistry?: any; + index?: number; + } + + type AcePopupEventsCombined = Ace.EditorEvents & Ace.AcePopupEvents; + type AcePopupWithEditor = Ace.EventEmitter & Ace.Editor; + } @@ -925,18 +1097,20 @@ export type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineA export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; + declare module "./src/anchor" { export interface Anchor extends Ace.EventEmitter { markerId?: number; + document?: Ace.Document; } - + } declare module "./src/autocomplete" { export interface Autocomplete { popup: Ace.AcePopup; - emptyMessage?: Function + emptyMessage?: Function, } export interface CompletionProvider { @@ -944,7 +1118,6 @@ declare module "./src/autocomplete" { } } - declare module "./src/background_tokenizer" { export interface BackgroundTokenizer extends Ace.EventEmitter { @@ -960,10 +1133,9 @@ declare module "./src/document" { } declare module "./src/editor" { - export interface Editor extends - Ace.EventEmitter, - Ace.OptionsProvider, - EditorMultiSelectProperties + export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider, + Ace.EventEmitter, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, + Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension { session: Ace.EditSession; $mergeUndoDeltas?: any, @@ -976,81 +1148,14 @@ declare module "./src/editor" { $copyWithEmptySelection?: any $selectionStyle?: string, env?: any; - widgetManager?: import("./src/line_widgets").LineWidgets, - completer?: import("./src/autocomplete").Autocomplete | import("./src/ext/inline_autocomplete").InlineAutocomplete, + widgetManager?: Ace.LineWidgets, + completer?: Ace.Autocomplete | Ace.InlineAutocomplete, completers: Ace.Completer[], $highlightTagPending?: boolean, showKeyboardShortcuts?: () => void, showSettingsMenu?: () => void, - searchBox?: import("./src/ext/searchbox").SearchBox, - [key: string]: any; - } - - interface EditorMultiSelectProperties { - inMultiSelectMode?: boolean, - /** - * Updates the cursor and marker layers. - **/ - updateSelectionMarkers: () => void, - /** - * Adds the selection and cursor. - * @param orientedRange A range containing a cursor - **/ - addSelectionMarker: (orientedRange: Ace.Range & {marker?}) => Ace.Range & {marker?}, - /** - * Removes the selection marker. - * @param range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. - **/ - removeSelectionMarker: (range: Ace.Range & {marker?}) => void, - removeSelectionMarkers: (ranges: (Ace.Range & {marker?})[]) => void, - $onAddRange: (e) => void, - $onRemoveRange: (e) => void, - $onMultiSelect: (e) => void, - $onSingleSelect: (e) => void, - $onMultiSelectExec: (e) => void, - /** - * Executes a command for each selection range. - * @param cmd The command to execute - * @param [args] Any arguments for the command - **/ - forEachSelection: (cmd: Object, args?: string, options?: Object) => void, - /** - * Removes all the selections except the last added one. - **/ - exitMultiSelectMode: () => void, - getSelectedText: () => string, - $checkMultiselectChange: (e, anchor: Ace.Anchor) => void, - /** - * Finds and selects all the occurrences of `needle`. - * @param needle The text to find - * @param options The search options - * @param additive keeps - * @returns {Number} The cumulative count of all found matches - **/ - findAll: (needle?: string, options?: Partial, additive?: boolean) => number, - /** - * Adds a cursor above or below the active cursor. - * @param dir The direction of lines to select: -1 for up, 1 for down - * @param [skip] If `true`, removes the active selection range - */ - selectMoreLines: (dir: number, skip?: boolean) => void, - /** - * Transposes the selected ranges. - * @param {Number} dir The direction to rotate selections - **/ - transposeSelections: (dir: number) => void, - /** - * Finds the next occurrence of text in an active selection and adds it to the selections. - * @param {Number} dir The direction of lines to select: -1 for up, 1 for down - * @param {Boolean} [skip] If `true`, removes the active selection range - * @param {Boolean} [stopAtFirst] - **/ - selectMore: (dir: number, skip?: boolean, stopAtFirst?: boolean) => void, - /** - * Aligns the cursors or selected text. - **/ - alignCursors: () => void, - $reAlignText: (lines: string[], forceLeft: boolean) => string[], + searchBox?: Ace.SearchBox, + _eventRegistry?: any, } } @@ -1084,20 +1189,29 @@ declare module "./src/edit_session" { $getWidgetScreenLength?: () => number, _changedWidgets?: any, $options:any, - $wrapMethod?: any, $enableVarChar?: any, $wrap?:any, $navigateWithinSoftTabs?: boolean, getSelectionMarkers(): any[], - [key: string]: any; + $selectionMarkers?: any[], + gutterRenderer?: any, + $firstLineNumber?: number, + $emacsMark?: any, + selectionMarkerCount?: number, + multiSelect?: any, + $occurHighlight?: any, + $occur?: Ace.Occur, + $occurMatchingLines?: any, + $useEmacsStyleLineStart?: boolean, + $selectLongWords?: boolean, } } declare module "./src/edit_session/fold" { export interface Fold { - collapseChildren?: number; - } + collapseChildren?: number; + } } // @ts-expect-error @@ -1107,20 +1221,16 @@ declare module "./src/placeholder" { } declare module "./src/scrollbar" { - export interface Scrollbar extends Ace.EventEmitter { + export interface VScrollBar extends Ace.EventEmitter { } - export interface VScrollBar extends Scrollbar { - } - export interface HScrollBar extends Scrollbar { + export interface HScrollBar extends Ace.EventEmitter { } } declare module "./src/scrollbar_custom" { - export interface Scrollbar extends Ace.EventEmitter { - } - export interface VScrollBar extends Scrollbar { + export interface VScrollBar extends Ace.EventEmitter { } - export interface HScrollBar extends Scrollbar { + export interface HScrollBar extends Ace.EventEmitter { } } @@ -1132,75 +1242,9 @@ declare module "./src/line_widgets" { } declare module "./src/selection" { - export interface Selection extends Ace.EventEmitter, MultiSelectProperties { - } - - interface MultiSelectProperties { - ranges: Ace.Range[] | null; - rangeList: Ace.RangeList | null; - /** - * Adds a range to a selection by entering multiselect mode, if necessary. - * @param {Ace.Range} range The new range to add - * @param {Boolean} [$blockChangeEvents] Whether or not to block changing events - **/ - addRange(range: Ace.Range, $blockChangeEvents?: boolean): any; - inMultiSelectMode: boolean; - /** - * @param {Ace.Range} [range] - **/ - toSingleRange(range?: Ace.Range): void; - /** - * Removes a Range containing pos (if it exists). - * @param {Ace.Point} pos The position to remove, as a `{row, column}` object - **/ - substractPoint(pos: Ace.Point): any; - /** - * Merges overlapping ranges ensuring consistency after changes - **/ - mergeOverlappingRanges(): void; - /** - * @param {Ace.Range} range - */ - $onAddRange(range: Ace.Range): void; - rangeCount: number; - /** - * - * @param {Ace.Range[]} removed - */ - $onRemoveRange(removed: Ace.Range[]): void; - /** - * adds multicursor support to selection - */ - $initRangeList(): void; - /** - * Returns a concatenation of all the ranges. - * @returns {Ace.Range[]} - **/ - getAllRanges(): Ace.Range[]; - /** - * Splits all the ranges into lines. - **/ - splitIntoLines(): void; - /** - */ - joinSelections(): void; - /** - **/ - toggleBlockSelection(): void; - /** - * - * Gets list of ranges composing rectangular block on the screen - * - * @param {Ace.ScreenCoordinates} screenCursor The cursor to use - * @param {Ace.ScreenCoordinates} screenAnchor The anchor to use - * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping - * @returns {Ace.Range[]} - **/ - rectangularRangeBlock(screenCursor: Ace.ScreenCoordinates, screenAnchor: Ace.ScreenCoordinates, includeEmptyLines?: boolean): Ace.Range[]; - - _eventRegistry?: any; - index?: number; + export interface Selection extends Ace.EventEmitter, Ace.MultiSelectProperties { } + } declare module "./src/range" { @@ -1208,7 +1252,7 @@ declare module "./src/range" { id?: number; cursor?: Ace.Point; isBackwards?: boolean; - } + } } declare module "./src/virtual_renderer" { @@ -1262,9 +1306,8 @@ declare module "./src/commands/command_manager" { } declare module "./src/autocomplete/popup" { - type AcePopupEventsCombined = Ace.EditorEvents & Ace.AcePopupEvents; - type AcePopupWithEditor = Ace.EventEmitter & Ace.Editor; - export interface AcePopup extends AcePopupWithEditor { + + export interface AcePopup extends Ace.AcePopupWithEditor { setSelectOnHover: (val: boolean) => void, setRow: (line: number) => void, getRow: () => number, @@ -1312,13 +1355,10 @@ declare module "./src/lib/app_config" { } } + declare module "./src/mouse/mouse_handler" { - type DefaultHandlers = import("./src/mouse/default_handlers").DefaultHandlers; - //@ts-ignore - type GutterHandler = import("./src/mouse/default_gutter_handler").GutterHandler; - type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; - export interface MouseHandler extends DefaultHandlers, GutterHandler, DragdropHandler { + export interface MouseHandler extends Ace.DefaultHandlers, Ace.GutterHandler, Ace.DragdropHandler { $tooltipFollowsMouse?: boolean, cancelDrag?: boolean } diff --git a/src/config.js b/src/config.js index 115501f2cbd..9b6a45d0b5c 100644 --- a/src/config.js +++ b/src/config.js @@ -1,39 +1,9 @@ "no use strict"; -/** - * @typedef {import("./lib/app_config").AppConfig} AppConfig - */ -/** - * @typedef {AppConfig & Config} IConfig - * @export - */ - -/** - * @typedef Config - * @property {(key: string) => any} get - * @property {(key: string, value: any) => void} set - * @property {() => {[key: string]: any}} all - * @property {(name: string, component?: string) => string} moduleUrl - * @property {(name: string, subst: string) => string} setModuleUrl - * @property {(moduleName: string | [string, string], cb: (module: any) => void) => void} loadModule - * @property {(cb: (moduleName: string, afterLoad: (err: Error | null, module: unknown) => void) => void) => void} setLoader - * @property {(moduleName: string, onLoad: (module: any) => void) => void} setModuleLoader - * @property {string} version - * @property {any} $modes - * @property {any} $loading - * @property {any} $loaded - * @property {any} dynamicModules - * @property {any} $require - */ - var lang = require("./lib/lang"); var net = require("./lib/net"); var dom = require("./lib/dom"); -/**@type{any}*/var AppConfig = require("./lib/app_config").AppConfig; +var AppConfig = require("./lib/app_config").AppConfig; -/** - * - * @type {IConfig} - */ module.exports = exports = new AppConfig(); var options = { diff --git a/src/ext/searchbox.js b/src/ext/searchbox.js index 9c2669a8495..036853f027d 100644 --- a/src/ext/searchbox.js +++ b/src/ext/searchbox.js @@ -157,7 +157,7 @@ class SearchBox { } /** - * @param {boolean} preventScroll + * @param {boolean} [preventScroll] */ $syncOptions(preventScroll) { dom.setCssClass(this.replaceOption, "checked", this.searchRange); diff --git a/src/mouse/default_gutter_handler.js b/src/mouse/default_gutter_handler.js index 32c148f7dc6..e3b07646853 100644 --- a/src/mouse/default_gutter_handler.js +++ b/src/mouse/default_gutter_handler.js @@ -1,11 +1,15 @@ "use strict"; +/** + * @typedef {import("./mouse_handler").MouseHandler} MouseHandler + */ var dom = require("../lib/dom"); var event = require("../lib/event"); var Tooltip = require("../tooltip").Tooltip; var nls = require("../config").nls; /** - * @param {import("../mouse/mouse_handler").MouseHandler} mouseHandler + * @param {MouseHandler} mouseHandler + * @this {MouseHandler} */ function GutterHandler(mouseHandler) { var editor = mouseHandler.editor; diff --git a/src/mouse/dragdrop_handler.js b/src/mouse/dragdrop_handler.js index a10e514f5e1..0257881b66b 100644 --- a/src/mouse/dragdrop_handler.js +++ b/src/mouse/dragdrop_handler.js @@ -11,9 +11,7 @@ var SCROLL_CURSOR_DELAY = 200; var SCROLL_CURSOR_HYSTERESIS = 5; /** - * * @param {MouseHandler} mouseHandler - * @constructor * @this {MouseHandler} */ function DragdropHandler(mouseHandler) { diff --git a/src/snippets.js b/src/snippets.js index 2563f561f06..f014395855d 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -1058,7 +1058,6 @@ dom.importCssString(` position: absolute; }`, "snippets.css", false); -/**@type {any}*/ exports.snippetManager = new SnippetManager(); diff --git a/tsconfig.json b/tsconfig.json index c0d20c8ac69..9ec91bff577 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,14 +5,11 @@ "skipLibCheck": true, "module": "commonjs", "target": "es2019", - "sourceMap": true, "allowJs": true, "checkJs": true, "declaration": true, - "declarationDir": "./types", "emitDeclarationOnly": true, - "outDir": "./out", - "declarationMap": true, + "outFile": "./types/index.d.ts" }, "exclude": [ "node_modules", @@ -22,7 +19,6 @@ "src/keyboard/emacs.js", "src/keyboard/sublime.js", "src/keyboard/vscode.js", - "types", "src/mode" ], "include": [ From 07f9b8e793c7c42da1a2fdd33b58ee2712eda69c Mon Sep 17 00:00:00 2001 From: mkslanc Date: Sun, 15 Oct 2023 18:10:04 +0400 Subject: [PATCH 24/36] first version of declaration generator for ace-code --- generate.js | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 generate.js diff --git a/generate.js b/generate.js new file mode 100644 index 00000000000..60e27dc68a1 --- /dev/null +++ b/generate.js @@ -0,0 +1,227 @@ +const ts = require('typescript'); +const fs = require("fs"); +function generateDeclaration() { + const configPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json'); + const config = ts.readConfigFile(configPath, ts.sys.readFile).config; + const parseConfigHost = { + fileExists: ts.sys.fileExists, + readFile: ts.sys.readFile, + readDirectory: ts.sys.readDirectory, + useCaseSensitiveFileNames: true + }; + const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, './'); + const program = ts.createProgram(parsed.fileNames, parsed.options); + program.emit(); +} + +function fixDeclaration(declarationName) { + const program = ts.createProgram([declarationName], { + noEmit: true + }); + var checker = program.getTypeChecker(); + + const diagnostics = ts.getPreEmitDiagnostics(program); + + diagnostics.forEach(diagnostic => { + if (diagnostic.file) { + const { + line, + character + } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); + } + else { + console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); + } + }); + + let interfaces = collectInterfaces(program.getSourceFile('./ace.d.ts')); + + /** + * @param {ts.TransformationContext} context + * @return {function(*): *} + */ + function transformer(context) { + return (sourceFile) => { + function visit(node) { + let updatedNode = node; + if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { + if (interfaces[node.name.text]) { + if (node.body && ts.isModuleBlock(node.body)) { + const newBody = ts.factory.createModuleBlock( + node.body.statements.concat(interfaces[node.name.text]) + ); + + updatedNode = ts.factory.updateModuleDeclaration( + node, + node.modifiers, + node.name, + newBody + ); + + } + } else if (node.name.text.endsWith("/config") || node.name.text.endsWith("textarea")) {//TODO: should be better way to do this + if (node.body && ts.isModuleBlock(node.body)) { + const newBody = ts.factory.createModuleBlock( + node.body.statements.filter(statement => { + const exportsStatement = ts.isVariableStatement(statement) && statement.declarationList.declarations[0].name.getText() == "_exports"; + return exportsStatement || ts.isExportAssignment(statement) || ts.isImportEqualsDeclaration(statement); + }) + ); + updatedNode = ts.factory.updateModuleDeclaration( + node, + node.modifiers, + node.name, + newBody + ); + + } + } + } else + if (ts.isInterfaceDeclaration(node) && node.heritageClauses) { + for (const clause of node.heritageClauses) { + if (clause.token === ts.SyntaxKind.ExtendsKeyword && clause.types.length === 0) { + // Remove the extends clause if it's empty + return context.factory.updateInterfaceDeclaration( + node, + node.modifiers, + node.name, + node.typeParameters, + [], + node.members + ); + } + } + } else if (ts.isClassDeclaration(node) && node.heritageClauses) { + let updatedHeritageClauses = []; + for (let i = 0; i < node.heritageClauses.length; i++) { + let clause = node.heritageClauses[i]; + if (clause.token === ts.SyntaxKind.ExtendsKeyword) { + const updatedTypes = clause.types.filter(type => { + if (diagnostics.some(//TODO: + diagnostic => [2507, 1174].includes(diagnostic.code) && diagnostic.file + === sourceFile && diagnostic.start >= type.pos && type.end >= diagnostic.start + + diagnostic.length)) return false; + const symbol = checker.getSymbolAtLocation(type.expression); + if (symbol) { + const declaredType = checker.getDeclaredTypeOfSymbol(symbol); + + return declaredType.flags !== ts.TypeFlags.Undefined + && declaredType["intrinsicName"] !== "error"; + } + return true; // keep the type if the symbol can't be resolved + }); + if (updatedTypes.length === 0) { + continue; + } + var updatedHeritageClause = clause; + if (updatedTypes.length !== clause.types.length) { + updatedHeritageClause = context.factory.createHeritageClause( + ts.SyntaxKind.ExtendsKeyword, updatedTypes); + } + } + if (updatedHeritageClause) { + updatedHeritageClauses.push(updatedHeritageClause); + } + else { + updatedHeritageClauses.push(clause); + } + } + return context.factory.updateClassDeclaration(node, node.modifiers, node.name, node.typeParameters, + updatedHeritageClauses, node.members + ); + } + return ts.visitEachChild(updatedNode, visit, context); + } + return ts.visitNode(sourceFile, visit); + }; + } + const sourceCode = program.getSourceFiles().filter(f => f.fileName.includes(declarationName)); + const result = ts.transform(sourceCode, [transformer]); + + const printer = ts.createPrinter(); + result.transformed.forEach(transformedFile => { + const output = printer.printFile(transformedFile); + fs.writeFileSync(declarationName, output); + }); + + result.dispose(); +} + +function collectInterfaces(sourceFile) { + const result = {}; + const printer = ts.createPrinter(); + + function visit(node) { + if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { + let nodes= []; + if (node.body && ts.isModuleBlock(node.body)) { + ts.forEachChild(node.body, (child) => { + if (ts.isInterfaceDeclaration(child)) + nodes.push(child); + }); + } + if (nodes.length > 0) { + const interfaceStrings = nodes.map(interfaceNode => printer.printNode(ts.EmitHint.Unspecified, interfaceNode, sourceFile)); + + let concatenatedInterfaceStrings = interfaceStrings.join('\n\n'); + //TODO: + let identifiers = concatenatedInterfaceStrings.match(/Ace\.[\w]+ 0) { + identifiers = [...new Set(identifiers)]; + let importAlias = ''; + identifiers.forEach(identifier => { + let typeName = identifier.replace("Ace.", ""); + + if (typeName.includes("<")) { + typeName = typeName + "T>"; + } + importAlias += "type " + typeName + " = import(\"../ace\").Ace." + typeName + ";\n\n"; + }); + concatenatedInterfaceStrings = "namespace Ace {"+ importAlias + "}" + concatenatedInterfaceStrings; + } + + const newSourceFile = ts.createSourceFile('temp.d.ts', concatenatedInterfaceStrings, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); + nodes = newSourceFile.statements; + } + result[node.name.text.replace("./", "ace-code/")] = nodes; + } + ts.forEachChild(node, visit); + } + + visit(sourceFile); + + return result; +} + +function fixImports(inputFileName, outputFileName) { + fs.readFile(inputFileName, 'utf8', (err, data) => { + if (err) { + console.error('Error reading the file:', err); + return; + } + + // Replace the content + let updatedContent = data.replaceAll(/(declare module ")/g, "$1ace-code/"); + updatedContent = updatedContent.replaceAll(/(import\(")(ace"\).Ace)/g, "$1../$2"); + updatedContent = updatedContent.replaceAll(/(require\(")/g, "$1ace-code/"); + updatedContent = updatedContent.replaceAll(/(import\(")(?=[^\.])/g, "$1ace-code/"); + updatedContent = updatedContent.replaceAll("../../", "../"); + updatedContent = updatedContent.replaceAll("ace-code/src/ace", "ace-code"); + // Write to a new file + fs.writeFile(outputFileName, updatedContent, 'utf8', (err) => { + if (err) { + console.error('Error writing to file:', err); + } else { + console.log('File processing complete, saved as', outputFileName); + fixDeclaration(outputFileName); + } + }); + }); +} +generateDeclaration(); +fixImports('types/index.d.ts', 'types/index.d.ts'); + + + From 6bfc9e3141647ba036959948d96f7d66660b4bb2 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Tue, 17 Oct 2023 17:15:07 +0400 Subject: [PATCH 25/36] correct declarations --- ace-extensions.d.ts | 7 ---- ace.d.ts | 60 ++++++++++++++++++++++------------ src/anchor.js | 1 + src/ext/command_bar.js | 4 +-- src/ext/inline_autocomplete.js | 2 +- src/ext/language_tools.js | 2 +- src/ext/modelist.js | 2 +- src/ext/simple_tokenizer.js | 2 +- src/lib/keys.js | 1 + src/line_widgets.js | 1 + src/mouse/default_handlers.js | 2 +- src/mouse/dragdrop_handler.js | 32 ++++++++++++++---- src/mouse/mouse_handler.js | 4 +++ 13 files changed, 80 insertions(+), 40 deletions(-) delete mode 100644 ace-extensions.d.ts diff --git a/ace-extensions.d.ts b/ace-extensions.d.ts deleted file mode 100644 index 79f704ae254..00000000000 --- a/ace-extensions.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module "ace-code/src/ext/simple_tokenizer" { - export type TokenizeResult = Array> - export function tokenize(content: string, highlightRules: import("./ace").Ace.HighlightRules): TokenizeResult; -} diff --git a/ace.d.ts b/ace.d.ts index dbef21f52aa..f1b0ca31edd 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,5 +1,3 @@ -/// -/// export namespace Ace { type Anchor = import("./src/anchor").Anchor; @@ -18,7 +16,6 @@ export namespace Ace { type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; type CompletionProvider = import("./src/autocomplete").CompletionProvider; type AcePopup = import("./src/autocomplete/popup").AcePopup; - type Config = import("./src/config").Config; type AceInline = import("./src/autocomplete/inline").AceInline; type MouseEvent = import("./src/mouse/mouse_event").MouseEvent; type RangeList = import("./src/range_list").RangeList; @@ -29,7 +26,7 @@ export namespace Ace { type DefaultHandlers = import("./src/mouse/default_handlers").DefaultHandlers; type GutterHandler = import("./src/mouse/default_gutter_handler").GutterHandler; type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; - type AppConfig = import("./src/config").AppConfig; + type AppConfig = import("./src/lib/app_config").AppConfig; interface Theme { cssClass?: string; @@ -1050,7 +1047,24 @@ export namespace Ace { type AcePopupEventsCombined = Ace.EditorEvents & Ace.AcePopupEvents; type AcePopupWithEditor = Ace.EventEmitter & Ace.Editor; - + type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; + + type TooltipCommandFunction = (editor: Ace.Editor) => T; + + export interface TooltipCommand extends Ace.Command { + enabled: TooltipCommandFunction | boolean, + getValue?: TooltipCommandFunction, + type: "button" | "text" | "checkbox" + iconCssClass?: string, + cssClass?: string + } + + export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; + + export type TokenizeResult = Array> } @@ -1080,21 +1094,9 @@ export const Range: { comparePoints(p1: Ace.Point, p2: Ace.Point): number; }; +export type InlineAutocomplete = Ace.InlineAutocomplete; +export type CommandBarTooltip = Ace.CommandBarTooltip; -type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; - -type TooltipCommandFunction = (editor: Ace.Editor) => T; - -export interface TooltipCommand extends Ace.Command { - enabled: TooltipCommandFunction | boolean, - getValue?: TooltipCommandFunction, - type: "button" | "text" | "checkbox" - iconCssClass?: string, - cssClass?: string -} - -export type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; -export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; @@ -1206,6 +1208,7 @@ declare module "./src/edit_session" { $useEmacsStyleLineStart?: boolean, $selectLongWords?: boolean, } + } declare module "./src/edit_session/fold" { @@ -1355,12 +1358,24 @@ declare module "./src/lib/app_config" { } } +declare module "./src/mouse/mouse_event" { + export interface MouseEvent { + time?: number; + } +} declare module "./src/mouse/mouse_handler" { - export interface MouseHandler extends Ace.DefaultHandlers, Ace.GutterHandler, Ace.DragdropHandler { + export interface MouseHandler { $tooltipFollowsMouse?: boolean, cancelDrag?: boolean + //from DefaultHandlers + $clickSelection?: null | Ace.Range, + mousedownEvent?: Ace.MouseEvent, + startSelect?: (pos?: Ace.Point, waitForClickSelection?: boolean) => void, + select?: () => void + $lastScroll?: { t: number, vx: number, vy: number, allowed: number } + selectEnd?: () => void } } @@ -1380,3 +1395,8 @@ declare module "./src/tooltip" { row: number; } } + +declare module "./src/mouse/default_gutter_handler" { + export interface GutterHandler { + } +} diff --git a/src/anchor.js b/src/anchor.js index fb04e87cef2..c1109405f91 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -105,6 +105,7 @@ class Anchor { * **/ attach(doc) { + /**@type{Document}*/ this.document = doc || this.document; this.document.on("change", this.$onChange); } diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 7395eab53f2..498090bdd21 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -90,7 +90,7 @@ class CommandBarTooltip { * toolbar, the remaining elements are added to the overflow menu. * * @param {string} id - * @param {import("../../ace").TooltipCommand} command + * @param {import("../../ace").Ace.TooltipCommand} command */ registerCommand(id, command) { var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip; @@ -288,7 +288,7 @@ class CommandBarTooltip { /** * @param {string} id - * @param {import("../../ace").TooltipCommand} command + * @param {import("../../ace").Ace.TooltipCommand} command * @param {boolean} forMainTooltip */ $createCommand(id, command, forMainTooltip) { diff --git a/src/ext/inline_autocomplete.js b/src/ext/inline_autocomplete.js index c78b5c764b5..f9846157f53 100644 --- a/src/ext/inline_autocomplete.js +++ b/src/ext/inline_autocomplete.js @@ -121,7 +121,7 @@ class InlineAutocomplete { } /** - * @param {import("../../ace").InlineAutocompleteAction} where + * @param {import("../../ace").Ace.InlineAutocompleteAction} where */ goTo(where) { if (!this.completions || !this.completions.filtered) { diff --git a/src/ext/language_tools.js b/src/ext/language_tools.js index ab23e7752f3..2a32a631671 100644 --- a/src/ext/language_tools.js +++ b/src/ext/language_tools.js @@ -1,5 +1,5 @@ "use strict"; - +/**@type{import("../snippets").snippetManager & {files?: {[key: string]: any}}}*/ var snippetManager = require("../snippets").snippetManager; var Autocomplete = require("../autocomplete").Autocomplete; var config = require("../config"); diff --git a/src/ext/modelist.js b/src/ext/modelist.js index d7d4eb6243b..6a1cd711873 100644 --- a/src/ext/modelist.js +++ b/src/ext/modelist.js @@ -4,7 +4,7 @@ var modes = []; /** * Suggests a mode based on the file extension present in the given path * @param {string} path The path to the file - * @returns {object} Returns an object containing information about the + * @returns {Mode} Returns an object containing information about the * suggested mode. */ function getModeForPath(path) { diff --git a/src/ext/simple_tokenizer.js b/src/ext/simple_tokenizer.js index 5592f326310..fde23c99282 100644 --- a/src/ext/simple_tokenizer.js +++ b/src/ext/simple_tokenizer.js @@ -41,7 +41,7 @@ class SimpleTokenizer { * * @param {string} content to tokenize * @param {import("../../ace").Ace.HighlightRules} highlightRules defining the language grammar - * @returns {import("ace-code/src/ext/simple_tokenizer").TokenizeResult} tokenization result containing a list of token for each of the lines from content + * @returns {import("../../ace").Ace.TokenizeResult} tokenization result containing a list of token for each of the lines from content */ function tokenize(content, highlightRules) { const tokenizer = new SimpleTokenizer(content, new Tokenizer(highlightRules.getRules())); diff --git a/src/lib/keys.js b/src/lib/keys.js index 0c67bf0dfa1..0be5d55ad46 100644 --- a/src/lib/keys.js +++ b/src/lib/keys.js @@ -151,6 +151,7 @@ var Keys = (function() { })(); oop.mixin(exports, Keys); +/**@type{{keyCodeToString: (keyCode: string) => string}}*/ exports.default = exports; exports.keyCodeToString = function(keyCode) { diff --git a/src/line_widgets.js b/src/line_widgets.js index 94f3a045d7c..c3df596fe31 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -77,6 +77,7 @@ class LineWidgets { return; this.detach(); + /**@type {Editor} */ this.editor = editor; if (editor) { diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index bed8dc5dca6..4a776454318 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -36,7 +36,7 @@ class DefaultHandlers { } /** - * @param ev + * @param {MouseEvent} ev * @this {MouseHandler} */ onMouseDown(ev) { diff --git a/src/mouse/dragdrop_handler.js b/src/mouse/dragdrop_handler.js index 0257881b66b..859ff299a89 100644 --- a/src/mouse/dragdrop_handler.js +++ b/src/mouse/dragdrop_handler.js @@ -12,7 +12,6 @@ var SCROLL_CURSOR_HYSTERESIS = 5; /** * @param {MouseHandler} mouseHandler - * @this {MouseHandler} */ function DragdropHandler(mouseHandler) { @@ -27,6 +26,7 @@ function DragdropHandler(mouseHandler) { exports.forEach(function(x) { mouseHandler[x] = this[x]; }, this); + // @ts-ignore editor.on("mousedown", this.onMouseDown.bind(mouseHandler)); var mouseTarget = editor.container; @@ -38,7 +38,11 @@ function DragdropHandler(mouseHandler) { var autoScrollStartTime; var cursorMovedTime; var cursorPointOnCaretMoved; - + /** + * @param e + * @this {MouseHandler} + * @return {*} + */ this.onDragStart = function(e) { // webkit workaround, see this.onMouseDown if (this.cancelDrag || !mouseTarget.draggable) { @@ -66,7 +70,11 @@ function DragdropHandler(mouseHandler) { isInternal = true; this.setState("drag"); }; - + /** + * @param e + * @this {MouseHandler} + * @return {*} + */ this.onDragEnd = function(e) { mouseTarget.draggable = false; isInternal = false; @@ -81,7 +89,11 @@ function DragdropHandler(mouseHandler) { this.editor.unsetStyle("ace_dragging"); this.editor.renderer.setCursorStyle(""); }; - + /** + * @param e + * @this {MouseHandler} + * @return {*} + */ this.onDragEnter = function(e) { if (editor.getReadOnly() || !canAccept(e.dataTransfer)) return; @@ -94,7 +106,11 @@ function DragdropHandler(mouseHandler) { e.dataTransfer.dropEffect = dragOperation = getDropEffect(e); return event.preventDefault(e); }; - + /** + * @param e + * @this {MouseHandler} + * @return {*} + */ this.onDragOver = function(e) { if (editor.getReadOnly() || !canAccept(e.dataTransfer)) return; @@ -120,7 +136,11 @@ function DragdropHandler(mouseHandler) { return event.preventDefault(e); } }; - + /** + * @param e + * @this {MouseHandler} + * @return {*} + */ this.onDrop = function(e) { if (!dragCursor) return; diff --git a/src/mouse/mouse_handler.js b/src/mouse/mouse_handler.js index bb2a25b3f90..7ec0623020e 100644 --- a/src/mouse/mouse_handler.js +++ b/src/mouse/mouse_handler.js @@ -99,6 +99,10 @@ class MouseHandler { this.editor._emit(name, new MouseEvent(e, this.editor)); } + /** + * @param {string} name + * @param {{ wheelX: number; wheelY: number; }} e + */ onMouseWheel(name, e) { var mouseEvent = new MouseEvent(e, this.editor); //@ts-expect-error TODO: couldn't find this property init in the ace codebase From feacbc80f20328393b799cb919f6af81078d0bff Mon Sep 17 00:00:00 2001 From: mkslanc Date: Tue, 17 Oct 2023 17:17:22 +0400 Subject: [PATCH 26/36] generate declaration for ace-builds --- generate.js | 251 +++++++++++++++++++++++++++++++------------------- tsconfig.json | 2 - 2 files changed, 155 insertions(+), 98 deletions(-) diff --git a/generate.js b/generate.js index 60e27dc68a1..1d13f29d71e 100644 --- a/generate.js +++ b/generate.js @@ -1,8 +1,9 @@ const ts = require('typescript'); const fs = require("fs"); -function generateDeclaration() { + +function generateInitialDeclaration() { const configPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json'); - const config = ts.readConfigFile(configPath, ts.sys.readFile).config; + const config = ts.readConfigFile(configPath, ts.sys.readFile).config; //TODO: emit output path? const parseConfigHost = { fileExists: ts.sys.fileExists, readFile: ts.sys.readFile, @@ -14,29 +15,17 @@ function generateDeclaration() { program.emit(); } -function fixDeclaration(declarationName) { +/** + * @param {string} declarationName + * @param {string} aceNamespacePath + * @param {boolean} forAceBuilds + */ +function fixDeclaration(declarationName, aceNamespacePath, forAceBuilds) { const program = ts.createProgram([declarationName], { noEmit: true }); var checker = program.getTypeChecker(); - - const diagnostics = ts.getPreEmitDiagnostics(program); - - diagnostics.forEach(diagnostic => { - if (diagnostic.file) { - const { - line, - character - } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); - const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); - } - else { - console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); - } - }); - - let interfaces = collectInterfaces(program.getSourceFile('./ace.d.ts')); + let interfaces = collectInterfaces(aceNamespacePath, forAceBuilds); /** * @param {ts.TransformationContext} context @@ -47,62 +36,51 @@ function fixDeclaration(declarationName) { function visit(node) { let updatedNode = node; if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { - if (interfaces[node.name.text]) { + // remove wrong generated modules + if (node.name.text.endsWith("lib/keys") || node.name.text.endsWith("linking")) { + const newBody = ts.factory.createModuleBlock([]); + updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); + } + else if (interfaces[node.name.text]) { + // add corresponding interfaces to support mixins (EventEmitter, OptionsProvider, etc.) if (node.body && ts.isModuleBlock(node.body)) { const newBody = ts.factory.createModuleBlock( - node.body.statements.concat(interfaces[node.name.text]) - ); - - updatedNode = ts.factory.updateModuleDeclaration( - node, - node.modifiers, - node.name, - newBody - ); - + node.body.statements.concat(interfaces[node.name.text])); + updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); } - } else if (node.name.text.endsWith("/config") || node.name.text.endsWith("textarea")) {//TODO: should be better way to do this + } + else if (node.name.text.endsWith("/config") || node.name.text.endsWith("textarea")) { + //TODO: should be better way to do this + //correct mixed exports (export function + export = _exports) if (node.body && ts.isModuleBlock(node.body)) { - const newBody = ts.factory.createModuleBlock( - node.body.statements.filter(statement => { - const exportsStatement = ts.isVariableStatement(statement) && statement.declarationList.declarations[0].name.getText() == "_exports"; - return exportsStatement || ts.isExportAssignment(statement) || ts.isImportEqualsDeclaration(statement); - }) - ); - updatedNode = ts.factory.updateModuleDeclaration( - node, - node.modifiers, - node.name, - newBody - ); + const newBody = ts.factory.createModuleBlock(node.body.statements.filter(statement => { + const exportsStatement = ts.isVariableStatement(statement) + && statement.declarationList.declarations[0].name.getText() == "_exports"; + return exportsStatement || ts.isExportAssignment(statement) + || ts.isImportEqualsDeclaration(statement); + })); + updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); } } - } else - if (ts.isInterfaceDeclaration(node) && node.heritageClauses) { + } + else if (ts.isInterfaceDeclaration(node) && node.heritageClauses) { for (const clause of node.heritageClauses) { if (clause.token === ts.SyntaxKind.ExtendsKeyword && clause.types.length === 0) { // Remove the extends clause if it's empty - return context.factory.updateInterfaceDeclaration( - node, - node.modifiers, - node.name, - node.typeParameters, - [], - node.members + return context.factory.updateInterfaceDeclaration(node, node.modifiers, node.name, + node.typeParameters, [], node.members ); } } - } else if (ts.isClassDeclaration(node) && node.heritageClauses) { + } + else if (ts.isClassDeclaration(node) && node.heritageClauses) { let updatedHeritageClauses = []; + // remove inheritances from undefined types for (let i = 0; i < node.heritageClauses.length; i++) { let clause = node.heritageClauses[i]; if (clause.token === ts.SyntaxKind.ExtendsKeyword) { const updatedTypes = clause.types.filter(type => { - if (diagnostics.some(//TODO: - diagnostic => [2507, 1174].includes(diagnostic.code) && diagnostic.file - === sourceFile && diagnostic.start >= type.pos && type.end >= diagnostic.start - + diagnostic.length)) return false; const symbol = checker.getSymbolAtLocation(type.expression); if (symbol) { const declaredType = checker.getDeclaredTypeOfSymbol(symbol); @@ -134,94 +112,175 @@ function fixDeclaration(declarationName) { } return ts.visitEachChild(updatedNode, visit, context); } + return ts.visitNode(sourceFile, visit); }; } - const sourceCode = program.getSourceFiles().filter(f => f.fileName.includes(declarationName)); + + const sourceCode = program.getSourceFile(declarationName); const result = ts.transform(sourceCode, [transformer]); const printer = ts.createPrinter(); result.transformed.forEach(transformedFile => { - const output = printer.printFile(transformedFile); + let output = printer.printFile(transformedFile); + if (forAceBuilds) { + // correct paths for ace-builds + output = output.replace( + /ace\-builds\/src\/(mode|theme|ext|keybinding|snippets)\//g, "ace-builds/src-noconflict/$1-"); + output = output.replace(/ace\-builds\/src(?!\-noconflict)/g, "ace-builds-internal"); + } fs.writeFileSync(declarationName, output); }); result.dispose(); + + checkFinalDeclaration(declarationName); +} + +/** + * @param {string} declarationName + */ +function checkFinalDeclaration(declarationName) { + const program = ts.createProgram([declarationName], { + noEmit: true + }); + const diagnostics = ts.getPreEmitDiagnostics(program); + + diagnostics.forEach(diagnostic => { + if (diagnostic.file) { + const { + line, + character + } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); + const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); + console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); + } + else { + console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); + } + }); } -function collectInterfaces(sourceFile) { +/** + * @param {string} aceNamespacePath + * @param {boolean} forAceBuilds + */ +function collectInterfaces(aceNamespacePath, forAceBuilds) { + const program = ts.createProgram([aceNamespacePath], { + noEmit: true + }); + const sourceFile = program.getSourceFile(aceNamespacePath); const result = {}; const printer = ts.createPrinter(); + let packageName = "ace-code"; + if (forAceBuilds) { + packageName = "ace-builds"; + } function visit(node) { - if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { - let nodes= []; + if (node && ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { + let nodes = []; if (node.body && ts.isModuleBlock(node.body)) { ts.forEachChild(node.body, (child) => { - if (ts.isInterfaceDeclaration(child)) - nodes.push(child); + if (ts.isInterfaceDeclaration(child)) nodes.push(child); }); } if (nodes.length > 0) { - const interfaceStrings = nodes.map(interfaceNode => printer.printNode(ts.EmitHint.Unspecified, interfaceNode, sourceFile)); - + const interfaceStrings = nodes.map( + interfaceNode => printer.printNode(ts.EmitHint.Unspecified, interfaceNode, sourceFile)); + let concatenatedInterfaceStrings = interfaceStrings.join('\n\n'); - //TODO: let identifiers = concatenatedInterfaceStrings.match(/Ace\.[\w]+ 0) { identifiers = [...new Set(identifiers)]; let importAlias = ''; identifiers.forEach(identifier => { - let typeName = identifier.replace("Ace.", ""); - - if (typeName.includes("<")) { - typeName = typeName + "T>"; - } - importAlias += "type " + typeName + " = import(\"../ace\").Ace." + typeName + ";\n\n"; + let typeName = identifier.replace("Ace.", ""); + + if (typeName.includes("<")) { + typeName = typeName + "T>"; + } + importAlias += "type " + typeName + " = import(\"" + packageName + "\").Ace." + typeName + + ";\n\n"; }); - concatenatedInterfaceStrings = "namespace Ace {"+ importAlias + "}" + concatenatedInterfaceStrings; + concatenatedInterfaceStrings = "namespace Ace {" + importAlias + "}" + concatenatedInterfaceStrings; } - - const newSourceFile = ts.createSourceFile('temp.d.ts', concatenatedInterfaceStrings, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); + + const newSourceFile = ts.createSourceFile( + 'temp.d.ts', concatenatedInterfaceStrings, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); nodes = newSourceFile.statements; } - result[node.name.text.replace("./", "ace-code/")] = nodes; + result[node.name.text.replace("./", packageName + "/")] = nodes; } ts.forEachChild(node, visit); } visit(sourceFile); - + return result; } -function fixImports(inputFileName, outputFileName) { - fs.readFile(inputFileName, 'utf8', (err, data) => { +/** + * @param {string} packageName + * @param {string} aceNamespacePath + * @return {string} + */ +function cloneAceNamespace(packageName, aceNamespacePath) { + const program = ts.createProgram([aceNamespacePath], { + noEmit: true + }); + const sourceFile = program.getSourceFile(aceNamespacePath); + const printer = ts.createPrinter(); + for (let i = 0; i < sourceFile.statements.length; i++) { + const node = sourceFile.statements[i]; + if (ts.isModuleDeclaration(node) && node.name.text == "Ace") { + let aceModule = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile); + aceModule = aceModule.replace(/"\.\/src/g, "\"" + packageName + "/src"); + aceModule = '\n' + aceModule + '\n'; + return aceModule; + } + } +} + +/** + * @param {string} fileName + * @param {string} aceNamespacePath + * @param {boolean} [forAceBuilds] + */ +function generateDeclaration(fileName, aceNamespacePath, forAceBuilds) { + generateInitialDeclaration(); + + fs.readFile(fileName, 'utf8', (err, data) => { if (err) { console.error('Error reading the file:', err); return; } + let packageName = "ace-code"; + if (forAceBuilds) { + packageName = "ace-builds"; + } - // Replace the content - let updatedContent = data.replaceAll(/(declare module ")/g, "$1ace-code/"); - updatedContent = updatedContent.replaceAll(/(import\(")(ace"\).Ace)/g, "$1../$2"); - updatedContent = updatedContent.replaceAll(/(require\(")/g, "$1ace-code/"); - updatedContent = updatedContent.replaceAll(/(import\(")(?=[^\.])/g, "$1ace-code/"); - updatedContent = updatedContent.replaceAll("../../", "../"); - updatedContent = updatedContent.replaceAll("ace-code/src/ace", "ace-code"); - // Write to a new file - fs.writeFile(outputFileName, updatedContent, 'utf8', (err) => { + let updatedContent = data.replace(/(declare module ")/g, "$1" + packageName + "/"); + updatedContent = updatedContent.replace(/(require\(")/g, "$1" + packageName + "/"); + updatedContent = updatedContent.replace(/(import\(")(?!(?:\.|ace\-code))/g, "$1" + packageName + "/"); + updatedContent = updatedContent.replace(/ace\-(?:code|builds)(\/src)?\/ace/g, packageName); + let aceModule = cloneAceNamespace(packageName, aceNamespacePath); + + updatedContent = updatedContent.replace(/(declare\s+module\s+"ace-(?:code|builds)"\s+{)/, "$1" + aceModule); + updatedContent = updatedContent.replace(/(import\(")[./]*ace("\).Ace)/g, "$1" + packageName + "$2"); + + fs.writeFile(fileName, updatedContent, 'utf8', (err) => { if (err) { console.error('Error writing to file:', err); - } else { - console.log('File processing complete, saved as', outputFileName); - fixDeclaration(outputFileName); + } + else { + fixDeclaration(fileName, aceNamespacePath, forAceBuilds); } }); }); } -generateDeclaration(); -fixImports('types/index.d.ts', 'types/index.d.ts'); + +generateDeclaration('types/index.d.ts', "./ace.d.ts", true); diff --git a/tsconfig.json b/tsconfig.json index 9ec91bff577..e77dd668596 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,7 +23,5 @@ ], "include": [ "./src/**/*", - "./ace.d.ts", - "./ace-extensions.d.ts" ] } From 7575de555c6fb47bfb2ef678e866b0645655c0be Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 19 Oct 2023 18:05:33 +0400 Subject: [PATCH 27/36] separate building for ace-code and ace-builds; correct build script --- Makefile.dryice.js | 19 +- package.json | 3 +- .../ace_declaration_generator.js | 167 +++++++++++------- 3 files changed, 121 insertions(+), 68 deletions(-) rename generate.js => tool/ace_declaration_generator.js (70%) diff --git a/Makefile.dryice.js b/Makefile.dryice.js index a54a73866a8..1ed0b7cbcdd 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -35,6 +35,7 @@ var fs = require("fs"); var path = require("path"); var copy = require('architect-build/copy'); var build = require('architect-build/build'); +var {correctModulesForAceBuilds, generateDeclaration} = require('./tool/ace_declaration_generator'); var ACE_HOME = __dirname; var BUILD_DIR = ACE_HOME + "/build"; @@ -179,9 +180,7 @@ function buildTypes() { var aceCodeExtensionDefinitions = '/// '; // ace-builds package has different structure and can't use mode types defined for the ace-code. // ace-builds modes are declared along with other modules in the ace-modules.d.ts file below. - var definitions = fs.readFileSync(ACE_HOME + '/ace.d.ts', 'utf8').replace(aceCodeModeDefinitions, '').replace(aceCodeExtensionDefinitions, ''); var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict'); - var moduleRef = '/// '; fs.readdirSync(BUILD_DIR + '/src-noconflict/snippets').forEach(function(path) { paths.push("snippets/" + path); @@ -189,7 +188,8 @@ function buildTypes() { var moduleNameRegex = /^(mode|theme|ext|keybinding)-|^snippets\//; - var pathModules = [ + //TODO: +/* var pathModules = [ "declare module 'ace-builds/webpack-resolver';", "declare module 'ace-builds/esm-resolver';", "declare module 'ace-builds/src-noconflict/ace';" @@ -198,10 +198,15 @@ function buildTypes() { var moduleName = path.split('.')[0]; return "declare module 'ace-builds/src-noconflict/" + moduleName + "';"; } - }).filter(Boolean)).join("\n") + "\n"; - - fs.writeFileSync(BUILD_DIR + '/ace.d.ts', moduleRef + '\n' + definitions); - fs.writeFileSync(BUILD_DIR + '/ace-modules.d.ts', pathModules); + }).filter(Boolean)).join("\n") + "\n";*/ + + //TODO: + fs.copyFileSync(ACE_HOME + '/ace.d.ts', BUILD_DIR + '/ace.d.ts'); + generateDeclaration(BUILD_DIR + '/ace.d.ts'); + var definitions = fs.readFileSync(BUILD_DIR + '/ace.d.ts', 'utf8'); + var newDefinitions = correctModulesForAceBuilds(definitions); + fs.writeFileSync(BUILD_DIR + '/ace.d.ts', newDefinitions); + // var esmUrls = []; var loader = paths.map(function(path) { diff --git a/package.json b/package.json index 920377b4815..13dacdf21ef 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "styles", "ace.d.ts", "ace-modes.d.ts", - "ace-extensions.d.ts", "esm-resolver.js", "translations", "!**/*_test.js", @@ -45,7 +44,7 @@ "lint": "eslint \"src/**/*.js\"", "fix": "eslint --fix \"src/**/*.js\"", "changelog": "standard-version", - "prepack": "node tool/esm_resolver_generator.js && node Makefile.dryice.js css --target build-styles && rm -rf styles && mv build-styles/css styles", + "prepack": "node tool/esm_resolver_generator.js && node tool/ace_declaration_generator.js && node Makefile.dryice.js css --target build-styles && rm -rf styles && mv build-styles/css styles", "tsc": "rimraf types && tsc --project tsconfig.json" }, "standard-version": { diff --git a/generate.js b/tool/ace_declaration_generator.js similarity index 70% rename from generate.js rename to tool/ace_declaration_generator.js index 1d13f29d71e..022596dbd61 100644 --- a/generate.js +++ b/tool/ace_declaration_generator.js @@ -1,31 +1,91 @@ const ts = require('typescript'); const fs = require("fs"); +const path = require("path"); -function generateInitialDeclaration() { - const configPath = ts.findConfigFile('./', ts.sys.fileExists, 'tsconfig.json'); - const config = ts.readConfigFile(configPath, ts.sys.readFile).config; //TODO: emit output path? +/** + * @param {string} directoryPath + */ +function getParsedConfigFromDirectory(directoryPath) { + const configPath = ts.findConfigFile(directoryPath, ts.sys.fileExists, 'tsconfig.json'); + if (!configPath) throw new Error("Could not find tsconfig.json"); + + const configFile = ts.readConfigFile(configPath, ts.sys.readFile); const parseConfigHost = { fileExists: ts.sys.fileExists, readFile: ts.sys.readFile, readDirectory: ts.sys.readDirectory, useCaseSensitiveFileNames: true }; - const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, './'); - const program = ts.createProgram(parsed.fileNames, parsed.options); + + return ts.parseJsonConfigFileContent(configFile.config, parseConfigHost, directoryPath); +} + +/** + * @return {string} + */ +function generateInitialDeclaration() { + const baseDirectory = path.resolve(__dirname, '..'); + const parsedConfig = getParsedConfigFromDirectory(baseDirectory); + const defaultCompilerHost = ts.createCompilerHost({}); + let fileContent; + + const customCompilerHost = { + ...defaultCompilerHost, + writeFile: function (fileName, content) { + fileContent = content; + return; + } + }; + + const program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options, customCompilerHost); program.emit(); + return fileContent; } /** - * @param {string} declarationName + * @param {string} fileName + * @param {string} content + */ +function createCustomCompilerHost(fileName, content) { + const newSourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); + + const defaultCompilerHost = ts.createCompilerHost({}); + return { + ...defaultCompilerHost, + getSourceFile: (name, languageVersion) => { + if (name === fileName) { + return newSourceFile; + } + return defaultCompilerHost.getSourceFile(name, languageVersion); + }, + fileExists: (name) => { + if (name === fileName) { + return true; + } + return defaultCompilerHost.fileExists(name); + }, + readFile: (name) => { + if (name === fileName) { + return content; + } + return defaultCompilerHost.readFile(name); + } + }; +} + +/** + * @param {string} content * @param {string} aceNamespacePath - * @param {boolean} forAceBuilds */ -function fixDeclaration(declarationName, aceNamespacePath, forAceBuilds) { - const program = ts.createProgram([declarationName], { +function fixDeclaration(content, aceNamespacePath) { + const temporaryName = "temp.d.ts"; + const customCompilerHost = createCustomCompilerHost(temporaryName, content); + const program = ts.createProgram([temporaryName], { noEmit: true - }); + }, customCompilerHost); + var checker = program.getTypeChecker(); - let interfaces = collectInterfaces(aceNamespacePath, forAceBuilds); + let interfaces = collectInterfaces(aceNamespacePath); /** * @param {ts.TransformationContext} context @@ -117,24 +177,18 @@ function fixDeclaration(declarationName, aceNamespacePath, forAceBuilds) { }; } - const sourceCode = program.getSourceFile(declarationName); + const sourceCode = program.getSourceFile(temporaryName); const result = ts.transform(sourceCode, [transformer]); const printer = ts.createPrinter(); result.transformed.forEach(transformedFile => { let output = printer.printFile(transformedFile); - if (forAceBuilds) { - // correct paths for ace-builds - output = output.replace( - /ace\-builds\/src\/(mode|theme|ext|keybinding|snippets)\//g, "ace-builds/src-noconflict/$1-"); - output = output.replace(/ace\-builds\/src(?!\-noconflict)/g, "ace-builds-internal"); - } - fs.writeFileSync(declarationName, output); + fs.writeFileSync(aceNamespacePath, output); }); result.dispose(); - checkFinalDeclaration(declarationName); + checkFinalDeclaration(aceNamespacePath); } /** @@ -163,9 +217,8 @@ function checkFinalDeclaration(declarationName) { /** * @param {string} aceNamespacePath - * @param {boolean} forAceBuilds */ -function collectInterfaces(aceNamespacePath, forAceBuilds) { +function collectInterfaces(aceNamespacePath) { const program = ts.createProgram([aceNamespacePath], { noEmit: true }); @@ -173,9 +226,6 @@ function collectInterfaces(aceNamespacePath, forAceBuilds) { const result = {}; const printer = ts.createPrinter(); let packageName = "ace-code"; - if (forAceBuilds) { - packageName = "ace-builds"; - } function visit(node) { if (node && ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { @@ -221,11 +271,10 @@ function collectInterfaces(aceNamespacePath, forAceBuilds) { } /** - * @param {string} packageName * @param {string} aceNamespacePath * @return {string} */ -function cloneAceNamespace(packageName, aceNamespacePath) { +function cloneAceNamespace(aceNamespacePath) { const program = ts.createProgram([aceNamespacePath], { noEmit: true }); @@ -235,7 +284,7 @@ function cloneAceNamespace(packageName, aceNamespacePath) { const node = sourceFile.statements[i]; if (ts.isModuleDeclaration(node) && node.name.text == "Ace") { let aceModule = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile); - aceModule = aceModule.replace(/"\.\/src/g, "\"" + packageName + "/src"); + aceModule = aceModule.replace(/"\.\/src/g, "\"ace-code/src"); aceModule = '\n' + aceModule + '\n'; return aceModule; } @@ -243,44 +292,44 @@ function cloneAceNamespace(packageName, aceNamespacePath) { } /** - * @param {string} fileName * @param {string} aceNamespacePath - * @param {boolean} [forAceBuilds] */ -function generateDeclaration(fileName, aceNamespacePath, forAceBuilds) { - generateInitialDeclaration(); +function generateDeclaration(aceNamespacePath) { + let data = generateInitialDeclaration(); - fs.readFile(fileName, 'utf8', (err, data) => { - if (err) { - console.error('Error reading the file:', err); - return; - } - let packageName = "ace-code"; - if (forAceBuilds) { - packageName = "ace-builds"; - } + let packageName = "ace-code"; - let updatedContent = data.replace(/(declare module ")/g, "$1" + packageName + "/"); - updatedContent = updatedContent.replace(/(require\(")/g, "$1" + packageName + "/"); - updatedContent = updatedContent.replace(/(import\(")(?!(?:\.|ace\-code))/g, "$1" + packageName + "/"); - updatedContent = updatedContent.replace(/ace\-(?:code|builds)(\/src)?\/ace/g, packageName); - let aceModule = cloneAceNamespace(packageName, aceNamespacePath); + let updatedContent = data.replace(/(declare module ")/g, "$1" + packageName + "/"); + updatedContent = updatedContent.replace(/(require\(")/g, "$1" + packageName + "/"); + updatedContent = updatedContent.replace(/(import\(")(?!(?:\.|ace\-code))/g, "$1" + packageName + "/"); + updatedContent = updatedContent.replace(/ace\-(?:code|builds)(\/src)?\/ace/g, packageName); + let aceModule = cloneAceNamespace(aceNamespacePath); - updatedContent = updatedContent.replace(/(declare\s+module\s+"ace-(?:code|builds)"\s+{)/, "$1" + aceModule); - updatedContent = updatedContent.replace(/(import\(")[./]*ace("\).Ace)/g, "$1" + packageName + "$2"); + updatedContent = updatedContent.replace(/(declare\s+module\s+"ace-(?:code|builds)"\s+{)/, "$1" + aceModule); + updatedContent = updatedContent.replace(/(import\(")[./]*ace("\).Ace)/g, "$1" + packageName + "$2"); - fs.writeFile(fileName, updatedContent, 'utf8', (err) => { - if (err) { - console.error('Error writing to file:', err); - } - else { - fixDeclaration(fileName, aceNamespacePath, forAceBuilds); - } - }); - }); + fixDeclaration(updatedContent, aceNamespacePath); } -generateDeclaration('types/index.d.ts', "./ace.d.ts", true); - +/** + * @param {string} content + */ +function correctModulesForAceBuilds(content) { + let output = content.replace( + /ace\-code(?:\/src)?\/(mode|theme|ext|keybinding|snippets)\//g, "ace-builds/src-noconflict/$1-"); + output = output.replace(/ace\-code(?:\/src)?/g, "ace-builds-internal"); + output = output.replace(/ace\-code/g, "ace-builds"); + output = output + '\n' + "declare module 'ace-builds/webpack-resolver';\n" + + "declare module 'ace-builds/esm-resolver';"; + //TODO: modes/worker + return output; +} +if (!module.parent) { + generateDeclaration("../ace.d.ts"); +} +else { + exports.generateDeclaration = generateDeclaration; + exports.correctModulesForAceBuilds = correctModulesForAceBuilds; +} From ca733da277ab492247010ec8a7b0eac06b63d41f Mon Sep 17 00:00:00 2001 From: mkslanc Date: Mon, 23 Oct 2023 14:42:51 +0400 Subject: [PATCH 28/36] rename `correctModulesForAceBuilds` to `updateDeclarationModuleNames` --- Makefile.dryice.js | 5 ++--- tool/ace_declaration_generator.js | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 1ed0b7cbcdd..290f79ed85e 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -35,7 +35,7 @@ var fs = require("fs"); var path = require("path"); var copy = require('architect-build/copy'); var build = require('architect-build/build'); -var {correctModulesForAceBuilds, generateDeclaration} = require('./tool/ace_declaration_generator'); +var {updateDeclarationModuleNames, generateDeclaration} = require('./tool/ace_declaration_generator'); var ACE_HOME = __dirname; var BUILD_DIR = ACE_HOME + "/build"; @@ -177,7 +177,6 @@ function ace() { function buildTypes() { var aceCodeModeDefinitions = '/// '; - var aceCodeExtensionDefinitions = '/// '; // ace-builds package has different structure and can't use mode types defined for the ace-code. // ace-builds modes are declared along with other modules in the ace-modules.d.ts file below. var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict'); @@ -204,7 +203,7 @@ function buildTypes() { fs.copyFileSync(ACE_HOME + '/ace.d.ts', BUILD_DIR + '/ace.d.ts'); generateDeclaration(BUILD_DIR + '/ace.d.ts'); var definitions = fs.readFileSync(BUILD_DIR + '/ace.d.ts', 'utf8'); - var newDefinitions = correctModulesForAceBuilds(definitions); + var newDefinitions = updateDeclarationModuleNames(definitions); fs.writeFileSync(BUILD_DIR + '/ace.d.ts', newDefinitions); // var esmUrls = []; diff --git a/tool/ace_declaration_generator.js b/tool/ace_declaration_generator.js index 022596dbd61..ee1698f589d 100644 --- a/tool/ace_declaration_generator.js +++ b/tool/ace_declaration_generator.js @@ -314,7 +314,7 @@ function generateDeclaration(aceNamespacePath) { /** * @param {string} content */ -function correctModulesForAceBuilds(content) { +function updateDeclarationModuleNames(content) { let output = content.replace( /ace\-code(?:\/src)?\/(mode|theme|ext|keybinding|snippets)\//g, "ace-builds/src-noconflict/$1-"); output = output.replace(/ace\-code(?:\/src)?/g, "ace-builds-internal"); @@ -331,5 +331,5 @@ if (!module.parent) { } else { exports.generateDeclaration = generateDeclaration; - exports.correctModulesForAceBuilds = correctModulesForAceBuilds; + exports.updateDeclarationModuleNames = updateDeclarationModuleNames; } From da92d095dcc54f324f114fd33aba60c7c6a109b7 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 2 Nov 2023 16:26:40 +0400 Subject: [PATCH 29/36] fix left errors in generation --- ace.d.ts | 36 +++++++++++++++------------- src/ace.js | 3 ++- src/lib/keys.js | 4 ++++ tool/ace_declaration_generator.js | 39 ++++++++++++++++++++++++------- tsconfig.json | 1 + 5 files changed, 57 insertions(+), 26 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index f1b0ca31edd..1219dad4c36 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -801,7 +801,7 @@ export namespace Ace { [key: string]: any; } - class OptionsProvider { + class OptionsProvider { setOptions(optList: Partial): void; getOptions(optionNames?: Array | Partial): Partial; @@ -861,8 +861,8 @@ export namespace Ace { cancel?(): void; id?: string; - triggerCharacters?: string[]; - hideInlinePreview?: boolean; + triggerCharacters?: string[]; + hideInlinePreview?: boolean; } interface CompletionOptions { @@ -954,7 +954,7 @@ export namespace Ace { $multiselectOnSessionChange?: any, $blockSelectEnabled?: boolean, } - + interface CodeLenseEditorExtension{ codeLensProviders?: any[]; $codeLensClickHandler?: any; @@ -965,15 +965,15 @@ export namespace Ace { interface ElasticTabstopsEditorExtension { elasticTabstops?: import("./src/ext/elastic_tabstops_lite").ElasticTabstopsLite; } - + interface TextareaEditorExtension { setDisplaySettings?: (settings: any) => void; } - + interface PromptEditorExtension { cmdLine?: Editor; } - + interface OptionsEditorExtension { $options?: any; } @@ -1114,7 +1114,7 @@ declare module "./src/autocomplete" { popup: Ace.AcePopup; emptyMessage?: Function, } - + export interface CompletionProvider { completions: Ace.FilteredList; } @@ -1135,8 +1135,8 @@ declare module "./src/document" { } declare module "./src/editor" { - export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider, - Ace.EventEmitter, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, + export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider, + Ace.EventEmitter, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension { session: Ace.EditSession; @@ -1208,7 +1208,7 @@ declare module "./src/edit_session" { $useEmacsStyleLineStart?: boolean, $selectLongWords?: boolean, } - + } declare module "./src/edit_session/fold" { @@ -1247,7 +1247,7 @@ declare module "./src/line_widgets" { declare module "./src/selection" { export interface Selection extends Ace.EventEmitter, Ace.MultiSelectProperties { } - + } declare module "./src/range" { @@ -1271,7 +1271,7 @@ declare module "./src/virtual_renderer" { textarea?: HTMLTextAreaElement, $hScrollBarAlwaysVisible?: boolean, $vScrollBarAlwaysVisible?: boolean - $maxLines?: number | null, + $maxLines?: number, $scrollPastEnd?: number, enableKeyboardAccessibility?: boolean, keyboardFocusClassName?: string, @@ -1309,7 +1309,7 @@ declare module "./src/commands/command_manager" { } declare module "./src/autocomplete/popup" { - + export interface AcePopup extends Ace.AcePopupWithEditor { setSelectOnHover: (val: boolean) => void, setRow: (line: number) => void, @@ -1325,7 +1325,7 @@ declare module "./src/autocomplete/popup" { hide: () => void, anchor: "top" | "bottom", anchorPosition: Ace.Point, - tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean) => boolean, + tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom", forceShow?: boolean) => boolean, $borderSize: number, show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, goTo: (where: Ace.AcePopupNavigation) => void, @@ -1370,7 +1370,7 @@ declare module "./src/mouse/mouse_handler" { $tooltipFollowsMouse?: boolean, cancelDrag?: boolean //from DefaultHandlers - $clickSelection?: null | Ace.Range, + $clickSelection?: Ace.Range, mousedownEvent?: Ace.MouseEvent, startSelect?: (pos?: Ace.Point, waitForClickSelection?: boolean) => void, select?: () => void @@ -1400,3 +1400,7 @@ declare module "./src/mouse/default_gutter_handler" { export interface GutterHandler { } } + +declare module "./src/lib/keys" { + export function keyCodeToString(keyCode: string): string +} diff --git a/src/ace.js b/src/ace.js index 7556f15d384..1c75696bbe1 100644 --- a/src/ace.js +++ b/src/ace.js @@ -86,4 +86,5 @@ exports.Editor = Editor; exports.EditSession = EditSession; exports.UndoManager = UndoManager; exports.VirtualRenderer = Renderer; -exports.version = exports.config.version; +let version= exports.config.version; +exports.version = version; diff --git a/src/lib/keys.js b/src/lib/keys.js index 0be5d55ad46..6dc0869774e 100644 --- a/src/lib/keys.js +++ b/src/lib/keys.js @@ -154,6 +154,10 @@ oop.mixin(exports, Keys); /**@type{{keyCodeToString: (keyCode: string) => string}}*/ exports.default = exports; +/** + * @param {string} keyCode + * @return {string} + */ exports.keyCodeToString = function(keyCode) { // Language-switching keystroke in Chrome/Linux emits keyCode 0. var keyString = Keys[keyCode]; diff --git a/tool/ace_declaration_generator.js b/tool/ace_declaration_generator.js index ee1698f589d..413bd49cbb7 100644 --- a/tool/ace_declaration_generator.js +++ b/tool/ace_declaration_generator.js @@ -96,16 +96,26 @@ function fixDeclaration(content, aceNamespacePath) { function visit(node) { let updatedNode = node; if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { - // remove wrong generated modules + // replace wrong generated modules if (node.name.text.endsWith("lib/keys") || node.name.text.endsWith("linking")) { - const newBody = ts.factory.createModuleBlock([]); + let statements = []; + if (interfaces[node.name.text]) { + statements = interfaces[node.name.text]; + } + const newBody = ts.factory.createModuleBlock(statements); updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); } else if (interfaces[node.name.text]) { // add corresponding interfaces to support mixins (EventEmitter, OptionsProvider, etc.) if (node.body && ts.isModuleBlock(node.body)) { const newBody = ts.factory.createModuleBlock( - node.body.statements.concat(interfaces[node.name.text])); + node.body.statements.concat(interfaces[node.name.text]).filter(statement => { + if (node.name.text.endsWith("autocomplete")) { + return !(ts.isModuleDeclaration(statement) && statement.name.text + === 'Autocomplete'); + } + return true; + })); updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); } } @@ -123,10 +133,21 @@ function fixDeclaration(content, aceNamespacePath) { } } + else if (node.name.text.endsWith("static_highlight")) { + if (node.body && ts.isModuleBlock(node.body)) { + const newBody = ts.factory.createModuleBlock(node.body.statements.filter(statement => { + return !ts.isExportAssignment(statement); + })); + updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); + } + } } else if (ts.isInterfaceDeclaration(node) && node.heritageClauses) { for (const clause of node.heritageClauses) { if (clause.token === ts.SyntaxKind.ExtendsKeyword && clause.types.length === 0) { + if (node.members.length === 0) { + return; // remove entire interface declaration + } // Remove the extends clause if it's empty return context.factory.updateInterfaceDeclaration(node, node.modifiers, node.name, node.typeParameters, [], node.members @@ -232,7 +253,7 @@ function collectInterfaces(aceNamespacePath) { let nodes = []; if (node.body && ts.isModuleBlock(node.body)) { ts.forEachChild(node.body, (child) => { - if (ts.isInterfaceDeclaration(child)) nodes.push(child); + if (ts.isInterfaceDeclaration(child) || ts.isFunctionDeclaration(child)) nodes.push(child); }); } if (nodes.length > 0) { @@ -299,15 +320,15 @@ function generateDeclaration(aceNamespacePath) { let packageName = "ace-code"; - let updatedContent = data.replace(/(declare module ")/g, "$1" + packageName + "/"); - updatedContent = updatedContent.replace(/(require\(")/g, "$1" + packageName + "/"); - updatedContent = updatedContent.replace(/(import\(")(?!(?:\.|ace\-code))/g, "$1" + packageName + "/"); + let updatedContent = data.replace(/(declare module ")/g, "$1" + packageName + "/src/"); + updatedContent = updatedContent.replace(/(require\(")/g, "$1" + packageName + "/src/"); + updatedContent = updatedContent.replace(/(import\(")(?!(?:\.|ace\-code))/g, "$1" + packageName + "/src/"); updatedContent = updatedContent.replace(/ace\-(?:code|builds)(\/src)?\/ace/g, packageName); let aceModule = cloneAceNamespace(aceNamespacePath); updatedContent = updatedContent.replace(/(declare\s+module\s+"ace-(?:code|builds)"\s+{)/, "$1" + aceModule); updatedContent = updatedContent.replace(/(import\(")[./]*ace("\).Ace)/g, "$1" + packageName + "$2"); - + updatedContent = updatedContent.replace(/(?:export)?\snamespace(?!\sAce)/g, "export namespace"); fixDeclaration(updatedContent, aceNamespacePath); } @@ -327,7 +348,7 @@ function updateDeclarationModuleNames(content) { if (!module.parent) { - generateDeclaration("../ace.d.ts"); + generateDeclaration(__dirname + "../ace.d.ts"); } else { exports.generateDeclaration = generateDeclaration; diff --git a/tsconfig.json b/tsconfig.json index e77dd668596..16a61043a27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,5 +23,6 @@ ], "include": [ "./src/**/*", + "./ace.d.ts" ] } From 9a5b4d0b6642cab8abf52d7f3602a796fbbbc76f Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 2 Nov 2023 19:11:44 +0400 Subject: [PATCH 30/36] change declaration structure for ace-code --- ace-extensions.d.ts | 7 + ace-internal.d.ts | 1163 +++++++++++++++++++++++++ ace.d.ts | 192 ++-- src/ace.js | 2 +- src/anchor.js | 8 +- src/apply_delta.js | 2 +- src/autocomplete.js | 16 +- src/autocomplete/inline.js | 2 +- src/autocomplete/popup.js | 2 +- src/background_tokenizer.js | 4 +- src/commands/command_manager.js | 2 +- src/commands/default_commands.js | 2 +- src/commands/multi_select_commands.js | 4 +- src/document.js | 60 +- src/edit_session.js | 46 +- src/edit_session/bracket_match.js | 16 +- src/edit_session/fold.js | 18 +- src/edit_session/fold_line.js | 2 +- src/edit_session/folding.js | 10 +- src/editor.js | 36 +- src/ext/command_bar.js | 6 +- src/ext/hardwrap.js | 2 +- src/ext/inline_autocomplete.js | 10 +- src/ext/language_tools.js | 4 +- src/ext/rtl.js | 2 +- src/ext/simple_tokenizer.js | 6 +- src/ext/static_highlight.js | 4 +- src/keyboard/emacs_test.js | 2 +- src/keyboard/hash_handler.js | 22 +- src/keyboard/keybinding.js | 12 +- src/keyboard/keybinding_test.js | 2 +- src/keyboard/sublime_test.js | 2 +- src/keyboard/vim_test.js | 2 +- src/layer/cursor.js | 2 +- src/layer/gutter.js | 14 +- src/layer/lines.js | 10 +- src/layer/marker.js | 18 +- src/layer/text.js | 2 +- src/lib/keys.js | 6 +- src/line_widgets.js | 16 +- src/marker_group.js | 4 +- src/mode/text.js | 18 +- src/mode/text_highlight_rules.js | 18 +- src/mouse/default_handlers.js | 2 +- src/multi_select.js | 12 +- src/occur.js | 12 +- src/placeholder.js | 6 +- src/range.js | 26 +- src/range_list.js | 10 +- src/search.js | 6 +- src/search_highlight.js | 2 +- src/selection.js | 14 +- src/split.js | 2 +- src/token_iterator.js | 8 +- src/tokenizer.js | 6 +- src/tooltip.js | 2 +- src/undomanager.js | 12 +- src/virtual_renderer.js | 24 +- tsconfig.json | 3 +- 59 files changed, 1593 insertions(+), 332 deletions(-) create mode 100644 ace-extensions.d.ts create mode 100644 ace-internal.d.ts diff --git a/ace-extensions.d.ts b/ace-extensions.d.ts new file mode 100644 index 00000000000..79f704ae254 --- /dev/null +++ b/ace-extensions.d.ts @@ -0,0 +1,7 @@ +declare module "ace-code/src/ext/simple_tokenizer" { + export type TokenizeResult = Array> + export function tokenize(content: string, highlightRules: import("./ace").Ace.HighlightRules): TokenizeResult; +} diff --git a/ace-internal.d.ts b/ace-internal.d.ts new file mode 100644 index 00000000000..b7386b8a29c --- /dev/null +++ b/ace-internal.d.ts @@ -0,0 +1,1163 @@ +/// +/// + +export namespace Ace { + export type NewLineMode = 'auto' | 'unix' | 'windows'; + + export interface Anchor extends EventEmitter { + getPosition(): Position; + getDocument(): Document; + setPosition(row: number, column: number, noClip?: boolean): void; + detach(): void; + attach(doc: Document): void; + } + + export interface Document extends EventEmitter { + setValue(text: string): void; + getValue(): string; + createAnchor(row: number, column: number): Anchor; + getNewLineCharacter(): string; + setNewLineMode(newLineMode: NewLineMode): void; + getNewLineMode(): NewLineMode; + isNewLine(text: string): boolean; + getLine(row: number): string; + getLines(firstRow: number, lastRow: number): string[]; + getAllLines(): string[]; + getLength(): number; + getTextRange(range: Range): string; + getLinesForRange(range: Range): string[]; + insert(position: Position, text: string): Position; + insert(position: {row: number, column: number}, text: string): Position; + insertInLine(position: Position, text: string): Position; + insertNewLine(position: Point): Point; + clippedPos(row: number, column: number): Point; + clonePos(pos: Point): Point; + pos(row: number, column: number): Point; + insertFullLines(row: number, lines: string[]): void; + insertMergedLines(position: Position, lines: string[]): Point; + remove(range: Range): Position; + removeInLine(row: number, startColumn: number, endColumn: number): Position; + removeFullLines(firstRow: number, lastRow: number): string[]; + removeNewLine(row: number): void; + replace(range: Range, text: string): Position; + applyDeltas(deltas: Delta[]): void; + revertDeltas(deltas: Delta[]): void; + applyDelta(delta: Delta, doNotValidate?: boolean): void; + revertDelta(delta: Delta): void; + indexToPosition(index: number, startRow: number): Position; + positionToIndex(pos: Position, startRow?: number): number; + } + + export interface FoldLine { + folds: Fold[]; + range: Range; + start: Point; + end: Point; + + shiftRow(shift: number): void; + addFold(fold: Fold): void; + containsRow(row: number): boolean; + walk(callback: Function, endRow?: number, endColumn?: number): void; + getNextFoldTo(row: number, column: number): null | { fold: Fold, kind: string }; + addRemoveChars(row: number, column: number, len: number): void; + split(row: number, column: number): FoldLine; + merge(foldLineNext: FoldLine): void; + idxToPosition(idx: number): Point; + } + + export interface Fold { + range: Range; + start: Point; + end: Point; + foldLine?: FoldLine; + sameRow: boolean; + subFolds: Fold[]; + + setFoldLine(foldLine: FoldLine): void; + clone(): Fold; + addSubFold(fold: Fold): Fold; + restoreRange(range: Range): void; + } + + interface Folding { + getFoldAt(row: number, column: number, side: number): Fold; + getFoldsInRange(range: Range): Fold[]; + getFoldsInRangeList(ranges: Range[]): Fold[]; + getAllFolds(): Fold[]; + getFoldStringAt(row: number, + column: number, + trim?: number, + foldLine?: FoldLine): string | null; + getFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; + getNextFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; + getFoldedRowCount(first: number, last: number): number; + addFold(placeholder: string | Fold, range?: Range): Fold; + addFolds(folds: Fold[]): void; + removeFold(fold: Fold): void; + removeFolds(folds: Fold[]): void; + expandFold(fold: Fold): void; + expandFolds(folds: Fold[]): void; + unfold(location: null | number | Point | Range, + expandInner?: boolean): Fold[] | undefined; + isRowFolded(docRow: number, startFoldRow?: FoldLine): boolean; + getFoldRowEnd(docRow: number, startFoldRow?: FoldLine): number; + getFoldRowStart(docRow: number, startFoldRow?: FoldLine): number; + getFoldDisplayLine(foldLine: FoldLine, + endRow: number | null, + endColumn: number | null, + startRow: number | null, + startColumn: number | null): string; + getDisplayLine(row: number, + endColumn: number | null, + startRow: number | null, + startColumn: number | null): string; + toggleFold(tryToUnfold?: boolean): void; + getCommentFoldRange(row: number, + column: number, + dir: number): Range | undefined; + foldAll(startRow?: number, endRow?: number, depth?: number): void; + setFoldStyle(style: string): void; + getParentFoldRangeData(row: number, ignoreCurrent?: boolean): { + range?: Range, + firstRange: Range + }; + toggleFoldWidget(toggleParent?: boolean): void; + updateFoldWidgets(delta: Delta): void; + } + + export interface Range { + start: Point; + end: Point; + + isEqual(range: Range): boolean; + toString(): string; + contains(row: number, column: number): boolean; + compareRange(range: Range): number; + comparePoint(p: Point): number; + containsRange(range: Range): boolean; + intersects(range: Range): boolean; + isEnd(row: number, column: number): boolean; + isStart(row: number, column: number): boolean; + setStart(row: number, column: number): void; + setEnd(row: number, column: number): void; + inside(row: number, column: number): boolean; + insideStart(row: number, column: number): boolean; + insideEnd(row: number, column: number): boolean; + compare(row: number, column: number): number; + compareStart(row: number, column: number): number; + compareEnd(row: number, column: number): number; + compareInside(row: number, column: number): number; + clipRows(firstRow: number, lastRow: number): Range; + extend(row: number, column: number): Range; + isEmpty(): boolean; + isMultiLine(): boolean; + clone(): Range; + collapseRows(): Range; + toScreenRange(session: EditSession): Range; + moveBy(row: number, column: number): void; + } + + export interface EditSessionOptions { + wrap: "off" | "free" | "printmargin" | boolean | number; + wrapMethod: 'code' | 'text' | 'auto'; + indentedSoftWrap: boolean; + firstLineNumber: number; + useWorker: boolean; + useSoftTabs: boolean; + tabSize: number; + navigateWithinSoftTabs: boolean; + foldStyle: 'markbegin' | 'markbeginend' | 'manual'; + overwrite: boolean; + newLineMode: NewLineMode; + mode: string; + } + + export interface VirtualRendererOptions { + animatedScroll: boolean; + showInvisibles: boolean; + showPrintMargin: boolean; + printMarginColumn: number; + printMargin: boolean | number; + showGutter: boolean; + fadeFoldWidgets: boolean; + showFoldWidgets: boolean; + showLineNumbers: boolean; + displayIndentGuides: boolean; + highlightIndentGuides: boolean; + highlightGutterLine: boolean; + hScrollBarAlwaysVisible: boolean; + vScrollBarAlwaysVisible: boolean; + fontSize: number; + fontFamily: string; + maxLines: number; + minLines: number; + scrollPastEnd: boolean; + fixedWidthGutter: boolean; + customScrollbar: boolean; + theme: string; + hasCssTransforms: boolean; + maxPixelHeight: number; + useSvgGutterIcons: boolean; + showFoldedAnnotations: boolean; + } + + export interface MouseHandlerOptions { + scrollSpeed: number; + dragDelay: number; + dragEnabled: boolean; + focusTimeout: number; + tooltipFollowsMouse: boolean; + } + + export interface EditorOptions extends EditSessionOptions, + MouseHandlerOptions, + VirtualRendererOptions { + selectionStyle: string; + highlightActiveLine: boolean; + highlightSelectedWord: boolean; + readOnly: boolean; + copyWithEmptySelection: boolean; + cursorStyle: 'ace' | 'slim' | 'smooth' | 'wide'; + mergeUndoDeltas: true | false | 'always'; + behavioursEnabled: boolean; + wrapBehavioursEnabled: boolean; + enableAutoIndent: boolean; + enableBasicAutocompletion: boolean | Completer[]; + enableLiveAutocompletion: boolean | Completer[]; + liveAutocompletionDelay: number; + liveAutocompletionThreshold: number; + enableSnippets: boolean; + autoScrollEditorIntoView: boolean; + keyboardHandler: string | null; + placeholder: string; + value: string; + session: EditSession; + relativeLineNumbers: boolean; + enableMultiselect: boolean; + enableKeyboardAccessibility: boolean; + } + + export interface SearchOptions { + needle: string | RegExp; + preventScroll: boolean; + backwards: boolean; + start: Range; + skipCurrent: boolean; + range: Range; + preserveCase: boolean; + regExp: boolean; + wholeWord: boolean; + caseSensitive: boolean; + wrap: boolean; + } + + export interface EventEmitter { + once(name: string, callback: Function): void; + setDefaultHandler(name: string, callback: Function): void; + removeDefaultHandler(name: string, callback: Function): void; + on(name: string, callback: Function, capturing?: boolean): void; + addEventListener(name: string, callback: Function, capturing?: boolean): void; + off(name: string, callback: Function): void; + removeListener(name: string, callback: Function): void; + removeEventListener(name: string, callback: Function): void; + removeAllListeners(name?: string): void; + } + + export interface Point { + row: number; + column: number; + } + + export interface Delta { + action: 'insert' | 'remove'; + start: Point; + end: Point; + lines: string[]; + } + + export interface Annotation { + row?: number; + column?: number; + text: string; + type: string; + } + + export interface MarkerGroupItem { + range: Range; + className: string; + } + + export class MarkerGroup { + constructor(session: EditSession); + setMarkers(markers: MarkerGroupItem[]): void; + getMarkerAtPosition(pos: Position): MarkerGroupItem; + } + + + export interface Command { + name?: string; + bindKey?: string | { mac?: string, win?: string }; + readOnly?: boolean; + exec: (editor: Editor, args?: any) => void; + } + + export type CommandLike = Command | ((editor: Editor) => void); + + export interface KeyboardHandler { + handleKeyboard: Function; + } + + export interface MarkerLike { + range?: Range; + type: string; + renderer?: MarkerRenderer; + clazz: string; + inFront: boolean; + id: number; + update?: (html: string[], + // TODO maybe define Marker class + marker: any, + session: EditSession, + config: any) => void; + } + + export type MarkerRenderer = (html: string[], + range: Range, + left: number, + top: number, + config: any) => void; + + export interface Token { + type: string; + value: string; + index?: number; + start?: number; + } + + interface BaseCompletion { + score?: number; + meta?: string; + caption?: string; + docHTML?: string; + docText?: string; + completerId?: string; + } + + export interface SnippetCompletion extends BaseCompletion { + snippet: string; + } + + export interface ValueCompletion extends BaseCompletion { + value: string; + } + + export type Completion = SnippetCompletion | ValueCompletion + + export interface Tokenizer { + removeCapturingGroups(src: string): string; + createSplitterRegexp(src: string, flag?: string): RegExp; + getLineTokens(line: string, startState: string | string[]): Token[]; + } + + interface TokenIterator { + getCurrentToken(): Token; + getCurrentTokenColumn(): number; + getCurrentTokenRow(): number; + getCurrentTokenPosition(): Point; + getCurrentTokenRange(): Range; + stepBackward(): Token; + stepForward(): Token; + } + + export type HighlightRule = {defaultToken: string} | {include: string} | {todo: string} | { + token: string | string[] | ((value: string) => string); + regex: string | RegExp; + next?: string; + push?: string; + comment?: string; + caseInsensitive?: boolean; + } + + export type HighlightRulesMap = Record; + + export type KeywordMapper = (keyword: string) => string; + + export interface HighlightRules { + addRules(rules: HighlightRulesMap, prefix?: string): void; + getRules(): HighlightRulesMap; + embedRules(rules: (new () => HighlightRules) | HighlightRulesMap, prefix: string, escapeRules?: boolean, append?: boolean): void; + getEmbeds(): string[]; + normalizeRules(): void; + createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; + } + + export interface FoldMode { + foldingStartMarker: RegExp; + foldingStopMarker?: RegExp; + getFoldWidget(session: EditSession, foldStyle: string, row: number): string; + getFoldWidgetRange(session: EditSession, foldStyle: string, row: number, forceMultiline?: boolean): Range | undefined; + indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; + openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + } + + type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => {text: string, selection: number[]} | Range | undefined; + type BehaviorMap = Record>; + + export interface Behaviour { + add(name: string, action: string, callback: BehaviorAction): void; + addBehaviours(behaviours: BehaviorMap): void; + remove(name: string): void; + inherit(mode: SyntaxMode | (new () => SyntaxMode), filter: string[]): void; + getBehaviours(filter: string[]): BehaviorMap; + } + + export interface Outdent { + checkOutdent(line: string, input: string): boolean; + autoOutdent(doc: Document, row: number): number | undefined; + } + + export interface SyntaxMode { + HighlightRules: new () => HighlightRules; + foldingRules?: FoldMode; + $behaviour?: Behaviour; + $defaultBehaviour?: Behaviour; + lineCommentStart?: string; + getTokenizer(): Tokenizer; + toggleCommentLines(state: any, + session: EditSession, + startRow: number, + endRow: number): void; + toggleBlockComment(state: any, + session: EditSession, + range: Range, + cursor: Point): void; + getNextLineIndent(state: any, line: string, tab: string): string; + checkOutdent(state: any, line: string, input: string): boolean; + autoOutdent(state: any, doc: Document, row: number): void; + // TODO implement WorkerClient types + createWorker(session: EditSession): any; + createModeDelegates(mapping: { [key: string]: string }): void; + transformAction: BehaviorAction; + getKeywords(append?: boolean): Array; + getCompletions(state: string, + session: EditSession, + pos: Point, + prefix: string): Completion[]; + } + + type AfterLoadCallback = (err: Error | null, module: unknown) => void; + type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; + + export interface Config { + get(key: string): any; + set(key: string, value: any): void; + all(): { [key: string]: any }; + moduleUrl(name: string, component?: string): string; + setModuleUrl(name: string, subst: string): string; + setLoader(cb: LoaderFunction): void; + setModuleLoader(name: string, onLoad: Function): void; + loadModule(moduleName: string | [string, string], + onLoad?: (module: any) => void): void; + init(packaged: any): any; + defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; + resetOptions(obj: any): void; + setDefaultValue(path: string, name: string, value: any): void; + setDefaultValues(path: string, optionHash: { [key: string]: any }): void; + } + + export interface OptionsProvider { + setOptions(optList: { [key: string]: any }): void; + getOptions(optionNames?: string[] | { [key: string]: any }): { [key: string]: any }; + setOption(name: string, value: any): void; + getOption(name: string): any; + } + + export interface UndoManager { + addSession(session: EditSession): void; + add(delta: Delta, allowMerge: boolean, session: EditSession): void; + addSelection(selection: string, rev?: number): void; + startNewGroup(): void; + markIgnored(from: number, to?: number): void; + getSelection(rev: number, after?: boolean): { value: string, rev: number }; + getRevision(): number; + getDeltas(from: number, to?: number): Delta[]; + undo(session: EditSession, dontSelect?: boolean): void; + redo(session: EditSession, dontSelect?: boolean): void; + reset(): void; + canUndo(): boolean; + canRedo(): boolean; + bookmark(rev?: number): void; + isAtBookmark(): boolean; + hasUndo(): boolean; + hasRedo(): boolean; + isClean(): boolean; + markClean(rev?: number): void; + toJSON(): object; + fromJSON(json: object): void; + } + + export interface Position { + row: number, + column: number + } + + export interface EditSession extends EventEmitter, OptionsProvider, Folding { + selection: Selection; + + // TODO: define BackgroundTokenizer + + on(name: 'changeFold', + callback: (obj: { data: Fold, action: string }) => void): Function; + on(name: 'changeScrollLeft', callback: (scrollLeft: number) => void): Function; + on(name: 'changeScrollTop', callback: (scrollTop: number) => void): Function; + on(name: 'tokenizerUpdate', + callback: (obj: { data: { first: number, last: number } }) => void): Function; + on(name: 'change', callback: () => void): Function; + on(name: 'changeTabSize', callback: () => void): Function; + + + setOption(name: T, value: EditSessionOptions[T]): void; + getOption(name: T): EditSessionOptions[T]; + + readonly doc: Document; + + setDocument(doc: Document): void; + getDocument(): Document; + resetCaches(): void; + setValue(text: string): void; + getValue(): string; + getSelection(): Selection; + getState(row: number): string; + getTokens(row: number): Token[]; + getTokenAt(row: number, column: number): Token | null; + setUndoManager(undoManager: UndoManager): void; + markUndoGroup(): void; + getUndoManager(): UndoManager; + getTabString(): string; + setUseSoftTabs(val: boolean): void; + getUseSoftTabs(): boolean; + setTabSize(tabSize: number): void; + getTabSize(): number; + isTabStop(position: Position): boolean; + setNavigateWithinSoftTabs(navigateWithinSoftTabs: boolean): void; + getNavigateWithinSoftTabs(): boolean; + setOverwrite(overwrite: boolean): void; + getOverwrite(): boolean; + toggleOverwrite(): void; + addGutterDecoration(row: number, className: string): void; + removeGutterDecoration(row: number, className: string): void; + getBreakpoints(): string[]; + setBreakpoints(rows: number[]): void; + clearBreakpoints(): void; + setBreakpoint(row: number, className: string): void; + clearBreakpoint(row: number): void; + addMarker(range: Range, + className: string, + type: "fullLine" | "screenLine" | "text" | MarkerRenderer, + inFront?: boolean): number; + addDynamicMarker(marker: MarkerLike, inFront: boolean): MarkerLike; + removeMarker(markerId: number): void; + getMarkers(inFront?: boolean): {[id: number]: MarkerLike}; + highlight(re: RegExp): void; + highlightLines(startRow: number, + endRow: number, + className: string, + inFront?: boolean): Range; + setAnnotations(annotations: Annotation[]): void; + getAnnotations(): Annotation[]; + clearAnnotations(): void; + getWordRange(row: number, column: number): Range; + getAWordRange(row: number, column: number): Range; + setNewLineMode(newLineMode: NewLineMode): void; + getNewLineMode(): NewLineMode; + setUseWorker(useWorker: boolean): void; + getUseWorker(): boolean; + setMode(mode: string | SyntaxMode, callback?: () => void): void; + getMode(): SyntaxMode; + setScrollTop(scrollTop: number): void; + getScrollTop(): number; + setScrollLeft(scrollLeft: number): void; + getScrollLeft(): number; + getScreenWidth(): number; + getLineWidgetMaxWidth(): number; + getLine(row: number): string; + getLines(firstRow: number, lastRow: number): string[]; + getLength(): number; + getTextRange(range: Range): string; + insert(position: Position, text: string): void; + remove(range: Range): void; + removeFullLines(firstRow: number, lastRow: number): void; + undoChanges(deltas: Delta[], dontSelect?: boolean): void; + redoChanges(deltas: Delta[], dontSelect?: boolean): void; + setUndoSelect(enable: boolean): void; + replace(range: Range, text: string): void; + moveText(fromRange: Range, toPosition: Position, copy?: boolean): void; + indentRows(startRow: number, endRow: number, indentString: string): void; + outdentRows(range: Range): void; + moveLinesUp(firstRow: number, lastRow: number): void; + moveLinesDown(firstRow: number, lastRow: number): void; + duplicateLines(firstRow: number, lastRow: number): void; + setUseWrapMode(useWrapMode: boolean): void; + getUseWrapMode(): boolean; + setWrapLimitRange(min: number, max: number): void; + adjustWrapLimit(desiredLimit: number): boolean; + getWrapLimit(): number; + setWrapLimit(limit: number): void; + getWrapLimitRange(): { min: number, max: number }; + getRowLineCount(row: number): number; + getRowWrapIndent(screenRow: number): number; + getScreenLastRowColumn(screenRow: number): number; + getDocumentLastRowColumn(docRow: number, docColumn: number): number; + getdocumentLastRowColumnPosition(docRow: number, docColumn: number): Position; + getRowSplitData(row: number): string | undefined; + getScreenTabSize(screenColumn: number): number; + screenToDocumentRow(screenRow: number, screenColumn: number): number; + screenToDocumentColumn(screenRow: number, screenColumn: number): number; + screenToDocumentPosition(screenRow: number, + screenColumn: number, + offsetX?: number): Position; + documentToScreenPosition(docRow: number, docColumn: number): Position; + documentToScreenPosition(position: Position): Position; + documentToScreenColumn(row: number, docColumn: number): number; + documentToScreenRow(docRow: number, docColumn: number): number; + getScreenLength(): number; + toJSON(): Object; + destroy(): void; + } + + export interface KeyBinding { + setDefaultHandler(handler: KeyboardHandler): void; + setKeyboardHandler(handler: KeyboardHandler): void; + addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; + removeKeyboardHandler(handler: KeyboardHandler): boolean; + getKeyboardHandler(): KeyboardHandler; + getStatusText(): string; + onCommandKey(e: any, hashId: number, keyCode: number): boolean; + onTextInput(text: string): boolean; + } + + interface CommandMap { + [name: string]: Command; + } + + type execEventHandler = (obj: { + editor: Editor, + command: Command, + args: any[] + }) => void; + + export interface CommandManager extends EventEmitter { + byName: CommandMap, + commands: CommandMap, + on(name: 'exec', callback: execEventHandler): Function; + on(name: 'afterExec', callback: execEventHandler): Function; + once(name: string, callback: Function): void; + setDefaultHandler(name: string, callback: Function): void; + removeDefaultHandler(name: string, callback: Function): void; + on(name: string, callback: Function, capturing?: boolean): void; + addEventListener(name: string, callback: Function, capturing?: boolean): void; + off(name: string, callback: Function): void; + removeListener(name: string, callback: Function): void; + removeEventListener(name: string, callback: Function): void; + + exec(command: string, editor: Editor, args: any): boolean; + toggleRecording(editor: Editor): void; + replay(editor: Editor): void; + addCommand(command: Command): void; + addCommands(command: Command[]): void; + removeCommand(command: Command | string, keepCommand?: boolean): void; + removeCommands(command: Command[]): void; + bindKey(key: string | { mac?: string, win?: string}, + command: CommandLike, + position?: number): void; + bindKeys(keys: {[s: string]: Function}): void; + parseKeys(keyPart: string): {key: string, hashId: number}; + findKeyCommand(hashId: number, keyString: string): string | undefined; + handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | {command: string}; + getStatusText(editor: Editor, data: {}): string; + } + + export interface VirtualRenderer extends OptionsProvider, EventEmitter { + readonly container: HTMLElement; + readonly scroller: HTMLElement; + readonly content: HTMLElement; + readonly characterWidth: number; + readonly lineHeight: number; + readonly scrollLeft: number; + readonly scrollTop: number; + readonly $padding: number; + + setOption(name: T, value: VirtualRendererOptions[T]): void; + getOption(name: T): VirtualRendererOptions[T]; + + setSession(session: EditSession): void; + updateLines(firstRow: number, lastRow: number, force?: boolean): void; + updateText(): void; + updateFull(force?: boolean): void; + updateFontSize(): void; + adjustWrapLimit(): boolean; + setAnimatedScroll(shouldAnimate: boolean): void; + getAnimatedScroll(): boolean; + setShowInvisibles(showInvisibles: boolean): void; + getShowInvisibles(): boolean; + setDisplayIndentGuides(display: boolean): void; + getDisplayIndentGuides(): boolean; + setShowPrintMargin(showPrintMargin: boolean): void; + getShowPrintMargin(): boolean; + setPrintMarginColumn(showPrintMargin: boolean): void; + getPrintMarginColumn(): boolean; + setShowGutter(show: boolean): void; + getShowGutter(): boolean; + setFadeFoldWidgets(show: boolean): void; + getFadeFoldWidgets(): boolean; + setHighlightGutterLine(shouldHighlight: boolean): void; + getHighlightGutterLine(): boolean; + getContainerElement(): HTMLElement; + getMouseEventTarget(): HTMLElement; + getTextAreaContainer(): HTMLElement; + getFirstVisibleRow(): number; + getFirstFullyVisibleRow(): number; + getLastFullyVisibleRow(): number; + getLastVisibleRow(): number; + setPadding(padding: number): void; + setScrollMargin(top: number, + bottom: number, + left: number, + right: number): void; + setHScrollBarAlwaysVisible(alwaysVisible: boolean): void; + getHScrollBarAlwaysVisible(): boolean; + setVScrollBarAlwaysVisible(alwaysVisible: boolean): void; + getVScrollBarAlwaysVisible(): boolean; + freeze(): void; + unfreeze(): void; + updateFrontMarkers(): void; + updateBackMarkers(): void; + updateBreakpoints(): void; + setAnnotations(annotations: Annotation[]): void; + updateCursor(): void; + hideCursor(): void; + showCursor(): void; + scrollSelectionIntoView(anchor: Position, + lead: Position, + offset?: number): void; + scrollCursorIntoView(cursor: Position, offset?: number): void; + getScrollTop(): number; + getScrollLeft(): number; + getScrollTopRow(): number; + getScrollBottomRow(): number; + scrollToRow(row: number): void; + alignCursor(cursor: Position | number, alignment: number): number; + scrollToLine(line: number, + center: boolean, + animate: boolean, + callback: () => void): void; + animateScrolling(fromValue: number, callback: () => void): void; + scrollToY(scrollTop: number): void; + scrollToX(scrollLeft: number): void; + scrollTo(x: number, y: number): void; + scrollBy(deltaX: number, deltaY: number): void; + isScrollableBy(deltaX: number, deltaY: number): boolean; + textToScreenCoordinates(row: number, column: number): { pageX: number, pageY: number}; + pixelToScreenCoordinates(x: number, y: number): {row: number, column: number, side: 1|-1, offsetX: number}; + visualizeFocus(): void; + visualizeBlur(): void; + showComposition(position: number): void; + setCompositionText(text: string): void; + hideComposition(): void; + setGhostText(text: string, position: Point): void; + removeGhostText(): void; + setTheme(theme: string, callback?: () => void): void; + getTheme(): string; + setStyle(style: string, include?: boolean): void; + unsetStyle(style: string): void; + setCursorStyle(style: string): void; + setMouseCursor(cursorStyle: string): void; + attachToShadowRoot(): void; + destroy(): void; + } + + + export interface Selection extends EventEmitter { + moveCursorWordLeft(): void; + moveCursorWordRight(): void; + fromOrientedRange(range: Range): void; + setSelectionRange(match: any): void; + getAllRanges(): Range[]; + addRange(range: Range): void; + isEmpty(): boolean; + isMultiLine(): boolean; + setCursor(row: number, column: number): void; + setAnchor(row: number, column: number): void; + getAnchor(): Position; + getCursor(): Position; + isBackwards(): boolean; + getRange(): Range; + clearSelection(): void; + selectAll(): void; + setRange(range: Range, reverse?: boolean): void; + selectTo(row: number, column: number): void; + selectToPosition(pos: any): void; + selectUp(): void; + selectDown(): void; + selectRight(): void; + selectLeft(): void; + selectLineStart(): void; + selectLineEnd(): void; + selectFileEnd(): void; + selectFileStart(): void; + selectWordRight(): void; + selectWordLeft(): void; + getWordRange(): void; + selectWord(): void; + selectAWord(): void; + selectLine(): void; + moveCursorUp(): void; + moveCursorDown(): void; + moveCursorLeft(): void; + moveCursorRight(): void; + moveCursorLineStart(): void; + moveCursorLineEnd(): void; + moveCursorFileEnd(): void; + moveCursorFileStart(): void; + moveCursorLongWordRight(): void; + moveCursorLongWordLeft(): void; + moveCursorBy(rows: number, chars: number): void; + moveCursorToPosition(position: any): void; + moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void; + moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void; + + toJSON(): SavedSelection | SavedSelection[]; + fromJSON(selection: SavedSelection | SavedSelection[]): void; + } + interface SavedSelection { + start: Point; + end: Point; + isBackwards: boolean; + } + + var Selection: { + new(session: EditSession): Selection; + } + + export interface TextInput { + resetSelection(): void; + setAriaOption(activeDescendant: string, role: string): void; + } + + export interface Editor extends OptionsProvider, EventEmitter { + container: HTMLElement; + renderer: VirtualRenderer; + id: string; + commands: CommandManager; + keyBinding: KeyBinding; + session: EditSession; + selection: Selection; + textInput: TextInput; + + on(name: 'blur', callback: (e: Event) => void): void; + on(name: 'input', callback: () => void): void; + on(name: 'change', callback: (delta: Delta) => void): void; + on(name: 'changeSelectionStyle', callback: (obj: { data: string }) => void): void; + on(name: 'changeSession', + callback: (obj: { session: EditSession, oldSession: EditSession }) => void): void; + on(name: 'copy', callback: (obj: { text: string }) => void): void; + on(name: 'focus', callback: (e: Event) => void): void; + on(name: 'paste', callback: (obj: { text: string }) => void): void; + on(name: 'mousemove', callback: (e: any) => void): void; + on(name: 'mouseup', callback: (e: any) => void): void; + on(name: 'mousewheel', callback: (e: any) => void): void; + on(name: 'click', callback: (e: any) => void): void; + on(name: 'guttermousedown', callback: (e: any) => void): void; + on(name: 'gutterkeydown', callback: (e: any) => void): void; + + onPaste(text: string, event: any): void; + + setOption(name: T, value: EditorOptions[T]): void; + getOption(name: T): EditorOptions[T]; + + setKeyboardHandler(keyboardHandler: string, callback?: () => void): void; + setKeyboardHandler(keyboardHandler: KeyboardHandler|null): void; + getKeyboardHandler(): string; + setSession(session: EditSession | undefined): void; + getSession(): EditSession; + setValue(val: string, cursorPos?: number): string; + getValue(): string; + getSelection(): Selection; + resize(force?: boolean): void; + setTheme(theme: string, callback?: () => void): void; + getTheme(): string; + setStyle(style: string): void; + unsetStyle(style: string): void; + getFontSize(): string; + setFontSize(size: number|string): void; + focus(): void; + isFocused(): boolean; + blur(): void; + getSelectedText(): string; + getCopyText(): string; + execCommand(command: string | string[], args?: any): boolean; + insert(text: string, pasted?: boolean): void; + setOverwrite(overwrite: boolean): void; + getOverwrite(): boolean; + toggleOverwrite(): void; + setScrollSpeed(speed: number): void; + getScrollSpeed(): number; + setDragDelay(dragDelay: number): void; + getDragDelay(): number; + setSelectionStyle(val: string): void; + getSelectionStyle(): string; + setHighlightActiveLine(shouldHighlight: boolean): void; + getHighlightActiveLine(): boolean; + setHighlightGutterLine(shouldHighlight: boolean): void; + getHighlightGutterLine(): boolean; + setHighlightSelectedWord(shouldHighlight: boolean): void; + getHighlightSelectedWord(): boolean; + setAnimatedScroll(shouldAnimate: boolean): void; + getAnimatedScroll(): boolean; + setShowInvisibles(showInvisibles: boolean): void; + getShowInvisibles(): boolean; + setDisplayIndentGuides(display: boolean): void; + getDisplayIndentGuides(): boolean; + setShowPrintMargin(showPrintMargin: boolean): void; + getShowPrintMargin(): boolean; + setPrintMarginColumn(showPrintMargin: number): void; + getPrintMarginColumn(): number; + setReadOnly(readOnly: boolean): void; + getReadOnly(): boolean; + setBehavioursEnabled(enabled: boolean): void; + getBehavioursEnabled(): boolean; + setWrapBehavioursEnabled(enabled: boolean): void; + getWrapBehavioursEnabled(): boolean; + setShowFoldWidgets(show: boolean): void; + getShowFoldWidgets(): boolean; + setFadeFoldWidgets(fade: boolean): void; + getFadeFoldWidgets(): boolean; + remove(dir?: 'left' | 'right'): void; + removeWordRight(): void; + removeWordLeft(): void; + removeLineToEnd(): void; + splitLine(): void; + setGhostText(text: string, position: Point): void; + removeGhostText(): void; + transposeLetters(): void; + toLowerCase(): void; + toUpperCase(): void; + indent(): void; + blockIndent(): void; + blockOutdent(): void; + sortLines(): void; + toggleCommentLines(): void; + toggleBlockComment(): void; + modifyNumber(amount: number): void; + removeLines(): void; + duplicateSelection(): void; + moveLinesDown(): void; + moveLinesUp(): void; + moveText(range: Range, toPosition: Point, copy?: boolean): Range; + copyLinesUp(): void; + copyLinesDown(): void; + getFirstVisibleRow(): number; + getLastVisibleRow(): number; + isRowVisible(row: number): boolean; + isRowFullyVisible(row: number): boolean; + selectPageDown(): void; + selectPageUp(): void; + gotoPageDown(): void; + gotoPageUp(): void; + scrollPageDown(): void; + scrollPageUp(): void; + scrollToRow(row: number): void; + scrollToLine(line: number, center: boolean, animate: boolean, callback: () => void): void; + centerSelection(): void; + getCursorPosition(): Point; + getCursorPositionScreen(): Point; + getSelectionRange(): Range; + selectAll(): void; + clearSelection(): void; + moveCursorTo(row: number, column: number): void; + moveCursorToPosition(pos: Point): void; + jumpToMatching(select: boolean, expand: boolean): void; + gotoLine(lineNumber: number, column: number, animate: boolean): void; + navigateTo(row: number, column: number): void; + navigateUp(times?: number): void; + navigateDown(times?: number): void; + navigateLeft(times?: number): void; + navigateRight(times?: number): void; + navigateLineStart(): void; + navigateLineEnd(): void; + navigateFileEnd(): void; + navigateFileStart(): void; + navigateWordRight(): void; + navigateWordLeft(): void; + replace(replacement: string, options?: Partial): number; + replaceAll(replacement: string, options?: Partial): number; + getLastSearchOptions(): Partial; + find(needle: string | RegExp, options?: Partial, animate?: boolean): Ace.Range | undefined; + findNext(options?: Partial, animate?: boolean): void; + findPrevious(options?: Partial, animate?: boolean): void; + findAll(needle: string | RegExp, options?: Partial, additive?: boolean): number; + undo(): void; + redo(): void; + destroy(): void; + setAutoScrollEditorIntoView(enable: boolean): void; + completers: Completer[]; + } + + type CompleterCallback = (error: any, completions: Completion[]) => void; + + interface Completer { + identifierRegexps?: Array, + getCompletions(editor: Editor, + session: EditSession, + position: Point, + prefix: string, + callback: CompleterCallback): void; + getDocTooltip?(item: Completion): undefined | string | Completion; + cancel?(): void; + id?: string; + triggerCharacters?: string[]; + hideInlinePreview?: boolean; + } + + export class AceInline { + show(editor: Editor, completion: Completion, prefix: string): void; + isOpen(): void; + hide(): void; + destroy(): void; + } + + interface CompletionOptions { + matches?: Completion[]; + } + + type CompletionProviderOptions = { + exactMatch?: boolean; + ignoreCaption?: boolean; + } + + type CompletionRecord = { + all: Completion[]; + filtered: Completion[]; + filterText: string; + } | CompletionProviderOptions + + type GatherCompletionRecord = { + prefix: string; + matches: Completion[]; + finished: boolean; + } + + type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; + type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; + + export class CompletionProvider { + insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; + insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; + completions: CompletionRecord; + gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; + provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; + detach(): void; + } + + export class Autocomplete { + constructor(); + autoInsert?: boolean; + autoSelect?: boolean; + autoShown?: boolean; + exactMatch?: boolean; + inlineEnabled?: boolean; + parentNode?: HTMLElement; + setSelectOnHover?: Boolean; + stickySelectionDelay?: Number; + ignoreCaption?: Boolean; + emptyMessage?(prefix: String): String; + getPopup(): AcePopup; + showPopup(editor: Editor, options: CompletionOptions): void; + detach(): void; + destroy(): void; + } + + type AcePopupNavigation = "up" | "down" | "start" | "end"; + + export class AcePopup { + constructor(parentNode: HTMLElement); + setData(list: Completion[], filterText: string): void; + getData(row: number): Completion; + getRow(): number; + getRow(line: number): void; + hide(): void; + show(pos: Point, lineHeight: number, topdownOnly: boolean): void; + tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; + goTo(where: AcePopupNavigation): void; + } +} + + +export const version: string; +export const config: Ace.Config; +export function require(name: string): any; +export function edit(el: Element | string, options?: Partial): Ace.Editor; +export function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; +export const VirtualRenderer: { + new(container: HTMLElement, theme?: string): Ace.VirtualRenderer; +}; +export const EditSession: { + new(text: string | Ace.Document, mode?: Ace.SyntaxMode): Ace.EditSession; +}; +export const UndoManager: { + new(): Ace.UndoManager; +}; +export const Editor: { + new(): Ace.Editor; +}; +export const Range: { + new(startRow: number, startColumn: number, endRow: number, endColumn: number): Ace.Range; + fromPoints(start: Ace.Point, end: Ace.Point): Ace.Range; + comparePoints(p1: Ace.Point, p2: Ace.Point): number; +}; + + +type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; + +type TooltipCommandFunction = (editor: Ace.Editor) => T; + +interface TooltipCommand extends Ace.Command { + enabled: TooltipCommandFunction | boolean, + getValue?: TooltipCommandFunction, + type: "button" | "text" | "checkbox" + iconCssClass: string, + cssClass: string +} + +export class InlineAutocomplete { + constructor(); + getInlineRenderer(): Ace.AceInline; + getInlineTooltip(): CommandBarTooltip; + getCompletionProvider(): Ace.CompletionProvider; + show(editor: Ace.Editor): void; + isOpen(): boolean; + detach(): void; + destroy(): void; + goTo(action: InlineAutocompleteAction): void; + tooltipEnabled: boolean; + commands: Record + getIndex(): number; + setIndex(value: number): void; + getLength(): number; + getData(index?: number): Ace.Completion | undefined; + updateCompletions(options: Ace.CompletionOptions): void; +} + +export class CommandBarTooltip { + constructor(parentElement: HTMLElement); + registerCommand(id: string, command: TooltipCommand): void; + attach(editor: Ace.Editor): void; + updatePosition(): void; + update(): void; + isShown(): boolean; + getAlwaysShow(): boolean; + setAlwaysShow(alwaysShow: boolean): void; + detach(): void; + destroy(): void; +} diff --git a/ace.d.ts b/ace.d.ts index 1219dad4c36..b37451c4fac 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,4 +1,3 @@ - export namespace Ace { type Anchor = import("./src/anchor").Anchor; type Editor = import("./src/editor").Editor; @@ -28,6 +27,39 @@ export namespace Ace { type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; type AppConfig = import("./src/lib/app_config").AppConfig; + + type AfterLoadCallback = (err: Error | null, module: unknown) => void; + type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; + + export interface Config { + get(key: string): any; + + set(key: string, value: any): void; + + all(): { [key: string]: any }; + + moduleUrl(name: string, component?: string): string; + + setModuleUrl(name: string, subst: string): string; + + setLoader(cb: LoaderFunction): void; + + setModuleLoader(name: string, onLoad: Function): void; + + loadModule(moduleName: string | [string, string], + onLoad?: (module: any) => void): void; + + init(packaged: any): any; + + defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; + + resetOptions(obj: any): void; + + setDefaultValue(path: string, name: string, value: any): void; + + setDefaultValues(path: string, optionHash: { [key: string]: any }): void; + } + interface Theme { cssClass?: string; cssText?: string; @@ -35,8 +67,10 @@ export namespace Ace { padding?: number | string; isDark?: boolean; } + interface ScrollBar { setVisible(visible: boolean): void; + [key: string]: any; } @@ -49,19 +83,20 @@ export namespace Ace { } interface LayerConfig { - width : number, - padding : number, - firstRow : number, + width: number, + padding: number, + firstRow: number, firstRowScreen: number, - lastRow : number, - lineHeight : number, - characterWidth : number, - minHeight : number, - maxHeight : number, - offset : number, - height : number, + lastRow: number, + lineHeight: number, + characterWidth: number, + minHeight: number, + maxHeight: number, + offset: number, + height: number, gutterOffset: number } + interface HardWrapOptions { startRow: number; endRow: number; @@ -75,6 +110,7 @@ export namespace Ace { showDelay: number; hideDelay: number; } + interface ScreenCoordinates { row: number, column: number, @@ -84,21 +120,26 @@ export namespace Ace { interface Folding { $foldData: FoldLine[]; + /** * Looks up a fold at a given row/column. Possible values for side: * -1: ignore a fold if fold.start = row/column * +1: ignore a fold if fold.end = row/column **/ getFoldAt(row: number, column: number, side?: number): Ace.Fold; + /** * Returns all folds in the given range. Note, that this will return folds **/ getFoldsInRange(range: Ace.Range | Ace.Delta): Ace.Fold[]; + getFoldsInRangeList(ranges: Ace.Range[] | Ace.Range): Ace.Fold[]; + /** * Returns all folds in the document */ getAllFolds(): Ace.Fold[]; + /** * Returns the string between folds at the given position. * E.g. @@ -117,13 +158,18 @@ export namespace Ace { * fo|obarwolrd -trim=00> "foo" */ getFoldStringAt(row: number, column: number, trim?: number, foldLine?: Ace.FoldLine): string | null; + getFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; + /** * Returns the fold which starts after or contains docRow */ getNextFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; + getFoldedRowCount(first: number, last: number): number; + $addFoldLine(foldLine: FoldLine): Ace.FoldLine; + /** * Adds a new fold. * @returns {Ace.Fold} @@ -131,54 +177,82 @@ export namespace Ace { * passed in range fits an existing fold exactly. */ addFold(placeholder: Ace.Fold | string, range?: Ace.Range): Ace.Fold; + $modified: boolean; + addFolds(folds: Ace.Fold[]): void; + removeFold(fold: Ace.Fold): void; + removeFolds(folds: Ace.Fold[]): void; + expandFold(fold: Ace.Fold): void; + expandFolds(folds: Ace.Fold[]): void; + unfold(location?: number | null | Ace.Point | Ace.Range | Ace.Range[], expandInner?: boolean): Ace.Fold[] | undefined; + /** * Checks if a given documentRow is folded. This is true if there are some * folded parts such that some parts of the line is still visible. **/ isRowFolded(docRow: number, startFoldRow?: Ace.FoldLine): boolean; + getRowFoldEnd(docRow: number, startFoldRow?: Ace.FoldLine): number; + getRowFoldStart(docRow: number, startFoldRow?: Ace.FoldLine): number; + getFoldDisplayLine(foldLine: Ace.FoldLine, endRow?: number | null, endColumn?: number | null, startRow?: number | null, startColumn?: number | null): string; + getDisplayLine(row: number, endColumn: number | null, startRow: number | null, startColumn: number | null): string; + $cloneFoldData(): Ace.FoldLine[]; + toggleFold(tryToUnfold?: boolean): void; + getCommentFoldRange(row: number, column: number, dir?: number): Ace.Range | undefined; + foldAll(startRow?: number | null, endRow?: number | null, depth?: number | null, test?: Function): void; + foldToLevel(level: number): void; + foldAllComments(): void; + $foldStyles: { manual: number; markbegin: number; markbeginend: number; }; $foldStyle: string; + setFoldStyle(style: string): void; + $setFolding(foldMode: Ace.FoldMode): void; + $foldMode: any; foldWidgets: any[]; getFoldWidget: any; getFoldWidgetRange: any; $updateFoldWidgets: any; $tokenizerUpdateFoldWidgets: any; + getParentFoldRangeData(row: number, ignoreCurrent?: boolean): { range?: Ace.Range; firstRange?: Ace.Range; }; + onFoldWidgetClick(row: number, e: any): void; + $toggleFoldWidget(row: number, options: any): Fold | any; + /** * * @param {boolean} [toggleParent] */ toggleFoldWidget(toggleParent?: boolean): void; + updateFoldWidgets(delta: Ace.Delta): void; + tokenizerUpdateFoldWidgets(e: any): void; } @@ -228,10 +302,12 @@ export namespace Ace { closeTagName: Range; }; } + interface IRange { start: Point; end: Point; } + interface LineWidget { el: HTMLElement; rowCount: number; @@ -383,7 +459,7 @@ export namespace Ace { /** * Emitted when a background tokenizer asynchronously processes new rows. */ - "tokenizerUpdate": (e: {data: { first: string, last: string }}) => void; + "tokenizerUpdate": (e: { data: { first: string, last: string } }) => void; /** * Emitted when the current mode changes. * @param e @@ -417,7 +493,7 @@ export namespace Ace { "changeEditor": (e: { editor: Editor }) => void; } - interface EditorEvents{ + interface EditorEvents { "change": (delta: Delta) => void; "changeSelection": () => void; "input": () => void; @@ -425,10 +501,10 @@ export namespace Ace { * Emitted whenever the [[EditSession]] changes. * @param e An object with two properties, `oldSession` and `session`, that represent the old and new [[EditSession]]s. **/ - "changeSession": (e: {oldSession: EditSession, session: EditSession}) => void; + "changeSession": (e: { oldSession: EditSession, session: EditSession }) => void; "blur": (e) => void; "mousedown": (e: MouseEvent) => void; - "mousemove": (e: MouseEvent & {scrollTop?}, editor?: Editor) => void; + "mousemove": (e: MouseEvent & { scrollTop? }, editor?: Editor) => void; "changeStatus": () => void; "keyboardActivity": () => void; "mousewheel": (e: MouseEvent) => void; @@ -453,7 +529,7 @@ export namespace Ace { "changeSelectionStyle": (data: "fullLine" | "screenLine" | "text" | "line") => void; } - interface AcePopupEvents{ + interface AcePopupEvents { "click": (e: MouseEvent) => void; "dblclick": (e: MouseEvent) => void; "tripleclick": (e: MouseEvent) => void; @@ -497,7 +573,7 @@ export namespace Ace { * Fires whenever the background tokeniziers between a range of rows are going to be updated. * @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated. **/ - "update": (e: {first:number, last:number}) => void; + "update": (e: { first: number, last: number }) => void; } interface SelectionEvents { @@ -550,6 +626,7 @@ export namespace Ace { _signal(eventName: string, e: any): void; _emit(eventName: string, e: any): void; + _dispatchEvent(eventName: string, e: any): void; } @@ -606,8 +683,8 @@ export namespace Ace { exec?: (editor?: Editor | any, args?: any) => void; isAvailable?: (editor: Editor) => boolean; description?: string, - multiSelectAction?: "forEach"|"forEachLine"|Function, - scrollIntoView?: true|"cursor"|"center"|"selectionPart"|"animate"|"selection"|"none", + multiSelectAction?: "forEach" | "forEachLine" | Function, + scrollIntoView?: true | "cursor" | "center" | "selectionPart" | "animate" | "selection" | "none", aceCommandGroup?: string, passEvent?: boolean, level?: number, @@ -634,6 +711,7 @@ export namespace Ace { marker: any, session: EditSession, config: any) => void; + [key: string]: any; } @@ -705,7 +783,7 @@ export namespace Ace { closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; } - type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string | Range) => ({ text: string, selection: number[] } | Range) & {[key: string]: any} | undefined; + type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string | Range) => ({ text: string, selection: number[] } | Range) & { [key: string]: any } | undefined; type BehaviorMap = Record>; interface Behaviour { @@ -730,7 +808,7 @@ export namespace Ace { /** * quotes used by language mode */ - $quotes: {[quote: string]: string}; + $quotes: { [quote: string]: string }; HighlightRules: { new(config: any): HighlightRules }; //TODO: fix this @@ -744,13 +822,13 @@ export namespace Ace { /** * characters that indicate the start and end of a block comment */ - blockComment?: {start: string, end: string} + blockComment?: { start: string, end: string } tokenRe?: RegExp; nonTokenRe?: RegExp; /** * An object containing conditions to determine whether to apply matching quote or not. */ - $pairQuotesAfter: {[quote: string]: RegExp} + $pairQuotesAfter: { [quote: string]: RegExp } $tokenizer: Tokenizer; $highlightRules: HighlightRules; $embeds?: string[]; @@ -792,7 +870,9 @@ export namespace Ace { prefix: string): Completion[]; $getIndent(line: string): string; + $createKeywordList(): string[]; + $delegator(method: string, args: IArguments, defaultHandler): any; } @@ -812,6 +892,7 @@ export namespace Ace { } type KeyBinding = import("./src/keyboard/keybinding").KeyBinding; + interface CommandMap { [name: string]: Command; } @@ -824,8 +905,10 @@ export namespace Ace { interface CommandManagerEvents { on(name: 'exec', callback: execEventHandler): Function; + on(name: 'afterExec', callback: execEventHandler): Function; } + type CommandManager = import("./src/commands/command_manager").CommandManager; @@ -842,7 +925,7 @@ export namespace Ace { interface TextInput { resetSelection(): void; - setAriaOption(options?: {activeDescendant: string, role: string, setLabel}): void; + setAriaOption(options?: { activeDescendant: string, role: string, setLabel }): void; } type CompleterCallback = (error: any, completions: Completion[]) => void; @@ -895,13 +978,13 @@ export namespace Ace { * Adds the selection and cursor. * @param orientedRange A range containing a cursor **/ - addSelectionMarker: (orientedRange: Ace.Range & {marker?}) => Ace.Range & {marker?}, + addSelectionMarker: (orientedRange: Ace.Range & { marker? }) => Ace.Range & { marker? }, /** * Removes the selection marker. * @param range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. **/ - removeSelectionMarker: (range: Ace.Range & {marker?}) => void, - removeSelectionMarkers: (ranges: (Ace.Range & {marker?})[]) => void, + removeSelectionMarker: (range: Ace.Range & { marker? }) => void, + removeSelectionMarkers: (ranges: (Ace.Range & { marker? })[]) => void, $onAddRange: (e) => void, $onRemoveRange: (e) => void, $onMultiSelect: (e) => void, @@ -955,7 +1038,7 @@ export namespace Ace { $blockSelectEnabled?: boolean, } - interface CodeLenseEditorExtension{ + interface CodeLenseEditorExtension { codeLensProviders?: any[]; $codeLensClickHandler?: any; $updateLenses?: () => void; @@ -981,55 +1064,69 @@ export namespace Ace { interface MultiSelectProperties { ranges: Ace.Range[] | null; rangeList: Ace.RangeList | null; + /** * Adds a range to a selection by entering multiselect mode, if necessary. * @param {Ace.Range} range The new range to add * @param {Boolean} [$blockChangeEvents] Whether or not to block changing events **/ addRange(range: Ace.Range, $blockChangeEvents?: boolean): any; + inMultiSelectMode: boolean; + /** * @param {Ace.Range} [range] **/ toSingleRange(range?: Ace.Range): void; + /** * Removes a Range containing pos (if it exists). * @param {Ace.Point} pos The position to remove, as a `{row, column}` object **/ substractPoint(pos: Ace.Point): any; + /** * Merges overlapping ranges ensuring consistency after changes **/ mergeOverlappingRanges(): void; + /** * @param {Ace.Range} range */ $onAddRange(range: Ace.Range): void; + rangeCount: number; + /** * * @param {Ace.Range[]} removed */ $onRemoveRange(removed: Ace.Range[]): void; + /** * adds multicursor support to selection */ $initRangeList(): void; + /** * Returns a concatenation of all the ranges. * @returns {Ace.Range[]} **/ getAllRanges(): Ace.Range[]; + /** * Splits all the ranges into lines. **/ splitIntoLines(): void; + /** */ joinSelections(): void; + /** **/ toggleBlockSelection(): void; + /** * * Gets list of ranges composing rectangular block on the screen @@ -1070,12 +1167,16 @@ export namespace Ace { export const version: string; export const config: Ace.Config; + export function require(name: string): any; + export function edit(el: string | (Element & { env?; value?; }), options?: Partial): Ace.Editor; + export function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; + export const VirtualRenderer: { new(container: HTMLElement, theme?: string): Ace.VirtualRenderer; }; @@ -1086,7 +1187,7 @@ export const UndoManager: { new(): Ace.UndoManager; }; export const Editor: { - new(): Ace.Editor; + new(renderer: Ace.VirtualRenderer, session?: Ace.EditSession, options?: Partial): Ace.Editor; }; export const Range: { new(startRow: number, startColumn: number, endRow: number, endColumn: number): Ace.Range; @@ -1098,12 +1199,10 @@ export type InlineAutocomplete = Ace.InlineAutocomplete; export type CommandBarTooltip = Ace.CommandBarTooltip; - - declare module "./src/anchor" { export interface Anchor extends Ace.EventEmitter { markerId?: number; - document?: Ace.Document; + document: Ace.Document; } @@ -1127,8 +1226,7 @@ declare module "./src/background_tokenizer" { } declare module "./src/document" { - export interface Document extends - Ace.EventEmitter { + export interface Document extends Ace.EventEmitter { } @@ -1137,8 +1235,7 @@ declare module "./src/document" { declare module "./src/editor" { export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider, Ace.EventEmitter, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, - Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension - { + Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension { session: Ace.EditSession; $mergeUndoDeltas?: any, $highlightSelectedWord?: boolean, @@ -1162,11 +1259,9 @@ declare module "./src/editor" { } declare module "./src/edit_session" { - export interface EditSession extends - Ace.EventEmitter, + export interface EditSession extends Ace.EventEmitter, Ace.OptionsProvider, - Ace.Folding, Ace.BracketMatch - { + Ace.Folding, Ace.BracketMatch { doc: Ace.Document, $highlightLineMarker?: { start: Ace.Point, @@ -1190,12 +1285,14 @@ declare module "./src/edit_session" { lineWidgetsWidth?: number, $getWidgetScreenLength?: () => number, _changedWidgets?: any, - $options:any, + $options: any, $wrapMethod?: any, $enableVarChar?: any, - $wrap?:any, + $wrap?: any, $navigateWithinSoftTabs?: boolean, + getSelectionMarkers(): any[], + $selectionMarkers?: any[], gutterRenderer?: any, $firstLineNumber?: number, @@ -1226,6 +1323,7 @@ declare module "./src/placeholder" { declare module "./src/scrollbar" { export interface VScrollBar extends Ace.EventEmitter { } + export interface HScrollBar extends Ace.EventEmitter { } } @@ -1233,6 +1331,7 @@ declare module "./src/scrollbar" { declare module "./src/scrollbar_custom" { export interface VScrollBar extends Ace.EventEmitter { } + export interface HScrollBar extends Ace.EventEmitter { } } @@ -1259,8 +1358,7 @@ declare module "./src/range" { } declare module "./src/virtual_renderer" { - export interface VirtualRenderer extends - Ace.EventEmitter, Ace.OptionsProvider { + export interface VirtualRenderer extends Ace.EventEmitter, Ace.OptionsProvider { $customScrollbar?: boolean, $extraHeight?: number, $showGutter?: boolean, @@ -1310,7 +1408,7 @@ declare module "./src/commands/command_manager" { declare module "./src/autocomplete/popup" { - export interface AcePopup extends Ace.AcePopupWithEditor { + export interface AcePopup extends Ace.AcePopupWithEditor { setSelectOnHover: (val: boolean) => void, setRow: (line: number) => void, getRow: () => number, @@ -1400,7 +1498,3 @@ declare module "./src/mouse/default_gutter_handler" { export interface GutterHandler { } } - -declare module "./src/lib/keys" { - export function keyCodeToString(keyCode: string): string -} diff --git a/src/ace.js b/src/ace.js index 1c75696bbe1..47ecb6a841d 100644 --- a/src/ace.js +++ b/src/ace.js @@ -73,7 +73,7 @@ exports.edit = function(el, options) { /** * Creates a new [[EditSession]], and returns the associated [[Document]]. * @param {import('./document').Document | String} text {:textParam} - * @param {import("../ace").Ace.SyntaxMode} [mode] {:modeParam} + * @param {import("../").Ace.SyntaxMode} [mode] {:modeParam} * @returns {EditSession} **/ exports.createEditSession = function(text, mode) { diff --git a/src/anchor.js b/src/anchor.js index c1109405f91..7e1dd89f521 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -13,7 +13,7 @@ class Anchor { * Creates a new `Anchor` and associates it with a document. * * @param {Document} doc The document to associate with the anchor - * @param {Number|import("../ace").Ace.Point} row The starting row position + * @param {Number|import("../").Ace.Point} row The starting row position * @param {Number} [column] The starting column position **/ constructor(doc, row, column) { @@ -28,7 +28,7 @@ class Anchor { /** * Returns an object identifying the `row` and `column` position of the current anchor. - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} **/ getPosition() { return this.$clipPositionToDocument(this.row, this.column); @@ -45,7 +45,7 @@ class Anchor { /** * Internal function called when `"change"` event fired. - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ onChange(delta) { if (delta.start.row == delta.end.row && delta.start.row != this.row) @@ -114,7 +114,7 @@ class Anchor { * Clips the anchor position to the specified row and column. * @param {Number} row The row index to clip the anchor to * @param {Number} column The column index to clip the anchor to - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} * **/ $clipPositionToDocument(row, column) { diff --git a/src/apply_delta.js b/src/apply_delta.js index e52c78d40b8..d5c7b6a2218 100644 --- a/src/apply_delta.js +++ b/src/apply_delta.js @@ -43,7 +43,7 @@ function validateDelta(docLines, delta) { /** * Applies a delta to a document. * @param {string[]} docLines - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta * @param [doNotValidate] */ exports.applyDelta = function(docLines, delta, doNotValidate) { diff --git a/src/autocomplete.js b/src/autocomplete.js index ca71ab39d87..6854516fe4e 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -23,7 +23,7 @@ var config = require("./config"); * @property {string} [docText] - a plain text that would be displayed as an additional popup. If `docHTML` exists, * it would be used instead of `docText`. * @property {string} [completerId] - the identifier of the completer - * @property {import("../ace").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental) + * @property {import("../").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental) * @property {string} [command] - A command to be executed after the completion is inserted (experimental) * @property {string} [snippet] - a text snippet that would be inserted when the completion is selected * @property {string} [value] - The text that would be inserted when selecting this completion. @@ -361,7 +361,7 @@ class Autocomplete { /** * This is the entry point for the autocompletion class, triggers the actions which collect and display suggestions * @param {Editor} editor - * @param {import("../ace").Ace.CompletionOptions} options + * @param {import("../").Ace.CompletionOptions} options */ showPopup(editor, options) { if (this.editor) @@ -401,7 +401,7 @@ class Autocomplete { /** * @param {boolean} keepPopupPosition - * @param {import("../ace").Ace.CompletionOptions} options + * @param {import("../").Ace.CompletionOptions} options */ updateCompletions(keepPopupPosition, options) { if (keepPopupPosition && this.base && this.completions) { @@ -665,7 +665,7 @@ class CompletionProvider { /** - * @param {{pos: import("../ace").Ace.Position, prefix: string}} initialPosition + * @param {{pos: import("../").Ace.Position, prefix: string}} initialPosition */ constructor(initialPosition) { this.initialPosition = initialPosition; @@ -675,7 +675,7 @@ class CompletionProvider { /** * @param {Editor} editor * @param {number} index - * @param {import("../ace").Ace.CompletionProviderOptions} [options] + * @param {import("../").Ace.CompletionProviderOptions} [options] * @returns {boolean} */ insertByIndex(editor, index, options) { @@ -688,7 +688,7 @@ class CompletionProvider { /** * @param {Editor} editor * @param {Completion} data - * @param {import("../ace").Ace.CompletionProviderOptions} [options] + * @param {import("../").Ace.CompletionProviderOptions} [options] * @returns {boolean} */ insertMatch(editor, data, options) { @@ -752,7 +752,7 @@ class CompletionProvider { /** * @param {Editor} editor - * @param {import("../ace").Ace.CompletionCallbackFunction} callback + * @param {import("../").Ace.CompletionCallbackFunction} callback */ gatherCompletions(editor, callback) { var session = editor.getSession(); @@ -787,7 +787,7 @@ class CompletionProvider { * This is the entry point to the class, it gathers, then provides the completions asynchronously via callback. * The callback function may be called multiple times, the last invokation is marked with a `finished` flag * @param {Editor} editor - * @param {import("../ace").Ace.CompletionProviderOptions} options + * @param {import("../").Ace.CompletionProviderOptions} options * @param {(err: Error | undefined, completions: FilteredList | [], finished: boolean) => void} callback */ provideCompletions(editor, options, callback) { diff --git a/src/autocomplete/inline.js b/src/autocomplete/inline.js index 614760204b4..01fd62d6c48 100644 --- a/src/autocomplete/inline.js +++ b/src/autocomplete/inline.js @@ -18,7 +18,7 @@ class AceInline { /** * Renders the completion as ghost text to the current cursor position * @param {Editor} editor - * @param {import("../../ace").Ace.Completion} completion + * @param {import("../../").Ace.Completion} completion * @param {string} prefix * @returns {boolean} True if the completion could be rendered to the editor, false otherwise */ diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 99896bb0957..35901371e20 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -179,7 +179,7 @@ class AcePopup { var bgTokenizer = popup.session.bgTokenizer; bgTokenizer.$tokenizeRow = function (row) { - /**@type {import("../../ace").Ace.Completion &{name?, className?, matchMask?, message?}}*/ + /**@type {import("../../").Ace.Completion &{name?, className?, matchMask?, message?}}*/ var data = popup.data[row]; var tokens = []; if (!data) return tokens; diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index a0e494a16ba..190191d63a8 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -136,7 +136,7 @@ class BackgroundTokenizer { } /** - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ $updateOnChange(delta) { var startRow = delta.start.row; @@ -171,7 +171,7 @@ class BackgroundTokenizer { /** * Gives list of [[Token]]'s of the row. (tokens are cached) * @param {Number} row The row to get tokens at - * @returns {import("../ace").Ace.Token[]} + * @returns {import("../").Ace.Token[]} **/ getTokens(row) { return this.lines[row] || this.$tokenizeRow(row); diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index 104c7f08d66..0f9f8ef4899 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -26,7 +26,7 @@ class CommandManager extends MultiHashHandler{ /** * - * @param {string | string[] | import("../../ace").Ace.Command} command + * @param {string | string[] | import("../../").Ace.Command} command * @param {Editor} editor * @param {any} args * @returns {boolean} diff --git a/src/commands/default_commands.js b/src/commands/default_commands.js index d963851d763..5be0884c055 100644 --- a/src/commands/default_commands.js +++ b/src/commands/default_commands.js @@ -12,7 +12,7 @@ function bindKey(win, mac) { multiSelectAction: "forEach"|"forEachLine"|function|undefined, scrollIntoView: true|"cursor"|"center"|"selectionPart" */ -/**@type {import("../../ace").Ace.Command[]} */ +/**@type {import("../../").Ace.Command[]} */ exports.commands = [{ name: "showSettingsMenu", description: "Show settings menu", diff --git a/src/commands/multi_select_commands.js b/src/commands/multi_select_commands.js index 0c5dcd02d44..928803f418e 100644 --- a/src/commands/multi_select_commands.js +++ b/src/commands/multi_select_commands.js @@ -1,7 +1,7 @@ /** * commands to enter multiselect mode - * @type {import("../../ace").Ace.Command[]} + * @type {import("../../").Ace.Command[]} */ exports.defaultCommands = [{ name: "addCursorAbove", @@ -92,7 +92,7 @@ exports.defaultCommands = [{ /** * commands active only in multiselect mode - * @type {import("../../ace").Ace.Command[]} + * @type {import("../../").Ace.Command[]} */ exports.multiSelectCommands = [{ name: "singleSelection", diff --git a/src/document.js b/src/document.js index 43e7ff3a519..f1f91efc350 100644 --- a/src/document.js +++ b/src/document.js @@ -90,7 +90,7 @@ class Document { /** * [Sets the new line mode.]{: #Document.setNewLineMode.desc} - * @param {import("../ace").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} + * @param {import("../").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} **/ setNewLineMode(newLineMode) { @@ -103,7 +103,7 @@ class Document { /** * [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode} - * @returns {import("../ace").Ace.NewLineMode} + * @returns {import("../").Ace.NewLineMode} **/ getNewLineMode() { return this.$newLineMode; @@ -155,7 +155,7 @@ class Document { /** * Returns all the text within `range` as a single string. - * @param {import("../ace").Ace.IRange} range The range to work with. + * @param {import("../").Ace.IRange} range The range to work with. * * @returns {String} **/ @@ -165,7 +165,7 @@ class Document { /** * Returns all the text within `range` as an array of lines. - * @param {import("../ace").Ace.IRange} range The range to work with. + * @param {import("../").Ace.IRange} range The range to work with. * * @returns {string[]} **/ @@ -212,7 +212,7 @@ class Document { /** * @param position - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} * @deprecated */ @@ -223,9 +223,9 @@ class Document { /** * Inserts a block of `text` at the indicated `position`. - * @param {import("../ace").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` + * @param {import("../").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text to insert - * @returns {import("../ace").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @returns {import("../").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. **/ insert(position, text) { @@ -243,9 +243,9 @@ class Document { * 1. This does NOT handle newline characters (single-line text only). * 2. This is faster than the `insert` method for single-line text insertions. * - * @param {import("../ace").Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` + * @param {import("../").Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text - * @returns {import("../ace").Ace.Point} Returns an object containing the final row and column, like this: + * @returns {import("../").Ace.Point} Returns an object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -269,7 +269,7 @@ class Document { * * @param {number} row * @param {number} column - * @return {import("../ace").Ace.Point} + * @return {import("../").Ace.Point} */ clippedPos(row, column) { var length = this.getLength(); @@ -289,8 +289,8 @@ class Document { } /** - * @param {import("../ace").Ace.Point} pos - * @return {import("../ace").Ace.Point} + * @param {import("../").Ace.Point} pos + * @return {import("../").Ace.Point} */ clonePos(pos) { return {row: pos.row, column: pos.column}; @@ -299,15 +299,15 @@ class Document { /** * @param {number} row * @param {number} column - * @return {import("../ace").Ace.Point} + * @return {import("../").Ace.Point} */ pos(row, column) { return {row: row, column: column}; } /** - * @param {import("../ace").Ace.Point} position - * @return {import("../ace").Ace.Point} + * @param {import("../").Ace.Point} position + * @return {import("../").Ace.Point} * @private */ $clipPosition(position) { @@ -352,9 +352,9 @@ class Document { /** * Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event. - * @param {import("../ace").Ace.Position} position + * @param {import("../").Ace.Position} position * @param {string[]} lines An array of strings - * @returns {import("../ace").Ace.Point} Contains the final row and column, like this: + * @returns {import("../").Ace.Point} Contains the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -383,8 +383,8 @@ class Document { /** * Removes the `range` from the document. - * @param {import("../ace").Ace.IRange} range A specified Range to remove - * @returns {import("../ace").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @param {import("../").Ace.IRange} range A specified Range to remove + * @returns {import("../").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -404,7 +404,7 @@ class Document { * @param {Number} row The row to remove from * @param {Number} startColumn The column to start removing at * @param {Number} endColumn The column to stop removing at - * @returns {import("../ace").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. + * @returns {import("../").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. **/ removeInLine(row, startColumn, endColumn) { @@ -476,9 +476,9 @@ class Document { /** * Replaces a range in the document with the new `text`. - * @param {Range | import("../ace").Ace.IRange} range A specified Range to replace + * @param {Range | import("../").Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {import("../ace").Ace.Point} Returns an object containing the final row and column, like this: + * @returns {import("../").Ace.Point} Returns an object containing the final row and column, like this: * {row: endRow, column: 0} * If the text and range are empty, this function returns an object containing the current `range.start` value. * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value. @@ -510,7 +510,7 @@ class Document { /** * Applies all changes in `deltas` to the document. - * @param {import("../ace").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @param {import("../").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) **/ applyDeltas(deltas) { @@ -521,7 +521,7 @@ class Document { /** * Reverts all changes in `deltas` from the document. - * @param {import("../ace").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @param {import("../").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) **/ revertDeltas(deltas) { @@ -532,7 +532,7 @@ class Document { /** * Applies `delta` to the document. - * @param {import("../ace").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {import("../").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) * @param {boolean} [doNotValidate] **/ @@ -554,7 +554,7 @@ class Document { } /** - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ $safeApplyDelta(delta) { @@ -570,7 +570,7 @@ class Document { /** * - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta * @param {number} MAX */ @@ -608,7 +608,7 @@ class Document { /** * Reverts `delta` from the document. - * @param {import("../ace").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {import("../").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) **/ revertDelta(delta) { @@ -634,7 +634,7 @@ class Document { * * @param {Number} index An index to convert * @param {Number} [startRow=0] The row from which to start the conversion - * @returns {import("../ace").Ace.Point} A `{row, column}` object of the `index` position + * @returns {import("../").Ace.Point} A `{row, column}` object of the `index` position */ indexToPosition(index, startRow) { var lines = this.$lines || this.getAllLines(); @@ -659,7 +659,7 @@ class Document { * * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second. * - * @param {import("../ace").Ace.Point} pos The `{row, column}` to convert + * @param {import("../").Ace.Point} pos The `{row, column}` to convert * @param {Number} [startRow=0] The row from which to start the conversion * @returns {Number} The index position in the document */ diff --git a/src/edit_session.js b/src/edit_session.js index 875978e4646..62c602a9ff0 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -6,7 +6,7 @@ * @typedef {import("./edit_session/fold_line").FoldLine} FoldLine */ /** - * @typedef {import("../ace").Ace.Point} Point + * @typedef {import("../").Ace.Point} Point */ /** * @typedef {import("./layer/font_metrics").FontMetrics} FontMetrics @@ -26,7 +26,7 @@ var SearchHighlight = require("./search_highlight").SearchHighlight; /** * @typedef TextMode - * @type {import("../ace").Ace.SyntaxMode} + * @type {import("../").Ace.SyntaxMode} */ /** @@ -38,7 +38,7 @@ class EditSession { /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. * @param {Document | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} - * @param {import("../ace").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} + * @param {import("../").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} **/ constructor(text, mode) { /**@type {Document}*/this.doc; @@ -162,7 +162,7 @@ class EditSession { /** * - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ onChange(delta) { this.$modified = true; @@ -234,7 +234,7 @@ class EditSession { /** * Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows. * @param {Number} row The row to start at - * @returns {import("../ace").Ace.Token[]} + * @returns {import("../").Ace.Token[]} **/ getTokens(row) { return this.bgTokenizer.getTokens(row); @@ -244,7 +244,7 @@ class EditSession { * Returns an object indicating the token at the current row. The object has two properties: `index` and `start`. * @param {Number} row The row number to retrieve from * @param {Number} column The column number to retrieve from - * @returns {import("../ace").Ace.Token} + * @returns {import("../").Ace.Token} * **/ getTokenAt(row, column) { @@ -478,7 +478,7 @@ class EditSession { * Adds a new marker to the given `Range`. If `inFront` is `true`, a front marker is defined, and the `'changeFrontMarker'` event fires; otherwise, the `'changeBackMarker'` event fires. * @param {Range} range Define the range of the marker * @param {String} clazz Set the CSS class for the marker - * @param {import("../ace").Ace.MarkerRenderer | "fullLine" | "screenLine" | "text" | "line"} [type] Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. + * @param {import("../").Ace.MarkerRenderer | "fullLine" | "screenLine" | "text" | "line"} [type] Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. * @param {Boolean} [inFront] Set to `true` to establish a front marker * * @return {Number} The new marker id @@ -508,10 +508,10 @@ class EditSession { /** * Adds a dynamic marker to the session. - * @param {import("../ace").Ace.MarkerLike} marker object with update method + * @param {import("../").Ace.MarkerLike} marker object with update method * @param {Boolean} [inFront] Set to `true` to establish a front marker * - * @return {import("../ace").Ace.MarkerLike} The added marker + * @return {import("../").Ace.MarkerLike} The added marker **/ addDynamicMarker(marker, inFront) { if (!marker.update) @@ -549,7 +549,7 @@ class EditSession { * Returns an object containing all of the markers, either front or back. * @param {Boolean} [inFront] If `true`, indicates you only want front markers; `false` indicates only back markers * - * @returns {{[id: number]: import("../ace").Ace.MarkerLike}} + * @returns {{[id: number]: import("../").Ace.MarkerLike}} **/ getMarkers(inFront) { return inFront ? this.$frontMarkers : this.$backMarkers; @@ -599,7 +599,7 @@ class EditSession { */ /** * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event. - * @param {import("../ace").Ace.Annotation[]} annotations A list of annotations + * @param {import("../").Ace.Annotation[]} annotations A list of annotations **/ setAnnotations(annotations) { this.$annotations = annotations; @@ -608,7 +608,7 @@ class EditSession { /** * Returns the annotations for the `EditSession`. - * @returns {import("../ace").Ace.Annotation[]} + * @returns {import("../").Ace.Annotation[]} **/ getAnnotations() { return this.$annotations || []; @@ -695,7 +695,7 @@ class EditSession { /** * {:Document.setNewLineMode.desc} - * @param {import("../ace").Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} + * @param {import("../").Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} * * * @related Document.setNewLineMode @@ -707,7 +707,7 @@ class EditSession { /** * * Returns the current new line mode. - * @returns {import("../ace").Ace.NewLineMode} + * @returns {import("../").Ace.NewLineMode} * @related Document.getNewLineMode **/ getNewLineMode() { @@ -736,7 +736,7 @@ class EditSession { /** * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. - * @param {import("../ace").Ace.SyntaxMode | string} mode Set a new text mode + * @param {import("../").Ace.SyntaxMode | string} mode Set a new text mode * @param {() => void} [cb] optional callback **/ setMode(mode, cb) { @@ -985,7 +985,7 @@ class EditSession { /** * {:Document.getTextRange.desc} - * @param {import("../ace").Ace.IRange} [range] The range to work with + * @param {import("../").Ace.IRange} [range] The range to work with * * @returns {String} **/ @@ -1005,7 +1005,7 @@ class EditSession { /** * Removes the `range` from the document. - * @param {import("../ace").Ace.IRange} range A specified Range to remove + * @param {import("../").Ace.IRange} range A specified Range to remove * @returns {Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -1027,7 +1027,7 @@ class EditSession { /** * Reverts previous changes to your document. - * @param {import("../ace").Ace.Delta[]} deltas An array of previous changes + * @param {import("../").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] [If `true`, doesn't select the range of where the change occured]{: #dontSelect} **/ undoChanges(deltas, dontSelect) { @@ -1056,7 +1056,7 @@ class EditSession { /** * Re-implements a previously undone change to your document. - * @param {import("../ace").Ace.Delta[]} deltas An array of previous changes + * @param {import("../").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] {:dontSelect} **/ redoChanges(deltas, dontSelect) { @@ -1093,7 +1093,7 @@ class EditSession { /** * - * @param {import("../ace").Ace.Delta[]} deltas + * @param {import("../").Ace.Delta[]} deltas * @param {boolean} [isUndo] * @return {Range} */ @@ -1138,7 +1138,7 @@ class EditSession { /** * Replaces a range in the document with the new `text`. * - * @param {import("../ace").Ace.IRange} range A specified Range to replace + * @param {import("../").Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement * @returns {Point} An object containing the final row and column, like this: * ``` @@ -1516,7 +1516,7 @@ class EditSession { /** * - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ $updateInternalDataOnChange(delta) { var useWrapMode = this.$useWrapMode; @@ -2376,7 +2376,7 @@ EditSession.prototype.$wrapLimitRange = { }; /** * - * @type {null | import("../ace").Ace.LineWidget[]} + * @type {null | import("../").Ace.LineWidget[]} */ EditSession.prototype.lineWidgets = null; EditSession.prototype.isFullWidth = isFullWidth; diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index ebbf2c9a714..8fff6b24b56 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -9,7 +9,7 @@ function BracketMatch() { /** * - * @param {import("../../ace").Ace.Point} position + * @param {import("../../").Ace.Point} position * @param {string} [chr] * @this {EditSession} */ @@ -30,7 +30,7 @@ function BracketMatch() { }; /** - * @param {import("../../ace").Ace.Point} pos + * @param {import("../../").Ace.Point} pos * @return {null|Range} * @this {EditSession} */ @@ -80,7 +80,7 @@ function BracketMatch() { * * two Ranges if there is opening and closing brackets; * * one Range if there is only one bracket * - * @param {import("../../ace").Ace.Point} pos + * @param {import("../../").Ace.Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} * @this {EditSession} @@ -126,9 +126,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {import("../../ace").Ace.Point} position + * @param {import("../../").Ace.Point} position * @param {RegExp} [typeRe] - * @return {import("../../ace").Ace.Point|null} + * @return {import("../../").Ace.Point|null} * @this {EditSession} */ this.$findOpeningBracket = function(bracket, position, typeRe) { @@ -192,9 +192,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {import("../../ace").Ace.Point} position + * @param {import("../../").Ace.Point} position * @param {RegExp} [typeRe] - * @return {import("../../ace").Ace.Point|null} + * @return {import("../../").Ace.Point|null} * @this {EditSession} */ this.$findClosingBracket = function(bracket, position, typeRe) { @@ -257,7 +257,7 @@ function BracketMatch() { /** * Returns [[Range]]'s for matching tags and tag names, if there are any - * @param {import("../../ace").Ace.Point} pos + * @param {import("../../").Ace.Point} pos * @returns {{closeTag: Range, closeTagName: Range, openTag: Range, openTagName: Range} | undefined} * @this {EditSession} */ diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index ff65f3c3c4a..002c76f69cf 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -98,7 +98,7 @@ class Fold extends RangeList { } /** - * @param {import("../../ace").Ace.IRange} range + * @param {import("../../").Ace.IRange} range */ restoreRange(range) { return restoreRange(range, this.start); @@ -107,8 +107,8 @@ class Fold extends RangeList { } /** - * @param {import("../../ace").Ace.Point} point - * @param {import("../../ace").Ace.Point} anchor + * @param {import("../../").Ace.Point} point + * @param {import("../../").Ace.Point} anchor */ function consumePoint(point, anchor) { point.row -= anchor.row; @@ -116,16 +116,16 @@ function consumePoint(point, anchor) { point.column -= anchor.column; } /** - * @param {import("../../ace").Ace.IRange} range - * @param {import("../../ace").Ace.Point} anchor + * @param {import("../../").Ace.IRange} range + * @param {import("../../").Ace.Point} anchor */ function consumeRange(range, anchor) { consumePoint(range.start, anchor); consumePoint(range.end, anchor); } /** - * @param {import("../../ace").Ace.Point} point - * @param {import("../../ace").Ace.Point} anchor + * @param {import("../../").Ace.Point} point + * @param {import("../../").Ace.Point} anchor */ function restorePoint(point, anchor) { if (point.row == 0) @@ -133,8 +133,8 @@ function restorePoint(point, anchor) { point.row += anchor.row; } /** - * @param {import("../../ace").Ace.IRange} range - * @param {import("../../ace").Ace.Point} anchor + * @param {import("../../").Ace.IRange} range + * @param {import("../../").Ace.Point} anchor */ function restoreRange(range, anchor) { restorePoint(range.start, anchor); diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index f8775dcfd71..ddcd6b788d5 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -244,7 +244,7 @@ class FoldLine { /** * @param {number} idx - * @return {import("../../ace").Ace.Point} + * @return {import("../../").Ace.Point} */ idxToPosition(idx) { var lastFoldEndColumn = 0; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 0554e2e5c09..0ab6fd4d233 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -8,7 +8,7 @@ var TokenIterator = require("../token_iterator").TokenIterator; var MouseEvent = require("../mouse/mouse_event").MouseEvent; /** - * @typedef {import("../edit_session").EditSession & import("../../ace").Ace.Folding} IFolding + * @typedef {import("../edit_session").EditSession & import("../../").Ace.Folding} IFolding */ /** @@ -46,7 +46,7 @@ function Folding() { /** * Returns all folds in the given range. Note, that this will return folds - * @param {Range| import("../../ace").Ace.Delta} range + * @param {Range| import("../../").Ace.Delta} range * @returns {Fold[]} **/ this.getFoldsInRange = function(range) { @@ -476,7 +476,7 @@ function Folding() { /** * - * @param {number|null|import("../../ace").Ace.Point|Range|Range[]} [location] + * @param {number|null|import("../../").Ace.Point|Range|Range[]} [location] * @param {boolean} [expandInner] * @return {Fold[]| undefined} */ @@ -843,7 +843,7 @@ function Folding() { }; /** - * @param {import("../../ace").Ace.FoldMode} foldMode + * @param {import("../../").Ace.FoldMode} foldMode */ this.$setFolding = function(foldMode) { if (this.$foldMode == foldMode) @@ -1005,7 +1005,7 @@ function Folding() { }; /** - * @param {import("../../ace").Ace.Delta} delta + * @param {import("../../").Ace.Delta} delta */ this.updateFoldWidgets = function(delta) { var firstRow = delta.start.row; diff --git a/src/editor.js b/src/editor.js index 9cc588dd54b..18aecbc0f0f 100644 --- a/src/editor.js +++ b/src/editor.js @@ -44,7 +44,7 @@ class Editor { * * @param {VirtualRenderer} renderer Associated `VirtualRenderer` that draws everything * @param {EditSession} [session] The `EditSession` to refer to - * @param {Object} [options] The default options + * @param {Partial} [options] The default options **/ constructor(renderer, session, options) { /**@type{EditSession}*/this.session; @@ -233,7 +233,7 @@ class Editor { /** * Sets a new key handler, such as "vim" or "windows". - * @param {String | import("../ace").Ace.KeyboardHandler | null} keyboardHandler The new key handler + * @param {String | import("../").Ace.KeyboardHandler | null} keyboardHandler The new key handler * @param {() => void} [cb] **/ setKeyboardHandler(keyboardHandler, cb) { @@ -439,7 +439,7 @@ class Editor { /** * {:VirtualRenderer.setTheme} - * @param {string | import("../ace").Ace.Theme} theme The path to a theme + * @param {string | import("../").Ace.Theme} theme The path to a theme * @param {() => void} [cb] optional callback called when theme is loaded **/ setTheme(theme, cb) { @@ -613,7 +613,7 @@ class Editor { /** * Emitted whenever the document is changed. - * @param {import("../ace").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes + * @param {import("../").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes **/ onDocumentChange(delta) { // Rerender and emit "change" event. @@ -653,7 +653,7 @@ class Editor { */ $updateHighlightActiveLine() { var session = this.getSession(); - /**@type {import("../ace").Ace.Point|false}*/ + /**@type {import("../").Ace.Point|false}*/ var highlight; if (this.$highlightActiveLine) { if (this.$selectionStyle != "line" || !this.selection.isMultiLine()) @@ -1133,7 +1133,7 @@ class Editor { /** * Returns the current selection style. - * @returns {import("../ace").Ace.EditorOptions["selectionStyle"]} + * @returns {import("../").Ace.EditorOptions["selectionStyle"]} **/ getSelectionStyle() { return this.getOption("selectionStyle"); @@ -1462,7 +1462,7 @@ class Editor { * inline in the editor such as, for example, code completions. * * @param {String} text Text to be inserted as "ghost" text - * @param {import("../ace").Ace.Point} [position] Position to insert text to + * @param {import("../").Ace.Point} [position] Position to insert text to */ setGhostText(text, position) { if (!this.session.widgetManager) { @@ -1850,7 +1850,7 @@ class Editor { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} range The range of text you want moved within the document - * @param {import("../ace").Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {import("../").Ace.Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * * @returns {Range} The new range where the text was moved to. @@ -2113,7 +2113,7 @@ class Editor { /** * Gets the current position of the cursor. - * @returns {import("../ace").Ace.Point} An object that looks something like this: + * @returns {import("../").Ace.Point} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -2127,7 +2127,7 @@ class Editor { /** * Returns the screen position of the cursor. - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} * @related EditSession.documentToScreenPosition **/ getCursorPositionScreen() { @@ -2171,7 +2171,7 @@ class Editor { /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. - * @param {import("../ace").Ace.Point} pos An object with two properties, row and column + * @param {import("../").Ace.Point} pos An object with two properties, row and column * @related Selection.moveCursorToPosition **/ moveCursorToPosition(pos) { @@ -2480,7 +2480,7 @@ class Editor { /** * Replaces the first occurrence of `options.needle` with the value in `replacement`. * @param {String} [replacement] The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replace(replacement, options) { @@ -2505,7 +2505,7 @@ class Editor { /** * Replaces all occurrences of `options.needle` with the value in `replacement`. * @param {String} [replacement] The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replaceAll(replacement, options) { @@ -2533,7 +2533,7 @@ class Editor { } /** - * @param {import("../ace").Ace.IRange} range + * @param {import("../").Ace.IRange} range * @param {string} [replacement] */ $tryReplace(range, replacement) { @@ -2550,7 +2550,7 @@ class Editor { /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions - * @returns {Partial} + * @returns {Partial} **/ getLastSearchOptions() { return this.$search.getOptions(); @@ -2559,7 +2559,7 @@ class Editor { /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String|RegExp|Object} needle The text to search for (optional) - * @param {Partial} [options] An object defining various search properties + * @param {Partial} [options] An object defining various search properties * @param {Boolean} [animate] If `true` animate scrolling * @related Search.find **/ @@ -2604,7 +2604,7 @@ class Editor { /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find @@ -2615,7 +2615,7 @@ class Editor { /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 498090bdd21..eb87570f6f5 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -52,7 +52,7 @@ var keyDisplayMap = { class CommandBarTooltip { /** * @param {HTMLElement} parentNode - * @param {Partial} [options] + * @param {Partial} [options] */ constructor(parentNode, options) { options = options || {}; @@ -90,7 +90,7 @@ class CommandBarTooltip { * toolbar, the remaining elements are added to the overflow menu. * * @param {string} id - * @param {import("../../ace").Ace.TooltipCommand} command + * @param {import("../../").Ace.TooltipCommand} command */ registerCommand(id, command) { var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip; @@ -288,7 +288,7 @@ class CommandBarTooltip { /** * @param {string} id - * @param {import("../../ace").Ace.TooltipCommand} command + * @param {import("../../").Ace.TooltipCommand} command * @param {boolean} forMainTooltip */ $createCommand(id, command, forMainTooltip) { diff --git a/src/ext/hardwrap.js b/src/ext/hardwrap.js index 2efac5c171d..5674ffbf975 100644 --- a/src/ext/hardwrap.js +++ b/src/ext/hardwrap.js @@ -4,7 +4,7 @@ var Range = require("../range").Range; /** * @param {import("../editor").Editor} editor - * @param {import("../../ace").Ace.HardWrapOptions} options + * @param {import("../../").Ace.HardWrapOptions} options */ function hardWrap(editor, options) { var max = options.column || editor.getOption("printMarginColumn"); diff --git a/src/ext/inline_autocomplete.js b/src/ext/inline_autocomplete.js index f9846157f53..2ff98c1bd1d 100644 --- a/src/ext/inline_autocomplete.js +++ b/src/ext/inline_autocomplete.js @@ -65,7 +65,7 @@ class InlineAutocomplete { /** * This function is the entry point to the class. This triggers the gathering of the autocompletion and displaying the results; - * @param {import("../../ace").Ace.CompletionOptions} options + * @param {import("../../").Ace.CompletionOptions} options */ show(options) { this.activated = true; @@ -121,7 +121,7 @@ class InlineAutocomplete { } /** - * @param {import("../../ace").Ace.InlineAutocompleteAction} where + * @param {import("../../").Ace.InlineAutocompleteAction} where */ goTo(where) { if (!this.completions || !this.completions.filtered) { @@ -153,7 +153,7 @@ class InlineAutocomplete { /** * @param {number} [index] - * @returns {import("../../ace").Ace.Completion | undefined} + * @returns {import("../../").Ace.Completion | undefined} */ getData(index) { if (index == undefined || index === null) { @@ -223,7 +223,7 @@ class InlineAutocomplete { } /** - * @param {import("../../ace").Ace.CompletionOptions} [options] + * @param {import("../../").Ace.CompletionOptions} [options] */ updateCompletions(options) { var prefix = ""; @@ -327,7 +327,7 @@ class InlineAutocomplete { /** * - * @type {{[key: string]: import("../../ace").Ace.Command}} + * @type {{[key: string]: import("../../").Ace.Command}} */ InlineAutocomplete.prototype.commands = { "Previous": { diff --git a/src/ext/language_tools.js b/src/ext/language_tools.js index 2a32a631671..3a857346bac 100644 --- a/src/ext/language_tools.js +++ b/src/ext/language_tools.js @@ -7,7 +7,7 @@ var lang = require("../lib/lang"); var util = require("../autocomplete/util"); var textCompleter = require("../autocomplete/text_completer"); -/**@type {import("../../ace").Ace.Completer}*/ +/**@type {import("../../").Ace.Completer}*/ var keyWordCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { if (session.$mode.completer) { @@ -32,7 +32,7 @@ var transformSnippetTooltip = function(str) { return record[p1]; }); }; -/**@type {import("../../ace").Ace.Completer} */ +/**@type {import("../../").Ace.Completer} */ var snippetCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { var scopes = []; diff --git a/src/ext/rtl.js b/src/ext/rtl.js index dc7f93deb24..7a8cbf34246 100644 --- a/src/ext/rtl.js +++ b/src/ext/rtl.js @@ -93,7 +93,7 @@ function onCommandEmitted(commadEvent) { * Whenever the document is changed make sure that line break operatin * on right-to-left line (like pressing Enter or pasting multi-line text) * produces new right-to-left lines - * @param {import("../../ace").Ace.Delta} delta + * @param {import("../../").Ace.Delta} delta * @param {Editor} editor */ function onChange(delta, editor) { diff --git a/src/ext/simple_tokenizer.js b/src/ext/simple_tokenizer.js index fde23c99282..e1906e6f390 100644 --- a/src/ext/simple_tokenizer.js +++ b/src/ext/simple_tokenizer.js @@ -15,7 +15,7 @@ class SimpleTokenizer { /** * @param {number} row - * @returns {import("../../ace").Ace.Token[]} + * @returns {import("../../").Ace.Token[]} */ getTokens(row) { const line = this._lines[row]; @@ -40,8 +40,8 @@ class SimpleTokenizer { * Result is a list of list of tokens, where each line from the provided content is a separate list of tokens. * * @param {string} content to tokenize - * @param {import("../../ace").Ace.HighlightRules} highlightRules defining the language grammar - * @returns {import("../../ace").Ace.TokenizeResult} tokenization result containing a list of token for each of the lines from content + * @param {import("../../").Ace.HighlightRules} highlightRules defining the language grammar + * @returns {import("../../").Ace.TokenizeResult} tokenization result containing a list of token for each of the lines from content */ function tokenize(content, highlightRules) { const tokenizer = new SimpleTokenizer(content, new Tokenizer(highlightRules.getRules())); diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index 6e532018317..086d4789d69 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -131,7 +131,7 @@ var highlight = function(el, opts, callback) { * Transforms a given input code snippet into HTML using the given mode * * @param {string} input Code snippet - * @param {string|import("../../ace").Ace.SyntaxMode} mode String specifying the mode to load such as + * @param {string|import("../../").Ace.SyntaxMode} mode String specifying the mode to load such as * `ace/mode/javascript` or, a mode loaded from `/ace/mode` * (use 'ServerSideHiglighter.getMode'). * @param {string} theme String specifying the theme to load such as @@ -186,7 +186,7 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba /** * Transforms a given input code snippet into HTML using the given mode * @param {string} input Code snippet - * @param {import("../../ace").Ace.SyntaxMode|string} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') + * @param {import("../../").Ace.SyntaxMode|string} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') * @param {any} theme * @param {any} lineStart * @param {boolean} disableGutter diff --git a/src/keyboard/emacs_test.js b/src/keyboard/emacs_test.js index 9cfbb21be58..18bcd3c2b10 100644 --- a/src/keyboard/emacs_test.js +++ b/src/keyboard/emacs_test.js @@ -8,7 +8,7 @@ if (typeof process !== "undefined") { require("../multi_select"); var EditSession = require("./../edit_session").EditSession, - Editor = require("./../editor").Editor, + Editor = require("../editor").Editor, Range = require("./../range").Range, MockRenderer = require("./../test/mockrenderer").MockRenderer, emacs = require('./emacs'), diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index b4f6c0a4802..0019e1bdb1c 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -7,7 +7,7 @@ var KEY_MODS = keyUtil.KEY_MODS; class MultiHashHandler { /** - * @param {Record | import("../../ace").Ace.Command[]} [config] + * @param {Record | import("../../").Ace.Command[]} [config] * @param {string} [platform] */ constructor(config, platform) { @@ -15,13 +15,13 @@ class MultiHashHandler { } /** - * @param {Record | import("../../ace").Ace.Command[]} config + * @param {Record | import("../../").Ace.Command[]} config * @param {string} [platform] * @param {boolean} [$singleCommand] */ $init(config, platform, $singleCommand) { this.platform = platform || (useragent.isMac ? "mac" : "win"); - /**@type {Record}*/ + /**@type {Record}*/ this.commands = {}; this.commandKeyBinding = {}; this.addCommands(config); @@ -29,7 +29,7 @@ class MultiHashHandler { } /** - * @param {import("../../ace").Ace.Command} command + * @param {import("../../").Ace.Command} command */ addCommand(command) { if (this.commands[command.name]) @@ -42,7 +42,7 @@ class MultiHashHandler { } /** - * @param {import("../../ace").Ace.Command | string} command + * @param {import("../../").Ace.Command | string} command * @param {boolean} [keepCommand] */ removeCommand(command, keepCommand) { @@ -71,7 +71,7 @@ class MultiHashHandler { /** * @param {string | { win?: string; mac?: string; position?:number}} key - * @param {import("../../ace").Ace.CommandLike | string} command + * @param {import("../../").Ace.CommandLike | string} command * @param {number} [position] */ bindKey(key, command, position) { @@ -138,7 +138,7 @@ class MultiHashHandler { } /** - * @param {Record | import("../../ace").Ace.Command[]} [commands] + * @param {Record | import("../../").Ace.Command[]} [commands] */ addCommands(commands) { commands && Object.keys(commands).forEach(function(name) { @@ -163,7 +163,7 @@ class MultiHashHandler { } /** - * @param {Record} commands + * @param {Record} commands */ removeCommands(commands) { Object.keys(commands).forEach(function(name) { @@ -172,7 +172,7 @@ class MultiHashHandler { } /** - * @param {Record} keyList + * @param {Record} keyList */ bindKeys(keyList) { Object.keys(keyList).forEach(function(key) { @@ -218,7 +218,7 @@ class MultiHashHandler { /** * @param {number} hashId * @param {string} keyString - * @returns {import("../../ace").Ace.Command} + * @returns {import("../../").Ace.Command} */ findKeyCommand(hashId, keyString) { var key = KEY_MODS[hashId] + keyString; @@ -276,7 +276,7 @@ function getPosition(command) { class HashHandler extends MultiHashHandler { /** - * @param {Record | import("../../ace").Ace.Command[]} [config] + * @param {Record | import("../../").Ace.Command[]} [config] * @param {string} [platform] */ constructor(config, platform) { diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 06be9ff4a07..1c9aa9ee20a 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -13,13 +13,13 @@ class KeyBinding { constructor(editor) { this.$editor = editor; this.$data = {editor: editor}; - /**@type {(import("../../ace").Ace.KeyboardHandler)[]}*/ + /**@type {(import("../../").Ace.KeyboardHandler)[]}*/ this.$handlers = []; this.setDefaultHandler(editor.commands); } /** - * @param {import("../../ace").Ace.KeyboardHandler} kb + * @param {import("../../").Ace.KeyboardHandler} kb */ setDefaultHandler(kb) { this.removeKeyboardHandler(this.$defaultHandler); @@ -28,7 +28,7 @@ class KeyBinding { } /** - * @param {import("../../ace").Ace.KeyboardHandler} kb + * @param {import("../../").Ace.KeyboardHandler} kb */ setKeyboardHandler(kb) { var h = this.$handlers; @@ -42,7 +42,7 @@ class KeyBinding { } /** - * @param {import("../../ace").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] + * @param {import("../../").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] * @param {number} [pos] */ addKeyboardHandler(kb, pos) { @@ -66,7 +66,7 @@ class KeyBinding { } /** - * @param {import("../../ace").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb + * @param {import("../../").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb * @returns {boolean} */ removeKeyboardHandler(kb) { @@ -79,7 +79,7 @@ class KeyBinding { } /** - * @return {import("../../ace").Ace.KeyboardHandler} + * @return {import("../../").Ace.KeyboardHandler} */ getKeyboardHandler() { return this.$handlers[this.$handlers.length - 1]; diff --git a/src/keyboard/keybinding_test.js b/src/keyboard/keybinding_test.js index 36a8bdcfe7c..fb1114bff36 100644 --- a/src/keyboard/keybinding_test.js +++ b/src/keyboard/keybinding_test.js @@ -5,7 +5,7 @@ if (typeof process !== "undefined") { "use strict"; var EditSession = require("./../edit_session").EditSession, - Editor = require("./../editor").Editor, + Editor = require("../editor").Editor, MockRenderer = require("./../test/mockrenderer").MockRenderer, assert = require("./../test/assertions"), HashHandler = require('./hash_handler').HashHandler, diff --git a/src/keyboard/sublime_test.js b/src/keyboard/sublime_test.js index 0f3a694525c..9971586735c 100644 --- a/src/keyboard/sublime_test.js +++ b/src/keyboard/sublime_test.js @@ -8,7 +8,7 @@ if (typeof process !== "undefined") { require("../multi_select"); var EditSession = require("./../edit_session").EditSession; -var Editor = require("./../editor").Editor; +var Editor = require("../editor").Editor; var Range = require("./../range").Range; var MockRenderer = require("./../test/mockrenderer").MockRenderer; var assert = require("./../test/assertions"); diff --git a/src/keyboard/vim_test.js b/src/keyboard/vim_test.js index c877cd50029..fe357a16aa5 100644 --- a/src/keyboard/vim_test.js +++ b/src/keyboard/vim_test.js @@ -5,7 +5,7 @@ if (typeof process !== "undefined") { var EditSession = require("./../edit_session").EditSession; -var Editor = require("./../editor").Editor; +var Editor = require("../editor").Editor; var UndoManager = require("./../undomanager").UndoManager; var MockRenderer = require("./../test/mockrenderer").MockRenderer; var JavaScriptMode = require("./../mode/javascript").Mode; diff --git a/src/layer/cursor.js b/src/layer/cursor.js index 7be358ca137..5bb4913c4f0 100644 --- a/src/layer/cursor.js +++ b/src/layer/cursor.js @@ -171,7 +171,7 @@ class Cursor { } /** - * @param {import("../../ace").Ace.Point} [position] + * @param {import("../../").Ace.Point} [position] * @param {boolean} [onScreen] */ getPixelPosition(position, onScreen) { diff --git a/src/layer/gutter.js b/src/layer/gutter.js index 6d3e9b1f24d..5ebbd60de4f 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -94,7 +94,7 @@ class Gutter{ } /** - * @param {import("../../ace").Ace.Delta} delta + * @param {import("../../").Ace.Delta} delta */ $updateAnnotations(delta) { if (!this.$annotations.length) @@ -113,7 +113,7 @@ class Gutter{ } /** - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config */ update(config) { this.config = config; @@ -166,7 +166,7 @@ class Gutter{ } /** - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config */ $updateGutterWidth(config) { var session = this.session; @@ -234,7 +234,7 @@ class Gutter{ } /** - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config */ scrollLines(config) { var oldConfig = this.config; @@ -280,7 +280,7 @@ class Gutter{ } /** - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config * @param {number} firstRow * @param {number} lastRow */ @@ -311,8 +311,8 @@ class Gutter{ /** * @param {any} cell - * @param {import("../../ace").Ace.LayerConfig} config - * @param {import("../../ace").Ace.IRange | undefined} fold + * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../").Ace.IRange | undefined} fold * @param {number} row */ $renderCell(cell, config, fold, row) { diff --git a/src/layer/lines.js b/src/layer/lines.js index c30f806b3ac..2c49d058ec6 100644 --- a/src/layer/lines.js +++ b/src/layer/lines.js @@ -20,15 +20,15 @@ class Lines { } /** - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config */ moveContainer(config) { dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient); } /** - * @param {import("../../ace").Ace.LayerConfig} oldConfig - * @param {import("../../ace").Ace.LayerConfig} newConfig + * @param {import("../../").Ace.LayerConfig} oldConfig + * @param {import("../../").Ace.LayerConfig} newConfig */ pageChanged(oldConfig, newConfig) { return ( @@ -39,7 +39,7 @@ class Lines { /** * @param {number} row - * @param {Partial} config + * @param {Partial} config * @param {EditSession} session */ computeLineTop(row, config, session) { @@ -51,7 +51,7 @@ class Lines { /** * @param {number} row - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config * @param {EditSession} session */ computeLineHeight(row, config, session) { diff --git a/src/layer/marker.js b/src/layer/marker.js index a7e30a85ab2..916f3ada2e1 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -31,7 +31,7 @@ class Marker { } /** - * @param {{ [x: number]: import("../../ace").Ace.MarkerLike; }} markers + * @param {{ [x: number]: import("../../").Ace.MarkerLike; }} markers */ setMarkers(markers) { this.markers = markers; @@ -56,7 +56,7 @@ class Marker { } /** - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config */ update(config) { if (!config) return; @@ -102,7 +102,7 @@ class Marker { /** * @param {number} row - * @param {Partial} layerConfig + * @param {Partial} layerConfig */ $getTop(row, layerConfig) { return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; @@ -114,7 +114,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} layerConfig + * @param {Partial} layerConfig * @param {string} [extraStyle] */ drawTextMarker(stringBuilder, range, clazz, layerConfig, extraStyle) { @@ -145,7 +145,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {import("../../ace").Ace.LayerConfig} config + * @param {import("../../").Ace.LayerConfig} config * @param {string} [extraStyle] */ drawMultiLineMarker(stringBuilder, range, clazz, config, extraStyle) { @@ -207,7 +207,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {number} [extraLength] * @param {string} [extraStyle] */ @@ -234,7 +234,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {number} extraLength * @param {string} extraStyle */ @@ -257,7 +257,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {undefined} [extraStyle] */ drawFullLineMarker(stringBuilder, range, clazz, config, extraStyle) { @@ -278,7 +278,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {undefined} [extraStyle] */ drawScreenLineMarker(stringBuilder, range, clazz, config, extraStyle) { diff --git a/src/layer/text.js b/src/layer/text.js index 0ef36e7cb3a..6782a5c4329 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -689,7 +689,7 @@ class Text { /** * @param {any} row * @param {{ walk: (arg0: (placeholder: any, row: any, column: any, lastColumn: any, isNewRow: any) => void, arg1: any, arg2: any) => void; end: { row: any; }; }} foldLine - * @return {import("../../ace").Ace.Token[]} + * @return {import("../../").Ace.Token[]} */ $getFoldLineTokens(row, foldLine) { var session = this.session; diff --git a/src/lib/keys.js b/src/lib/keys.js index 6dc0869774e..ef8ddfcd3d2 100644 --- a/src/lib/keys.js +++ b/src/lib/keys.js @@ -151,13 +151,9 @@ var Keys = (function() { })(); oop.mixin(exports, Keys); -/**@type{{keyCodeToString: (keyCode: string) => string}}*/ exports.default = exports; -/** - * @param {string} keyCode - * @return {string} - */ +// @ts-ignore exports.keyCodeToString = function(keyCode) { // Language-switching keystroke in Chrome/Linux emits keyCode 0. var keyString = Keys[keyCode]; diff --git a/src/line_widgets.js b/src/line_widgets.js index c3df596fe31..5085a55576e 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -138,7 +138,7 @@ class LineWidgets { /** * - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ updateOnChange(delta) { var lineWidgets = this.session.lineWidgets; @@ -190,8 +190,8 @@ class LineWidgets { /** * - * @param {import("../ace").Ace.LineWidget} w - * @return {import("../ace").Ace.LineWidget} + * @param {import("../").Ace.LineWidget} w + * @return {import("../").Ace.LineWidget} */ $registerLineWidget(w) { if (!this.session.lineWidgets) @@ -212,8 +212,8 @@ class LineWidgets { /** * - * @param {import("../ace").Ace.LineWidget} w - * @return {import("../ace").Ace.LineWidget} + * @param {import("../").Ace.LineWidget} w + * @return {import("../").Ace.LineWidget} */ addLineWidget(w) { this.$registerLineWidget(w); @@ -270,7 +270,7 @@ class LineWidgets { } /** - * @param {import("../ace").Ace.LineWidget} w + * @param {import("../").Ace.LineWidget} w */ removeLineWidget(w) { w._inDocument = false; @@ -303,7 +303,7 @@ class LineWidgets { /** * * @param {number} row - * @return {import("../ace").Ace.LineWidget[]} + * @return {import("../").Ace.LineWidget[]} */ getWidgetsAtRow(row) { var lineWidgets = this.session.lineWidgets; @@ -317,7 +317,7 @@ class LineWidgets { } /** - * @param {import("../ace").Ace.LineWidget} w + * @param {import("../").Ace.LineWidget} w */ onWidgetChanged(w) { this.session._changedWidgets.push(w); diff --git a/src/marker_group.js b/src/marker_group.js index 36482db28e7..b09b121f8fb 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -28,8 +28,8 @@ class MarkerGroup { /** * Finds the first marker containing pos - * @param {import("../ace").Ace.Point} pos - * @returns import("../ace").Ace.MarkerGroupItem + * @param {import("../").Ace.Point} pos + * @returns import("../").Ace.MarkerGroupItem */ getMarkerAtPosition(pos) { return this.markers.find(function(marker) { diff --git a/src/mode/text.js b/src/mode/text.js index c4e06434d2b..0550ea7ce1e 100644 --- a/src/mode/text.js +++ b/src/mode/text.js @@ -23,7 +23,7 @@ Mode = function() { this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g"); /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.getTokenizer = function() { if (!this.$tokenizer) { @@ -37,7 +37,7 @@ Mode = function() { this.blockComment = ""; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.toggleCommentLines = function(state, session, startRow, endRow) { var doc = session.doc; @@ -170,7 +170,7 @@ Mode = function() { }; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.toggleBlockComment = function(state, session, range, cursor) { var comment = this.blockComment; @@ -276,7 +276,7 @@ Mode = function() { var functionName = delegations[i]; var defaultHandler = scope[functionName]; scope[delegations[i]] = - /** @this {import("../../ace").Ace.SyntaxMode} */ + /** @this {import("../../").Ace.SyntaxMode} */ function () { return this.$delegator(functionName, arguments, defaultHandler); }; @@ -285,7 +285,7 @@ Mode = function() { }; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.$delegator = function(method, args, defaultHandler) { var state = args[0] || "start"; @@ -314,7 +314,7 @@ Mode = function() { }; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.transformAction = function(state, action, editor, session, param) { if (this.$behaviour) { @@ -331,7 +331,7 @@ Mode = function() { }; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.getKeywords = function(append) { // this is for autocompletion to pick up regexp'ed keywords @@ -365,7 +365,7 @@ Mode = function() { }; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.$createKeywordList = function() { if (!this.$highlightRules) @@ -374,7 +374,7 @@ Mode = function() { }; /** - * @this {import("../../ace").Ace.SyntaxMode} + * @this {import("../../").Ace.SyntaxMode} */ this.getCompletions = function(state, session, pos, prefix) { var keywords = this.$keywordList || this.$createKeywordList(); diff --git a/src/mode/text_highlight_rules.js b/src/mode/text_highlight_rules.js index 212b80687fa..af5589c9d79 100644 --- a/src/mode/text_highlight_rules.js +++ b/src/mode/text_highlight_rules.js @@ -2,7 +2,7 @@ const deepCopy = require("../lib/deep_copy").deepCopy; -/**@type {(new() => Partial) & {prototype: import("../../ace").Ace.HighlightRules}}*/ +/**@type {(new() => Partial) & {prototype: import("../../").Ace.HighlightRules}}*/ var TextHighlightRules; TextHighlightRules = function() { @@ -22,9 +22,9 @@ TextHighlightRules = function() { (function() { /** - * @param {import("../../ace").Ace.HighlightRulesMap} rules + * @param {import("../../").Ace.HighlightRulesMap} rules * @param {string} [prefix] - * @this {import("../../ace").Ace.HighlightRules} + * @this {import("../../").Ace.HighlightRules} */ this.addRules = function(rules, prefix) { if (!prefix) { @@ -50,8 +50,8 @@ TextHighlightRules = function() { }; /** - * @returns {import("../../ace").Ace.HighlightRulesMap} - * @this {import("../../ace").Ace.HighlightRules} + * @returns {import("../../").Ace.HighlightRulesMap} + * @this {import("../../").Ace.HighlightRules} */ this.getRules = function() { return this.$rules; @@ -63,7 +63,7 @@ TextHighlightRules = function() { * @param escapeRules * @param states * @param append - * @this {import("../../ace").Ace.HighlightRules} + * @this {import("../../").Ace.HighlightRules} */ this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) { var embedRules = typeof HighlightRules == "function" @@ -92,7 +92,7 @@ TextHighlightRules = function() { }; /** - * @this {import("../../ace").Ace.HighlightRules} + * @this {import("../../").Ace.HighlightRules} */ this.getEmbeds = function() { return this.$embeds; @@ -110,7 +110,7 @@ TextHighlightRules = function() { }; /** - * @this {import("../../ace").Ace.HighlightRules} + * @this {import("../../").Ace.HighlightRules} */ this.normalizeRules = function() { var id = 0; @@ -229,7 +229,7 @@ TextHighlightRules = function() { }; /** - * @this {import("../../ace").Ace.HighlightRules} + * @this {import("../../").Ace.HighlightRules} */ this.getKeywords = function() { return this.$keywords; diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index 4a776454318..edc2244246f 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -81,7 +81,7 @@ class DefaultHandlers { /** * - * @param {import("../../ace").Ace.Position} [pos] + * @param {import("../../").Ace.Position} [pos] * @param {boolean} [waitForClickSelection] * @this {MouseHandler} */ diff --git a/src/multi_select.js b/src/multi_select.js index 1ad26587466..e94869f1d59 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -150,7 +150,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Removes a Range containing pos (if it exists). - * @param {import("../ace").Ace.Point} pos The position to remove, as a `{row, column}` object + * @param {import("../").Ace.Point} pos The position to remove, as a `{row, column}` object * @this {Selection} **/ this.substractPoint = function(pos) { @@ -300,8 +300,8 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { * * Gets list of ranges composing rectangular block on the screen * - * @param {import("../ace").Ace.ScreenCoordinates} screenCursor The cursor to use - * @param {import("../ace").Ace.ScreenCoordinates} screenAnchor The anchor to use + * @param {import("../").Ace.ScreenCoordinates} screenCursor The cursor to use + * @param {import("../").Ace.ScreenCoordinates} screenAnchor The anchor to use * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping * @returns {Range[]} * @this {Selection} @@ -638,7 +638,7 @@ var Editor = require("./editor").Editor; /** * Finds and selects all the occurrences of `needle`. * @param {String} [needle] The text to find - * @param {Partial} [options] The search options + * @param {Partial} [options] The search options * @param {Boolean} [additive] keeps * * @returns {Number} The cumulative count of all found matches @@ -940,8 +940,8 @@ var Editor = require("./editor").Editor; /** - * @param {import("../ace").Ace.Point} p1 - * @param {import("../ace").Ace.Point} p2 + * @param {import("../").Ace.Point} p1 + * @param {import("../").Ace.Point} p2 */ function isSamePoint(p1, p2) { return p1.row == p2.row && p1.column == p2.column; diff --git a/src/occur.js b/src/occur.js index df1b894ce5e..92146f10b37 100644 --- a/src/occur.js +++ b/src/occur.js @@ -66,7 +66,7 @@ class Occur extends Search { /** * @param {Editor} editor - * @param {Partial} options + * @param {Partial} options */ displayOccurContent(editor, options) { // this.setSession(session || new EditSession("")) @@ -97,8 +97,8 @@ class Occur extends Search { * the document or the beginning if the doc {row: 0, column: 0} if not * found. * @param {EditSession} session The occur session - * @param {import("../ace").Ace.Point} pos The position in the original document - * @return {import("../ace").Ace.Point} position in occur doc + * @param {import("../").Ace.Point} pos The position in the original document + * @return {import("../").Ace.Point} position in occur doc **/ originalToOccurPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -115,8 +115,8 @@ class Occur extends Search { * Translates the position from the occur document to the original document * or `pos` if not found. * @param {EditSession} session The occur session - * @param {import("../ace").Ace.Point} pos The position in the occur session document - * @return {import("../ace").Ace.Point} position + * @param {import("../").Ace.Point} pos The position in the occur session document + * @return {import("../").Ace.Point} position **/ occurToOriginalPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -127,7 +127,7 @@ class Occur extends Search { /** * @param {EditSession} session - * @param {Partial} options + * @param {Partial} options */ matchingLines(session, options) { options = oop.mixin({}, options); diff --git a/src/placeholder.js b/src/placeholder.js index 7b7cf385789..e9fdfa52830 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -10,7 +10,7 @@ class PlaceHolder { /** * @param {EditSession} session * @param {Number} length - * @param {import("../ace").Ace.Point} pos + * @param {import("../").Ace.Point} pos * @param {any[]} others * @param {String} mainClass * @param {String} othersClass @@ -105,7 +105,7 @@ class PlaceHolder { * PlaceHolder@onUpdate(e) * * Emitted when the place holder updates. - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ onUpdate(delta) { if (this.$updating) @@ -145,7 +145,7 @@ class PlaceHolder { } /** - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ updateAnchors(delta) { this.pos.onChange(delta); diff --git a/src/range.js b/src/range.js index 158ef59c8a3..0bb9b6a7baa 100644 --- a/src/range.js +++ b/src/range.js @@ -16,12 +16,12 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { - /**@type {import("../ace").Ace.Point}*/ + /**@type {import("../").Ace.Point}*/ this.start = { row: startRow, column: startColumn }; - /**@type {import("../ace").Ace.Point}*/ + /**@type {import("../").Ace.Point}*/ this.end = { row: endRow, column: endColumn @@ -30,7 +30,7 @@ class Range { /** * Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`. - * @param {import("../ace").Ace.IRange} range A range to check against + * @param {import("../").Ace.IRange} range A range to check against * @return {Boolean} **/ isEqual(range) { @@ -70,7 +70,7 @@ class Range { /** * Compares `this` range (A) with another range (B). - * @param {import("../ace").Ace.IRange} range A range to compare with + * @param {import("../").Ace.IRange} range A range to compare with * @related [[Range.compare]] * @returns {Number} This method returns one of the following numbers: * * `-2`: (B) is in front of (A), and doesn't intersect with (A) @@ -111,7 +111,7 @@ class Range { /** * Compares the row and column of `p` with the starting and ending [[Point]]'s of the calling range (by calling [[Range.compare]]). - * @param {import("../ace").Ace.Point} p A point to compare with + * @param {import("../").Ace.Point} p A point to compare with * @related [[Range.compare]] * @returns {Number} **/ @@ -121,7 +121,7 @@ class Range { /** * Checks the start and end [[Point]]'s of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range. - * @param {import("../ace").Ace.IRange} range A range to compare with + * @param {import("../").Ace.IRange} range A range to compare with * @returns {Boolean} * @related [[Range.comparePoint]] **/ @@ -131,7 +131,7 @@ class Range { /** * Returns `true` if passed in `range` intersects with the one calling this method. - * @param {import("../ace").Ace.IRange} range A range to compare with + * @param {import("../").Ace.IRange} range A range to compare with * @returns {Boolean} **/ intersects(range) { @@ -161,7 +161,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|import("../ace").Ace.Point} row A row to set + * @param {Number|import("../").Ace.Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -177,7 +177,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|import("../ace").Ace.Point} row A row to set + * @param {Number|import("../").Ace.Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -442,8 +442,8 @@ class Range { /** * Creates and returns a new `Range` based on the `start` [[Point]] and `end` [[Point]] of the given parameters. - * @param {import("../ace").Ace.Point} start A starting point to use - * @param {import("../ace").Ace.Point} end An ending point to use + * @param {import("../").Ace.Point} start A starting point to use + * @param {import("../").Ace.Point} end An ending point to use * @returns {Range} **/ Range.fromPoints = function(start, end) { @@ -452,8 +452,8 @@ Range.fromPoints = function(start, end) { /** * Compares `p1` and `p2` [[Point]]'s, useful for sorting - * @param {import("../ace").Ace.Point} p1 - * @param {import("../ace").Ace.Point} p2 + * @param {import("../").Ace.Point} p1 + * @param {import("../").Ace.Point} p2 * @returns {Number} */ Range.comparePoints = function(p1, p2) { diff --git a/src/range_list.js b/src/range_list.js index dc79200a2c1..3f70938c932 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -13,7 +13,7 @@ class RangeList { } /** - * @param {import("../ace").Ace.Point} pos + * @param {import("../").Ace.Point} pos * @param {boolean} [excludeEdges] * @param {number} [startIndex] * @return {number} @@ -67,7 +67,7 @@ class RangeList { } /** - * @param {import("../ace").Ace.Point} pos + * @param {import("../").Ace.Point} pos */ substractPoint(pos) { var i = this.pointIndex(pos); @@ -121,14 +121,14 @@ class RangeList { } /** - * @param {import("../ace").Ace.Point} pos + * @param {import("../").Ace.Point} pos */ containsPoint(pos) { return this.pointIndex(pos) >= 0; } /** - * @param {import("../ace").Ace.Point} pos + * @param {import("../").Ace.Point} pos */ rangeAtPoint(pos) { var i = this.pointIndex(pos); @@ -186,7 +186,7 @@ class RangeList { } /** - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta */ $onChange(delta) { var start = delta.start; diff --git a/src/search.js b/src/search.js index 0be5d046862..05c766a30dc 100644 --- a/src/search.js +++ b/src/search.js @@ -21,7 +21,7 @@ class Search { * @property {boolean} [wholeWord] - Whether the search matches only on whole words * @property {Range|null} [range] - The [[Range]] to search within. Set this to `null` for the whole document * @property {boolean} [regExp] - Whether the search is a regular expression or not - * @property {Range|import("../ace").Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search + * @property {Range|import("../").Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search * @property {boolean} [skipCurrent] - Whether or not to include the current line in the search * @property {boolean} [$isMultiLine] - true, if needle has \n or \r\n * @property {boolean} [preserveCase] @@ -37,7 +37,7 @@ class Search { /** * Sets the search options via the `options` parameter. - * @param {Partial} options An object containing all the new search properties + * @param {Partial} options An object containing all the new search properties * @returns {Search} * @chainable **/ @@ -48,7 +48,7 @@ class Search { /** * [Returns an object containing all the search options.]{: #Search.getOptions} - * @returns {Partial} + * @returns {Partial} **/ getOptions() { return lang.copyObject(this.$options); diff --git a/src/search_highlight.js b/src/search_highlight.js index 8a0522950df..8d53bfb3bb4 100644 --- a/src/search_highlight.js +++ b/src/search_highlight.js @@ -30,7 +30,7 @@ class SearchHighlight { * @param {any} html * @param {Marker} markerLayer * @param {EditSession} session - * @param {Partial} config + * @param {Partial} config */ update(html, markerLayer, session, config) { if (!this.regExp) diff --git a/src/selection.js b/src/selection.js index 91f06e742d5..5f8402d6c45 100644 --- a/src/selection.js +++ b/src/selection.js @@ -69,7 +69,7 @@ class Selection { /** * Returns an object containing the `row` and `column` current position of the cursor. - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} **/ getCursor() { return this.lead.getPosition(); @@ -90,7 +90,7 @@ class Selection { /** * Returns an object containing the `row` and `column` of the calling selection anchor. * - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} * @related Anchor.getPosition **/ getAnchor() { @@ -154,7 +154,7 @@ class Selection { /** * Sets the selection to the provided range. - * @param {import("../ace").Ace.IRange} range The range of text to select + * @param {import("../").Ace.IRange} range The range of text to select * @param {Boolean} [reverse] Indicates if the range should go backwards (`true`) or not **/ setRange(range, reverse) { @@ -207,7 +207,7 @@ class Selection { /** * Moves the selection cursor to the row and column indicated by `pos`. - * @param {import("../ace").Ace.Point} pos An object containing the row and column + * @param {import("../").Ace.Point} pos An object containing the row and column **/ selectToPosition(pos) { this.$moveSelection(function() { @@ -376,7 +376,7 @@ class Selection { /** * * Returns `true` if moving the character next to the cursor in the specified direction is a soft tab. - * @param {import("../ace").Ace.Point} cursor the current cursor position + * @param {import("../").Ace.Point} cursor the current cursor position * @param {Number} tabSize the tab size * @param {Number} direction 1 for right, -1 for left */ @@ -433,7 +433,7 @@ class Selection { else { var tabSize = this.session.getTabSize(); /** - * @type {import("../ace").Ace.Point} + * @type {import("../").Ace.Point} */ var cursor = this.lead; if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) { @@ -749,7 +749,7 @@ class Selection { /** * Moves the selection to the position indicated by its `row` and `column`. - * @param {import("../ace").Ace.Point} position The position to move to + * @param {import("../").Ace.Point} position The position to move to **/ moveCursorToPosition(position) { this.moveCursorTo(position.row, position.column); diff --git a/src/split.js b/src/split.js index ba07e9c3f40..e6349b91a8a 100644 --- a/src/split.js +++ b/src/split.js @@ -8,7 +8,7 @@ var Renderer = require("./virtual_renderer").VirtualRenderer; var EditSession = require("./edit_session").EditSession; /** - * @typedef {import("../ace").Ace.EventEmitter & {[key: string]: any}} ISplit + * @typedef {import("../").Ace.EventEmitter & {[key: string]: any}} ISplit */ var Split; diff --git a/src/token_iterator.js b/src/token_iterator.js index cd7831a02d5..f3fbd9c49b3 100644 --- a/src/token_iterator.js +++ b/src/token_iterator.js @@ -26,7 +26,7 @@ class TokenIterator { /** * Moves iterator position to the start of previous token. - * @returns {import("../ace").Ace.Token|null} + * @returns {import("../").Ace.Token|null} **/ stepBackward() { this.$tokenIndex -= 1; @@ -47,7 +47,7 @@ class TokenIterator { /** * Moves iterator position to the start of next token. - * @returns {import("../ace").Ace.Token|null} + * @returns {import("../").Ace.Token|null} **/ stepForward() { this.$tokenIndex += 1; @@ -71,7 +71,7 @@ class TokenIterator { /** * * Returns current token. - * @returns {import("../ace").Ace.Token} + * @returns {import("../").Ace.Token} **/ getCurrentToken() { return this.$rowTokens[this.$tokenIndex]; @@ -111,7 +111,7 @@ class TokenIterator { /** * Return the current token position. - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} */ getCurrentTokenPosition() { return {row: this.$row, column: this.getCurrentTokenColumn()}; diff --git a/src/tokenizer.js b/src/tokenizer.js index 070b6612410..846a276d486 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -111,7 +111,7 @@ class Tokenizer { /** * @param {string} str - * @return {import("../ace").Ace.Token[]} + * @return {import("../").Ace.Token[]} */ $applyToken(str) { var values = this.splitRegex.exec(str).slice(1); @@ -135,7 +135,7 @@ class Tokenizer { /** * @param {string} str - * @return {import("../ace").Ace.Token[] | string} + * @return {import("../").Ace.Token[] | string} */ $arrayTokens(str) { if (!str) @@ -215,7 +215,7 @@ class Tokenizer { * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state. * @param {string} line * @param {string | string[]} startState - * @returns {{tokens:import("../ace").Ace.Token[], state: string|string[]}} + * @returns {{tokens:import("../").Ace.Token[], state: string|string[]}} */ getLineTokens(line, startState) { if (startState && typeof startState != "string") { diff --git a/src/tooltip.js b/src/tooltip.js index 5428777b66b..3702e4d6265 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -70,7 +70,7 @@ class Tooltip { } /** - * @param {import("../ace").Ace.Theme} theme + * @param {import("../").Ace.Theme} theme */ setTheme(theme) { this.$element.className = CLASSNAME + " " + diff --git a/src/undomanager.js b/src/undomanager.js index 928dd76470f..2caaf333d54 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -4,11 +4,11 @@ */ /** - * @typedef {import("../ace").Ace.Delta} Delta + * @typedef {import("../").Ace.Delta} Delta */ /** - * @typedef {import("../ace").Ace.Point} Point + * @typedef {import("../").Ace.Point} Point */ /** @@ -40,7 +40,7 @@ class UndoManager { * - `args[0]` is an array of deltas * - `args[1]` is the document to associate with * - * @param {import("../ace").Ace.Delta} delta + * @param {import("../").Ace.Delta} delta * @param {boolean} allowMerge * @param {EditSession} [session] **/ @@ -126,7 +126,7 @@ class UndoManager { * * @param {number} from * @param {number} [to] - * @return {import("../ace").Ace.Delta[]} + * @return {import("../").Ace.Delta[]} */ getDeltas(from, to) { if (to == null) to = this.$rev + 1; @@ -585,8 +585,8 @@ function xform(d1, c1) { /** * - * @param {import("../ace").Ace.IRange} d1 - * @param {import("../ace").Ace.IRange} d2 + * @param {import("../").Ace.IRange} d1 + * @param {import("../").Ace.IRange} d2 * @param {number} dir */ function shift(d1, d2, dir) { diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index ee36b434bf7..49314dbb83c 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1269,7 +1269,7 @@ class VirtualRenderer { /** * Sets annotations for the gutter. - * @param {import("../ace").Ace.Annotation[]} annotations An array containing annotations + * @param {import("../").Ace.Annotation[]} annotations An array containing annotations * **/ setAnnotations(annotations) { @@ -1303,8 +1303,8 @@ class VirtualRenderer { /** * - * @param {import("../ace").Ace.Point} anchor - * @param {import("../ace").Ace.Point} lead + * @param {import("../").Ace.Point} anchor + * @param {import("../").Ace.Point} lead * @param {number} [offset] */ scrollSelectionIntoView(anchor, lead, offset) { @@ -1316,7 +1316,7 @@ class VirtualRenderer { /** * * Scrolls the cursor into the first visibile area of the editor - * @param {import("../ace").Ace.Point} [cursor] + * @param {import("../").Ace.Point} [cursor] * @param {number} [offset] * @param {{ top?: any; bottom?: any; }} [$viewMargin] */ @@ -1417,7 +1417,7 @@ class VirtualRenderer { /** * - * @param {import("../ace").Ace.Point} cursor + * @param {import("../").Ace.Point} cursor * @param {number} [alignment] * @returns {number} */ @@ -1604,7 +1604,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {import("../ace").Ace.ScreenCoordinates} + * @returns {import("../").Ace.ScreenCoordinates} */ pixelToScreenCoordinates(x, y) { @@ -1630,7 +1630,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {import("../ace").Ace.Point} + * @returns {import("../").Ace.Point} */ screenToTextCoordinates(x, y) { @@ -1749,7 +1749,7 @@ class VirtualRenderer { /** * @param {string} text - * @param {import("../ace").Ace.Point} [position] + * @param {import("../").Ace.Point} [position] */ setGhostText(text, position) { var cursor = this.session.selection.cursor; @@ -1828,7 +1828,7 @@ class VirtualRenderer { /** * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} - * @param {String | import("../ace").Ace.Theme} [theme] The path to a theme + * @param {String | import("../").Ace.Theme} [theme] The path to a theme * @param {() => void} [cb] optional callback **/ @@ -1847,7 +1847,7 @@ class VirtualRenderer { } /** - * @param {import("../ace").Ace.Theme} module + * @param {import("../").Ace.Theme} module */ function afterLoad(module) { if (_self.$themeId != theme) @@ -1961,9 +1961,9 @@ class VirtualRenderer { delete this.$scrollDecorator; } if (val === true) { - /**@type {import("../ace").Ace.VScrollbar}*/ + /**@type {import("../").Ace.VScrollbar}*/ this.scrollBarV = new VScrollBarCustom(this.container, this); - /**@type {import("../ace").Ace.HScrollbar}*/ + /**@type {import("../").Ace.HScrollbar}*/ this.scrollBarH = new HScrollBarCustom(this.container, this); this.scrollBarV.setHeight(this.$size.scrollerHeight); this.scrollBarH.setWidth(this.$size.scrollerWidth); diff --git a/tsconfig.json b/tsconfig.json index 16a61043a27..977a3d93d14 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,8 @@ "src/keyboard/emacs.js", "src/keyboard/sublime.js", "src/keyboard/vscode.js", - "src/mode" + "src/mode", + "./ace-internal.d.ts" ], "include": [ "./src/**/*", From f36b98e7796040697ab0f198f1c9968ae4c1a43d Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 2 Nov 2023 19:29:20 +0400 Subject: [PATCH 31/36] add types to new declarations --- ace.d.ts | 3 ++- src/autocomplete.js | 6 +++-- src/autocomplete/inline_screenreader.js | 8 +++---- src/edit_session.js | 29 +++++++++++-------------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ace.d.ts b/ace.d.ts index b37451c4fac..9e0300552d6 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1429,7 +1429,8 @@ declare module "./src/autocomplete/popup" { goTo: (where: Ace.AcePopupNavigation) => void, getTextLeftOffset: () => number, $imageSize: number, - anchorPos: any + anchorPos: any, + isMouseOver?: boolean } } diff --git a/src/autocomplete.js b/src/autocomplete.js index a1dd9d8626a..1eed16ba969 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -99,7 +99,7 @@ class Autocomplete { this.stickySelection = true; }.bind(this), this.stickySelectionDelay); - this.$firstOpenTimer = lang.delayedCall(function() { + this.$firstOpenTimer = lang.delayedCall(/**@this{Autocomplete}*/function() { var initialPosition = this.completionProvider && this.completionProvider.initialPosition; if (this.autoShown || (this.popup && this.popup.isOpen) || !initialPosition) return; @@ -162,7 +162,8 @@ class Autocomplete { // If the mouse is over the tooltip, and we're changing selection on hover don't // move the tooltip while hovering over the popup. - if (this.popup.isMouseOver && this.setSelectOnHover) { + if (this.popup.isMouseOver && this.setSelectOnHover) { + // @ts-expect-error TODO: potential wrong arguments this.tooltipTimer.call(null, null); return; } @@ -469,6 +470,7 @@ class Autocomplete { this.base.$insertRight = true; var completionOptions = { exactMatch: this.exactMatch, + // @ts-expect-error TODO: couldn't find initializer ignoreCaption: this.ignoreCaption }; this.getCompletionProvider({ diff --git a/src/autocomplete/inline_screenreader.js b/src/autocomplete/inline_screenreader.js index 9df04c2916a..93b7ed0e036 100644 --- a/src/autocomplete/inline_screenreader.js +++ b/src/autocomplete/inline_screenreader.js @@ -6,7 +6,7 @@ class AceInlineScreenReader { /** * Creates the off-screen div in which the ghost text content in redered and which the screen reader reads. - * @param {Editor} editor + * @param {import("../editor").Editor} editor */ constructor(editor) { this.editor = editor; @@ -22,8 +22,8 @@ class AceInlineScreenReader { */ setScreenReaderContent(content) { // Path for when inline preview is used with 'normal' completion popup. - if (!this.popup && this.editor.completer && this.editor.completer.popup) { - this.popup = this.editor.completer.popup; + if (!this.popup && this.editor.completer && /**@type{import("../autocomplete").Autocomplete}*/(this.editor.completer).popup) { + this.popup = /**@type{import("../autocomplete").Autocomplete}*/(this.editor.completer).popup; this.popup.renderer.on("afterRender", function() { let row = this.popup.getRow(); @@ -75,4 +75,4 @@ class AceInlineScreenReader { } } -exports.AceInlineScreenReader = AceInlineScreenReader; \ No newline at end of file +exports.AceInlineScreenReader = AceInlineScreenReader; diff --git a/src/edit_session.js b/src/edit_session.js index b0622c0978a..68c86b6b9c9 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,7 +1,4 @@ "use strict"; -/** - * @typedef {import("./undomanager").UndoManager} UndoManager - */ /** * @typedef {import("./edit_session/fold_line").FoldLine} FoldLine */ @@ -206,28 +203,28 @@ class EditSession { /** * Returns a new instance of EditSession with state from JSON. * @method fromJSON - * @param {String} session The EditSession state. + * @param {string} session The EditSession state. * @returns {EditSession} */ static fromJSON(session) { session = JSON.parse(session); const undoManager = new UndoManager(); - undoManager.$undoStack = session.history.undo; - undoManager.$redoStack = session.history.redo; - undoManager.mark = session.history.mark; - undoManager.$rev = session.history.rev; + undoManager.$undoStack = /**@type{Object}*/(session).history.undo; + undoManager.$redoStack = /**@type{Object}*/(session).history.redo; + undoManager.mark = /**@type{Object}*/(session).history.mark; + undoManager.$rev = /**@type{Object}*/(session).history.rev; - const editSession = new EditSession(session.value); - session.folds.forEach(function(fold) { + const editSession = new EditSession(/**@type{Object}*/(session).value); + /**@type{Object}*/(session).folds.forEach(function(fold) { editSession.addFold("...", Range.fromPoints(fold.start, fold.end)); }); - editSession.setAnnotations(session.annotations); - editSession.setBreakpoints(session.breakpoints); - editSession.setMode(session.mode); - editSession.setScrollLeft(session.scrollLeft); - editSession.setScrollTop(session.scrollTop); + editSession.setAnnotations(/**@type{Object}*/(session).annotations); + editSession.setBreakpoints(/**@type{Object}*/(session).breakpoints); + editSession.setMode(/**@type{Object}*/(session).mode); + editSession.setScrollLeft(/**@type{Object}*/(session).scrollLeft); + editSession.setScrollTop(/**@type{Object}*/(session).scrollTop); editSession.setUndoManager(undoManager); - editSession.selection.fromJSON(session.selection); + editSession.selection.fromJSON(/**@type{Object}*/(session).selection); return editSession; } From 16db9ca06bb0466faa2d52d4f30ddb9621f8e4eb Mon Sep 17 00:00:00 2001 From: mkslanc Date: Thu, 2 Nov 2023 19:35:33 +0400 Subject: [PATCH 32/36] remove declaration_generator; make ace-builds to use old declaration --- Makefile.dryice.js | 20 +- package.json | 4 +- tool/ace_declaration_generator.js | 356 ------------------------------ 3 files changed, 10 insertions(+), 370 deletions(-) delete mode 100644 tool/ace_declaration_generator.js diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 4ca6246728d..a745e15fe76 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -35,7 +35,6 @@ var fs = require("fs"); var path = require("path"); var copy = require('architect-build/copy'); var build = require('architect-build/build'); -var {updateDeclarationModuleNames, generateDeclaration} = require('./tool/ace_declaration_generator'); var ACE_HOME = __dirname; var BUILD_DIR = ACE_HOME + "/build"; @@ -177,9 +176,12 @@ function ace() { function buildTypes() { var aceCodeModeDefinitions = '/// '; + var aceCodeExtensionDefinitions = '/// '; // ace-builds package has different structure and can't use mode types defined for the ace-code. // ace-builds modes are declared along with other modules in the ace-modules.d.ts file below. + var definitions = fs.readFileSync(ACE_HOME + '/ace-internal.d.ts', 'utf8').replace(aceCodeModeDefinitions, '').replace(aceCodeExtensionDefinitions, ''); var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict'); + var moduleRef = '/// '; fs.readdirSync(BUILD_DIR + '/src-noconflict/snippets').forEach(function(path) { paths.push("snippets/" + path); @@ -187,8 +189,7 @@ function buildTypes() { var moduleNameRegex = /^(mode|theme|ext|keybinding)-|^snippets\//; - //TODO: -/* var pathModules = [ + var pathModules = [ "declare module 'ace-builds/webpack-resolver';", "declare module 'ace-builds/esm-resolver';", "declare module 'ace-builds/src-noconflict/ace';" @@ -197,15 +198,10 @@ function buildTypes() { var moduleName = path.split('.')[0]; return "declare module 'ace-builds/src-noconflict/" + moduleName + "';"; } - }).filter(Boolean)).join("\n") + "\n";*/ - - //TODO: - fs.copyFileSync(ACE_HOME + '/ace.d.ts', BUILD_DIR + '/ace.d.ts'); - generateDeclaration(BUILD_DIR + '/ace.d.ts'); - var definitions = fs.readFileSync(BUILD_DIR + '/ace.d.ts', 'utf8'); - var newDefinitions = updateDeclarationModuleNames(definitions); - fs.writeFileSync(BUILD_DIR + '/ace.d.ts', newDefinitions); - // + }).filter(Boolean)).join("\n") + "\n"; + + fs.writeFileSync(BUILD_DIR + '/ace.d.ts', moduleRef + '\n' + definitions); + fs.writeFileSync(BUILD_DIR + '/ace-modules.d.ts', pathModules); var esmUrls = []; var loader = paths.map(function(path) { diff --git a/package.json b/package.json index f1725812e07..afa32de447e 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "styles", "ace.d.ts", "ace-modes.d.ts", + "ace-extensions.d.ts", "esm-resolver.js", "translations", "!**/*_test.js", @@ -44,8 +45,7 @@ "lint": "eslint \"src/**/*.js\"", "fix": "eslint --fix \"src/**/*.js\"", "changelog": "standard-version", - "prepack": "node tool/esm_resolver_generator.js && node tool/ace_declaration_generator.js && node Makefile.dryice.js css --target build-styles && rm -rf styles && mv build-styles/css styles", - "tsc": "rimraf types && tsc --project tsconfig.json" + "prepack": "node tool/esm_resolver_generator.js && node Makefile.dryice.js css --target build-styles && rm -rf styles && mv build-styles/css styles" }, "standard-version": { "skip": { diff --git a/tool/ace_declaration_generator.js b/tool/ace_declaration_generator.js deleted file mode 100644 index 413bd49cbb7..00000000000 --- a/tool/ace_declaration_generator.js +++ /dev/null @@ -1,356 +0,0 @@ -const ts = require('typescript'); -const fs = require("fs"); -const path = require("path"); - -/** - * @param {string} directoryPath - */ -function getParsedConfigFromDirectory(directoryPath) { - const configPath = ts.findConfigFile(directoryPath, ts.sys.fileExists, 'tsconfig.json'); - if (!configPath) throw new Error("Could not find tsconfig.json"); - - const configFile = ts.readConfigFile(configPath, ts.sys.readFile); - const parseConfigHost = { - fileExists: ts.sys.fileExists, - readFile: ts.sys.readFile, - readDirectory: ts.sys.readDirectory, - useCaseSensitiveFileNames: true - }; - - return ts.parseJsonConfigFileContent(configFile.config, parseConfigHost, directoryPath); -} - -/** - * @return {string} - */ -function generateInitialDeclaration() { - const baseDirectory = path.resolve(__dirname, '..'); - const parsedConfig = getParsedConfigFromDirectory(baseDirectory); - const defaultCompilerHost = ts.createCompilerHost({}); - let fileContent; - - const customCompilerHost = { - ...defaultCompilerHost, - writeFile: function (fileName, content) { - fileContent = content; - return; - } - }; - - const program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options, customCompilerHost); - program.emit(); - return fileContent; -} - -/** - * @param {string} fileName - * @param {string} content - */ -function createCustomCompilerHost(fileName, content) { - const newSourceFile = ts.createSourceFile(fileName, content, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); - - const defaultCompilerHost = ts.createCompilerHost({}); - return { - ...defaultCompilerHost, - getSourceFile: (name, languageVersion) => { - if (name === fileName) { - return newSourceFile; - } - return defaultCompilerHost.getSourceFile(name, languageVersion); - }, - fileExists: (name) => { - if (name === fileName) { - return true; - } - return defaultCompilerHost.fileExists(name); - }, - readFile: (name) => { - if (name === fileName) { - return content; - } - return defaultCompilerHost.readFile(name); - } - }; -} - -/** - * @param {string} content - * @param {string} aceNamespacePath - */ -function fixDeclaration(content, aceNamespacePath) { - const temporaryName = "temp.d.ts"; - const customCompilerHost = createCustomCompilerHost(temporaryName, content); - const program = ts.createProgram([temporaryName], { - noEmit: true - }, customCompilerHost); - - var checker = program.getTypeChecker(); - let interfaces = collectInterfaces(aceNamespacePath); - - /** - * @param {ts.TransformationContext} context - * @return {function(*): *} - */ - function transformer(context) { - return (sourceFile) => { - function visit(node) { - let updatedNode = node; - if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { - // replace wrong generated modules - if (node.name.text.endsWith("lib/keys") || node.name.text.endsWith("linking")) { - let statements = []; - if (interfaces[node.name.text]) { - statements = interfaces[node.name.text]; - } - const newBody = ts.factory.createModuleBlock(statements); - updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); - } - else if (interfaces[node.name.text]) { - // add corresponding interfaces to support mixins (EventEmitter, OptionsProvider, etc.) - if (node.body && ts.isModuleBlock(node.body)) { - const newBody = ts.factory.createModuleBlock( - node.body.statements.concat(interfaces[node.name.text]).filter(statement => { - if (node.name.text.endsWith("autocomplete")) { - return !(ts.isModuleDeclaration(statement) && statement.name.text - === 'Autocomplete'); - } - return true; - })); - updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); - } - } - else if (node.name.text.endsWith("/config") || node.name.text.endsWith("textarea")) { - //TODO: should be better way to do this - //correct mixed exports (export function + export = _exports) - if (node.body && ts.isModuleBlock(node.body)) { - const newBody = ts.factory.createModuleBlock(node.body.statements.filter(statement => { - const exportsStatement = ts.isVariableStatement(statement) - && statement.declarationList.declarations[0].name.getText() == "_exports"; - return exportsStatement || ts.isExportAssignment(statement) - || ts.isImportEqualsDeclaration(statement); - })); - updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); - - } - } - else if (node.name.text.endsWith("static_highlight")) { - if (node.body && ts.isModuleBlock(node.body)) { - const newBody = ts.factory.createModuleBlock(node.body.statements.filter(statement => { - return !ts.isExportAssignment(statement); - })); - updatedNode = ts.factory.updateModuleDeclaration(node, node.modifiers, node.name, newBody); - } - } - } - else if (ts.isInterfaceDeclaration(node) && node.heritageClauses) { - for (const clause of node.heritageClauses) { - if (clause.token === ts.SyntaxKind.ExtendsKeyword && clause.types.length === 0) { - if (node.members.length === 0) { - return; // remove entire interface declaration - } - // Remove the extends clause if it's empty - return context.factory.updateInterfaceDeclaration(node, node.modifiers, node.name, - node.typeParameters, [], node.members - ); - } - } - } - else if (ts.isClassDeclaration(node) && node.heritageClauses) { - let updatedHeritageClauses = []; - // remove inheritances from undefined types - for (let i = 0; i < node.heritageClauses.length; i++) { - let clause = node.heritageClauses[i]; - if (clause.token === ts.SyntaxKind.ExtendsKeyword) { - const updatedTypes = clause.types.filter(type => { - const symbol = checker.getSymbolAtLocation(type.expression); - if (symbol) { - const declaredType = checker.getDeclaredTypeOfSymbol(symbol); - - return declaredType.flags !== ts.TypeFlags.Undefined - && declaredType["intrinsicName"] !== "error"; - } - return true; // keep the type if the symbol can't be resolved - }); - if (updatedTypes.length === 0) { - continue; - } - var updatedHeritageClause = clause; - if (updatedTypes.length !== clause.types.length) { - updatedHeritageClause = context.factory.createHeritageClause( - ts.SyntaxKind.ExtendsKeyword, updatedTypes); - } - } - if (updatedHeritageClause) { - updatedHeritageClauses.push(updatedHeritageClause); - } - else { - updatedHeritageClauses.push(clause); - } - } - return context.factory.updateClassDeclaration(node, node.modifiers, node.name, node.typeParameters, - updatedHeritageClauses, node.members - ); - } - return ts.visitEachChild(updatedNode, visit, context); - } - - return ts.visitNode(sourceFile, visit); - }; - } - - const sourceCode = program.getSourceFile(temporaryName); - const result = ts.transform(sourceCode, [transformer]); - - const printer = ts.createPrinter(); - result.transformed.forEach(transformedFile => { - let output = printer.printFile(transformedFile); - fs.writeFileSync(aceNamespacePath, output); - }); - - result.dispose(); - - checkFinalDeclaration(aceNamespacePath); -} - -/** - * @param {string} declarationName - */ -function checkFinalDeclaration(declarationName) { - const program = ts.createProgram([declarationName], { - noEmit: true - }); - const diagnostics = ts.getPreEmitDiagnostics(program); - - diagnostics.forEach(diagnostic => { - if (diagnostic.file) { - const { - line, - character - } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); - const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n'); - console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); - } - else { - console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')); - } - }); -} - -/** - * @param {string} aceNamespacePath - */ -function collectInterfaces(aceNamespacePath) { - const program = ts.createProgram([aceNamespacePath], { - noEmit: true - }); - const sourceFile = program.getSourceFile(aceNamespacePath); - const result = {}; - const printer = ts.createPrinter(); - let packageName = "ace-code"; - - function visit(node) { - if (node && ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name)) { - let nodes = []; - if (node.body && ts.isModuleBlock(node.body)) { - ts.forEachChild(node.body, (child) => { - if (ts.isInterfaceDeclaration(child) || ts.isFunctionDeclaration(child)) nodes.push(child); - }); - } - if (nodes.length > 0) { - const interfaceStrings = nodes.map( - interfaceNode => printer.printNode(ts.EmitHint.Unspecified, interfaceNode, sourceFile)); - - let concatenatedInterfaceStrings = interfaceStrings.join('\n\n'); - let identifiers = concatenatedInterfaceStrings.match(/Ace\.[\w]+ 0) { - identifiers = [...new Set(identifiers)]; - let importAlias = ''; - identifiers.forEach(identifier => { - let typeName = identifier.replace("Ace.", ""); - - if (typeName.includes("<")) { - typeName = typeName + "T>"; - } - importAlias += "type " + typeName + " = import(\"" + packageName + "\").Ace." + typeName - + ";\n\n"; - }); - concatenatedInterfaceStrings = "namespace Ace {" + importAlias + "}" + concatenatedInterfaceStrings; - } - - const newSourceFile = ts.createSourceFile( - 'temp.d.ts', concatenatedInterfaceStrings, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS); - nodes = newSourceFile.statements; - } - result[node.name.text.replace("./", packageName + "/")] = nodes; - } - ts.forEachChild(node, visit); - } - - visit(sourceFile); - - return result; -} - -/** - * @param {string} aceNamespacePath - * @return {string} - */ -function cloneAceNamespace(aceNamespacePath) { - const program = ts.createProgram([aceNamespacePath], { - noEmit: true - }); - const sourceFile = program.getSourceFile(aceNamespacePath); - const printer = ts.createPrinter(); - for (let i = 0; i < sourceFile.statements.length; i++) { - const node = sourceFile.statements[i]; - if (ts.isModuleDeclaration(node) && node.name.text == "Ace") { - let aceModule = printer.printNode(ts.EmitHint.Unspecified, node, sourceFile); - aceModule = aceModule.replace(/"\.\/src/g, "\"ace-code/src"); - aceModule = '\n' + aceModule + '\n'; - return aceModule; - } - } -} - -/** - * @param {string} aceNamespacePath - */ -function generateDeclaration(aceNamespacePath) { - let data = generateInitialDeclaration(); - - let packageName = "ace-code"; - - let updatedContent = data.replace(/(declare module ")/g, "$1" + packageName + "/src/"); - updatedContent = updatedContent.replace(/(require\(")/g, "$1" + packageName + "/src/"); - updatedContent = updatedContent.replace(/(import\(")(?!(?:\.|ace\-code))/g, "$1" + packageName + "/src/"); - updatedContent = updatedContent.replace(/ace\-(?:code|builds)(\/src)?\/ace/g, packageName); - let aceModule = cloneAceNamespace(aceNamespacePath); - - updatedContent = updatedContent.replace(/(declare\s+module\s+"ace-(?:code|builds)"\s+{)/, "$1" + aceModule); - updatedContent = updatedContent.replace(/(import\(")[./]*ace("\).Ace)/g, "$1" + packageName + "$2"); - updatedContent = updatedContent.replace(/(?:export)?\snamespace(?!\sAce)/g, "export namespace"); - fixDeclaration(updatedContent, aceNamespacePath); -} - -/** - * @param {string} content - */ -function updateDeclarationModuleNames(content) { - let output = content.replace( - /ace\-code(?:\/src)?\/(mode|theme|ext|keybinding|snippets)\//g, "ace-builds/src-noconflict/$1-"); - output = output.replace(/ace\-code(?:\/src)?/g, "ace-builds-internal"); - output = output.replace(/ace\-code/g, "ace-builds"); - output = output + '\n' + "declare module 'ace-builds/webpack-resolver';\n" - + "declare module 'ace-builds/esm-resolver';"; - //TODO: modes/worker - return output; -} - - -if (!module.parent) { - generateDeclaration(__dirname + "../ace.d.ts"); -} -else { - exports.generateDeclaration = generateDeclaration; - exports.updateDeclarationModuleNames = updateDeclarationModuleNames; -} From 858136561671ce559439325010e0349e42f7bd4f Mon Sep 17 00:00:00 2001 From: mkslanc Date: Fri, 17 Nov 2023 19:00:57 +0400 Subject: [PATCH 33/36] update to last version --- ace-internal.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ace-internal.d.ts b/ace-internal.d.ts index b7386b8a29c..b63857932eb 100644 --- a/ace-internal.d.ts +++ b/ace-internal.d.ts @@ -1071,6 +1071,7 @@ export namespace Ace { setSelectOnHover?: Boolean; stickySelectionDelay?: Number; ignoreCaption?: Boolean; + showLoadingState?: Boolean; emptyMessage?(prefix: String): String; getPopup(): AcePopup; showPopup(editor: Editor, options: CompletionOptions): void; From cec9e2ab9c8cd7ee62daa7b65ede12240e5edff1 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Mon, 4 Dec 2023 18:36:16 +0400 Subject: [PATCH 34/36] return base ace.d.ts; use `ace-internal` for inner typings --- ace-internal.d.ts | 2037 ++++++++++++++----------- ace.d.ts | 2036 +++++++++++------------- src/ace.js | 2 +- src/anchor.js | 8 +- src/apply_delta.js | 2 +- src/autocomplete.js | 16 +- src/autocomplete/inline.js | 2 +- src/autocomplete/popup.js | 2 +- src/background_tokenizer.js | 4 +- src/commands/command_manager.js | 2 +- src/commands/default_commands.js | 2 +- src/commands/multi_select_commands.js | 4 +- src/document.js | 60 +- src/edit_session.js | 53 +- src/edit_session/bracket_match.js | 16 +- src/edit_session/fold.js | 18 +- src/edit_session/fold_line.js | 2 +- src/edit_session/folding.js | 10 +- src/editor.js | 36 +- src/ext/command_bar.js | 6 +- src/ext/hardwrap.js | 2 +- src/ext/inline_autocomplete.js | 14 +- src/ext/language_tools.js | 9 +- src/ext/rtl.js | 2 +- src/ext/simple_tokenizer.js | 6 +- src/ext/static_highlight.js | 4 +- src/keyboard/hash_handler.js | 22 +- src/keyboard/keybinding.js | 12 +- src/layer/cursor.js | 2 +- src/layer/gutter.js | 14 +- src/layer/lines.js | 10 +- src/layer/marker.js | 18 +- src/layer/text.js | 2 +- src/lib/app_config.js | 1 + src/line_widgets.js | 16 +- src/marker_group.js | 4 +- src/mode/text.js | 18 +- src/mode/text_highlight_rules.js | 18 +- src/mouse/default_handlers.js | 2 +- src/multi_select.js | 12 +- src/occur.js | 12 +- src/placeholder.js | 6 +- src/range.js | 26 +- src/range_list.js | 10 +- src/search.js | 6 +- src/search_highlight.js | 2 +- src/selection.js | 14 +- src/split.js | 2 +- src/token_iterator.js | 8 +- src/tokenizer.js | 6 +- src/tooltip.js | 2 +- src/undomanager.js | 12 +- src/virtual_renderer.js | 32 +- 53 files changed, 2330 insertions(+), 2314 deletions(-) diff --git a/ace-internal.d.ts b/ace-internal.d.ts index b63857932eb..9e0300552d6 100644 --- a/ace-internal.d.ts +++ b/ace-internal.d.ts @@ -1,163 +1,340 @@ -/// -/// - export namespace Ace { - export type NewLineMode = 'auto' | 'unix' | 'windows'; - - export interface Anchor extends EventEmitter { - getPosition(): Position; - getDocument(): Document; - setPosition(row: number, column: number, noClip?: boolean): void; - detach(): void; - attach(doc: Document): void; - } - - export interface Document extends EventEmitter { - setValue(text: string): void; - getValue(): string; - createAnchor(row: number, column: number): Anchor; - getNewLineCharacter(): string; - setNewLineMode(newLineMode: NewLineMode): void; - getNewLineMode(): NewLineMode; - isNewLine(text: string): boolean; - getLine(row: number): string; - getLines(firstRow: number, lastRow: number): string[]; - getAllLines(): string[]; - getLength(): number; - getTextRange(range: Range): string; - getLinesForRange(range: Range): string[]; - insert(position: Position, text: string): Position; - insert(position: {row: number, column: number}, text: string): Position; - insertInLine(position: Position, text: string): Position; - insertNewLine(position: Point): Point; - clippedPos(row: number, column: number): Point; - clonePos(pos: Point): Point; - pos(row: number, column: number): Point; - insertFullLines(row: number, lines: string[]): void; - insertMergedLines(position: Position, lines: string[]): Point; - remove(range: Range): Position; - removeInLine(row: number, startColumn: number, endColumn: number): Position; - removeFullLines(firstRow: number, lastRow: number): string[]; - removeNewLine(row: number): void; - replace(range: Range, text: string): Position; - applyDeltas(deltas: Delta[]): void; - revertDeltas(deltas: Delta[]): void; - applyDelta(delta: Delta, doNotValidate?: boolean): void; - revertDelta(delta: Delta): void; - indexToPosition(index: number, startRow: number): Position; - positionToIndex(pos: Position, startRow?: number): number; - } - - export interface FoldLine { - folds: Fold[]; - range: Range; - start: Point; - end: Point; + type Anchor = import("./src/anchor").Anchor; + type Editor = import("./src/editor").Editor; + type EditSession = import("./src/edit_session").EditSession; + type Document = import("./src/document").Document; + type Fold = import("./src/edit_session/fold").Fold; + type FoldLine = import("./src/edit_session/fold_line").FoldLine; + type Range = import("./src/range").Range; + type VirtualRenderer = import("./src/virtual_renderer").VirtualRenderer; + type UndoManager = import("./src/undomanager").UndoManager; + type Tokenizer = import("./src/tokenizer").Tokenizer; + type TokenIterator = import("./src/token_iterator").TokenIterator; + type Selection = import("./src/selection").Selection; + type Autocomplete = import("./src/autocomplete").Autocomplete; + type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; + type CompletionProvider = import("./src/autocomplete").CompletionProvider; + type AcePopup = import("./src/autocomplete/popup").AcePopup; + type AceInline = import("./src/autocomplete/inline").AceInline; + type MouseEvent = import("./src/mouse/mouse_event").MouseEvent; + type RangeList = import("./src/range_list").RangeList; + type FilteredList = import("./src/autocomplete").FilteredList; + type LineWidgets = import("./src/line_widgets").LineWidgets; + type SearchBox = import("./src/ext/searchbox").SearchBox; + type Occur = import("./src/occur").Occur; + type DefaultHandlers = import("./src/mouse/default_handlers").DefaultHandlers; + type GutterHandler = import("./src/mouse/default_gutter_handler").GutterHandler; + type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; + type AppConfig = import("./src/lib/app_config").AppConfig; + + + type AfterLoadCallback = (err: Error | null, module: unknown) => void; + type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; + + export interface Config { + get(key: string): any; + + set(key: string, value: any): void; + + all(): { [key: string]: any }; + + moduleUrl(name: string, component?: string): string; + + setModuleUrl(name: string, subst: string): string; + + setLoader(cb: LoaderFunction): void; + + setModuleLoader(name: string, onLoad: Function): void; - shiftRow(shift: number): void; - addFold(fold: Fold): void; - containsRow(row: number): boolean; - walk(callback: Function, endRow?: number, endColumn?: number): void; - getNextFoldTo(row: number, column: number): null | { fold: Fold, kind: string }; - addRemoveChars(row: number, column: number, len: number): void; - split(row: number, column: number): FoldLine; - merge(foldLineNext: FoldLine): void; - idxToPosition(idx: number): Point; + loadModule(moduleName: string | [string, string], + onLoad?: (module: any) => void): void; + + init(packaged: any): any; + + defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; + + resetOptions(obj: any): void; + + setDefaultValue(path: string, name: string, value: any): void; + + setDefaultValues(path: string, optionHash: { [key: string]: any }): void; } - export interface Fold { - range: Range; - start: Point; - end: Point; - foldLine?: FoldLine; - sameRow: boolean; - subFolds: Fold[]; + interface Theme { + cssClass?: string; + cssText?: string; + $id?: string; + padding?: number | string; + isDark?: boolean; + } + + interface ScrollBar { + setVisible(visible: boolean): void; + + [key: string]: any; + } + + interface HScrollbar extends ScrollBar { + setWidth(width: number): void; + } - setFoldLine(foldLine: FoldLine): void; - clone(): Fold; - addSubFold(fold: Fold): Fold; - restoreRange(range: Range): void; + interface VScrollbar extends ScrollBar { + setHeight(width: number): void; + } + + interface LayerConfig { + width: number, + padding: number, + firstRow: number, + firstRowScreen: number, + lastRow: number, + lineHeight: number, + characterWidth: number, + minHeight: number, + maxHeight: number, + offset: number, + height: number, + gutterOffset: number + } + + interface HardWrapOptions { + startRow: number; + endRow: number; + allowMerge?: boolean; + column?: number; + } + + interface CommandBarOptions { + maxElementsOnTooltip: number; + alwaysShow: boolean; + showDelay: number; + hideDelay: number; + } + + interface ScreenCoordinates { + row: number, + column: number, + side?: 1 | -1, + offsetX?: number } interface Folding { - getFoldAt(row: number, column: number, side: number): Fold; - getFoldsInRange(range: Range): Fold[]; - getFoldsInRangeList(ranges: Range[]): Fold[]; - getAllFolds(): Fold[]; - getFoldStringAt(row: number, - column: number, - trim?: number, - foldLine?: FoldLine): string | null; - getFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; - getNextFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; + $foldData: FoldLine[]; + + /** + * Looks up a fold at a given row/column. Possible values for side: + * -1: ignore a fold if fold.start = row/column + * +1: ignore a fold if fold.end = row/column + **/ + getFoldAt(row: number, column: number, side?: number): Ace.Fold; + + /** + * Returns all folds in the given range. Note, that this will return folds + **/ + getFoldsInRange(range: Ace.Range | Ace.Delta): Ace.Fold[]; + + getFoldsInRangeList(ranges: Ace.Range[] | Ace.Range): Ace.Fold[]; + + /** + * Returns all folds in the document + */ + getAllFolds(): Ace.Fold[]; + + /** + * Returns the string between folds at the given position. + * E.g. + * foob|arwolrd -> "bar" + * foobarwol|rd -> "world" + * foobarwolrd -> + * + * where | means the position of row/column + * + * The trim option determs if the return string should be trimed according + * to the "side" passed with the trim value: + * + * E.g. + * foob|arwolrd -trim=-1> "b" + * foobarwol|rd -trim=+1> "rld" + * fo|obarwolrd -trim=00> "foo" + */ + getFoldStringAt(row: number, column: number, trim?: number, foldLine?: Ace.FoldLine): string | null; + + getFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; + + /** + * Returns the fold which starts after or contains docRow + */ + getNextFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; + getFoldedRowCount(first: number, last: number): number; - addFold(placeholder: string | Fold, range?: Range): Fold; - addFolds(folds: Fold[]): void; - removeFold(fold: Fold): void; - removeFolds(folds: Fold[]): void; - expandFold(fold: Fold): void; - expandFolds(folds: Fold[]): void; - unfold(location: null | number | Point | Range, - expandInner?: boolean): Fold[] | undefined; - isRowFolded(docRow: number, startFoldRow?: FoldLine): boolean; - getFoldRowEnd(docRow: number, startFoldRow?: FoldLine): number; - getFoldRowStart(docRow: number, startFoldRow?: FoldLine): number; - getFoldDisplayLine(foldLine: FoldLine, - endRow: number | null, - endColumn: number | null, - startRow: number | null, - startColumn: number | null): string; - getDisplayLine(row: number, - endColumn: number | null, - startRow: number | null, - startColumn: number | null): string; + + $addFoldLine(foldLine: FoldLine): Ace.FoldLine; + + /** + * Adds a new fold. + * @returns {Ace.Fold} + * The new created Fold object or an existing fold object in case the + * passed in range fits an existing fold exactly. + */ + addFold(placeholder: Ace.Fold | string, range?: Ace.Range): Ace.Fold; + + $modified: boolean; + + addFolds(folds: Ace.Fold[]): void; + + removeFold(fold: Ace.Fold): void; + + removeFolds(folds: Ace.Fold[]): void; + + expandFold(fold: Ace.Fold): void; + + expandFolds(folds: Ace.Fold[]): void; + + unfold(location?: number | null | Ace.Point | Ace.Range | Ace.Range[], expandInner?: boolean): Ace.Fold[] | undefined; + + /** + * Checks if a given documentRow is folded. This is true if there are some + * folded parts such that some parts of the line is still visible. + **/ + isRowFolded(docRow: number, startFoldRow?: Ace.FoldLine): boolean; + + getRowFoldEnd(docRow: number, startFoldRow?: Ace.FoldLine): number; + + getRowFoldStart(docRow: number, startFoldRow?: Ace.FoldLine): number; + + getFoldDisplayLine(foldLine: Ace.FoldLine, endRow?: number | null, endColumn?: number | null, startRow?: number | null, startColumn?: number | null): string; + + getDisplayLine(row: number, endColumn: number | null, startRow: number | null, startColumn: number | null): string; + + $cloneFoldData(): Ace.FoldLine[]; + toggleFold(tryToUnfold?: boolean): void; - getCommentFoldRange(row: number, - column: number, - dir: number): Range | undefined; - foldAll(startRow?: number, endRow?: number, depth?: number): void; + + getCommentFoldRange(row: number, column: number, dir?: number): Ace.Range | undefined; + + foldAll(startRow?: number | null, endRow?: number | null, depth?: number | null, test?: Function): void; + + foldToLevel(level: number): void; + + foldAllComments(): void; + + $foldStyles: { + manual: number; + markbegin: number; + markbeginend: number; + }; + $foldStyle: string; + setFoldStyle(style: string): void; + + $setFolding(foldMode: Ace.FoldMode): void; + + $foldMode: any; + foldWidgets: any[]; + getFoldWidget: any; + getFoldWidgetRange: any; + $updateFoldWidgets: any; + $tokenizerUpdateFoldWidgets: any; + getParentFoldRangeData(row: number, ignoreCurrent?: boolean): { - range?: Range, - firstRange: Range + range?: Ace.Range; + firstRange?: Ace.Range; }; + + onFoldWidgetClick(row: number, e: any): void; + + $toggleFoldWidget(row: number, options: any): Fold | any; + + /** + * + * @param {boolean} [toggleParent] + */ toggleFoldWidget(toggleParent?: boolean): void; - updateFoldWidgets(delta: Delta): void; + + updateFoldWidgets(delta: Ace.Delta): void; + + tokenizerUpdateFoldWidgets(e: any): void; } - export interface Range { + interface BracketMatch { + findMatchingBracket: (position: Point, chr?: string) => Point; + + getBracketRange: (pos: Point) => null | Range; + /** + * Returns: + * * null if there is no any bracket at `pos`; + * * two Ranges if there is opening and closing brackets; + * * one Range if there is only one bracket + */ + getMatchingBracketRanges: (pos: Point, isBackwards?: boolean) => null | Range[]; + $brackets: { + ")": string; + "(": string; + "]": string; + "[": string; + "{": string; + "}": string; + "<": string; + ">": string; + }; + $findOpeningBracket: (bracket: string, position: Point, typeRe?: RegExp) => Point | null; + $findClosingBracket: (bracket: string, position: Point, typeRe?: RegExp) => Point | null; + /** + * Returns [[Range]]'s for matching tags and tag names, if there are any + */ + getMatchingTags: (pos: Point) => { + closeTag: Range; + closeTagName: Range; + openTag: Range; + openTagName: Range; + }; + $findTagName: (iterator: any) => any; + $findClosingTag: (iterator: any, token: any) => { + openTag: Range; + closeTag: Range; + openTagName: Range; + closeTagName: Range; + }; + $findOpeningTag: (iterator: any, token: any) => { + openTag: Range; + closeTag: Range; + openTagName: Range; + closeTagName: Range; + }; + } + + interface IRange { start: Point; end: Point; + } + + interface LineWidget { + el: HTMLElement; + rowCount: number; + hidden: boolean; + _inDocument: boolean; + column?: number; + row?: number; + $oldWidget?: LineWidget, + session: EditSession, + html?: string, + text?: string, + className?: string, + coverGutter?: boolean, + pixelHeight?: number, + $fold?: Fold, + editor: Editor, + coverLine?: boolean, + fixedWidth?: boolean, + fullWidth?: boolean, + screenWidth?: number, + rowsAbove?: number, + lenses?: any[], + } + + type NewLineMode = 'auto' | 'unix' | 'windows'; - isEqual(range: Range): boolean; - toString(): string; - contains(row: number, column: number): boolean; - compareRange(range: Range): number; - comparePoint(p: Point): number; - containsRange(range: Range): boolean; - intersects(range: Range): boolean; - isEnd(row: number, column: number): boolean; - isStart(row: number, column: number): boolean; - setStart(row: number, column: number): void; - setEnd(row: number, column: number): void; - inside(row: number, column: number): boolean; - insideStart(row: number, column: number): boolean; - insideEnd(row: number, column: number): boolean; - compare(row: number, column: number): number; - compareStart(row: number, column: number): number; - compareEnd(row: number, column: number): number; - compareInside(row: number, column: number): number; - clipRows(firstRow: number, lastRow: number): Range; - extend(row: number, column: number): Range; - isEmpty(): boolean; - isMultiLine(): boolean; - clone(): Range; - collapseRows(): Range; - toScreenRange(session: EditSession): Range; - moveBy(row: number, column: number): void; - } - - export interface EditSessionOptions { + interface EditSessionOptions { wrap: "off" | "free" | "printmargin" | boolean | number; wrapMethod: 'code' | 'text' | 'auto'; indentedSoftWrap: boolean; @@ -172,7 +349,7 @@ export namespace Ace { mode: string; } - export interface VirtualRendererOptions { + interface VirtualRendererOptions { animatedScroll: boolean; showInvisibles: boolean; showPrintMargin: boolean; @@ -187,7 +364,7 @@ export namespace Ace { highlightGutterLine: boolean; hScrollBarAlwaysVisible: boolean; vScrollBarAlwaysVisible: boolean; - fontSize: number; + fontSize: string; fontFamily: string; maxLines: number; minLines: number; @@ -199,9 +376,10 @@ export namespace Ace { maxPixelHeight: number; useSvgGutterIcons: boolean; showFoldedAnnotations: boolean; + useResizeObserver: boolean; } - export interface MouseHandlerOptions { + interface MouseHandlerOptions { scrollSpeed: number; dragDelay: number; dragEnabled: boolean; @@ -209,10 +387,10 @@ export namespace Ace { tooltipFollowsMouse: boolean; } - export interface EditorOptions extends EditSessionOptions, + interface EditorOptions extends EditSessionOptions, MouseHandlerOptions, VirtualRendererOptions { - selectionStyle: string; + selectionStyle: "fullLine" | "screenLine" | "text" | "line"; highlightActiveLine: boolean; highlightSelectedWord: boolean; readOnly: boolean; @@ -235,9 +413,224 @@ export namespace Ace { relativeLineNumbers: boolean; enableMultiselect: boolean; enableKeyboardAccessibility: boolean; + enableCodeLens: boolean; + } + + interface EventsBase { + [key: string]: any; + } + + interface EditSessionEvents { + /** + * Emitted when the document changes. + * @param delta + */ + "change": (delta: Delta) => void; + /** + * Emitted when the tab size changes, via [[EditSession.setTabSize]]. + * @param tabSize + */ + "changeTabSize": (tabSize: number) => void; + /** + * Emitted when the ability to overwrite text changes, via [[EditSession.setOverwrite]]. + * @param overwrite + */ + "changeOverwrite": (overwrite: boolean) => void; + /** + * Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change. + * @param e + */ + "changeBreakpoint": (e: { row: number, breakpoint: boolean }) => void; + /** + * Emitted when a front marker changes. + * @param e + */ + "changeFrontMarker": (e: { row: number, marker: boolean }) => void; + /** + * Emitted when a back marker changes. + * @param e + */ + "changeBackMarker": (e: { row: number, marker: boolean }) => void; + /** + * Emitted when an annotation changes, like through [[EditSession.setAnnotations]]. + * @param e + */ + "changeAnnotation": (e: { row: number, lines: string[] }) => void; + /** + * Emitted when a background tokenizer asynchronously processes new rows. + */ + "tokenizerUpdate": (e: { data: { first: string, last: string } }) => void; + /** + * Emitted when the current mode changes. + * @param e + */ + "changeMode": (e) => void; + /** + * Emitted when the wrap mode changes. + * @param e + */ + "changeWrapMode": (e) => void; + /** + * Emitted when the wrapping limit changes. + * @param e + */ + "changeWrapLimit": (e) => void; + /** + * Emitted when a code fold is added or removed. + * @param e + */ + "changeFold": (e, session: EditSession) => void; + /** + * Emitted when the scroll top changes. + * @param scrollTop The new scroll top value + **/ + "changeScrollTop": (scrollTop: number) => void; + /** + * Emitted when the scroll left changes. + * @param scrollLeft The new scroll left value + **/ + "changeScrollLeft": (scrollLeft: number) => void; + "changeEditor": (e: { editor: Editor }) => void; + } + + interface EditorEvents { + "change": (delta: Delta) => void; + "changeSelection": () => void; + "input": () => void; + /** + * Emitted whenever the [[EditSession]] changes. + * @param e An object with two properties, `oldSession` and `session`, that represent the old and new [[EditSession]]s. + **/ + "changeSession": (e: { oldSession: EditSession, session: EditSession }) => void; + "blur": (e) => void; + "mousedown": (e: MouseEvent) => void; + "mousemove": (e: MouseEvent & { scrollTop? }, editor?: Editor) => void; + "changeStatus": () => void; + "keyboardActivity": () => void; + "mousewheel": (e: MouseEvent) => void; + "mouseup": (e: MouseEvent) => void; + "beforeEndOperation": (e) => void; + "nativecontextmenu": (e) => void; + "destroy": () => void; + "focus": () => void; + /** + * Emitted when text is copied. + * @param text The copied text + **/ + "copy": (text: string) => void; + /** + * Emitted when text is pasted. + **/ + "paste": (text: string, event) => void; + /** + * Emitted when the selection style changes, via [[Editor.setSelectionStyle]]. + * @param data Contains one property, `data`, which indicates the new selection style + **/ + "changeSelectionStyle": (data: "fullLine" | "screenLine" | "text" | "line") => void; + } + + interface AcePopupEvents { + "click": (e: MouseEvent) => void; + "dblclick": (e: MouseEvent) => void; + "tripleclick": (e: MouseEvent) => void; + "quadclick": (e: MouseEvent) => void; + "show": () => void; + "hide": () => void; + "select": (hide: boolean) => void; + "changeHoverMarker": (e) => void; + } + + interface DocumentEvents { + /** + * Fires whenever the document changes. + * Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available: + * * `"insert"` + * * `range`: the [[Range]] of the change within the document + * * `lines`: the lines being added + * * `"remove"` + * * `range`: the [[Range]] of the change within the document + * * `lines`: the lines being removed + * + **/ + "change": (e: Delta) => void; + "changeNewLineMode": () => void; + } + + interface AnchorEvents { + /** + * Fires whenever the anchor position changes. + * Both of these objects have a `row` and `column` property corresponding to the position. + * Events that can trigger this function include [[Anchor.setPosition `setPosition()`]]. + * @param {Object} e An object containing information about the anchor position. It has two properties: + * - `old`: An object describing the old Anchor position + * - `value`: An object describing the new Anchor position + **/ + "change": (e: { old: Point, value: Point }) => void; } - export interface SearchOptions { + interface BackgroundTokenizerEvents { + /** + * Fires whenever the background tokeniziers between a range of rows are going to be updated. + * @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated. + **/ + "update": (e: { first: number, last: number }) => void; + } + + interface SelectionEvents { + /** + * Emitted when the cursor position changes. + **/ + "changeCursor": () => void; + /** + * Emitted when the cursor selection changes. + **/ + "changeSelection": () => void; + } + + interface PlaceHolderEvents { + + } + + interface GutterEvents { + "changeGutterWidth": (width: number) => void; + } + + interface TextEvents { + "changeCharacterSize": (e) => void; + } + + interface VirtualRendererEvents { + "afterRender": (e, renderer: VirtualRenderer) => void; + "beforeRender": (e, renderer: VirtualRenderer) => void; + } + + class EventEmitter { + once(name: K, callback: T[K]): void; + + setDefaultHandler(name: string, callback: Function): void; + + removeDefaultHandler(name: string, callback: Function): void; + + on(name: K, callback: T[K], capturing?: boolean): T[K]; + + addEventListener(name: K, callback: T[K], capturing?: boolean): T[K]; + + off(name: K, callback: T[K]): void; + + removeListener(name: K, callback: T[K]): void; + + removeEventListener(name: K, callback: T[K]): void; + + removeAllListeners(name?: string): void; + + _signal(eventName: string, e: any): void; + + _emit(eventName: string, e: any): void; + + _dispatchEvent(eventName: string, e: any): void; + } + + interface SearchOptions { needle: string | RegExp; preventScroll: boolean; backwards: boolean; @@ -249,35 +642,28 @@ export namespace Ace { wholeWord: boolean; caseSensitive: boolean; wrap: boolean; + re: RegExp; } - export interface EventEmitter { - once(name: string, callback: Function): void; - setDefaultHandler(name: string, callback: Function): void; - removeDefaultHandler(name: string, callback: Function): void; - on(name: string, callback: Function, capturing?: boolean): void; - addEventListener(name: string, callback: Function, capturing?: boolean): void; - off(name: string, callback: Function): void; - removeListener(name: string, callback: Function): void; - removeEventListener(name: string, callback: Function): void; - removeAllListeners(name?: string): void; - } - - export interface Point { + interface Point { row: number; column: number; } - export interface Delta { + type Position = Point; + + interface Delta { action: 'insert' | 'remove'; start: Point; end: Point; lines: string[]; + id?: number, + folds?: Fold[] } - export interface Annotation { - row?: number; - column?: number; + interface Annotation { + row: number; + column: number; text: string; type: string; } @@ -287,24 +673,30 @@ export namespace Ace { className: string; } - export class MarkerGroup { - constructor(session: EditSession); - setMarkers(markers: MarkerGroupItem[]): void; - getMarkerAtPosition(pos: Position): MarkerGroupItem; - } + type MarkerGroup = import("./src/marker_group").MarkerGroup; export interface Command { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; - exec: (editor: Editor, args?: any) => void; + exec?: (editor?: Editor | any, args?: any) => void; + isAvailable?: (editor: Editor) => boolean; + description?: string, + multiSelectAction?: "forEach" | "forEachLine" | Function, + scrollIntoView?: true | "cursor" | "center" | "selectionPart" | "animate" | "selection" | "none", + aceCommandGroup?: string, + passEvent?: boolean, + level?: number, + action?: string, } - export type CommandLike = Command | ((editor: Editor) => void); + type CommandLike = Command | ((editor: Editor) => void) | ((sb: SearchBox) => void); - export interface KeyboardHandler { - handleKeyboard: Function; + type KeyboardHandler = Partial & { + attach?: (editor: Editor) => void; + detach?: (editor: Editor) => void; + getStatusText?: (editor?: any, data?) => string; } export interface MarkerLike { @@ -312,331 +704,195 @@ export namespace Ace { type: string; renderer?: MarkerRenderer; clazz: string; - inFront: boolean; - id: number; + inFront?: boolean; + id?: number; update?: (html: string[], // TODO maybe define Marker class marker: any, session: EditSession, config: any) => void; + + [key: string]: any; } - export type MarkerRenderer = (html: string[], - range: Range, - left: number, - top: number, - config: any) => void; + type MarkerRenderer = (html: string[], + range: Range, + left: number, + top: number, + config: any) => void; - export interface Token { + interface Token { type: string; value: string; index?: number; start?: number; } - interface BaseCompletion { - score?: number; - meta?: string; - caption?: string; - docHTML?: string; - docText?: string; - completerId?: string; - } - - export interface SnippetCompletion extends BaseCompletion { - snippet: string; - } - - export interface ValueCompletion extends BaseCompletion { - value: string; - } - - export type Completion = SnippetCompletion | ValueCompletion + type BaseCompletion = import("./src/autocomplete").BaseCompletion; + type SnippetCompletion = import("./src/autocomplete").SnippetCompletion; + type ValueCompletion = import("./src/autocomplete").ValueCompletion; + type Completion = import("./src/autocomplete").Completion; - export interface Tokenizer { - removeCapturingGroups(src: string): string; - createSplitterRegexp(src: string, flag?: string): RegExp; - getLineTokens(line: string, startState: string | string[]): Token[]; - } - - interface TokenIterator { - getCurrentToken(): Token; - getCurrentTokenColumn(): number; - getCurrentTokenRow(): number; - getCurrentTokenPosition(): Point; - getCurrentTokenRange(): Range; - stepBackward(): Token; - stepForward(): Token; - } - - export type HighlightRule = {defaultToken: string} | {include: string} | {todo: string} | { + type HighlightRule = ({ defaultToken: string } | { include: string } | { todo: string } | { token: string | string[] | ((value: string) => string); regex: string | RegExp; - next?: string; + next?: string | (() => void); push?: string; comment?: string; caseInsensitive?: boolean; - } + nextState?: string; + }) & { [key: string]: any }; + + type HighlightRulesMap = Record; - export type HighlightRulesMap = Record; + type KeywordMapper = (keyword: string) => string; - export type KeywordMapper = (keyword: string) => string; + interface HighlightRules { + $rules: HighlightRulesMap; + $embeds: string[]; + $keywords: any[]; + $keywordList: string[]; - export interface HighlightRules { addRules(rules: HighlightRulesMap, prefix?: string): void; + getRules(): HighlightRulesMap; + embedRules(rules: (new () => HighlightRules) | HighlightRulesMap, prefix: string, escapeRules?: boolean, append?: boolean): void; + getEmbeds(): string[]; + normalizeRules(): void; + createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; } - export interface FoldMode { + type FoldWidget = "start" | "end" | "" + + interface FoldMode { foldingStartMarker: RegExp; foldingStopMarker?: RegExp; - getFoldWidget(session: EditSession, foldStyle: string, row: number): string; - getFoldWidgetRange(session: EditSession, foldStyle: string, row: number, forceMultiline?: boolean): Range | undefined; + + getFoldWidget(session: EditSession, foldStyle: string, row: number): FoldWidget; + + getFoldWidgetRange(session: EditSession, foldStyle: string, row: number): Range | undefined; + indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; + openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; + closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; } - type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => {text: string, selection: number[]} | Range | undefined; + type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string | Range) => ({ text: string, selection: number[] } | Range) & { [key: string]: any } | undefined; type BehaviorMap = Record>; - export interface Behaviour { + interface Behaviour { add(name: string, action: string, callback: BehaviorAction): void; + addBehaviours(behaviours: BehaviorMap): void; + remove(name: string): void; + inherit(mode: SyntaxMode | (new () => SyntaxMode), filter: string[]): void; - getBehaviours(filter: string[]): BehaviorMap; + + getBehaviours(filter?: string[]): BehaviorMap; } - export interface Outdent { + interface Outdent { checkOutdent(line: string, input: string): boolean; + autoOutdent(doc: Document, row: number): number | undefined; } - export interface SyntaxMode { - HighlightRules: new () => HighlightRules; + interface SyntaxMode { + /** + * quotes used by language mode + */ + $quotes: { [quote: string]: string }; + HighlightRules: { + new(config: any): HighlightRules + }; //TODO: fix this foldingRules?: FoldMode; $behaviour?: Behaviour; $defaultBehaviour?: Behaviour; + /** + * characters that indicate the start of a line comment + */ lineCommentStart?: string; + /** + * characters that indicate the start and end of a block comment + */ + blockComment?: { start: string, end: string } + tokenRe?: RegExp; + nonTokenRe?: RegExp; + /** + * An object containing conditions to determine whether to apply matching quote or not. + */ + $pairQuotesAfter: { [quote: string]: RegExp } + $tokenizer: Tokenizer; + $highlightRules: HighlightRules; + $embeds?: string[]; + $modes?: SyntaxMode[]; + $keywordList?: string[]; + $highlightRuleConfig?: any; + completionKeywords: string[]; + transformAction: BehaviorAction; + path?: string; + getTokenizer(): Tokenizer; + toggleCommentLines(state: any, session: EditSession, startRow: number, endRow: number): void; + toggleBlockComment(state: any, session: EditSession, range: Range, cursor: Point): void; + getNextLineIndent(state: any, line: string, tab: string): string; + checkOutdent(state: any, line: string, input: string): boolean; - autoOutdent(state: any, doc: Document, row: number): void; + + autoOutdent(state: any, doc: EditSession, row: number): void; + // TODO implement WorkerClient types createWorker(session: EditSession): any; + createModeDelegates(mapping: { [key: string]: string }): void; - transformAction: BehaviorAction; + getKeywords(append?: boolean): Array; + getCompletions(state: string, session: EditSession, pos: Point, prefix: string): Completion[]; - } - type AfterLoadCallback = (err: Error | null, module: unknown) => void; - type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; + $getIndent(line: string): string; + + $createKeywordList(): string[]; + + $delegator(method: string, args: IArguments, defaultHandler): any; - export interface Config { - get(key: string): any; - set(key: string, value: any): void; - all(): { [key: string]: any }; - moduleUrl(name: string, component?: string): string; - setModuleUrl(name: string, subst: string): string; - setLoader(cb: LoaderFunction): void; - setModuleLoader(name: string, onLoad: Function): void; - loadModule(moduleName: string | [string, string], - onLoad?: (module: any) => void): void; - init(packaged: any): any; - defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; - resetOptions(obj: any): void; - setDefaultValue(path: string, name: string, value: any): void; - setDefaultValues(path: string, optionHash: { [key: string]: any }): void; } - export interface OptionsProvider { - setOptions(optList: { [key: string]: any }): void; - getOptions(optionNames?: string[] | { [key: string]: any }): { [key: string]: any }; - setOption(name: string, value: any): void; - getOption(name: string): any; - } - - export interface UndoManager { - addSession(session: EditSession): void; - add(delta: Delta, allowMerge: boolean, session: EditSession): void; - addSelection(selection: string, rev?: number): void; - startNewGroup(): void; - markIgnored(from: number, to?: number): void; - getSelection(rev: number, after?: boolean): { value: string, rev: number }; - getRevision(): number; - getDeltas(from: number, to?: number): Delta[]; - undo(session: EditSession, dontSelect?: boolean): void; - redo(session: EditSession, dontSelect?: boolean): void; - reset(): void; - canUndo(): boolean; - canRedo(): boolean; - bookmark(rev?: number): void; - isAtBookmark(): boolean; - hasUndo(): boolean; - hasRedo(): boolean; - isClean(): boolean; - markClean(rev?: number): void; - toJSON(): object; - fromJSON(json: object): void; - } - - export interface Position { - row: number, - column: number - } - - export interface EditSession extends EventEmitter, OptionsProvider, Folding { - selection: Selection; - - // TODO: define BackgroundTokenizer - - on(name: 'changeFold', - callback: (obj: { data: Fold, action: string }) => void): Function; - on(name: 'changeScrollLeft', callback: (scrollLeft: number) => void): Function; - on(name: 'changeScrollTop', callback: (scrollTop: number) => void): Function; - on(name: 'tokenizerUpdate', - callback: (obj: { data: { first: number, last: number } }) => void): Function; - on(name: 'change', callback: () => void): Function; - on(name: 'changeTabSize', callback: () => void): Function; - - - setOption(name: T, value: EditSessionOptions[T]): void; - getOption(name: T): EditSessionOptions[T]; - - readonly doc: Document; - - setDocument(doc: Document): void; - getDocument(): Document; - resetCaches(): void; - setValue(text: string): void; - getValue(): string; - getSelection(): Selection; - getState(row: number): string; - getTokens(row: number): Token[]; - getTokenAt(row: number, column: number): Token | null; - setUndoManager(undoManager: UndoManager): void; - markUndoGroup(): void; - getUndoManager(): UndoManager; - getTabString(): string; - setUseSoftTabs(val: boolean): void; - getUseSoftTabs(): boolean; - setTabSize(tabSize: number): void; - getTabSize(): number; - isTabStop(position: Position): boolean; - setNavigateWithinSoftTabs(navigateWithinSoftTabs: boolean): void; - getNavigateWithinSoftTabs(): boolean; - setOverwrite(overwrite: boolean): void; - getOverwrite(): boolean; - toggleOverwrite(): void; - addGutterDecoration(row: number, className: string): void; - removeGutterDecoration(row: number, className: string): void; - getBreakpoints(): string[]; - setBreakpoints(rows: number[]): void; - clearBreakpoints(): void; - setBreakpoint(row: number, className: string): void; - clearBreakpoint(row: number): void; - addMarker(range: Range, - className: string, - type: "fullLine" | "screenLine" | "text" | MarkerRenderer, - inFront?: boolean): number; - addDynamicMarker(marker: MarkerLike, inFront: boolean): MarkerLike; - removeMarker(markerId: number): void; - getMarkers(inFront?: boolean): {[id: number]: MarkerLike}; - highlight(re: RegExp): void; - highlightLines(startRow: number, - endRow: number, - className: string, - inFront?: boolean): Range; - setAnnotations(annotations: Annotation[]): void; - getAnnotations(): Annotation[]; - clearAnnotations(): void; - getWordRange(row: number, column: number): Range; - getAWordRange(row: number, column: number): Range; - setNewLineMode(newLineMode: NewLineMode): void; - getNewLineMode(): NewLineMode; - setUseWorker(useWorker: boolean): void; - getUseWorker(): boolean; - setMode(mode: string | SyntaxMode, callback?: () => void): void; - getMode(): SyntaxMode; - setScrollTop(scrollTop: number): void; - getScrollTop(): number; - setScrollLeft(scrollLeft: number): void; - getScrollLeft(): number; - getScreenWidth(): number; - getLineWidgetMaxWidth(): number; - getLine(row: number): string; - getLines(firstRow: number, lastRow: number): string[]; - getLength(): number; - getTextRange(range: Range): string; - insert(position: Position, text: string): void; - remove(range: Range): void; - removeFullLines(firstRow: number, lastRow: number): void; - undoChanges(deltas: Delta[], dontSelect?: boolean): void; - redoChanges(deltas: Delta[], dontSelect?: boolean): void; - setUndoSelect(enable: boolean): void; - replace(range: Range, text: string): void; - moveText(fromRange: Range, toPosition: Position, copy?: boolean): void; - indentRows(startRow: number, endRow: number, indentString: string): void; - outdentRows(range: Range): void; - moveLinesUp(firstRow: number, lastRow: number): void; - moveLinesDown(firstRow: number, lastRow: number): void; - duplicateLines(firstRow: number, lastRow: number): void; - setUseWrapMode(useWrapMode: boolean): void; - getUseWrapMode(): boolean; - setWrapLimitRange(min: number, max: number): void; - adjustWrapLimit(desiredLimit: number): boolean; - getWrapLimit(): number; - setWrapLimit(limit: number): void; - getWrapLimitRange(): { min: number, max: number }; - getRowLineCount(row: number): number; - getRowWrapIndent(screenRow: number): number; - getScreenLastRowColumn(screenRow: number): number; - getDocumentLastRowColumn(docRow: number, docColumn: number): number; - getdocumentLastRowColumnPosition(docRow: number, docColumn: number): Position; - getRowSplitData(row: number): string | undefined; - getScreenTabSize(screenColumn: number): number; - screenToDocumentRow(screenRow: number, screenColumn: number): number; - screenToDocumentColumn(screenRow: number, screenColumn: number): number; - screenToDocumentPosition(screenRow: number, - screenColumn: number, - offsetX?: number): Position; - documentToScreenPosition(docRow: number, docColumn: number): Position; - documentToScreenPosition(position: Position): Position; - documentToScreenColumn(row: number, docColumn: number): number; - documentToScreenRow(docRow: number, docColumn: number): number; - getScreenLength(): number; - toJSON(): Object; - destroy(): void; - } - - export interface KeyBinding { - setDefaultHandler(handler: KeyboardHandler): void; - setKeyboardHandler(handler: KeyboardHandler): void; - addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; - removeKeyboardHandler(handler: KeyboardHandler): boolean; - getKeyboardHandler(): KeyboardHandler; - getStatusText(): string; - onCommandKey(e: any, hashId: number, keyCode: number): boolean; - onTextInput(text: string): boolean; + interface OptionsBase { + [key: string]: any; } + class OptionsProvider { + setOptions(optList: Partial): void; + + getOptions(optionNames?: Array | Partial): Partial; + + setOption(name: K, value: T[K]): void; + + getOption(name: K): T[K]; + } + + type KeyBinding = import("./src/keyboard/keybinding").KeyBinding; + interface CommandMap { [name: string]: Command; } @@ -647,189 +903,15 @@ export namespace Ace { args: any[] }) => void; - export interface CommandManager extends EventEmitter { - byName: CommandMap, - commands: CommandMap, + interface CommandManagerEvents { on(name: 'exec', callback: execEventHandler): Function; + on(name: 'afterExec', callback: execEventHandler): Function; - once(name: string, callback: Function): void; - setDefaultHandler(name: string, callback: Function): void; - removeDefaultHandler(name: string, callback: Function): void; - on(name: string, callback: Function, capturing?: boolean): void; - addEventListener(name: string, callback: Function, capturing?: boolean): void; - off(name: string, callback: Function): void; - removeListener(name: string, callback: Function): void; - removeEventListener(name: string, callback: Function): void; - - exec(command: string, editor: Editor, args: any): boolean; - toggleRecording(editor: Editor): void; - replay(editor: Editor): void; - addCommand(command: Command): void; - addCommands(command: Command[]): void; - removeCommand(command: Command | string, keepCommand?: boolean): void; - removeCommands(command: Command[]): void; - bindKey(key: string | { mac?: string, win?: string}, - command: CommandLike, - position?: number): void; - bindKeys(keys: {[s: string]: Function}): void; - parseKeys(keyPart: string): {key: string, hashId: number}; - findKeyCommand(hashId: number, keyString: string): string | undefined; - handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | {command: string}; - getStatusText(editor: Editor, data: {}): string; - } - - export interface VirtualRenderer extends OptionsProvider, EventEmitter { - readonly container: HTMLElement; - readonly scroller: HTMLElement; - readonly content: HTMLElement; - readonly characterWidth: number; - readonly lineHeight: number; - readonly scrollLeft: number; - readonly scrollTop: number; - readonly $padding: number; - - setOption(name: T, value: VirtualRendererOptions[T]): void; - getOption(name: T): VirtualRendererOptions[T]; - - setSession(session: EditSession): void; - updateLines(firstRow: number, lastRow: number, force?: boolean): void; - updateText(): void; - updateFull(force?: boolean): void; - updateFontSize(): void; - adjustWrapLimit(): boolean; - setAnimatedScroll(shouldAnimate: boolean): void; - getAnimatedScroll(): boolean; - setShowInvisibles(showInvisibles: boolean): void; - getShowInvisibles(): boolean; - setDisplayIndentGuides(display: boolean): void; - getDisplayIndentGuides(): boolean; - setShowPrintMargin(showPrintMargin: boolean): void; - getShowPrintMargin(): boolean; - setPrintMarginColumn(showPrintMargin: boolean): void; - getPrintMarginColumn(): boolean; - setShowGutter(show: boolean): void; - getShowGutter(): boolean; - setFadeFoldWidgets(show: boolean): void; - getFadeFoldWidgets(): boolean; - setHighlightGutterLine(shouldHighlight: boolean): void; - getHighlightGutterLine(): boolean; - getContainerElement(): HTMLElement; - getMouseEventTarget(): HTMLElement; - getTextAreaContainer(): HTMLElement; - getFirstVisibleRow(): number; - getFirstFullyVisibleRow(): number; - getLastFullyVisibleRow(): number; - getLastVisibleRow(): number; - setPadding(padding: number): void; - setScrollMargin(top: number, - bottom: number, - left: number, - right: number): void; - setHScrollBarAlwaysVisible(alwaysVisible: boolean): void; - getHScrollBarAlwaysVisible(): boolean; - setVScrollBarAlwaysVisible(alwaysVisible: boolean): void; - getVScrollBarAlwaysVisible(): boolean; - freeze(): void; - unfreeze(): void; - updateFrontMarkers(): void; - updateBackMarkers(): void; - updateBreakpoints(): void; - setAnnotations(annotations: Annotation[]): void; - updateCursor(): void; - hideCursor(): void; - showCursor(): void; - scrollSelectionIntoView(anchor: Position, - lead: Position, - offset?: number): void; - scrollCursorIntoView(cursor: Position, offset?: number): void; - getScrollTop(): number; - getScrollLeft(): number; - getScrollTopRow(): number; - getScrollBottomRow(): number; - scrollToRow(row: number): void; - alignCursor(cursor: Position | number, alignment: number): number; - scrollToLine(line: number, - center: boolean, - animate: boolean, - callback: () => void): void; - animateScrolling(fromValue: number, callback: () => void): void; - scrollToY(scrollTop: number): void; - scrollToX(scrollLeft: number): void; - scrollTo(x: number, y: number): void; - scrollBy(deltaX: number, deltaY: number): void; - isScrollableBy(deltaX: number, deltaY: number): boolean; - textToScreenCoordinates(row: number, column: number): { pageX: number, pageY: number}; - pixelToScreenCoordinates(x: number, y: number): {row: number, column: number, side: 1|-1, offsetX: number}; - visualizeFocus(): void; - visualizeBlur(): void; - showComposition(position: number): void; - setCompositionText(text: string): void; - hideComposition(): void; - setGhostText(text: string, position: Point): void; - removeGhostText(): void; - setTheme(theme: string, callback?: () => void): void; - getTheme(): string; - setStyle(style: string, include?: boolean): void; - unsetStyle(style: string): void; - setCursorStyle(style: string): void; - setMouseCursor(cursorStyle: string): void; - attachToShadowRoot(): void; - destroy(): void; - } - - - export interface Selection extends EventEmitter { - moveCursorWordLeft(): void; - moveCursorWordRight(): void; - fromOrientedRange(range: Range): void; - setSelectionRange(match: any): void; - getAllRanges(): Range[]; - addRange(range: Range): void; - isEmpty(): boolean; - isMultiLine(): boolean; - setCursor(row: number, column: number): void; - setAnchor(row: number, column: number): void; - getAnchor(): Position; - getCursor(): Position; - isBackwards(): boolean; - getRange(): Range; - clearSelection(): void; - selectAll(): void; - setRange(range: Range, reverse?: boolean): void; - selectTo(row: number, column: number): void; - selectToPosition(pos: any): void; - selectUp(): void; - selectDown(): void; - selectRight(): void; - selectLeft(): void; - selectLineStart(): void; - selectLineEnd(): void; - selectFileEnd(): void; - selectFileStart(): void; - selectWordRight(): void; - selectWordLeft(): void; - getWordRange(): void; - selectWord(): void; - selectAWord(): void; - selectLine(): void; - moveCursorUp(): void; - moveCursorDown(): void; - moveCursorLeft(): void; - moveCursorRight(): void; - moveCursorLineStart(): void; - moveCursorLineEnd(): void; - moveCursorFileEnd(): void; - moveCursorFileStart(): void; - moveCursorLongWordRight(): void; - moveCursorLongWordLeft(): void; - moveCursorBy(rows: number, chars: number): void; - moveCursorToPosition(position: any): void; - moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void; - moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void; - - toJSON(): SavedSelection | SavedSelection[]; - fromJSON(selection: SavedSelection | SavedSelection[]): void; } + + type CommandManager = import("./src/commands/command_manager").CommandManager; + + interface SavedSelection { start: Point; end: Point; @@ -840,193 +922,32 @@ export namespace Ace { new(session: EditSession): Selection; } - export interface TextInput { + interface TextInput { resetSelection(): void; - setAriaOption(activeDescendant: string, role: string): void; - } - export interface Editor extends OptionsProvider, EventEmitter { - container: HTMLElement; - renderer: VirtualRenderer; - id: string; - commands: CommandManager; - keyBinding: KeyBinding; - session: EditSession; - selection: Selection; - textInput: TextInput; - - on(name: 'blur', callback: (e: Event) => void): void; - on(name: 'input', callback: () => void): void; - on(name: 'change', callback: (delta: Delta) => void): void; - on(name: 'changeSelectionStyle', callback: (obj: { data: string }) => void): void; - on(name: 'changeSession', - callback: (obj: { session: EditSession, oldSession: EditSession }) => void): void; - on(name: 'copy', callback: (obj: { text: string }) => void): void; - on(name: 'focus', callback: (e: Event) => void): void; - on(name: 'paste', callback: (obj: { text: string }) => void): void; - on(name: 'mousemove', callback: (e: any) => void): void; - on(name: 'mouseup', callback: (e: any) => void): void; - on(name: 'mousewheel', callback: (e: any) => void): void; - on(name: 'click', callback: (e: any) => void): void; - on(name: 'guttermousedown', callback: (e: any) => void): void; - on(name: 'gutterkeydown', callback: (e: any) => void): void; - - onPaste(text: string, event: any): void; - - setOption(name: T, value: EditorOptions[T]): void; - getOption(name: T): EditorOptions[T]; - - setKeyboardHandler(keyboardHandler: string, callback?: () => void): void; - setKeyboardHandler(keyboardHandler: KeyboardHandler|null): void; - getKeyboardHandler(): string; - setSession(session: EditSession | undefined): void; - getSession(): EditSession; - setValue(val: string, cursorPos?: number): string; - getValue(): string; - getSelection(): Selection; - resize(force?: boolean): void; - setTheme(theme: string, callback?: () => void): void; - getTheme(): string; - setStyle(style: string): void; - unsetStyle(style: string): void; - getFontSize(): string; - setFontSize(size: number|string): void; - focus(): void; - isFocused(): boolean; - blur(): void; - getSelectedText(): string; - getCopyText(): string; - execCommand(command: string | string[], args?: any): boolean; - insert(text: string, pasted?: boolean): void; - setOverwrite(overwrite: boolean): void; - getOverwrite(): boolean; - toggleOverwrite(): void; - setScrollSpeed(speed: number): void; - getScrollSpeed(): number; - setDragDelay(dragDelay: number): void; - getDragDelay(): number; - setSelectionStyle(val: string): void; - getSelectionStyle(): string; - setHighlightActiveLine(shouldHighlight: boolean): void; - getHighlightActiveLine(): boolean; - setHighlightGutterLine(shouldHighlight: boolean): void; - getHighlightGutterLine(): boolean; - setHighlightSelectedWord(shouldHighlight: boolean): void; - getHighlightSelectedWord(): boolean; - setAnimatedScroll(shouldAnimate: boolean): void; - getAnimatedScroll(): boolean; - setShowInvisibles(showInvisibles: boolean): void; - getShowInvisibles(): boolean; - setDisplayIndentGuides(display: boolean): void; - getDisplayIndentGuides(): boolean; - setShowPrintMargin(showPrintMargin: boolean): void; - getShowPrintMargin(): boolean; - setPrintMarginColumn(showPrintMargin: number): void; - getPrintMarginColumn(): number; - setReadOnly(readOnly: boolean): void; - getReadOnly(): boolean; - setBehavioursEnabled(enabled: boolean): void; - getBehavioursEnabled(): boolean; - setWrapBehavioursEnabled(enabled: boolean): void; - getWrapBehavioursEnabled(): boolean; - setShowFoldWidgets(show: boolean): void; - getShowFoldWidgets(): boolean; - setFadeFoldWidgets(fade: boolean): void; - getFadeFoldWidgets(): boolean; - remove(dir?: 'left' | 'right'): void; - removeWordRight(): void; - removeWordLeft(): void; - removeLineToEnd(): void; - splitLine(): void; - setGhostText(text: string, position: Point): void; - removeGhostText(): void; - transposeLetters(): void; - toLowerCase(): void; - toUpperCase(): void; - indent(): void; - blockIndent(): void; - blockOutdent(): void; - sortLines(): void; - toggleCommentLines(): void; - toggleBlockComment(): void; - modifyNumber(amount: number): void; - removeLines(): void; - duplicateSelection(): void; - moveLinesDown(): void; - moveLinesUp(): void; - moveText(range: Range, toPosition: Point, copy?: boolean): Range; - copyLinesUp(): void; - copyLinesDown(): void; - getFirstVisibleRow(): number; - getLastVisibleRow(): number; - isRowVisible(row: number): boolean; - isRowFullyVisible(row: number): boolean; - selectPageDown(): void; - selectPageUp(): void; - gotoPageDown(): void; - gotoPageUp(): void; - scrollPageDown(): void; - scrollPageUp(): void; - scrollToRow(row: number): void; - scrollToLine(line: number, center: boolean, animate: boolean, callback: () => void): void; - centerSelection(): void; - getCursorPosition(): Point; - getCursorPositionScreen(): Point; - getSelectionRange(): Range; - selectAll(): void; - clearSelection(): void; - moveCursorTo(row: number, column: number): void; - moveCursorToPosition(pos: Point): void; - jumpToMatching(select: boolean, expand: boolean): void; - gotoLine(lineNumber: number, column: number, animate: boolean): void; - navigateTo(row: number, column: number): void; - navigateUp(times?: number): void; - navigateDown(times?: number): void; - navigateLeft(times?: number): void; - navigateRight(times?: number): void; - navigateLineStart(): void; - navigateLineEnd(): void; - navigateFileEnd(): void; - navigateFileStart(): void; - navigateWordRight(): void; - navigateWordLeft(): void; - replace(replacement: string, options?: Partial): number; - replaceAll(replacement: string, options?: Partial): number; - getLastSearchOptions(): Partial; - find(needle: string | RegExp, options?: Partial, animate?: boolean): Ace.Range | undefined; - findNext(options?: Partial, animate?: boolean): void; - findPrevious(options?: Partial, animate?: boolean): void; - findAll(needle: string | RegExp, options?: Partial, additive?: boolean): number; - undo(): void; - redo(): void; - destroy(): void; - setAutoScrollEditorIntoView(enable: boolean): void; - completers: Completer[]; + setAriaOption(options?: { activeDescendant: string, role: string, setLabel }): void; } type CompleterCallback = (error: any, completions: Completion[]) => void; interface Completer { identifierRegexps?: Array, + getCompletions(editor: Editor, session: EditSession, position: Point, prefix: string, callback: CompleterCallback): void; - getDocTooltip?(item: Completion): undefined | string | Completion; + + getDocTooltip?(item: Completion): void | string | Completion; + cancel?(): void; + id?: string; triggerCharacters?: string[]; hideInlinePreview?: boolean; } - export class AceInline { - show(editor: Editor, completion: Completion, prefix: string): void; - isOpen(): void; - hide(): void; - destroy(): void; - } - interface CompletionOptions { matches?: Completion[]; } @@ -1036,12 +957,6 @@ export namespace Ace { ignoreCaption?: boolean; } - type CompletionRecord = { - all: Completion[]; - filtered: Completion[]; - filterText: string; - } | CompletionProviderOptions - type GatherCompletionRecord = { prefix: string; matches: Completion[]; @@ -1049,57 +964,219 @@ export namespace Ace { } type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; - type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; - - export class CompletionProvider { - insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; - insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; - completions: CompletionRecord; - gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; - provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; - detach(): void; - } - - export class Autocomplete { - constructor(); - autoInsert?: boolean; - autoSelect?: boolean; - autoShown?: boolean; - exactMatch?: boolean; - inlineEnabled?: boolean; - parentNode?: HTMLElement; - setSelectOnHover?: Boolean; - stickySelectionDelay?: Number; - ignoreCaption?: Boolean; - showLoadingState?: Boolean; - emptyMessage?(prefix: String): String; - getPopup(): AcePopup; - showPopup(editor: Editor, options: CompletionOptions): void; - detach(): void; - destroy(): void; - } + type CompletionProviderCallback = (this: import("./src/autocomplete").Autocomplete, err: Error | undefined, completions: import("./src/autocomplete").FilteredList, finished: boolean) => void; type AcePopupNavigation = "up" | "down" | "start" | "end"; - export class AcePopup { - constructor(parentNode: HTMLElement); - setData(list: Completion[], filterText: string): void; - getData(row: number): Completion; - getRow(): number; - getRow(line: number): void; - hide(): void; - show(pos: Point, lineHeight: number, topdownOnly: boolean): void; - tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; - goTo(where: AcePopupNavigation): void; + interface EditorMultiSelectProperties { + inMultiSelectMode?: boolean, + /** + * Updates the cursor and marker layers. + **/ + updateSelectionMarkers: () => void, + /** + * Adds the selection and cursor. + * @param orientedRange A range containing a cursor + **/ + addSelectionMarker: (orientedRange: Ace.Range & { marker? }) => Ace.Range & { marker? }, + /** + * Removes the selection marker. + * @param range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. + **/ + removeSelectionMarker: (range: Ace.Range & { marker? }) => void, + removeSelectionMarkers: (ranges: (Ace.Range & { marker? })[]) => void, + $onAddRange: (e) => void, + $onRemoveRange: (e) => void, + $onMultiSelect: (e) => void, + $onSingleSelect: (e) => void, + $onMultiSelectExec: (e) => void, + /** + * Executes a command for each selection range. + * @param cmd The command to execute + * @param [args] Any arguments for the command + **/ + forEachSelection: (cmd: Object, args?: string, options?: Object) => void, + /** + * Removes all the selections except the last added one. + **/ + exitMultiSelectMode: () => void, + getSelectedText: () => string, + $checkMultiselectChange: (e, anchor: Ace.Anchor) => void, + /** + * Finds and selects all the occurrences of `needle`. + * @param needle The text to find + * @param options The search options + * @param additive keeps + * @returns {Number} The cumulative count of all found matches + **/ + findAll: (needle?: string, options?: Partial, additive?: boolean) => number, + /** + * Adds a cursor above or below the active cursor. + * @param dir The direction of lines to select: -1 for up, 1 for down + * @param [skip] If `true`, removes the active selection range + */ + selectMoreLines: (dir: number, skip?: boolean) => void, + /** + * Transposes the selected ranges. + * @param {Number} dir The direction to rotate selections + **/ + transposeSelections: (dir: number) => void, + /** + * Finds the next occurrence of text in an active selection and adds it to the selections. + * @param {Number} dir The direction of lines to select: -1 for up, 1 for down + * @param {Boolean} [skip] If `true`, removes the active selection range + * @param {Boolean} [stopAtFirst] + **/ + selectMore: (dir: number, skip?: boolean, stopAtFirst?: boolean) => void, + /** + * Aligns the cursors or selected text. + **/ + alignCursors: () => void, + $reAlignText: (lines: string[], forceLeft: boolean) => string[], + multiSelect?: any, + $multiselectOnSessionChange?: any, + $blockSelectEnabled?: boolean, + } + + interface CodeLenseEditorExtension { + codeLensProviders?: any[]; + $codeLensClickHandler?: any; + $updateLenses?: () => void; + $updateLensesOnInput?: () => void; + } + + interface ElasticTabstopsEditorExtension { + elasticTabstops?: import("./src/ext/elastic_tabstops_lite").ElasticTabstopsLite; + } + + interface TextareaEditorExtension { + setDisplaySettings?: (settings: any) => void; } + + interface PromptEditorExtension { + cmdLine?: Editor; + } + + interface OptionsEditorExtension { + $options?: any; + } + + interface MultiSelectProperties { + ranges: Ace.Range[] | null; + rangeList: Ace.RangeList | null; + + /** + * Adds a range to a selection by entering multiselect mode, if necessary. + * @param {Ace.Range} range The new range to add + * @param {Boolean} [$blockChangeEvents] Whether or not to block changing events + **/ + addRange(range: Ace.Range, $blockChangeEvents?: boolean): any; + + inMultiSelectMode: boolean; + + /** + * @param {Ace.Range} [range] + **/ + toSingleRange(range?: Ace.Range): void; + + /** + * Removes a Range containing pos (if it exists). + * @param {Ace.Point} pos The position to remove, as a `{row, column}` object + **/ + substractPoint(pos: Ace.Point): any; + + /** + * Merges overlapping ranges ensuring consistency after changes + **/ + mergeOverlappingRanges(): void; + + /** + * @param {Ace.Range} range + */ + $onAddRange(range: Ace.Range): void; + + rangeCount: number; + + /** + * + * @param {Ace.Range[]} removed + */ + $onRemoveRange(removed: Ace.Range[]): void; + + /** + * adds multicursor support to selection + */ + $initRangeList(): void; + + /** + * Returns a concatenation of all the ranges. + * @returns {Ace.Range[]} + **/ + getAllRanges(): Ace.Range[]; + + /** + * Splits all the ranges into lines. + **/ + splitIntoLines(): void; + + /** + */ + joinSelections(): void; + + /** + **/ + toggleBlockSelection(): void; + + /** + * + * Gets list of ranges composing rectangular block on the screen + * + * @param {Ace.ScreenCoordinates} screenCursor The cursor to use + * @param {Ace.ScreenCoordinates} screenAnchor The anchor to use + * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping + * @returns {Ace.Range[]} + **/ + rectangularRangeBlock(screenCursor: Ace.ScreenCoordinates, screenAnchor: Ace.ScreenCoordinates, includeEmptyLines?: boolean): Ace.Range[]; + + _eventRegistry?: any; + index?: number; + } + + type AcePopupEventsCombined = Ace.EditorEvents & Ace.AcePopupEvents; + type AcePopupWithEditor = Ace.EventEmitter & Ace.Editor; + type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; + + type TooltipCommandFunction = (editor: Ace.Editor) => T; + + export interface TooltipCommand extends Ace.Command { + enabled: TooltipCommandFunction | boolean, + getValue?: TooltipCommandFunction, + type: "button" | "text" | "checkbox" + iconCssClass?: string, + cssClass?: string + } + + export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; + + export type TokenizeResult = Array> } export const version: string; export const config: Ace.Config; + export function require(name: string): any; -export function edit(el: Element | string, options?: Partial): Ace.Editor; + +export function edit(el: string | (Element & { + env?; + value?; +}), options?: Partial): Ace.Editor; + export function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; + export const VirtualRenderer: { new(container: HTMLElement, theme?: string): Ace.VirtualRenderer; }; @@ -1110,7 +1187,7 @@ export const UndoManager: { new(): Ace.UndoManager; }; export const Editor: { - new(): Ace.Editor; + new(renderer: Ace.VirtualRenderer, session?: Ace.EditSession, options?: Partial): Ace.Editor; }; export const Range: { new(startRow: number, startColumn: number, endRow: number, endColumn: number): Ace.Range; @@ -1118,47 +1195,307 @@ export const Range: { comparePoints(p1: Ace.Point, p2: Ace.Point): number; }; +export type InlineAutocomplete = Ace.InlineAutocomplete; +export type CommandBarTooltip = Ace.CommandBarTooltip; + + +declare module "./src/anchor" { + export interface Anchor extends Ace.EventEmitter { + markerId?: number; + document: Ace.Document; + } + + +} + +declare module "./src/autocomplete" { + export interface Autocomplete { + popup: Ace.AcePopup; + emptyMessage?: Function, + } + + export interface CompletionProvider { + completions: Ace.FilteredList; + } +} -type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; +declare module "./src/background_tokenizer" { + export interface BackgroundTokenizer extends Ace.EventEmitter { -type TooltipCommandFunction = (editor: Ace.Editor) => T; + } +} + +declare module "./src/document" { + export interface Document extends Ace.EventEmitter { + + } -interface TooltipCommand extends Ace.Command { - enabled: TooltipCommandFunction | boolean, - getValue?: TooltipCommandFunction, - type: "button" | "text" | "checkbox" - iconCssClass: string, - cssClass: string } -export class InlineAutocomplete { - constructor(); - getInlineRenderer(): Ace.AceInline; - getInlineTooltip(): CommandBarTooltip; - getCompletionProvider(): Ace.CompletionProvider; - show(editor: Ace.Editor): void; - isOpen(): boolean; - detach(): void; - destroy(): void; - goTo(action: InlineAutocompleteAction): void; - tooltipEnabled: boolean; - commands: Record - getIndex(): number; - setIndex(value: number): void; - getLength(): number; - getData(index?: number): Ace.Completion | undefined; - updateCompletions(options: Ace.CompletionOptions): void; +declare module "./src/editor" { + export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider, + Ace.EventEmitter, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, + Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension { + session: Ace.EditSession; + $mergeUndoDeltas?: any, + $highlightSelectedWord?: boolean, + $updatePlaceholder?: Function, + $cursorStyle?: string, + $readOnly?: any, + $highlightActiveLine?: any, + $enableAutoIndent?: any, + $copyWithEmptySelection?: any + $selectionStyle?: string, + env?: any; + widgetManager?: Ace.LineWidgets, + completer?: Ace.Autocomplete | Ace.InlineAutocomplete, + completers: Ace.Completer[], + $highlightTagPending?: boolean, + showKeyboardShortcuts?: () => void, + showSettingsMenu?: () => void, + searchBox?: Ace.SearchBox, + _eventRegistry?: any, + } +} + +declare module "./src/edit_session" { + export interface EditSession extends Ace.EventEmitter, + Ace.OptionsProvider, + Ace.Folding, Ace.BracketMatch { + doc: Ace.Document, + $highlightLineMarker?: { + start: Ace.Point, + end: Ace.Point, + id?: number + } + $useSoftTabs?: boolean, + $tabSize?: number, + $useWorker?: boolean, + $wrapAsCode?: boolean, + $indentedSoftWrap?: boolean, + widgetManager?: any, + $bracketHighlight?: any, + $selectionMarker?: number, + curOp?: { + command: {}, + args: string, + scrollTop: number, + [key: string]: any; + }, + lineWidgetsWidth?: number, + $getWidgetScreenLength?: () => number, + _changedWidgets?: any, + $options: any, + $wrapMethod?: any, + $enableVarChar?: any, + $wrap?: any, + $navigateWithinSoftTabs?: boolean, + + getSelectionMarkers(): any[], + + $selectionMarkers?: any[], + gutterRenderer?: any, + $firstLineNumber?: number, + $emacsMark?: any, + selectionMarkerCount?: number, + multiSelect?: any, + $occurHighlight?: any, + $occur?: Ace.Occur, + $occurMatchingLines?: any, + $useEmacsStyleLineStart?: boolean, + $selectLongWords?: boolean, + } + +} + +declare module "./src/edit_session/fold" { + export interface Fold { + collapseChildren?: number; + } +} + +// @ts-expect-error +declare module "./src/placeholder" { + export interface PlaceHolder extends Ace.EventEmitter { + } } -export class CommandBarTooltip { - constructor(parentElement: HTMLElement); - registerCommand(id: string, command: TooltipCommand): void; - attach(editor: Ace.Editor): void; - updatePosition(): void; - update(): void; - isShown(): boolean; - getAlwaysShow(): boolean; - setAlwaysShow(alwaysShow: boolean): void; - detach(): void; - destroy(): void; +declare module "./src/scrollbar" { + export interface VScrollBar extends Ace.EventEmitter { + } + + export interface HScrollBar extends Ace.EventEmitter { + } +} + +declare module "./src/scrollbar_custom" { + export interface VScrollBar extends Ace.EventEmitter { + } + + export interface HScrollBar extends Ace.EventEmitter { + } +} + +declare module "./src/line_widgets" { + export interface LineWidgets { + lineWidgets: Ace.LineWidget[]; + editor: Ace.Editor; + } +} + +declare module "./src/selection" { + export interface Selection extends Ace.EventEmitter, Ace.MultiSelectProperties { + } + +} + +declare module "./src/range" { + export interface Range { + id?: number; + cursor?: Ace.Point; + isBackwards?: boolean; + } +} + +declare module "./src/virtual_renderer" { + export interface VirtualRenderer extends Ace.EventEmitter, Ace.OptionsProvider { + $customScrollbar?: boolean, + $extraHeight?: number, + $showGutter?: boolean, + $showPrintMargin?: boolean, + $printMarginColumn?: number, + $animatedScroll?: boolean, + $isMousePressed?: boolean, + textarea?: HTMLTextAreaElement, + $hScrollBarAlwaysVisible?: boolean, + $vScrollBarAlwaysVisible?: boolean + $maxLines?: number, + $scrollPastEnd?: number, + enableKeyboardAccessibility?: boolean, + keyboardFocusClassName?: string, + $highlightGutterLine?: boolean, + $minLines?: number, + $maxPixelHeight?: number, + $gutterWidth?: number, + showInvisibles?: boolean, + $hasCssTransforms?: boolean, + $blockCursor?: boolean, + $useTextareaForIME?: boolean, + theme?: any, + $theme?: any, + destroyed?: boolean, + session: Ace.EditSession, + } + +} + +declare module "./src/snippets" { + export interface SnippetManager extends Ace.EventEmitter { + } +} + +declare module "./src/ext/command_bar" { + export interface CommandBarTooltip extends Ace.EventEmitter { + $shouldHideMoreOptions?: boolean, + } +} + +declare module "./src/commands/command_manager" { + export interface CommandManager extends Ace.EventEmitter { + $checkCommandState?: boolean + } +} + +declare module "./src/autocomplete/popup" { + + export interface AcePopup extends Ace.AcePopupWithEditor { + setSelectOnHover: (val: boolean) => void, + setRow: (line: number) => void, + getRow: () => number, + getHoveredRow: () => number, + filterText: string, + isOpen: boolean, + isTopdown: boolean, + autoSelect: boolean, + data: Ace.Completion[], + setData: (data: Ace.Completion[], filterText: string) => void, + getData: (row: number) => Ace.Completion, + hide: () => void, + anchor: "top" | "bottom", + anchorPosition: Ace.Point, + tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom", forceShow?: boolean) => boolean, + $borderSize: number, + show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, + goTo: (where: Ace.AcePopupNavigation) => void, + getTextLeftOffset: () => number, + $imageSize: number, + anchorPos: any, + isMouseOver?: boolean + } +} + +declare module "./src/layer/cursor" { + export interface Cursor { + timeoutId?: number; + } +} + +declare module "./src/layer/gutter" { + export interface Gutter extends Ace.EventEmitter { + $useSvgGutterIcons?: boolean, + $showFoldedAnnotations?: boolean, + } +} + +declare module "./src/layer/text" { + export interface Text extends Ace.EventEmitter { + } +} + +declare module "./src/lib/app_config" { + export interface AppConfig extends Ace.EventEmitter { + } +} + +declare module "./src/mouse/mouse_event" { + export interface MouseEvent { + time?: number; + } +} + +declare module "./src/mouse/mouse_handler" { + + export interface MouseHandler { + $tooltipFollowsMouse?: boolean, + cancelDrag?: boolean + //from DefaultHandlers + $clickSelection?: Ace.Range, + mousedownEvent?: Ace.MouseEvent, + startSelect?: (pos?: Ace.Point, waitForClickSelection?: boolean) => void, + select?: () => void + $lastScroll?: { t: number, vx: number, vy: number, allowed: number } + selectEnd?: () => void + } +} + +// @ts-expect-error +declare module "./src/ext/options" { + export interface OptionPanel extends Ace.EventEmitter { + } +} + +declare module "./src/layer/font_metrics" { + export interface FontMetrics extends Ace.EventEmitter { + } +} + +declare module "./src/tooltip" { + export interface HoverTooltip { + row: number; + } +} + +declare module "./src/mouse/default_gutter_handler" { + export interface GutterHandler { + } } diff --git a/ace.d.ts b/ace.d.ts index 9e0300552d6..b7386b8a29c 100644 --- a/ace.d.ts +++ b/ace.d.ts @@ -1,340 +1,163 @@ -export namespace Ace { - type Anchor = import("./src/anchor").Anchor; - type Editor = import("./src/editor").Editor; - type EditSession = import("./src/edit_session").EditSession; - type Document = import("./src/document").Document; - type Fold = import("./src/edit_session/fold").Fold; - type FoldLine = import("./src/edit_session/fold_line").FoldLine; - type Range = import("./src/range").Range; - type VirtualRenderer = import("./src/virtual_renderer").VirtualRenderer; - type UndoManager = import("./src/undomanager").UndoManager; - type Tokenizer = import("./src/tokenizer").Tokenizer; - type TokenIterator = import("./src/token_iterator").TokenIterator; - type Selection = import("./src/selection").Selection; - type Autocomplete = import("./src/autocomplete").Autocomplete; - type InlineAutocomplete = import("./src/ext/inline_autocomplete").InlineAutocomplete; - type CompletionProvider = import("./src/autocomplete").CompletionProvider; - type AcePopup = import("./src/autocomplete/popup").AcePopup; - type AceInline = import("./src/autocomplete/inline").AceInline; - type MouseEvent = import("./src/mouse/mouse_event").MouseEvent; - type RangeList = import("./src/range_list").RangeList; - type FilteredList = import("./src/autocomplete").FilteredList; - type LineWidgets = import("./src/line_widgets").LineWidgets; - type SearchBox = import("./src/ext/searchbox").SearchBox; - type Occur = import("./src/occur").Occur; - type DefaultHandlers = import("./src/mouse/default_handlers").DefaultHandlers; - type GutterHandler = import("./src/mouse/default_gutter_handler").GutterHandler; - type DragdropHandler = import("./src/mouse/dragdrop_handler").DragdropHandler; - type AppConfig = import("./src/lib/app_config").AppConfig; - - - type AfterLoadCallback = (err: Error | null, module: unknown) => void; - type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; - - export interface Config { - get(key: string): any; - - set(key: string, value: any): void; - - all(): { [key: string]: any }; - - moduleUrl(name: string, component?: string): string; - - setModuleUrl(name: string, subst: string): string; - - setLoader(cb: LoaderFunction): void; - - setModuleLoader(name: string, onLoad: Function): void; - - loadModule(moduleName: string | [string, string], - onLoad?: (module: any) => void): void; +/// +/// - init(packaged: any): any; - - defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; - - resetOptions(obj: any): void; - - setDefaultValue(path: string, name: string, value: any): void; - - setDefaultValues(path: string, optionHash: { [key: string]: any }): void; - } - - interface Theme { - cssClass?: string; - cssText?: string; - $id?: string; - padding?: number | string; - isDark?: boolean; - } - - interface ScrollBar { - setVisible(visible: boolean): void; - - [key: string]: any; - } - - interface HScrollbar extends ScrollBar { - setWidth(width: number): void; - } - - interface VScrollbar extends ScrollBar { - setHeight(width: number): void; - } - - interface LayerConfig { - width: number, - padding: number, - firstRow: number, - firstRowScreen: number, - lastRow: number, - lineHeight: number, - characterWidth: number, - minHeight: number, - maxHeight: number, - offset: number, - height: number, - gutterOffset: number - } +export namespace Ace { + export type NewLineMode = 'auto' | 'unix' | 'windows'; + + export interface Anchor extends EventEmitter { + getPosition(): Position; + getDocument(): Document; + setPosition(row: number, column: number, noClip?: boolean): void; + detach(): void; + attach(doc: Document): void; + } + + export interface Document extends EventEmitter { + setValue(text: string): void; + getValue(): string; + createAnchor(row: number, column: number): Anchor; + getNewLineCharacter(): string; + setNewLineMode(newLineMode: NewLineMode): void; + getNewLineMode(): NewLineMode; + isNewLine(text: string): boolean; + getLine(row: number): string; + getLines(firstRow: number, lastRow: number): string[]; + getAllLines(): string[]; + getLength(): number; + getTextRange(range: Range): string; + getLinesForRange(range: Range): string[]; + insert(position: Position, text: string): Position; + insert(position: {row: number, column: number}, text: string): Position; + insertInLine(position: Position, text: string): Position; + insertNewLine(position: Point): Point; + clippedPos(row: number, column: number): Point; + clonePos(pos: Point): Point; + pos(row: number, column: number): Point; + insertFullLines(row: number, lines: string[]): void; + insertMergedLines(position: Position, lines: string[]): Point; + remove(range: Range): Position; + removeInLine(row: number, startColumn: number, endColumn: number): Position; + removeFullLines(firstRow: number, lastRow: number): string[]; + removeNewLine(row: number): void; + replace(range: Range, text: string): Position; + applyDeltas(deltas: Delta[]): void; + revertDeltas(deltas: Delta[]): void; + applyDelta(delta: Delta, doNotValidate?: boolean): void; + revertDelta(delta: Delta): void; + indexToPosition(index: number, startRow: number): Position; + positionToIndex(pos: Position, startRow?: number): number; + } + + export interface FoldLine { + folds: Fold[]; + range: Range; + start: Point; + end: Point; - interface HardWrapOptions { - startRow: number; - endRow: number; - allowMerge?: boolean; - column?: number; + shiftRow(shift: number): void; + addFold(fold: Fold): void; + containsRow(row: number): boolean; + walk(callback: Function, endRow?: number, endColumn?: number): void; + getNextFoldTo(row: number, column: number): null | { fold: Fold, kind: string }; + addRemoveChars(row: number, column: number, len: number): void; + split(row: number, column: number): FoldLine; + merge(foldLineNext: FoldLine): void; + idxToPosition(idx: number): Point; } - interface CommandBarOptions { - maxElementsOnTooltip: number; - alwaysShow: boolean; - showDelay: number; - hideDelay: number; - } + export interface Fold { + range: Range; + start: Point; + end: Point; + foldLine?: FoldLine; + sameRow: boolean; + subFolds: Fold[]; - interface ScreenCoordinates { - row: number, - column: number, - side?: 1 | -1, - offsetX?: number + setFoldLine(foldLine: FoldLine): void; + clone(): Fold; + addSubFold(fold: Fold): Fold; + restoreRange(range: Range): void; } interface Folding { - $foldData: FoldLine[]; - - /** - * Looks up a fold at a given row/column. Possible values for side: - * -1: ignore a fold if fold.start = row/column - * +1: ignore a fold if fold.end = row/column - **/ - getFoldAt(row: number, column: number, side?: number): Ace.Fold; - - /** - * Returns all folds in the given range. Note, that this will return folds - **/ - getFoldsInRange(range: Ace.Range | Ace.Delta): Ace.Fold[]; - - getFoldsInRangeList(ranges: Ace.Range[] | Ace.Range): Ace.Fold[]; - - /** - * Returns all folds in the document - */ - getAllFolds(): Ace.Fold[]; - - /** - * Returns the string between folds at the given position. - * E.g. - * foob|arwolrd -> "bar" - * foobarwol|rd -> "world" - * foobarwolrd -> - * - * where | means the position of row/column - * - * The trim option determs if the return string should be trimed according - * to the "side" passed with the trim value: - * - * E.g. - * foob|arwolrd -trim=-1> "b" - * foobarwol|rd -trim=+1> "rld" - * fo|obarwolrd -trim=00> "foo" - */ - getFoldStringAt(row: number, column: number, trim?: number, foldLine?: Ace.FoldLine): string | null; - - getFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; - - /** - * Returns the fold which starts after or contains docRow - */ - getNextFoldLine(docRow: number, startFoldLine?: Ace.FoldLine): null | Ace.FoldLine; - + getFoldAt(row: number, column: number, side: number): Fold; + getFoldsInRange(range: Range): Fold[]; + getFoldsInRangeList(ranges: Range[]): Fold[]; + getAllFolds(): Fold[]; + getFoldStringAt(row: number, + column: number, + trim?: number, + foldLine?: FoldLine): string | null; + getFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; + getNextFoldLine(docRow: number, startFoldLine?: FoldLine): FoldLine | null; getFoldedRowCount(first: number, last: number): number; - - $addFoldLine(foldLine: FoldLine): Ace.FoldLine; - - /** - * Adds a new fold. - * @returns {Ace.Fold} - * The new created Fold object or an existing fold object in case the - * passed in range fits an existing fold exactly. - */ - addFold(placeholder: Ace.Fold | string, range?: Ace.Range): Ace.Fold; - - $modified: boolean; - - addFolds(folds: Ace.Fold[]): void; - - removeFold(fold: Ace.Fold): void; - - removeFolds(folds: Ace.Fold[]): void; - - expandFold(fold: Ace.Fold): void; - - expandFolds(folds: Ace.Fold[]): void; - - unfold(location?: number | null | Ace.Point | Ace.Range | Ace.Range[], expandInner?: boolean): Ace.Fold[] | undefined; - - /** - * Checks if a given documentRow is folded. This is true if there are some - * folded parts such that some parts of the line is still visible. - **/ - isRowFolded(docRow: number, startFoldRow?: Ace.FoldLine): boolean; - - getRowFoldEnd(docRow: number, startFoldRow?: Ace.FoldLine): number; - - getRowFoldStart(docRow: number, startFoldRow?: Ace.FoldLine): number; - - getFoldDisplayLine(foldLine: Ace.FoldLine, endRow?: number | null, endColumn?: number | null, startRow?: number | null, startColumn?: number | null): string; - - getDisplayLine(row: number, endColumn: number | null, startRow: number | null, startColumn: number | null): string; - - $cloneFoldData(): Ace.FoldLine[]; - + addFold(placeholder: string | Fold, range?: Range): Fold; + addFolds(folds: Fold[]): void; + removeFold(fold: Fold): void; + removeFolds(folds: Fold[]): void; + expandFold(fold: Fold): void; + expandFolds(folds: Fold[]): void; + unfold(location: null | number | Point | Range, + expandInner?: boolean): Fold[] | undefined; + isRowFolded(docRow: number, startFoldRow?: FoldLine): boolean; + getFoldRowEnd(docRow: number, startFoldRow?: FoldLine): number; + getFoldRowStart(docRow: number, startFoldRow?: FoldLine): number; + getFoldDisplayLine(foldLine: FoldLine, + endRow: number | null, + endColumn: number | null, + startRow: number | null, + startColumn: number | null): string; + getDisplayLine(row: number, + endColumn: number | null, + startRow: number | null, + startColumn: number | null): string; toggleFold(tryToUnfold?: boolean): void; - - getCommentFoldRange(row: number, column: number, dir?: number): Ace.Range | undefined; - - foldAll(startRow?: number | null, endRow?: number | null, depth?: number | null, test?: Function): void; - - foldToLevel(level: number): void; - - foldAllComments(): void; - - $foldStyles: { - manual: number; - markbegin: number; - markbeginend: number; - }; - $foldStyle: string; - + getCommentFoldRange(row: number, + column: number, + dir: number): Range | undefined; + foldAll(startRow?: number, endRow?: number, depth?: number): void; setFoldStyle(style: string): void; - - $setFolding(foldMode: Ace.FoldMode): void; - - $foldMode: any; - foldWidgets: any[]; - getFoldWidget: any; - getFoldWidgetRange: any; - $updateFoldWidgets: any; - $tokenizerUpdateFoldWidgets: any; - getParentFoldRangeData(row: number, ignoreCurrent?: boolean): { - range?: Ace.Range; - firstRange?: Ace.Range; + range?: Range, + firstRange: Range }; - - onFoldWidgetClick(row: number, e: any): void; - - $toggleFoldWidget(row: number, options: any): Fold | any; - - /** - * - * @param {boolean} [toggleParent] - */ toggleFoldWidget(toggleParent?: boolean): void; - - updateFoldWidgets(delta: Ace.Delta): void; - - tokenizerUpdateFoldWidgets(e: any): void; + updateFoldWidgets(delta: Delta): void; } - interface BracketMatch { - findMatchingBracket: (position: Point, chr?: string) => Point; - - getBracketRange: (pos: Point) => null | Range; - /** - * Returns: - * * null if there is no any bracket at `pos`; - * * two Ranges if there is opening and closing brackets; - * * one Range if there is only one bracket - */ - getMatchingBracketRanges: (pos: Point, isBackwards?: boolean) => null | Range[]; - $brackets: { - ")": string; - "(": string; - "]": string; - "[": string; - "{": string; - "}": string; - "<": string; - ">": string; - }; - $findOpeningBracket: (bracket: string, position: Point, typeRe?: RegExp) => Point | null; - $findClosingBracket: (bracket: string, position: Point, typeRe?: RegExp) => Point | null; - /** - * Returns [[Range]]'s for matching tags and tag names, if there are any - */ - getMatchingTags: (pos: Point) => { - closeTag: Range; - closeTagName: Range; - openTag: Range; - openTagName: Range; - }; - $findTagName: (iterator: any) => any; - $findClosingTag: (iterator: any, token: any) => { - openTag: Range; - closeTag: Range; - openTagName: Range; - closeTagName: Range; - }; - $findOpeningTag: (iterator: any, token: any) => { - openTag: Range; - closeTag: Range; - openTagName: Range; - closeTagName: Range; - }; - } - - interface IRange { + export interface Range { start: Point; end: Point; - } - - interface LineWidget { - el: HTMLElement; - rowCount: number; - hidden: boolean; - _inDocument: boolean; - column?: number; - row?: number; - $oldWidget?: LineWidget, - session: EditSession, - html?: string, - text?: string, - className?: string, - coverGutter?: boolean, - pixelHeight?: number, - $fold?: Fold, - editor: Editor, - coverLine?: boolean, - fixedWidth?: boolean, - fullWidth?: boolean, - screenWidth?: number, - rowsAbove?: number, - lenses?: any[], - } - - type NewLineMode = 'auto' | 'unix' | 'windows'; - interface EditSessionOptions { + isEqual(range: Range): boolean; + toString(): string; + contains(row: number, column: number): boolean; + compareRange(range: Range): number; + comparePoint(p: Point): number; + containsRange(range: Range): boolean; + intersects(range: Range): boolean; + isEnd(row: number, column: number): boolean; + isStart(row: number, column: number): boolean; + setStart(row: number, column: number): void; + setEnd(row: number, column: number): void; + inside(row: number, column: number): boolean; + insideStart(row: number, column: number): boolean; + insideEnd(row: number, column: number): boolean; + compare(row: number, column: number): number; + compareStart(row: number, column: number): number; + compareEnd(row: number, column: number): number; + compareInside(row: number, column: number): number; + clipRows(firstRow: number, lastRow: number): Range; + extend(row: number, column: number): Range; + isEmpty(): boolean; + isMultiLine(): boolean; + clone(): Range; + collapseRows(): Range; + toScreenRange(session: EditSession): Range; + moveBy(row: number, column: number): void; + } + + export interface EditSessionOptions { wrap: "off" | "free" | "printmargin" | boolean | number; wrapMethod: 'code' | 'text' | 'auto'; indentedSoftWrap: boolean; @@ -349,7 +172,7 @@ export namespace Ace { mode: string; } - interface VirtualRendererOptions { + export interface VirtualRendererOptions { animatedScroll: boolean; showInvisibles: boolean; showPrintMargin: boolean; @@ -364,7 +187,7 @@ export namespace Ace { highlightGutterLine: boolean; hScrollBarAlwaysVisible: boolean; vScrollBarAlwaysVisible: boolean; - fontSize: string; + fontSize: number; fontFamily: string; maxLines: number; minLines: number; @@ -376,10 +199,9 @@ export namespace Ace { maxPixelHeight: number; useSvgGutterIcons: boolean; showFoldedAnnotations: boolean; - useResizeObserver: boolean; } - interface MouseHandlerOptions { + export interface MouseHandlerOptions { scrollSpeed: number; dragDelay: number; dragEnabled: boolean; @@ -387,10 +209,10 @@ export namespace Ace { tooltipFollowsMouse: boolean; } - interface EditorOptions extends EditSessionOptions, + export interface EditorOptions extends EditSessionOptions, MouseHandlerOptions, VirtualRendererOptions { - selectionStyle: "fullLine" | "screenLine" | "text" | "line"; + selectionStyle: string; highlightActiveLine: boolean; highlightSelectedWord: boolean; readOnly: boolean; @@ -413,224 +235,9 @@ export namespace Ace { relativeLineNumbers: boolean; enableMultiselect: boolean; enableKeyboardAccessibility: boolean; - enableCodeLens: boolean; - } - - interface EventsBase { - [key: string]: any; - } - - interface EditSessionEvents { - /** - * Emitted when the document changes. - * @param delta - */ - "change": (delta: Delta) => void; - /** - * Emitted when the tab size changes, via [[EditSession.setTabSize]]. - * @param tabSize - */ - "changeTabSize": (tabSize: number) => void; - /** - * Emitted when the ability to overwrite text changes, via [[EditSession.setOverwrite]]. - * @param overwrite - */ - "changeOverwrite": (overwrite: boolean) => void; - /** - * Emitted when the gutter changes, either by setting or removing breakpoints, or when the gutter decorations change. - * @param e - */ - "changeBreakpoint": (e: { row: number, breakpoint: boolean }) => void; - /** - * Emitted when a front marker changes. - * @param e - */ - "changeFrontMarker": (e: { row: number, marker: boolean }) => void; - /** - * Emitted when a back marker changes. - * @param e - */ - "changeBackMarker": (e: { row: number, marker: boolean }) => void; - /** - * Emitted when an annotation changes, like through [[EditSession.setAnnotations]]. - * @param e - */ - "changeAnnotation": (e: { row: number, lines: string[] }) => void; - /** - * Emitted when a background tokenizer asynchronously processes new rows. - */ - "tokenizerUpdate": (e: { data: { first: string, last: string } }) => void; - /** - * Emitted when the current mode changes. - * @param e - */ - "changeMode": (e) => void; - /** - * Emitted when the wrap mode changes. - * @param e - */ - "changeWrapMode": (e) => void; - /** - * Emitted when the wrapping limit changes. - * @param e - */ - "changeWrapLimit": (e) => void; - /** - * Emitted when a code fold is added or removed. - * @param e - */ - "changeFold": (e, session: EditSession) => void; - /** - * Emitted when the scroll top changes. - * @param scrollTop The new scroll top value - **/ - "changeScrollTop": (scrollTop: number) => void; - /** - * Emitted when the scroll left changes. - * @param scrollLeft The new scroll left value - **/ - "changeScrollLeft": (scrollLeft: number) => void; - "changeEditor": (e: { editor: Editor }) => void; - } - - interface EditorEvents { - "change": (delta: Delta) => void; - "changeSelection": () => void; - "input": () => void; - /** - * Emitted whenever the [[EditSession]] changes. - * @param e An object with two properties, `oldSession` and `session`, that represent the old and new [[EditSession]]s. - **/ - "changeSession": (e: { oldSession: EditSession, session: EditSession }) => void; - "blur": (e) => void; - "mousedown": (e: MouseEvent) => void; - "mousemove": (e: MouseEvent & { scrollTop? }, editor?: Editor) => void; - "changeStatus": () => void; - "keyboardActivity": () => void; - "mousewheel": (e: MouseEvent) => void; - "mouseup": (e: MouseEvent) => void; - "beforeEndOperation": (e) => void; - "nativecontextmenu": (e) => void; - "destroy": () => void; - "focus": () => void; - /** - * Emitted when text is copied. - * @param text The copied text - **/ - "copy": (text: string) => void; - /** - * Emitted when text is pasted. - **/ - "paste": (text: string, event) => void; - /** - * Emitted when the selection style changes, via [[Editor.setSelectionStyle]]. - * @param data Contains one property, `data`, which indicates the new selection style - **/ - "changeSelectionStyle": (data: "fullLine" | "screenLine" | "text" | "line") => void; - } - - interface AcePopupEvents { - "click": (e: MouseEvent) => void; - "dblclick": (e: MouseEvent) => void; - "tripleclick": (e: MouseEvent) => void; - "quadclick": (e: MouseEvent) => void; - "show": () => void; - "hide": () => void; - "select": (hide: boolean) => void; - "changeHoverMarker": (e) => void; - } - - interface DocumentEvents { - /** - * Fires whenever the document changes. - * Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available: - * * `"insert"` - * * `range`: the [[Range]] of the change within the document - * * `lines`: the lines being added - * * `"remove"` - * * `range`: the [[Range]] of the change within the document - * * `lines`: the lines being removed - * - **/ - "change": (e: Delta) => void; - "changeNewLineMode": () => void; - } - - interface AnchorEvents { - /** - * Fires whenever the anchor position changes. - * Both of these objects have a `row` and `column` property corresponding to the position. - * Events that can trigger this function include [[Anchor.setPosition `setPosition()`]]. - * @param {Object} e An object containing information about the anchor position. It has two properties: - * - `old`: An object describing the old Anchor position - * - `value`: An object describing the new Anchor position - **/ - "change": (e: { old: Point, value: Point }) => void; } - interface BackgroundTokenizerEvents { - /** - * Fires whenever the background tokeniziers between a range of rows are going to be updated. - * @param {Object} e An object containing two properties, `first` and `last`, which indicate the rows of the region being updated. - **/ - "update": (e: { first: number, last: number }) => void; - } - - interface SelectionEvents { - /** - * Emitted when the cursor position changes. - **/ - "changeCursor": () => void; - /** - * Emitted when the cursor selection changes. - **/ - "changeSelection": () => void; - } - - interface PlaceHolderEvents { - - } - - interface GutterEvents { - "changeGutterWidth": (width: number) => void; - } - - interface TextEvents { - "changeCharacterSize": (e) => void; - } - - interface VirtualRendererEvents { - "afterRender": (e, renderer: VirtualRenderer) => void; - "beforeRender": (e, renderer: VirtualRenderer) => void; - } - - class EventEmitter { - once(name: K, callback: T[K]): void; - - setDefaultHandler(name: string, callback: Function): void; - - removeDefaultHandler(name: string, callback: Function): void; - - on(name: K, callback: T[K], capturing?: boolean): T[K]; - - addEventListener(name: K, callback: T[K], capturing?: boolean): T[K]; - - off(name: K, callback: T[K]): void; - - removeListener(name: K, callback: T[K]): void; - - removeEventListener(name: K, callback: T[K]): void; - - removeAllListeners(name?: string): void; - - _signal(eventName: string, e: any): void; - - _emit(eventName: string, e: any): void; - - _dispatchEvent(eventName: string, e: any): void; - } - - interface SearchOptions { + export interface SearchOptions { needle: string | RegExp; preventScroll: boolean; backwards: boolean; @@ -642,28 +249,35 @@ export namespace Ace { wholeWord: boolean; caseSensitive: boolean; wrap: boolean; - re: RegExp; } - interface Point { + export interface EventEmitter { + once(name: string, callback: Function): void; + setDefaultHandler(name: string, callback: Function): void; + removeDefaultHandler(name: string, callback: Function): void; + on(name: string, callback: Function, capturing?: boolean): void; + addEventListener(name: string, callback: Function, capturing?: boolean): void; + off(name: string, callback: Function): void; + removeListener(name: string, callback: Function): void; + removeEventListener(name: string, callback: Function): void; + removeAllListeners(name?: string): void; + } + + export interface Point { row: number; column: number; } - type Position = Point; - - interface Delta { + export interface Delta { action: 'insert' | 'remove'; start: Point; end: Point; lines: string[]; - id?: number, - folds?: Fold[] } - interface Annotation { - row: number; - column: number; + export interface Annotation { + row?: number; + column?: number; text: string; type: string; } @@ -673,30 +287,24 @@ export namespace Ace { className: string; } - type MarkerGroup = import("./src/marker_group").MarkerGroup; + export class MarkerGroup { + constructor(session: EditSession); + setMarkers(markers: MarkerGroupItem[]): void; + getMarkerAtPosition(pos: Position): MarkerGroupItem; + } export interface Command { name?: string; bindKey?: string | { mac?: string, win?: string }; readOnly?: boolean; - exec?: (editor?: Editor | any, args?: any) => void; - isAvailable?: (editor: Editor) => boolean; - description?: string, - multiSelectAction?: "forEach" | "forEachLine" | Function, - scrollIntoView?: true | "cursor" | "center" | "selectionPart" | "animate" | "selection" | "none", - aceCommandGroup?: string, - passEvent?: boolean, - level?: number, - action?: string, + exec: (editor: Editor, args?: any) => void; } - type CommandLike = Command | ((editor: Editor) => void) | ((sb: SearchBox) => void); + export type CommandLike = Command | ((editor: Editor) => void); - type KeyboardHandler = Partial & { - attach?: (editor: Editor) => void; - detach?: (editor: Editor) => void; - getStatusText?: (editor?: any, data?) => string; + export interface KeyboardHandler { + handleKeyboard: Function; } export interface MarkerLike { @@ -704,194 +312,330 @@ export namespace Ace { type: string; renderer?: MarkerRenderer; clazz: string; - inFront?: boolean; - id?: number; + inFront: boolean; + id: number; update?: (html: string[], // TODO maybe define Marker class marker: any, session: EditSession, config: any) => void; - - [key: string]: any; } - type MarkerRenderer = (html: string[], - range: Range, - left: number, - top: number, - config: any) => void; + export type MarkerRenderer = (html: string[], + range: Range, + left: number, + top: number, + config: any) => void; - interface Token { + export interface Token { type: string; value: string; index?: number; start?: number; } - type BaseCompletion = import("./src/autocomplete").BaseCompletion; - type SnippetCompletion = import("./src/autocomplete").SnippetCompletion; - type ValueCompletion = import("./src/autocomplete").ValueCompletion; - type Completion = import("./src/autocomplete").Completion; + interface BaseCompletion { + score?: number; + meta?: string; + caption?: string; + docHTML?: string; + docText?: string; + completerId?: string; + } + + export interface SnippetCompletion extends BaseCompletion { + snippet: string; + } + + export interface ValueCompletion extends BaseCompletion { + value: string; + } + + export type Completion = SnippetCompletion | ValueCompletion - type HighlightRule = ({ defaultToken: string } | { include: string } | { todo: string } | { + export interface Tokenizer { + removeCapturingGroups(src: string): string; + createSplitterRegexp(src: string, flag?: string): RegExp; + getLineTokens(line: string, startState: string | string[]): Token[]; + } + + interface TokenIterator { + getCurrentToken(): Token; + getCurrentTokenColumn(): number; + getCurrentTokenRow(): number; + getCurrentTokenPosition(): Point; + getCurrentTokenRange(): Range; + stepBackward(): Token; + stepForward(): Token; + } + + export type HighlightRule = {defaultToken: string} | {include: string} | {todo: string} | { token: string | string[] | ((value: string) => string); regex: string | RegExp; - next?: string | (() => void); + next?: string; push?: string; comment?: string; caseInsensitive?: boolean; - nextState?: string; - }) & { [key: string]: any }; - - type HighlightRulesMap = Record; + } - type KeywordMapper = (keyword: string) => string; + export type HighlightRulesMap = Record; - interface HighlightRules { - $rules: HighlightRulesMap; - $embeds: string[]; - $keywords: any[]; - $keywordList: string[]; + export type KeywordMapper = (keyword: string) => string; + export interface HighlightRules { addRules(rules: HighlightRulesMap, prefix?: string): void; - getRules(): HighlightRulesMap; - embedRules(rules: (new () => HighlightRules) | HighlightRulesMap, prefix: string, escapeRules?: boolean, append?: boolean): void; - getEmbeds(): string[]; - normalizeRules(): void; - createKeywordMapper(map: Record, defaultToken?: string, ignoreCase?: boolean, splitChar?: string): KeywordMapper; } - type FoldWidget = "start" | "end" | "" - - interface FoldMode { + export interface FoldMode { foldingStartMarker: RegExp; foldingStopMarker?: RegExp; - - getFoldWidget(session: EditSession, foldStyle: string, row: number): FoldWidget; - - getFoldWidgetRange(session: EditSession, foldStyle: string, row: number): Range | undefined; - + getFoldWidget(session: EditSession, foldStyle: string, row: number): string; + getFoldWidgetRange(session: EditSession, foldStyle: string, row: number, forceMultiline?: boolean): Range | undefined; indentationBlock(session: EditSession, row: number, column?: number): Range | undefined; - openingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; - closingBracketBlock(session: EditSession, bracket: string, row: number, column: number, typeRe?: RegExp): Range | undefined; } - type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string | Range) => ({ text: string, selection: number[] } | Range) & { [key: string]: any } | undefined; + type BehaviorAction = (state: string, action: string, editor: Editor, session: EditSession, text: string) => {text: string, selection: number[]} | Range | undefined; type BehaviorMap = Record>; - interface Behaviour { + export interface Behaviour { add(name: string, action: string, callback: BehaviorAction): void; - addBehaviours(behaviours: BehaviorMap): void; - remove(name: string): void; - inherit(mode: SyntaxMode | (new () => SyntaxMode), filter: string[]): void; - - getBehaviours(filter?: string[]): BehaviorMap; + getBehaviours(filter: string[]): BehaviorMap; } - interface Outdent { + export interface Outdent { checkOutdent(line: string, input: string): boolean; - autoOutdent(doc: Document, row: number): number | undefined; } - interface SyntaxMode { - /** - * quotes used by language mode - */ - $quotes: { [quote: string]: string }; - HighlightRules: { - new(config: any): HighlightRules - }; //TODO: fix this + export interface SyntaxMode { + HighlightRules: new () => HighlightRules; foldingRules?: FoldMode; $behaviour?: Behaviour; $defaultBehaviour?: Behaviour; - /** - * characters that indicate the start of a line comment - */ lineCommentStart?: string; - /** - * characters that indicate the start and end of a block comment - */ - blockComment?: { start: string, end: string } - tokenRe?: RegExp; - nonTokenRe?: RegExp; - /** - * An object containing conditions to determine whether to apply matching quote or not. - */ - $pairQuotesAfter: { [quote: string]: RegExp } - $tokenizer: Tokenizer; - $highlightRules: HighlightRules; - $embeds?: string[]; - $modes?: SyntaxMode[]; - $keywordList?: string[]; - $highlightRuleConfig?: any; - completionKeywords: string[]; - transformAction: BehaviorAction; - path?: string; - getTokenizer(): Tokenizer; - toggleCommentLines(state: any, session: EditSession, startRow: number, endRow: number): void; - toggleBlockComment(state: any, session: EditSession, range: Range, cursor: Point): void; - getNextLineIndent(state: any, line: string, tab: string): string; - checkOutdent(state: any, line: string, input: string): boolean; - - autoOutdent(state: any, doc: EditSession, row: number): void; - + autoOutdent(state: any, doc: Document, row: number): void; // TODO implement WorkerClient types createWorker(session: EditSession): any; - createModeDelegates(mapping: { [key: string]: string }): void; - + transformAction: BehaviorAction; getKeywords(append?: boolean): Array; - getCompletions(state: string, session: EditSession, pos: Point, prefix: string): Completion[]; - - $getIndent(line: string): string; - - $createKeywordList(): string[]; - - $delegator(method: string, args: IArguments, defaultHandler): any; - - } - - interface OptionsBase { - [key: string]: any; } - class OptionsProvider { - setOptions(optList: Partial): void; - - getOptions(optionNames?: Array | Partial): Partial; - - setOption(name: K, value: T[K]): void; + type AfterLoadCallback = (err: Error | null, module: unknown) => void; + type LoaderFunction = (moduleName: string, afterLoad: AfterLoadCallback) => void; - getOption(name: K): T[K]; + export interface Config { + get(key: string): any; + set(key: string, value: any): void; + all(): { [key: string]: any }; + moduleUrl(name: string, component?: string): string; + setModuleUrl(name: string, subst: string): string; + setLoader(cb: LoaderFunction): void; + setModuleLoader(name: string, onLoad: Function): void; + loadModule(moduleName: string | [string, string], + onLoad?: (module: any) => void): void; + init(packaged: any): any; + defineOptions(obj: any, path: string, options: { [key: string]: any }): Config; + resetOptions(obj: any): void; + setDefaultValue(path: string, name: string, value: any): void; + setDefaultValues(path: string, optionHash: { [key: string]: any }): void; } - type KeyBinding = import("./src/keyboard/keybinding").KeyBinding; + export interface OptionsProvider { + setOptions(optList: { [key: string]: any }): void; + getOptions(optionNames?: string[] | { [key: string]: any }): { [key: string]: any }; + setOption(name: string, value: any): void; + getOption(name: string): any; + } + + export interface UndoManager { + addSession(session: EditSession): void; + add(delta: Delta, allowMerge: boolean, session: EditSession): void; + addSelection(selection: string, rev?: number): void; + startNewGroup(): void; + markIgnored(from: number, to?: number): void; + getSelection(rev: number, after?: boolean): { value: string, rev: number }; + getRevision(): number; + getDeltas(from: number, to?: number): Delta[]; + undo(session: EditSession, dontSelect?: boolean): void; + redo(session: EditSession, dontSelect?: boolean): void; + reset(): void; + canUndo(): boolean; + canRedo(): boolean; + bookmark(rev?: number): void; + isAtBookmark(): boolean; + hasUndo(): boolean; + hasRedo(): boolean; + isClean(): boolean; + markClean(rev?: number): void; + toJSON(): object; + fromJSON(json: object): void; + } + + export interface Position { + row: number, + column: number + } + + export interface EditSession extends EventEmitter, OptionsProvider, Folding { + selection: Selection; + + // TODO: define BackgroundTokenizer + + on(name: 'changeFold', + callback: (obj: { data: Fold, action: string }) => void): Function; + on(name: 'changeScrollLeft', callback: (scrollLeft: number) => void): Function; + on(name: 'changeScrollTop', callback: (scrollTop: number) => void): Function; + on(name: 'tokenizerUpdate', + callback: (obj: { data: { first: number, last: number } }) => void): Function; + on(name: 'change', callback: () => void): Function; + on(name: 'changeTabSize', callback: () => void): Function; + + + setOption(name: T, value: EditSessionOptions[T]): void; + getOption(name: T): EditSessionOptions[T]; + + readonly doc: Document; + + setDocument(doc: Document): void; + getDocument(): Document; + resetCaches(): void; + setValue(text: string): void; + getValue(): string; + getSelection(): Selection; + getState(row: number): string; + getTokens(row: number): Token[]; + getTokenAt(row: number, column: number): Token | null; + setUndoManager(undoManager: UndoManager): void; + markUndoGroup(): void; + getUndoManager(): UndoManager; + getTabString(): string; + setUseSoftTabs(val: boolean): void; + getUseSoftTabs(): boolean; + setTabSize(tabSize: number): void; + getTabSize(): number; + isTabStop(position: Position): boolean; + setNavigateWithinSoftTabs(navigateWithinSoftTabs: boolean): void; + getNavigateWithinSoftTabs(): boolean; + setOverwrite(overwrite: boolean): void; + getOverwrite(): boolean; + toggleOverwrite(): void; + addGutterDecoration(row: number, className: string): void; + removeGutterDecoration(row: number, className: string): void; + getBreakpoints(): string[]; + setBreakpoints(rows: number[]): void; + clearBreakpoints(): void; + setBreakpoint(row: number, className: string): void; + clearBreakpoint(row: number): void; + addMarker(range: Range, + className: string, + type: "fullLine" | "screenLine" | "text" | MarkerRenderer, + inFront?: boolean): number; + addDynamicMarker(marker: MarkerLike, inFront: boolean): MarkerLike; + removeMarker(markerId: number): void; + getMarkers(inFront?: boolean): {[id: number]: MarkerLike}; + highlight(re: RegExp): void; + highlightLines(startRow: number, + endRow: number, + className: string, + inFront?: boolean): Range; + setAnnotations(annotations: Annotation[]): void; + getAnnotations(): Annotation[]; + clearAnnotations(): void; + getWordRange(row: number, column: number): Range; + getAWordRange(row: number, column: number): Range; + setNewLineMode(newLineMode: NewLineMode): void; + getNewLineMode(): NewLineMode; + setUseWorker(useWorker: boolean): void; + getUseWorker(): boolean; + setMode(mode: string | SyntaxMode, callback?: () => void): void; + getMode(): SyntaxMode; + setScrollTop(scrollTop: number): void; + getScrollTop(): number; + setScrollLeft(scrollLeft: number): void; + getScrollLeft(): number; + getScreenWidth(): number; + getLineWidgetMaxWidth(): number; + getLine(row: number): string; + getLines(firstRow: number, lastRow: number): string[]; + getLength(): number; + getTextRange(range: Range): string; + insert(position: Position, text: string): void; + remove(range: Range): void; + removeFullLines(firstRow: number, lastRow: number): void; + undoChanges(deltas: Delta[], dontSelect?: boolean): void; + redoChanges(deltas: Delta[], dontSelect?: boolean): void; + setUndoSelect(enable: boolean): void; + replace(range: Range, text: string): void; + moveText(fromRange: Range, toPosition: Position, copy?: boolean): void; + indentRows(startRow: number, endRow: number, indentString: string): void; + outdentRows(range: Range): void; + moveLinesUp(firstRow: number, lastRow: number): void; + moveLinesDown(firstRow: number, lastRow: number): void; + duplicateLines(firstRow: number, lastRow: number): void; + setUseWrapMode(useWrapMode: boolean): void; + getUseWrapMode(): boolean; + setWrapLimitRange(min: number, max: number): void; + adjustWrapLimit(desiredLimit: number): boolean; + getWrapLimit(): number; + setWrapLimit(limit: number): void; + getWrapLimitRange(): { min: number, max: number }; + getRowLineCount(row: number): number; + getRowWrapIndent(screenRow: number): number; + getScreenLastRowColumn(screenRow: number): number; + getDocumentLastRowColumn(docRow: number, docColumn: number): number; + getdocumentLastRowColumnPosition(docRow: number, docColumn: number): Position; + getRowSplitData(row: number): string | undefined; + getScreenTabSize(screenColumn: number): number; + screenToDocumentRow(screenRow: number, screenColumn: number): number; + screenToDocumentColumn(screenRow: number, screenColumn: number): number; + screenToDocumentPosition(screenRow: number, + screenColumn: number, + offsetX?: number): Position; + documentToScreenPosition(docRow: number, docColumn: number): Position; + documentToScreenPosition(position: Position): Position; + documentToScreenColumn(row: number, docColumn: number): number; + documentToScreenRow(docRow: number, docColumn: number): number; + getScreenLength(): number; + toJSON(): Object; + destroy(): void; + } + + export interface KeyBinding { + setDefaultHandler(handler: KeyboardHandler): void; + setKeyboardHandler(handler: KeyboardHandler): void; + addKeyboardHandler(handler: KeyboardHandler, pos?: number): void; + removeKeyboardHandler(handler: KeyboardHandler): boolean; + getKeyboardHandler(): KeyboardHandler; + getStatusText(): string; + onCommandKey(e: any, hashId: number, keyCode: number): boolean; + onTextInput(text: string): boolean; + } interface CommandMap { [name: string]: Command; @@ -903,15 +647,189 @@ export namespace Ace { args: any[] }) => void; - interface CommandManagerEvents { + export interface CommandManager extends EventEmitter { + byName: CommandMap, + commands: CommandMap, on(name: 'exec', callback: execEventHandler): Function; - on(name: 'afterExec', callback: execEventHandler): Function; + once(name: string, callback: Function): void; + setDefaultHandler(name: string, callback: Function): void; + removeDefaultHandler(name: string, callback: Function): void; + on(name: string, callback: Function, capturing?: boolean): void; + addEventListener(name: string, callback: Function, capturing?: boolean): void; + off(name: string, callback: Function): void; + removeListener(name: string, callback: Function): void; + removeEventListener(name: string, callback: Function): void; + + exec(command: string, editor: Editor, args: any): boolean; + toggleRecording(editor: Editor): void; + replay(editor: Editor): void; + addCommand(command: Command): void; + addCommands(command: Command[]): void; + removeCommand(command: Command | string, keepCommand?: boolean): void; + removeCommands(command: Command[]): void; + bindKey(key: string | { mac?: string, win?: string}, + command: CommandLike, + position?: number): void; + bindKeys(keys: {[s: string]: Function}): void; + parseKeys(keyPart: string): {key: string, hashId: number}; + findKeyCommand(hashId: number, keyString: string): string | undefined; + handleKeyboard(data: {}, hashId: number, keyString: string, keyCode: string | number): void | {command: string}; + getStatusText(editor: Editor, data: {}): string; + } + + export interface VirtualRenderer extends OptionsProvider, EventEmitter { + readonly container: HTMLElement; + readonly scroller: HTMLElement; + readonly content: HTMLElement; + readonly characterWidth: number; + readonly lineHeight: number; + readonly scrollLeft: number; + readonly scrollTop: number; + readonly $padding: number; + + setOption(name: T, value: VirtualRendererOptions[T]): void; + getOption(name: T): VirtualRendererOptions[T]; + + setSession(session: EditSession): void; + updateLines(firstRow: number, lastRow: number, force?: boolean): void; + updateText(): void; + updateFull(force?: boolean): void; + updateFontSize(): void; + adjustWrapLimit(): boolean; + setAnimatedScroll(shouldAnimate: boolean): void; + getAnimatedScroll(): boolean; + setShowInvisibles(showInvisibles: boolean): void; + getShowInvisibles(): boolean; + setDisplayIndentGuides(display: boolean): void; + getDisplayIndentGuides(): boolean; + setShowPrintMargin(showPrintMargin: boolean): void; + getShowPrintMargin(): boolean; + setPrintMarginColumn(showPrintMargin: boolean): void; + getPrintMarginColumn(): boolean; + setShowGutter(show: boolean): void; + getShowGutter(): boolean; + setFadeFoldWidgets(show: boolean): void; + getFadeFoldWidgets(): boolean; + setHighlightGutterLine(shouldHighlight: boolean): void; + getHighlightGutterLine(): boolean; + getContainerElement(): HTMLElement; + getMouseEventTarget(): HTMLElement; + getTextAreaContainer(): HTMLElement; + getFirstVisibleRow(): number; + getFirstFullyVisibleRow(): number; + getLastFullyVisibleRow(): number; + getLastVisibleRow(): number; + setPadding(padding: number): void; + setScrollMargin(top: number, + bottom: number, + left: number, + right: number): void; + setHScrollBarAlwaysVisible(alwaysVisible: boolean): void; + getHScrollBarAlwaysVisible(): boolean; + setVScrollBarAlwaysVisible(alwaysVisible: boolean): void; + getVScrollBarAlwaysVisible(): boolean; + freeze(): void; + unfreeze(): void; + updateFrontMarkers(): void; + updateBackMarkers(): void; + updateBreakpoints(): void; + setAnnotations(annotations: Annotation[]): void; + updateCursor(): void; + hideCursor(): void; + showCursor(): void; + scrollSelectionIntoView(anchor: Position, + lead: Position, + offset?: number): void; + scrollCursorIntoView(cursor: Position, offset?: number): void; + getScrollTop(): number; + getScrollLeft(): number; + getScrollTopRow(): number; + getScrollBottomRow(): number; + scrollToRow(row: number): void; + alignCursor(cursor: Position | number, alignment: number): number; + scrollToLine(line: number, + center: boolean, + animate: boolean, + callback: () => void): void; + animateScrolling(fromValue: number, callback: () => void): void; + scrollToY(scrollTop: number): void; + scrollToX(scrollLeft: number): void; + scrollTo(x: number, y: number): void; + scrollBy(deltaX: number, deltaY: number): void; + isScrollableBy(deltaX: number, deltaY: number): boolean; + textToScreenCoordinates(row: number, column: number): { pageX: number, pageY: number}; + pixelToScreenCoordinates(x: number, y: number): {row: number, column: number, side: 1|-1, offsetX: number}; + visualizeFocus(): void; + visualizeBlur(): void; + showComposition(position: number): void; + setCompositionText(text: string): void; + hideComposition(): void; + setGhostText(text: string, position: Point): void; + removeGhostText(): void; + setTheme(theme: string, callback?: () => void): void; + getTheme(): string; + setStyle(style: string, include?: boolean): void; + unsetStyle(style: string): void; + setCursorStyle(style: string): void; + setMouseCursor(cursorStyle: string): void; + attachToShadowRoot(): void; + destroy(): void; + } + + + export interface Selection extends EventEmitter { + moveCursorWordLeft(): void; + moveCursorWordRight(): void; + fromOrientedRange(range: Range): void; + setSelectionRange(match: any): void; + getAllRanges(): Range[]; + addRange(range: Range): void; + isEmpty(): boolean; + isMultiLine(): boolean; + setCursor(row: number, column: number): void; + setAnchor(row: number, column: number): void; + getAnchor(): Position; + getCursor(): Position; + isBackwards(): boolean; + getRange(): Range; + clearSelection(): void; + selectAll(): void; + setRange(range: Range, reverse?: boolean): void; + selectTo(row: number, column: number): void; + selectToPosition(pos: any): void; + selectUp(): void; + selectDown(): void; + selectRight(): void; + selectLeft(): void; + selectLineStart(): void; + selectLineEnd(): void; + selectFileEnd(): void; + selectFileStart(): void; + selectWordRight(): void; + selectWordLeft(): void; + getWordRange(): void; + selectWord(): void; + selectAWord(): void; + selectLine(): void; + moveCursorUp(): void; + moveCursorDown(): void; + moveCursorLeft(): void; + moveCursorRight(): void; + moveCursorLineStart(): void; + moveCursorLineEnd(): void; + moveCursorFileEnd(): void; + moveCursorFileStart(): void; + moveCursorLongWordRight(): void; + moveCursorLongWordLeft(): void; + moveCursorBy(rows: number, chars: number): void; + moveCursorToPosition(position: any): void; + moveCursorTo(row: number, column: number, keepDesiredColumn?: boolean): void; + moveCursorToScreen(row: number, column: number, keepDesiredColumn: boolean): void; + + toJSON(): SavedSelection | SavedSelection[]; + fromJSON(selection: SavedSelection | SavedSelection[]): void; } - - type CommandManager = import("./src/commands/command_manager").CommandManager; - - interface SavedSelection { start: Point; end: Point; @@ -922,32 +840,193 @@ export namespace Ace { new(session: EditSession): Selection; } - interface TextInput { + export interface TextInput { resetSelection(): void; + setAriaOption(activeDescendant: string, role: string): void; + } - setAriaOption(options?: { activeDescendant: string, role: string, setLabel }): void; + export interface Editor extends OptionsProvider, EventEmitter { + container: HTMLElement; + renderer: VirtualRenderer; + id: string; + commands: CommandManager; + keyBinding: KeyBinding; + session: EditSession; + selection: Selection; + textInput: TextInput; + + on(name: 'blur', callback: (e: Event) => void): void; + on(name: 'input', callback: () => void): void; + on(name: 'change', callback: (delta: Delta) => void): void; + on(name: 'changeSelectionStyle', callback: (obj: { data: string }) => void): void; + on(name: 'changeSession', + callback: (obj: { session: EditSession, oldSession: EditSession }) => void): void; + on(name: 'copy', callback: (obj: { text: string }) => void): void; + on(name: 'focus', callback: (e: Event) => void): void; + on(name: 'paste', callback: (obj: { text: string }) => void): void; + on(name: 'mousemove', callback: (e: any) => void): void; + on(name: 'mouseup', callback: (e: any) => void): void; + on(name: 'mousewheel', callback: (e: any) => void): void; + on(name: 'click', callback: (e: any) => void): void; + on(name: 'guttermousedown', callback: (e: any) => void): void; + on(name: 'gutterkeydown', callback: (e: any) => void): void; + + onPaste(text: string, event: any): void; + + setOption(name: T, value: EditorOptions[T]): void; + getOption(name: T): EditorOptions[T]; + + setKeyboardHandler(keyboardHandler: string, callback?: () => void): void; + setKeyboardHandler(keyboardHandler: KeyboardHandler|null): void; + getKeyboardHandler(): string; + setSession(session: EditSession | undefined): void; + getSession(): EditSession; + setValue(val: string, cursorPos?: number): string; + getValue(): string; + getSelection(): Selection; + resize(force?: boolean): void; + setTheme(theme: string, callback?: () => void): void; + getTheme(): string; + setStyle(style: string): void; + unsetStyle(style: string): void; + getFontSize(): string; + setFontSize(size: number|string): void; + focus(): void; + isFocused(): boolean; + blur(): void; + getSelectedText(): string; + getCopyText(): string; + execCommand(command: string | string[], args?: any): boolean; + insert(text: string, pasted?: boolean): void; + setOverwrite(overwrite: boolean): void; + getOverwrite(): boolean; + toggleOverwrite(): void; + setScrollSpeed(speed: number): void; + getScrollSpeed(): number; + setDragDelay(dragDelay: number): void; + getDragDelay(): number; + setSelectionStyle(val: string): void; + getSelectionStyle(): string; + setHighlightActiveLine(shouldHighlight: boolean): void; + getHighlightActiveLine(): boolean; + setHighlightGutterLine(shouldHighlight: boolean): void; + getHighlightGutterLine(): boolean; + setHighlightSelectedWord(shouldHighlight: boolean): void; + getHighlightSelectedWord(): boolean; + setAnimatedScroll(shouldAnimate: boolean): void; + getAnimatedScroll(): boolean; + setShowInvisibles(showInvisibles: boolean): void; + getShowInvisibles(): boolean; + setDisplayIndentGuides(display: boolean): void; + getDisplayIndentGuides(): boolean; + setShowPrintMargin(showPrintMargin: boolean): void; + getShowPrintMargin(): boolean; + setPrintMarginColumn(showPrintMargin: number): void; + getPrintMarginColumn(): number; + setReadOnly(readOnly: boolean): void; + getReadOnly(): boolean; + setBehavioursEnabled(enabled: boolean): void; + getBehavioursEnabled(): boolean; + setWrapBehavioursEnabled(enabled: boolean): void; + getWrapBehavioursEnabled(): boolean; + setShowFoldWidgets(show: boolean): void; + getShowFoldWidgets(): boolean; + setFadeFoldWidgets(fade: boolean): void; + getFadeFoldWidgets(): boolean; + remove(dir?: 'left' | 'right'): void; + removeWordRight(): void; + removeWordLeft(): void; + removeLineToEnd(): void; + splitLine(): void; + setGhostText(text: string, position: Point): void; + removeGhostText(): void; + transposeLetters(): void; + toLowerCase(): void; + toUpperCase(): void; + indent(): void; + blockIndent(): void; + blockOutdent(): void; + sortLines(): void; + toggleCommentLines(): void; + toggleBlockComment(): void; + modifyNumber(amount: number): void; + removeLines(): void; + duplicateSelection(): void; + moveLinesDown(): void; + moveLinesUp(): void; + moveText(range: Range, toPosition: Point, copy?: boolean): Range; + copyLinesUp(): void; + copyLinesDown(): void; + getFirstVisibleRow(): number; + getLastVisibleRow(): number; + isRowVisible(row: number): boolean; + isRowFullyVisible(row: number): boolean; + selectPageDown(): void; + selectPageUp(): void; + gotoPageDown(): void; + gotoPageUp(): void; + scrollPageDown(): void; + scrollPageUp(): void; + scrollToRow(row: number): void; + scrollToLine(line: number, center: boolean, animate: boolean, callback: () => void): void; + centerSelection(): void; + getCursorPosition(): Point; + getCursorPositionScreen(): Point; + getSelectionRange(): Range; + selectAll(): void; + clearSelection(): void; + moveCursorTo(row: number, column: number): void; + moveCursorToPosition(pos: Point): void; + jumpToMatching(select: boolean, expand: boolean): void; + gotoLine(lineNumber: number, column: number, animate: boolean): void; + navigateTo(row: number, column: number): void; + navigateUp(times?: number): void; + navigateDown(times?: number): void; + navigateLeft(times?: number): void; + navigateRight(times?: number): void; + navigateLineStart(): void; + navigateLineEnd(): void; + navigateFileEnd(): void; + navigateFileStart(): void; + navigateWordRight(): void; + navigateWordLeft(): void; + replace(replacement: string, options?: Partial): number; + replaceAll(replacement: string, options?: Partial): number; + getLastSearchOptions(): Partial; + find(needle: string | RegExp, options?: Partial, animate?: boolean): Ace.Range | undefined; + findNext(options?: Partial, animate?: boolean): void; + findPrevious(options?: Partial, animate?: boolean): void; + findAll(needle: string | RegExp, options?: Partial, additive?: boolean): number; + undo(): void; + redo(): void; + destroy(): void; + setAutoScrollEditorIntoView(enable: boolean): void; + completers: Completer[]; } type CompleterCallback = (error: any, completions: Completion[]) => void; interface Completer { identifierRegexps?: Array, - getCompletions(editor: Editor, session: EditSession, position: Point, prefix: string, callback: CompleterCallback): void; - - getDocTooltip?(item: Completion): void | string | Completion; - + getDocTooltip?(item: Completion): undefined | string | Completion; cancel?(): void; - id?: string; triggerCharacters?: string[]; hideInlinePreview?: boolean; } + export class AceInline { + show(editor: Editor, completion: Completion, prefix: string): void; + isOpen(): void; + hide(): void; + destroy(): void; + } + interface CompletionOptions { matches?: Completion[]; } @@ -957,6 +1036,12 @@ export namespace Ace { ignoreCaption?: boolean; } + type CompletionRecord = { + all: Completion[]; + filtered: Completion[]; + filterText: string; + } | CompletionProviderOptions + type GatherCompletionRecord = { prefix: string; matches: Completion[]; @@ -964,219 +1049,56 @@ export namespace Ace { } type CompletionCallbackFunction = (err: Error | undefined, data: GatherCompletionRecord) => void; - type CompletionProviderCallback = (this: import("./src/autocomplete").Autocomplete, err: Error | undefined, completions: import("./src/autocomplete").FilteredList, finished: boolean) => void; - - type AcePopupNavigation = "up" | "down" | "start" | "end"; - - interface EditorMultiSelectProperties { - inMultiSelectMode?: boolean, - /** - * Updates the cursor and marker layers. - **/ - updateSelectionMarkers: () => void, - /** - * Adds the selection and cursor. - * @param orientedRange A range containing a cursor - **/ - addSelectionMarker: (orientedRange: Ace.Range & { marker? }) => Ace.Range & { marker? }, - /** - * Removes the selection marker. - * @param range The selection range added with [[Editor.addSelectionMarker `addSelectionMarker()`]]. - **/ - removeSelectionMarker: (range: Ace.Range & { marker? }) => void, - removeSelectionMarkers: (ranges: (Ace.Range & { marker? })[]) => void, - $onAddRange: (e) => void, - $onRemoveRange: (e) => void, - $onMultiSelect: (e) => void, - $onSingleSelect: (e) => void, - $onMultiSelectExec: (e) => void, - /** - * Executes a command for each selection range. - * @param cmd The command to execute - * @param [args] Any arguments for the command - **/ - forEachSelection: (cmd: Object, args?: string, options?: Object) => void, - /** - * Removes all the selections except the last added one. - **/ - exitMultiSelectMode: () => void, - getSelectedText: () => string, - $checkMultiselectChange: (e, anchor: Ace.Anchor) => void, - /** - * Finds and selects all the occurrences of `needle`. - * @param needle The text to find - * @param options The search options - * @param additive keeps - * @returns {Number} The cumulative count of all found matches - **/ - findAll: (needle?: string, options?: Partial, additive?: boolean) => number, - /** - * Adds a cursor above or below the active cursor. - * @param dir The direction of lines to select: -1 for up, 1 for down - * @param [skip] If `true`, removes the active selection range - */ - selectMoreLines: (dir: number, skip?: boolean) => void, - /** - * Transposes the selected ranges. - * @param {Number} dir The direction to rotate selections - **/ - transposeSelections: (dir: number) => void, - /** - * Finds the next occurrence of text in an active selection and adds it to the selections. - * @param {Number} dir The direction of lines to select: -1 for up, 1 for down - * @param {Boolean} [skip] If `true`, removes the active selection range - * @param {Boolean} [stopAtFirst] - **/ - selectMore: (dir: number, skip?: boolean, stopAtFirst?: boolean) => void, - /** - * Aligns the cursors or selected text. - **/ - alignCursors: () => void, - $reAlignText: (lines: string[], forceLeft: boolean) => string[], - multiSelect?: any, - $multiselectOnSessionChange?: any, - $blockSelectEnabled?: boolean, - } - - interface CodeLenseEditorExtension { - codeLensProviders?: any[]; - $codeLensClickHandler?: any; - $updateLenses?: () => void; - $updateLensesOnInput?: () => void; - } - - interface ElasticTabstopsEditorExtension { - elasticTabstops?: import("./src/ext/elastic_tabstops_lite").ElasticTabstopsLite; - } - - interface TextareaEditorExtension { - setDisplaySettings?: (settings: any) => void; - } - - interface PromptEditorExtension { - cmdLine?: Editor; - } - - interface OptionsEditorExtension { - $options?: any; - } - - interface MultiSelectProperties { - ranges: Ace.Range[] | null; - rangeList: Ace.RangeList | null; - - /** - * Adds a range to a selection by entering multiselect mode, if necessary. - * @param {Ace.Range} range The new range to add - * @param {Boolean} [$blockChangeEvents] Whether or not to block changing events - **/ - addRange(range: Ace.Range, $blockChangeEvents?: boolean): any; - - inMultiSelectMode: boolean; - - /** - * @param {Ace.Range} [range] - **/ - toSingleRange(range?: Ace.Range): void; - - /** - * Removes a Range containing pos (if it exists). - * @param {Ace.Point} pos The position to remove, as a `{row, column}` object - **/ - substractPoint(pos: Ace.Point): any; - - /** - * Merges overlapping ranges ensuring consistency after changes - **/ - mergeOverlappingRanges(): void; - - /** - * @param {Ace.Range} range - */ - $onAddRange(range: Ace.Range): void; - - rangeCount: number; - - /** - * - * @param {Ace.Range[]} removed - */ - $onRemoveRange(removed: Ace.Range[]): void; - - /** - * adds multicursor support to selection - */ - $initRangeList(): void; - - /** - * Returns a concatenation of all the ranges. - * @returns {Ace.Range[]} - **/ - getAllRanges(): Ace.Range[]; - - /** - * Splits all the ranges into lines. - **/ - splitIntoLines(): void; - - /** - */ - joinSelections(): void; - - /** - **/ - toggleBlockSelection(): void; - - /** - * - * Gets list of ranges composing rectangular block on the screen - * - * @param {Ace.ScreenCoordinates} screenCursor The cursor to use - * @param {Ace.ScreenCoordinates} screenAnchor The anchor to use - * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping - * @returns {Ace.Range[]} - **/ - rectangularRangeBlock(screenCursor: Ace.ScreenCoordinates, screenAnchor: Ace.ScreenCoordinates, includeEmptyLines?: boolean): Ace.Range[]; - - _eventRegistry?: any; - index?: number; + type CompletionProviderCallback = (err: Error | undefined, completions: CompletionRecord, finished: boolean) => void; + + export class CompletionProvider { + insertByIndex(editor: Editor, index: number, options: CompletionProviderOptions): boolean; + insertMatch(editor: Editor, data: Completion, options: CompletionProviderOptions): boolean; + completions: CompletionRecord; + gatherCompletions(editor: Editor, callback: CompletionCallbackFunction): boolean; + provideCompletions(editor: Editor, options: CompletionProviderOptions, callback: CompletionProviderCallback): void; + detach(): void; + } + + export class Autocomplete { + constructor(); + autoInsert?: boolean; + autoSelect?: boolean; + autoShown?: boolean; + exactMatch?: boolean; + inlineEnabled?: boolean; + parentNode?: HTMLElement; + setSelectOnHover?: Boolean; + stickySelectionDelay?: Number; + ignoreCaption?: Boolean; + emptyMessage?(prefix: String): String; + getPopup(): AcePopup; + showPopup(editor: Editor, options: CompletionOptions): void; + detach(): void; + destroy(): void; } - type AcePopupEventsCombined = Ace.EditorEvents & Ace.AcePopupEvents; - type AcePopupWithEditor = Ace.EventEmitter & Ace.Editor; - type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; - - type TooltipCommandFunction = (editor: Ace.Editor) => T; + type AcePopupNavigation = "up" | "down" | "start" | "end"; - export interface TooltipCommand extends Ace.Command { - enabled: TooltipCommandFunction | boolean, - getValue?: TooltipCommandFunction, - type: "button" | "text" | "checkbox" - iconCssClass?: string, - cssClass?: string + export class AcePopup { + constructor(parentNode: HTMLElement); + setData(list: Completion[], filterText: string): void; + getData(row: number): Completion; + getRow(): number; + getRow(line: number): void; + hide(): void; + show(pos: Point, lineHeight: number, topdownOnly: boolean): void; + tryShow(pos: Point, lineHeight: number, anchor: "top" | "bottom" | undefined, forceShow?: boolean): boolean; + goTo(where: AcePopupNavigation): void; } - - export type CommandBarTooltip = import("./src/ext/command_bar").CommandBarTooltip; - - export type TokenizeResult = Array> } export const version: string; export const config: Ace.Config; - export function require(name: string): any; - -export function edit(el: string | (Element & { - env?; - value?; -}), options?: Partial): Ace.Editor; - +export function edit(el: Element | string, options?: Partial): Ace.Editor; export function createEditSession(text: Ace.Document | string, mode: Ace.SyntaxMode): Ace.EditSession; - export const VirtualRenderer: { new(container: HTMLElement, theme?: string): Ace.VirtualRenderer; }; @@ -1187,7 +1109,7 @@ export const UndoManager: { new(): Ace.UndoManager; }; export const Editor: { - new(renderer: Ace.VirtualRenderer, session?: Ace.EditSession, options?: Partial): Ace.Editor; + new(): Ace.Editor; }; export const Range: { new(startRow: number, startColumn: number, endRow: number, endColumn: number): Ace.Range; @@ -1195,307 +1117,47 @@ export const Range: { comparePoints(p1: Ace.Point, p2: Ace.Point): number; }; -export type InlineAutocomplete = Ace.InlineAutocomplete; -export type CommandBarTooltip = Ace.CommandBarTooltip; - - -declare module "./src/anchor" { - export interface Anchor extends Ace.EventEmitter { - markerId?: number; - document: Ace.Document; - } - - -} - -declare module "./src/autocomplete" { - export interface Autocomplete { - popup: Ace.AcePopup; - emptyMessage?: Function, - } - - export interface CompletionProvider { - completions: Ace.FilteredList; - } -} -declare module "./src/background_tokenizer" { - export interface BackgroundTokenizer extends Ace.EventEmitter { +type InlineAutocompleteAction = "prev" | "next" | "first" | "last"; - } -} - -declare module "./src/document" { - export interface Document extends Ace.EventEmitter { - - } +type TooltipCommandFunction = (editor: Ace.Editor) => T; +interface TooltipCommand extends Ace.Command { + enabled: TooltipCommandFunction | boolean, + getValue?: TooltipCommandFunction, + type: "button" | "text" | "checkbox" + iconCssClass: string, + cssClass: string } -declare module "./src/editor" { - export interface Editor extends Ace.EditorMultiSelectProperties, Ace.OptionsProvider, - Ace.EventEmitter, Ace.CodeLenseEditorExtension, Ace.ElasticTabstopsEditorExtension, - Ace.TextareaEditorExtension, Ace.PromptEditorExtension, Ace.OptionsEditorExtension { - session: Ace.EditSession; - $mergeUndoDeltas?: any, - $highlightSelectedWord?: boolean, - $updatePlaceholder?: Function, - $cursorStyle?: string, - $readOnly?: any, - $highlightActiveLine?: any, - $enableAutoIndent?: any, - $copyWithEmptySelection?: any - $selectionStyle?: string, - env?: any; - widgetManager?: Ace.LineWidgets, - completer?: Ace.Autocomplete | Ace.InlineAutocomplete, - completers: Ace.Completer[], - $highlightTagPending?: boolean, - showKeyboardShortcuts?: () => void, - showSettingsMenu?: () => void, - searchBox?: Ace.SearchBox, - _eventRegistry?: any, - } -} - -declare module "./src/edit_session" { - export interface EditSession extends Ace.EventEmitter, - Ace.OptionsProvider, - Ace.Folding, Ace.BracketMatch { - doc: Ace.Document, - $highlightLineMarker?: { - start: Ace.Point, - end: Ace.Point, - id?: number - } - $useSoftTabs?: boolean, - $tabSize?: number, - $useWorker?: boolean, - $wrapAsCode?: boolean, - $indentedSoftWrap?: boolean, - widgetManager?: any, - $bracketHighlight?: any, - $selectionMarker?: number, - curOp?: { - command: {}, - args: string, - scrollTop: number, - [key: string]: any; - }, - lineWidgetsWidth?: number, - $getWidgetScreenLength?: () => number, - _changedWidgets?: any, - $options: any, - $wrapMethod?: any, - $enableVarChar?: any, - $wrap?: any, - $navigateWithinSoftTabs?: boolean, - - getSelectionMarkers(): any[], - - $selectionMarkers?: any[], - gutterRenderer?: any, - $firstLineNumber?: number, - $emacsMark?: any, - selectionMarkerCount?: number, - multiSelect?: any, - $occurHighlight?: any, - $occur?: Ace.Occur, - $occurMatchingLines?: any, - $useEmacsStyleLineStart?: boolean, - $selectLongWords?: boolean, - } - -} - -declare module "./src/edit_session/fold" { - export interface Fold { - collapseChildren?: number; - } -} - -// @ts-expect-error -declare module "./src/placeholder" { - export interface PlaceHolder extends Ace.EventEmitter { - } +export class InlineAutocomplete { + constructor(); + getInlineRenderer(): Ace.AceInline; + getInlineTooltip(): CommandBarTooltip; + getCompletionProvider(): Ace.CompletionProvider; + show(editor: Ace.Editor): void; + isOpen(): boolean; + detach(): void; + destroy(): void; + goTo(action: InlineAutocompleteAction): void; + tooltipEnabled: boolean; + commands: Record + getIndex(): number; + setIndex(value: number): void; + getLength(): number; + getData(index?: number): Ace.Completion | undefined; + updateCompletions(options: Ace.CompletionOptions): void; } -declare module "./src/scrollbar" { - export interface VScrollBar extends Ace.EventEmitter { - } - - export interface HScrollBar extends Ace.EventEmitter { - } -} - -declare module "./src/scrollbar_custom" { - export interface VScrollBar extends Ace.EventEmitter { - } - - export interface HScrollBar extends Ace.EventEmitter { - } -} - -declare module "./src/line_widgets" { - export interface LineWidgets { - lineWidgets: Ace.LineWidget[]; - editor: Ace.Editor; - } -} - -declare module "./src/selection" { - export interface Selection extends Ace.EventEmitter, Ace.MultiSelectProperties { - } - -} - -declare module "./src/range" { - export interface Range { - id?: number; - cursor?: Ace.Point; - isBackwards?: boolean; - } -} - -declare module "./src/virtual_renderer" { - export interface VirtualRenderer extends Ace.EventEmitter, Ace.OptionsProvider { - $customScrollbar?: boolean, - $extraHeight?: number, - $showGutter?: boolean, - $showPrintMargin?: boolean, - $printMarginColumn?: number, - $animatedScroll?: boolean, - $isMousePressed?: boolean, - textarea?: HTMLTextAreaElement, - $hScrollBarAlwaysVisible?: boolean, - $vScrollBarAlwaysVisible?: boolean - $maxLines?: number, - $scrollPastEnd?: number, - enableKeyboardAccessibility?: boolean, - keyboardFocusClassName?: string, - $highlightGutterLine?: boolean, - $minLines?: number, - $maxPixelHeight?: number, - $gutterWidth?: number, - showInvisibles?: boolean, - $hasCssTransforms?: boolean, - $blockCursor?: boolean, - $useTextareaForIME?: boolean, - theme?: any, - $theme?: any, - destroyed?: boolean, - session: Ace.EditSession, - } - -} - -declare module "./src/snippets" { - export interface SnippetManager extends Ace.EventEmitter { - } -} - -declare module "./src/ext/command_bar" { - export interface CommandBarTooltip extends Ace.EventEmitter { - $shouldHideMoreOptions?: boolean, - } -} - -declare module "./src/commands/command_manager" { - export interface CommandManager extends Ace.EventEmitter { - $checkCommandState?: boolean - } -} - -declare module "./src/autocomplete/popup" { - - export interface AcePopup extends Ace.AcePopupWithEditor { - setSelectOnHover: (val: boolean) => void, - setRow: (line: number) => void, - getRow: () => number, - getHoveredRow: () => number, - filterText: string, - isOpen: boolean, - isTopdown: boolean, - autoSelect: boolean, - data: Ace.Completion[], - setData: (data: Ace.Completion[], filterText: string) => void, - getData: (row: number) => Ace.Completion, - hide: () => void, - anchor: "top" | "bottom", - anchorPosition: Ace.Point, - tryShow: (pos: any, lineHeight: number, anchor: "top" | "bottom", forceShow?: boolean) => boolean, - $borderSize: number, - show: (pos: any, lineHeight: number, topdownOnly?: boolean) => void, - goTo: (where: Ace.AcePopupNavigation) => void, - getTextLeftOffset: () => number, - $imageSize: number, - anchorPos: any, - isMouseOver?: boolean - } -} - -declare module "./src/layer/cursor" { - export interface Cursor { - timeoutId?: number; - } -} - -declare module "./src/layer/gutter" { - export interface Gutter extends Ace.EventEmitter { - $useSvgGutterIcons?: boolean, - $showFoldedAnnotations?: boolean, - } -} - -declare module "./src/layer/text" { - export interface Text extends Ace.EventEmitter { - } -} - -declare module "./src/lib/app_config" { - export interface AppConfig extends Ace.EventEmitter { - } -} - -declare module "./src/mouse/mouse_event" { - export interface MouseEvent { - time?: number; - } -} - -declare module "./src/mouse/mouse_handler" { - - export interface MouseHandler { - $tooltipFollowsMouse?: boolean, - cancelDrag?: boolean - //from DefaultHandlers - $clickSelection?: Ace.Range, - mousedownEvent?: Ace.MouseEvent, - startSelect?: (pos?: Ace.Point, waitForClickSelection?: boolean) => void, - select?: () => void - $lastScroll?: { t: number, vx: number, vy: number, allowed: number } - selectEnd?: () => void - } -} - -// @ts-expect-error -declare module "./src/ext/options" { - export interface OptionPanel extends Ace.EventEmitter { - } -} - -declare module "./src/layer/font_metrics" { - export interface FontMetrics extends Ace.EventEmitter { - } -} - -declare module "./src/tooltip" { - export interface HoverTooltip { - row: number; - } -} - -declare module "./src/mouse/default_gutter_handler" { - export interface GutterHandler { - } +export class CommandBarTooltip { + constructor(parentElement: HTMLElement); + registerCommand(id: string, command: TooltipCommand): void; + attach(editor: Ace.Editor): void; + updatePosition(): void; + update(): void; + isShown(): boolean; + getAlwaysShow(): boolean; + setAlwaysShow(alwaysShow: boolean): void; + detach(): void; + destroy(): void; } diff --git a/src/ace.js b/src/ace.js index 47ecb6a841d..21f67f98ea7 100644 --- a/src/ace.js +++ b/src/ace.js @@ -73,7 +73,7 @@ exports.edit = function(el, options) { /** * Creates a new [[EditSession]], and returns the associated [[Document]]. * @param {import('./document').Document | String} text {:textParam} - * @param {import("../").Ace.SyntaxMode} [mode] {:modeParam} + * @param {import("../ace-internal").Ace.SyntaxMode} [mode] {:modeParam} * @returns {EditSession} **/ exports.createEditSession = function(text, mode) { diff --git a/src/anchor.js b/src/anchor.js index 7e1dd89f521..b5d112c9a6d 100644 --- a/src/anchor.js +++ b/src/anchor.js @@ -13,7 +13,7 @@ class Anchor { * Creates a new `Anchor` and associates it with a document. * * @param {Document} doc The document to associate with the anchor - * @param {Number|import("../").Ace.Point} row The starting row position + * @param {Number|import("../ace-internal").Ace.Point} row The starting row position * @param {Number} [column] The starting column position **/ constructor(doc, row, column) { @@ -28,7 +28,7 @@ class Anchor { /** * Returns an object identifying the `row` and `column` position of the current anchor. - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} **/ getPosition() { return this.$clipPositionToDocument(this.row, this.column); @@ -45,7 +45,7 @@ class Anchor { /** * Internal function called when `"change"` event fired. - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ onChange(delta) { if (delta.start.row == delta.end.row && delta.start.row != this.row) @@ -114,7 +114,7 @@ class Anchor { * Clips the anchor position to the specified row and column. * @param {Number} row The row index to clip the anchor to * @param {Number} column The column index to clip the anchor to - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} * **/ $clipPositionToDocument(row, column) { diff --git a/src/apply_delta.js b/src/apply_delta.js index d5c7b6a2218..5d2fffb1925 100644 --- a/src/apply_delta.js +++ b/src/apply_delta.js @@ -43,7 +43,7 @@ function validateDelta(docLines, delta) { /** * Applies a delta to a document. * @param {string[]} docLines - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta * @param [doNotValidate] */ exports.applyDelta = function(docLines, delta, doNotValidate) { diff --git a/src/autocomplete.js b/src/autocomplete.js index 4bf08969c47..87b3b45cb75 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -24,7 +24,7 @@ var event = require("./lib/event"); * @property {string} [docText] - a plain text that would be displayed as an additional popup. If `docHTML` exists, * it would be used instead of `docText`. * @property {string} [completerId] - the identifier of the completer - * @property {import("../").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental) + * @property {import("../ace-internal").Ace.IRange} [range] - An object specifying the range of text to be replaced with the new completion value (experimental) * @property {string} [command] - A command to be executed after the completion is inserted (experimental) * @property {string} [snippet] - a text snippet that would be inserted when the completion is selected * @property {string} [value] - The text that would be inserted when selecting this completion. @@ -410,7 +410,7 @@ class Autocomplete { /** * This is the entry point for the autocompletion class, triggers the actions which collect and display suggestions * @param {Editor} editor - * @param {import("../").Ace.CompletionOptions} options + * @param {import("../ace-internal").Ace.CompletionOptions} options */ showPopup(editor, options) { if (this.editor) @@ -450,7 +450,7 @@ class Autocomplete { /** * @param {boolean} keepPopupPosition - * @param {import("../").Ace.CompletionOptions} options + * @param {import("../ace-internal").Ace.CompletionOptions} options */ updateCompletions(keepPopupPosition, options) { if (keepPopupPosition && this.base && this.completions) { @@ -731,7 +731,7 @@ class CompletionProvider { /** - * @param {{pos: import("../").Ace.Position, prefix: string}} initialPosition + * @param {{pos: import("../ace-internal").Ace.Position, prefix: string}} initialPosition */ constructor(initialPosition) { this.initialPosition = initialPosition; @@ -741,7 +741,7 @@ class CompletionProvider { /** * @param {Editor} editor * @param {number} index - * @param {import("../").Ace.CompletionProviderOptions} [options] + * @param {import("../ace-internal").Ace.CompletionProviderOptions} [options] * @returns {boolean} */ insertByIndex(editor, index, options) { @@ -754,7 +754,7 @@ class CompletionProvider { /** * @param {Editor} editor * @param {Completion} data - * @param {import("../").Ace.CompletionProviderOptions} [options] + * @param {import("../ace-internal").Ace.CompletionProviderOptions} [options] * @returns {boolean} */ insertMatch(editor, data, options) { @@ -818,7 +818,7 @@ class CompletionProvider { /** * @param {Editor} editor - * @param {import("../").Ace.CompletionCallbackFunction} callback + * @param {import("../ace-internal").Ace.CompletionCallbackFunction} callback */ gatherCompletions(editor, callback) { var session = editor.getSession(); @@ -853,7 +853,7 @@ class CompletionProvider { * This is the entry point to the class, it gathers, then provides the completions asynchronously via callback. * The callback function may be called multiple times, the last invokation is marked with a `finished` flag * @param {Editor} editor - * @param {import("../").Ace.CompletionProviderOptions} options + * @param {import("../ace-internal").Ace.CompletionProviderOptions} options * @param {(err: Error | undefined, completions: FilteredList | [], finished: boolean) => void} callback */ provideCompletions(editor, options, callback) { diff --git a/src/autocomplete/inline.js b/src/autocomplete/inline.js index 715680b0909..67b02d0f838 100644 --- a/src/autocomplete/inline.js +++ b/src/autocomplete/inline.js @@ -19,7 +19,7 @@ class AceInline { /** * Renders the completion as ghost text to the current cursor position * @param {Editor} editor - * @param {import("../../").Ace.Completion} completion + * @param {import("../../ace-internal").Ace.Completion} completion * @param {string} prefix * @returns {boolean} True if the completion could be rendered to the editor, false otherwise */ diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 948f28171a0..9bb417d01e9 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -183,7 +183,7 @@ class AcePopup { var bgTokenizer = popup.session.bgTokenizer; bgTokenizer.$tokenizeRow = function (row) { - /**@type {import("../../").Ace.Completion &{name?, className?, matchMask?, message?}}*/ + /**@type {import("../../ace-internal").Ace.Completion &{name?, className?, matchMask?, message?}}*/ var data = popup.data[row]; var tokens = []; if (!data) return tokens; diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 190191d63a8..016b344187f 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -136,7 +136,7 @@ class BackgroundTokenizer { } /** - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ $updateOnChange(delta) { var startRow = delta.start.row; @@ -171,7 +171,7 @@ class BackgroundTokenizer { /** * Gives list of [[Token]]'s of the row. (tokens are cached) * @param {Number} row The row to get tokens at - * @returns {import("../").Ace.Token[]} + * @returns {import("../ace-internal").Ace.Token[]} **/ getTokens(row) { return this.lines[row] || this.$tokenizeRow(row); diff --git a/src/commands/command_manager.js b/src/commands/command_manager.js index 0f9f8ef4899..add1f086220 100644 --- a/src/commands/command_manager.js +++ b/src/commands/command_manager.js @@ -26,7 +26,7 @@ class CommandManager extends MultiHashHandler{ /** * - * @param {string | string[] | import("../../").Ace.Command} command + * @param {string | string[] | import("../../ace-internal").Ace.Command} command * @param {Editor} editor * @param {any} args * @returns {boolean} diff --git a/src/commands/default_commands.js b/src/commands/default_commands.js index 9ea72e9c72d..1d1b7346b11 100644 --- a/src/commands/default_commands.js +++ b/src/commands/default_commands.js @@ -12,7 +12,7 @@ function bindKey(win, mac) { multiSelectAction: "forEach"|"forEachLine"|function|undefined, scrollIntoView: true|"cursor"|"center"|"selectionPart" */ -/**@type {import("../../").Ace.Command[]} */ +/**@type {import("../../ace-internal").Ace.Command[]} */ exports.commands = [{ name: "showSettingsMenu", description: "Show settings menu", diff --git a/src/commands/multi_select_commands.js b/src/commands/multi_select_commands.js index 928803f418e..3635c8bc119 100644 --- a/src/commands/multi_select_commands.js +++ b/src/commands/multi_select_commands.js @@ -1,7 +1,7 @@ /** * commands to enter multiselect mode - * @type {import("../../").Ace.Command[]} + * @type {import("../../ace-internal").Ace.Command[]} */ exports.defaultCommands = [{ name: "addCursorAbove", @@ -92,7 +92,7 @@ exports.defaultCommands = [{ /** * commands active only in multiselect mode - * @type {import("../../").Ace.Command[]} + * @type {import("../../ace-internal").Ace.Command[]} */ exports.multiSelectCommands = [{ name: "singleSelection", diff --git a/src/document.js b/src/document.js index f1f91efc350..56571e3d45a 100644 --- a/src/document.js +++ b/src/document.js @@ -90,7 +90,7 @@ class Document { /** * [Sets the new line mode.]{: #Document.setNewLineMode.desc} - * @param {import("../").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} + * @param {import("../ace-internal").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} **/ setNewLineMode(newLineMode) { @@ -103,7 +103,7 @@ class Document { /** * [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode} - * @returns {import("../").Ace.NewLineMode} + * @returns {import("../ace-internal").Ace.NewLineMode} **/ getNewLineMode() { return this.$newLineMode; @@ -155,7 +155,7 @@ class Document { /** * Returns all the text within `range` as a single string. - * @param {import("../").Ace.IRange} range The range to work with. + * @param {import("../ace-internal").Ace.IRange} range The range to work with. * * @returns {String} **/ @@ -165,7 +165,7 @@ class Document { /** * Returns all the text within `range` as an array of lines. - * @param {import("../").Ace.IRange} range The range to work with. + * @param {import("../ace-internal").Ace.IRange} range The range to work with. * * @returns {string[]} **/ @@ -212,7 +212,7 @@ class Document { /** * @param position - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} * @deprecated */ @@ -223,9 +223,9 @@ class Document { /** * Inserts a block of `text` at the indicated `position`. - * @param {import("../").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` + * @param {import("../ace-internal").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text to insert - * @returns {import("../").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @returns {import("../ace-internal").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. **/ insert(position, text) { @@ -243,9 +243,9 @@ class Document { * 1. This does NOT handle newline characters (single-line text only). * 2. This is faster than the `insert` method for single-line text insertions. * - * @param {import("../").Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` + * @param {import("../ace-internal").Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text - * @returns {import("../").Ace.Point} Returns an object containing the final row and column, like this: + * @returns {import("../ace-internal").Ace.Point} Returns an object containing the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -269,7 +269,7 @@ class Document { * * @param {number} row * @param {number} column - * @return {import("../").Ace.Point} + * @return {import("../ace-internal").Ace.Point} */ clippedPos(row, column) { var length = this.getLength(); @@ -289,8 +289,8 @@ class Document { } /** - * @param {import("../").Ace.Point} pos - * @return {import("../").Ace.Point} + * @param {import("../ace-internal").Ace.Point} pos + * @return {import("../ace-internal").Ace.Point} */ clonePos(pos) { return {row: pos.row, column: pos.column}; @@ -299,15 +299,15 @@ class Document { /** * @param {number} row * @param {number} column - * @return {import("../").Ace.Point} + * @return {import("../ace-internal").Ace.Point} */ pos(row, column) { return {row: row, column: column}; } /** - * @param {import("../").Ace.Point} position - * @return {import("../").Ace.Point} + * @param {import("../ace-internal").Ace.Point} position + * @return {import("../ace-internal").Ace.Point} * @private */ $clipPosition(position) { @@ -352,9 +352,9 @@ class Document { /** * Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event. - * @param {import("../").Ace.Position} position + * @param {import("../ace-internal").Ace.Position} position * @param {string[]} lines An array of strings - * @returns {import("../").Ace.Point} Contains the final row and column, like this: + * @returns {import("../ace-internal").Ace.Point} Contains the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -383,8 +383,8 @@ class Document { /** * Removes the `range` from the document. - * @param {import("../").Ace.IRange} range A specified Range to remove - * @returns {import("../").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @param {import("../ace-internal").Ace.IRange} range A specified Range to remove + * @returns {import("../ace-internal").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -404,7 +404,7 @@ class Document { * @param {Number} row The row to remove from * @param {Number} startColumn The column to start removing at * @param {Number} endColumn The column to stop removing at - * @returns {import("../").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. + * @returns {import("../ace-internal").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. **/ removeInLine(row, startColumn, endColumn) { @@ -476,9 +476,9 @@ class Document { /** * Replaces a range in the document with the new `text`. - * @param {Range | import("../").Ace.IRange} range A specified Range to replace + * @param {Range | import("../ace-internal").Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {import("../").Ace.Point} Returns an object containing the final row and column, like this: + * @returns {import("../ace-internal").Ace.Point} Returns an object containing the final row and column, like this: * {row: endRow, column: 0} * If the text and range are empty, this function returns an object containing the current `range.start` value. * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value. @@ -510,7 +510,7 @@ class Document { /** * Applies all changes in `deltas` to the document. - * @param {import("../").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @param {import("../ace-internal").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) **/ applyDeltas(deltas) { @@ -521,7 +521,7 @@ class Document { /** * Reverts all changes in `deltas` from the document. - * @param {import("../").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) + * @param {import("../ace-internal").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) **/ revertDeltas(deltas) { @@ -532,7 +532,7 @@ class Document { /** * Applies `delta` to the document. - * @param {import("../").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {import("../ace-internal").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) * @param {boolean} [doNotValidate] **/ @@ -554,7 +554,7 @@ class Document { } /** - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ $safeApplyDelta(delta) { @@ -570,7 +570,7 @@ class Document { /** * - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta * @param {number} MAX */ @@ -608,7 +608,7 @@ class Document { /** * Reverts `delta` from the document. - * @param {import("../").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {import("../ace-internal").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) **/ revertDelta(delta) { @@ -634,7 +634,7 @@ class Document { * * @param {Number} index An index to convert * @param {Number} [startRow=0] The row from which to start the conversion - * @returns {import("../").Ace.Point} A `{row, column}` object of the `index` position + * @returns {import("../ace-internal").Ace.Point} A `{row, column}` object of the `index` position */ indexToPosition(index, startRow) { var lines = this.$lines || this.getAllLines(); @@ -659,7 +659,7 @@ class Document { * * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second. * - * @param {import("../").Ace.Point} pos The `{row, column}` to convert + * @param {import("../ace-internal").Ace.Point} pos The `{row, column}` to convert * @param {Number} [startRow=0] The row from which to start the conversion * @returns {Number} The index position in the document */ diff --git a/src/edit_session.js b/src/edit_session.js index 68c86b6b9c9..db0d7f65874 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -3,7 +3,7 @@ * @typedef {import("./edit_session/fold_line").FoldLine} FoldLine */ /** - * @typedef {import("../").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.Point} Point */ /** * @typedef {import("./layer/font_metrics").FontMetrics} FontMetrics @@ -24,7 +24,7 @@ var UndoManager = require("./undomanager").UndoManager; /** * @typedef TextMode - * @type {import("../").Ace.SyntaxMode} + * @type {import("../ace-internal").Ace.SyntaxMode} */ /** @@ -36,7 +36,7 @@ class EditSession { /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. * @param {Document | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} - * @param {import("../").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} + * @param {import("../ace-internal").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} **/ constructor(text, mode) { /**@type {Document}*/this.doc; @@ -160,7 +160,7 @@ class EditSession { /** * - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ onChange(delta) { this.$modified = true; @@ -282,7 +282,7 @@ class EditSession { /** * Starts tokenizing at the row indicated. Returns a list of objects of the tokenized rows. * @param {Number} row The row to start at - * @returns {import("../").Ace.Token[]} + * @returns {import("../ace-internal").Ace.Token[]} **/ getTokens(row) { return this.bgTokenizer.getTokens(row); @@ -292,7 +292,7 @@ class EditSession { * Returns an object indicating the token at the current row. The object has two properties: `index` and `start`. * @param {Number} row The row number to retrieve from * @param {Number} column The column number to retrieve from - * @returns {import("../").Ace.Token} + * @returns {import("../ace-internal").Ace.Token} * **/ getTokenAt(row, column) { @@ -526,7 +526,7 @@ class EditSession { * Adds a new marker to the given `Range`. If `inFront` is `true`, a front marker is defined, and the `'changeFrontMarker'` event fires; otherwise, the `'changeBackMarker'` event fires. * @param {Range} range Define the range of the marker * @param {String} clazz Set the CSS class for the marker - * @param {import("../").Ace.MarkerRenderer | "fullLine" | "screenLine" | "text" | "line"} [type] Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. + * @param {import("../ace-internal").Ace.MarkerRenderer | "fullLine" | "screenLine" | "text" | "line"} [type] Identify the renderer type of the marker. If string provided, corresponding built-in renderer is used. Supported string types are "fullLine", "screenLine", "text" or "line". If a Function is provided, that Function is used as renderer. * @param {Boolean} [inFront] Set to `true` to establish a front marker * * @return {Number} The new marker id @@ -556,10 +556,10 @@ class EditSession { /** * Adds a dynamic marker to the session. - * @param {import("../").Ace.MarkerLike} marker object with update method + * @param {import("../ace-internal").Ace.MarkerLike} marker object with update method * @param {Boolean} [inFront] Set to `true` to establish a front marker * - * @return {import("../").Ace.MarkerLike} The added marker + * @return {import("../ace-internal").Ace.MarkerLike} The added marker **/ addDynamicMarker(marker, inFront) { if (!marker.update) @@ -597,7 +597,7 @@ class EditSession { * Returns an object containing all of the markers, either front or back. * @param {Boolean} [inFront] If `true`, indicates you only want front markers; `false` indicates only back markers * - * @returns {{[id: number]: import("../").Ace.MarkerLike}} + * @returns {{[id: number]: import("../ace-internal").Ace.MarkerLike}} **/ getMarkers(inFront) { return inFront ? this.$frontMarkers : this.$backMarkers; @@ -647,7 +647,7 @@ class EditSession { */ /** * Sets annotations for the `EditSession`. This functions emits the `'changeAnnotation'` event. - * @param {import("../").Ace.Annotation[]} annotations A list of annotations + * @param {import("../ace-internal").Ace.Annotation[]} annotations A list of annotations **/ setAnnotations(annotations) { this.$annotations = annotations; @@ -656,7 +656,7 @@ class EditSession { /** * Returns the annotations for the `EditSession`. - * @returns {import("../").Ace.Annotation[]} + * @returns {import("../ace-internal").Ace.Annotation[]} **/ getAnnotations() { return this.$annotations || []; @@ -743,7 +743,7 @@ class EditSession { /** * {:Document.setNewLineMode.desc} - * @param {import("../").Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} + * @param {import("../ace-internal").Ace.NewLineMode} newLineMode {:Document.setNewLineMode.param} * * * @related Document.setNewLineMode @@ -755,7 +755,7 @@ class EditSession { /** * * Returns the current new line mode. - * @returns {import("../").Ace.NewLineMode} + * @returns {import("../ace-internal").Ace.NewLineMode} * @related Document.getNewLineMode **/ getNewLineMode() { @@ -784,7 +784,7 @@ class EditSession { /** * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. - * @param {import("../").Ace.SyntaxMode | string} mode Set a new text mode + * @param {import("../ace-internal").Ace.SyntaxMode | string} mode Set a new text mode * @param {() => void} [cb] optional callback **/ setMode(mode, cb) { @@ -1033,7 +1033,7 @@ class EditSession { /** * {:Document.getTextRange.desc} - * @param {import("../").Ace.IRange} [range] The range to work with + * @param {import("../ace-internal").Ace.IRange} [range] The range to work with * * @returns {String} **/ @@ -1053,7 +1053,7 @@ class EditSession { /** * Removes the `range` from the document. - * @param {import("../").Ace.IRange} range A specified Range to remove + * @param {import("../ace-internal").Ace.IRange} range A specified Range to remove * @returns {Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -1075,7 +1075,7 @@ class EditSession { /** * Reverts previous changes to your document. - * @param {import("../").Ace.Delta[]} deltas An array of previous changes + * @param {import("../ace-internal").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] [If `true`, doesn't select the range of where the change occured]{: #dontSelect} **/ undoChanges(deltas, dontSelect) { @@ -1104,7 +1104,7 @@ class EditSession { /** * Re-implements a previously undone change to your document. - * @param {import("../").Ace.Delta[]} deltas An array of previous changes + * @param {import("../ace-internal").Ace.Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] {:dontSelect} **/ redoChanges(deltas, dontSelect) { @@ -1141,7 +1141,7 @@ class EditSession { /** * - * @param {import("../").Ace.Delta[]} deltas + * @param {import("../ace-internal").Ace.Delta[]} deltas * @param {boolean} [isUndo] * @return {Range} */ @@ -1186,7 +1186,7 @@ class EditSession { /** * Replaces a range in the document with the new `text`. * - * @param {import("../").Ace.IRange} range A specified Range to replace + * @param {import("../ace-internal").Ace.IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement * @returns {Point} An object containing the final row and column, like this: * ``` @@ -1564,7 +1564,7 @@ class EditSession { /** * - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ $updateInternalDataOnChange(delta) { var useWrapMode = this.$useWrapMode; @@ -2424,7 +2424,7 @@ EditSession.prototype.$wrapLimitRange = { }; /** * - * @type {null | import("../").Ace.LineWidget[]} + * @type {null | import("../ace-internal").Ace.LineWidget[]} */ EditSession.prototype.lineWidgets = null; EditSession.prototype.isFullWidth = isFullWidth; @@ -2486,6 +2486,7 @@ config.defineOptions(EditSession.prototype, "session", { wrap: { /** * @param {string | boolean | number} value + * @this {EditSession} */ set: function(value) { if (!value || value == "off") @@ -2523,6 +2524,7 @@ config.defineOptions(EditSession.prototype, "session", { wrapMethod: { /** * @param {"code"|"text"|"auto"|boolean} val + * @this{EditSession} */ set: function(val) { val = val == "auto" @@ -2539,6 +2541,9 @@ config.defineOptions(EditSession.prototype, "session", { initialValue: "auto" }, indentedSoftWrap: { + /** + * @this{EditSession} + */ set: function() { if (this.$useWrapMode) { this.$useWrapMode = false; @@ -2554,6 +2559,7 @@ config.defineOptions(EditSession.prototype, "session", { useWorker: { /** * @param {boolean} useWorker + * @this{EditSession} */ set: function(useWorker) { this.$useWorker = useWorker; @@ -2568,6 +2574,7 @@ config.defineOptions(EditSession.prototype, "session", { tabSize: { /** * @param tabSize + * @this{EditSession} */ set: function(tabSize) { tabSize = parseInt(tabSize); diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index 8fff6b24b56..ebe0c0deb76 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -9,7 +9,7 @@ function BracketMatch() { /** * - * @param {import("../../").Ace.Point} position + * @param {import("../../ace-internal").Ace.Point} position * @param {string} [chr] * @this {EditSession} */ @@ -30,7 +30,7 @@ function BracketMatch() { }; /** - * @param {import("../../").Ace.Point} pos + * @param {import("../../ace-internal").Ace.Point} pos * @return {null|Range} * @this {EditSession} */ @@ -80,7 +80,7 @@ function BracketMatch() { * * two Ranges if there is opening and closing brackets; * * one Range if there is only one bracket * - * @param {import("../../").Ace.Point} pos + * @param {import("../../ace-internal").Ace.Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} * @this {EditSession} @@ -126,9 +126,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {import("../../").Ace.Point} position + * @param {import("../../ace-internal").Ace.Point} position * @param {RegExp} [typeRe] - * @return {import("../../").Ace.Point|null} + * @return {import("../../ace-internal").Ace.Point|null} * @this {EditSession} */ this.$findOpeningBracket = function(bracket, position, typeRe) { @@ -192,9 +192,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {import("../../").Ace.Point} position + * @param {import("../../ace-internal").Ace.Point} position * @param {RegExp} [typeRe] - * @return {import("../../").Ace.Point|null} + * @return {import("../../ace-internal").Ace.Point|null} * @this {EditSession} */ this.$findClosingBracket = function(bracket, position, typeRe) { @@ -257,7 +257,7 @@ function BracketMatch() { /** * Returns [[Range]]'s for matching tags and tag names, if there are any - * @param {import("../../").Ace.Point} pos + * @param {import("../../ace-internal").Ace.Point} pos * @returns {{closeTag: Range, closeTagName: Range, openTag: Range, openTagName: Range} | undefined} * @this {EditSession} */ diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index 002c76f69cf..bcb3616593e 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -98,7 +98,7 @@ class Fold extends RangeList { } /** - * @param {import("../../").Ace.IRange} range + * @param {import("../../ace-internal").Ace.IRange} range */ restoreRange(range) { return restoreRange(range, this.start); @@ -107,8 +107,8 @@ class Fold extends RangeList { } /** - * @param {import("../../").Ace.Point} point - * @param {import("../../").Ace.Point} anchor + * @param {import("../../ace-internal").Ace.Point} point + * @param {import("../../ace-internal").Ace.Point} anchor */ function consumePoint(point, anchor) { point.row -= anchor.row; @@ -116,16 +116,16 @@ function consumePoint(point, anchor) { point.column -= anchor.column; } /** - * @param {import("../../").Ace.IRange} range - * @param {import("../../").Ace.Point} anchor + * @param {import("../../ace-internal").Ace.IRange} range + * @param {import("../../ace-internal").Ace.Point} anchor */ function consumeRange(range, anchor) { consumePoint(range.start, anchor); consumePoint(range.end, anchor); } /** - * @param {import("../../").Ace.Point} point - * @param {import("../../").Ace.Point} anchor + * @param {import("../../ace-internal").Ace.Point} point + * @param {import("../../ace-internal").Ace.Point} anchor */ function restorePoint(point, anchor) { if (point.row == 0) @@ -133,8 +133,8 @@ function restorePoint(point, anchor) { point.row += anchor.row; } /** - * @param {import("../../").Ace.IRange} range - * @param {import("../../").Ace.Point} anchor + * @param {import("../../ace-internal").Ace.IRange} range + * @param {import("../../ace-internal").Ace.Point} anchor */ function restoreRange(range, anchor) { restorePoint(range.start, anchor); diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index ddcd6b788d5..f105835e6bc 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -244,7 +244,7 @@ class FoldLine { /** * @param {number} idx - * @return {import("../../").Ace.Point} + * @return {import("../../ace-internal").Ace.Point} */ idxToPosition(idx) { var lastFoldEndColumn = 0; diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 0ab6fd4d233..627932d9f1c 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -8,7 +8,7 @@ var TokenIterator = require("../token_iterator").TokenIterator; var MouseEvent = require("../mouse/mouse_event").MouseEvent; /** - * @typedef {import("../edit_session").EditSession & import("../../").Ace.Folding} IFolding + * @typedef {import("../edit_session").EditSession & import("../../ace-internal").Ace.Folding} IFolding */ /** @@ -46,7 +46,7 @@ function Folding() { /** * Returns all folds in the given range. Note, that this will return folds - * @param {Range| import("../../").Ace.Delta} range + * @param {Range| import("../../ace-internal").Ace.Delta} range * @returns {Fold[]} **/ this.getFoldsInRange = function(range) { @@ -476,7 +476,7 @@ function Folding() { /** * - * @param {number|null|import("../../").Ace.Point|Range|Range[]} [location] + * @param {number|null|import("../../ace-internal").Ace.Point|Range|Range[]} [location] * @param {boolean} [expandInner] * @return {Fold[]| undefined} */ @@ -843,7 +843,7 @@ function Folding() { }; /** - * @param {import("../../").Ace.FoldMode} foldMode + * @param {import("../../ace-internal").Ace.FoldMode} foldMode */ this.$setFolding = function(foldMode) { if (this.$foldMode == foldMode) @@ -1005,7 +1005,7 @@ function Folding() { }; /** - * @param {import("../../").Ace.Delta} delta + * @param {import("../../ace-internal").Ace.Delta} delta */ this.updateFoldWidgets = function(delta) { var firstRow = delta.start.row; diff --git a/src/editor.js b/src/editor.js index 18aecbc0f0f..3f8368aab82 100644 --- a/src/editor.js +++ b/src/editor.js @@ -44,7 +44,7 @@ class Editor { * * @param {VirtualRenderer} renderer Associated `VirtualRenderer` that draws everything * @param {EditSession} [session] The `EditSession` to refer to - * @param {Partial} [options] The default options + * @param {Partial} [options] The default options **/ constructor(renderer, session, options) { /**@type{EditSession}*/this.session; @@ -233,7 +233,7 @@ class Editor { /** * Sets a new key handler, such as "vim" or "windows". - * @param {String | import("../").Ace.KeyboardHandler | null} keyboardHandler The new key handler + * @param {String | import("../ace-internal").Ace.KeyboardHandler | null} keyboardHandler The new key handler * @param {() => void} [cb] **/ setKeyboardHandler(keyboardHandler, cb) { @@ -439,7 +439,7 @@ class Editor { /** * {:VirtualRenderer.setTheme} - * @param {string | import("../").Ace.Theme} theme The path to a theme + * @param {string | import("../ace-internal").Ace.Theme} theme The path to a theme * @param {() => void} [cb] optional callback called when theme is loaded **/ setTheme(theme, cb) { @@ -613,7 +613,7 @@ class Editor { /** * Emitted whenever the document is changed. - * @param {import("../").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes + * @param {import("../ace-internal").Ace.Delta} delta Contains a single property, `data`, which has the delta of changes **/ onDocumentChange(delta) { // Rerender and emit "change" event. @@ -653,7 +653,7 @@ class Editor { */ $updateHighlightActiveLine() { var session = this.getSession(); - /**@type {import("../").Ace.Point|false}*/ + /**@type {import("../ace-internal").Ace.Point|false}*/ var highlight; if (this.$highlightActiveLine) { if (this.$selectionStyle != "line" || !this.selection.isMultiLine()) @@ -1133,7 +1133,7 @@ class Editor { /** * Returns the current selection style. - * @returns {import("../").Ace.EditorOptions["selectionStyle"]} + * @returns {import("../ace-internal").Ace.EditorOptions["selectionStyle"]} **/ getSelectionStyle() { return this.getOption("selectionStyle"); @@ -1462,7 +1462,7 @@ class Editor { * inline in the editor such as, for example, code completions. * * @param {String} text Text to be inserted as "ghost" text - * @param {import("../").Ace.Point} [position] Position to insert text to + * @param {import("../ace-internal").Ace.Point} [position] Position to insert text to */ setGhostText(text, position) { if (!this.session.widgetManager) { @@ -1850,7 +1850,7 @@ class Editor { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} range The range of text you want moved within the document - * @param {import("../").Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {import("../ace-internal").Ace.Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * * @returns {Range} The new range where the text was moved to. @@ -2113,7 +2113,7 @@ class Editor { /** * Gets the current position of the cursor. - * @returns {import("../").Ace.Point} An object that looks something like this: + * @returns {import("../ace-internal").Ace.Point} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -2127,7 +2127,7 @@ class Editor { /** * Returns the screen position of the cursor. - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} * @related EditSession.documentToScreenPosition **/ getCursorPositionScreen() { @@ -2171,7 +2171,7 @@ class Editor { /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. - * @param {import("../").Ace.Point} pos An object with two properties, row and column + * @param {import("../ace-internal").Ace.Point} pos An object with two properties, row and column * @related Selection.moveCursorToPosition **/ moveCursorToPosition(pos) { @@ -2480,7 +2480,7 @@ class Editor { /** * Replaces the first occurrence of `options.needle` with the value in `replacement`. * @param {String} [replacement] The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replace(replacement, options) { @@ -2505,7 +2505,7 @@ class Editor { /** * Replaces all occurrences of `options.needle` with the value in `replacement`. * @param {String} [replacement] The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replaceAll(replacement, options) { @@ -2533,7 +2533,7 @@ class Editor { } /** - * @param {import("../").Ace.IRange} range + * @param {import("../ace-internal").Ace.IRange} range * @param {string} [replacement] */ $tryReplace(range, replacement) { @@ -2550,7 +2550,7 @@ class Editor { /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions - * @returns {Partial} + * @returns {Partial} **/ getLastSearchOptions() { return this.$search.getOptions(); @@ -2559,7 +2559,7 @@ class Editor { /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String|RegExp|Object} needle The text to search for (optional) - * @param {Partial} [options] An object defining various search properties + * @param {Partial} [options] An object defining various search properties * @param {Boolean} [animate] If `true` animate scrolling * @related Search.find **/ @@ -2604,7 +2604,7 @@ class Editor { /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find @@ -2615,7 +2615,7 @@ class Editor { /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index eb87570f6f5..8c60280b69d 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -52,7 +52,7 @@ var keyDisplayMap = { class CommandBarTooltip { /** * @param {HTMLElement} parentNode - * @param {Partial} [options] + * @param {Partial} [options] */ constructor(parentNode, options) { options = options || {}; @@ -90,7 +90,7 @@ class CommandBarTooltip { * toolbar, the remaining elements are added to the overflow menu. * * @param {string} id - * @param {import("../../").Ace.TooltipCommand} command + * @param {import("../../ace-internal").Ace.TooltipCommand} command */ registerCommand(id, command) { var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip; @@ -288,7 +288,7 @@ class CommandBarTooltip { /** * @param {string} id - * @param {import("../../").Ace.TooltipCommand} command + * @param {import("../../ace-internal").Ace.TooltipCommand} command * @param {boolean} forMainTooltip */ $createCommand(id, command, forMainTooltip) { diff --git a/src/ext/hardwrap.js b/src/ext/hardwrap.js index 5674ffbf975..cc545ac98be 100644 --- a/src/ext/hardwrap.js +++ b/src/ext/hardwrap.js @@ -4,7 +4,7 @@ var Range = require("../range").Range; /** * @param {import("../editor").Editor} editor - * @param {import("../../").Ace.HardWrapOptions} options + * @param {import("../../ace-internal").Ace.HardWrapOptions} options */ function hardWrap(editor, options) { var max = options.column || editor.getOption("printMarginColumn"); diff --git a/src/ext/inline_autocomplete.js b/src/ext/inline_autocomplete.js index 2ff98c1bd1d..67edac3c7fd 100644 --- a/src/ext/inline_autocomplete.js +++ b/src/ext/inline_autocomplete.js @@ -65,7 +65,7 @@ class InlineAutocomplete { /** * This function is the entry point to the class. This triggers the gathering of the autocompletion and displaying the results; - * @param {import("../../").Ace.CompletionOptions} options + * @param {import("../../ace-internal").Ace.CompletionOptions} options */ show(options) { this.activated = true; @@ -121,7 +121,7 @@ class InlineAutocomplete { } /** - * @param {import("../../").Ace.InlineAutocompleteAction} where + * @param {import("../../ace-internal").Ace.InlineAutocompleteAction} where */ goTo(where) { if (!this.completions || !this.completions.filtered) { @@ -153,7 +153,7 @@ class InlineAutocomplete { /** * @param {number} [index] - * @returns {import("../../").Ace.Completion | undefined} + * @returns {import("../../ace-internal").Ace.Completion | undefined} */ getData(index) { if (index == undefined || index === null) { @@ -223,7 +223,7 @@ class InlineAutocomplete { } /** - * @param {import("../../").Ace.CompletionOptions} [options] + * @param {import("../../ace-internal").Ace.CompletionOptions} [options] */ updateCompletions(options) { var prefix = ""; @@ -327,7 +327,7 @@ class InlineAutocomplete { /** * - * @type {{[key: string]: import("../../").Ace.Command}} + * @type {{[key: string]: import("../../ace-internal").Ace.Command}} */ InlineAutocomplete.prototype.commands = { "Previous": { @@ -388,6 +388,10 @@ var completers = [snippetCompleter, textCompleter, keyWordCompleter]; require("../config").defineOptions(Editor.prototype, "editor", { enableInlineAutocompletion: { + /** + * @this{Editor} + * @param val + */ set: function(val) { if (val) { if (!this.completers) diff --git a/src/ext/language_tools.js b/src/ext/language_tools.js index 3a857346bac..28ffe73d34e 100644 --- a/src/ext/language_tools.js +++ b/src/ext/language_tools.js @@ -7,7 +7,7 @@ var lang = require("../lib/lang"); var util = require("../autocomplete/util"); var textCompleter = require("../autocomplete/text_completer"); -/**@type {import("../../").Ace.Completer}*/ +/**@type {import("../../ace-internal").Ace.Completer}*/ var keyWordCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { if (session.$mode.completer) { @@ -32,7 +32,7 @@ var transformSnippetTooltip = function(str) { return record[p1]; }); }; -/**@type {import("../../").Ace.Completer} */ +/**@type {import("../../ace-internal").Ace.Completer} */ var snippetCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { var scopes = []; @@ -174,6 +174,10 @@ var showLiveAutocomplete = function(e) { var Editor = require("../editor").Editor; require("../config").defineOptions(Editor.prototype, "editor", { enableBasicAutocompletion: { + /** + * @param val + * @this{Editor} + */ set: function(val) { if (val) { if (!this.completers) @@ -191,6 +195,7 @@ require("../config").defineOptions(Editor.prototype, "editor", { enableLiveAutocompletion: { /** * @param {boolean} val + * @this {Editor} */ set: function(val) { if (val) { diff --git a/src/ext/rtl.js b/src/ext/rtl.js index 7a8cbf34246..7c8e1f60edb 100644 --- a/src/ext/rtl.js +++ b/src/ext/rtl.js @@ -93,7 +93,7 @@ function onCommandEmitted(commadEvent) { * Whenever the document is changed make sure that line break operatin * on right-to-left line (like pressing Enter or pasting multi-line text) * produces new right-to-left lines - * @param {import("../../").Ace.Delta} delta + * @param {import("../../ace-internal").Ace.Delta} delta * @param {Editor} editor */ function onChange(delta, editor) { diff --git a/src/ext/simple_tokenizer.js b/src/ext/simple_tokenizer.js index e1906e6f390..c5e88f64e6b 100644 --- a/src/ext/simple_tokenizer.js +++ b/src/ext/simple_tokenizer.js @@ -15,7 +15,7 @@ class SimpleTokenizer { /** * @param {number} row - * @returns {import("../../").Ace.Token[]} + * @returns {import("../../ace-internal").Ace.Token[]} */ getTokens(row) { const line = this._lines[row]; @@ -40,8 +40,8 @@ class SimpleTokenizer { * Result is a list of list of tokens, where each line from the provided content is a separate list of tokens. * * @param {string} content to tokenize - * @param {import("../../").Ace.HighlightRules} highlightRules defining the language grammar - * @returns {import("../../").Ace.TokenizeResult} tokenization result containing a list of token for each of the lines from content + * @param {import("../../ace-internal").Ace.HighlightRules} highlightRules defining the language grammar + * @returns {import("../../ace-internal").Ace.TokenizeResult} tokenization result containing a list of token for each of the lines from content */ function tokenize(content, highlightRules) { const tokenizer = new SimpleTokenizer(content, new Tokenizer(highlightRules.getRules())); diff --git a/src/ext/static_highlight.js b/src/ext/static_highlight.js index 982221661d6..427f626a8d4 100644 --- a/src/ext/static_highlight.js +++ b/src/ext/static_highlight.js @@ -131,7 +131,7 @@ var highlight = function(el, opts, callback) { * Transforms a given input code snippet into HTML using the given mode * * @param {string} input Code snippet - * @param {string|import("../../").Ace.SyntaxMode} mode String specifying the mode to load such as + * @param {string|import("../../ace-internal").Ace.SyntaxMode} mode String specifying the mode to load such as * `ace/mode/javascript` or, a mode loaded from `/ace/mode` * (use 'ServerSideHiglighter.getMode'). * @param {string} theme String specifying the theme to load such as @@ -186,7 +186,7 @@ highlight.render = function(input, mode, theme, lineStart, disableGutter, callba /** * Transforms a given input code snippet into HTML using the given mode * @param {string} input Code snippet - * @param {import("../../").Ace.SyntaxMode|string} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') + * @param {import("../../ace-internal").Ace.SyntaxMode|string} mode Mode loaded from /ace/mode (use 'ServerSideHiglighter.getMode') * @param {any} theme * @param {any} lineStart * @param {boolean} disableGutter diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index 0019e1bdb1c..edd8b2d6b0b 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -7,7 +7,7 @@ var KEY_MODS = keyUtil.KEY_MODS; class MultiHashHandler { /** - * @param {Record | import("../../").Ace.Command[]} [config] + * @param {Record | import("../../ace-internal").Ace.Command[]} [config] * @param {string} [platform] */ constructor(config, platform) { @@ -15,13 +15,13 @@ class MultiHashHandler { } /** - * @param {Record | import("../../").Ace.Command[]} config + * @param {Record | import("../../ace-internal").Ace.Command[]} config * @param {string} [platform] * @param {boolean} [$singleCommand] */ $init(config, platform, $singleCommand) { this.platform = platform || (useragent.isMac ? "mac" : "win"); - /**@type {Record}*/ + /**@type {Record}*/ this.commands = {}; this.commandKeyBinding = {}; this.addCommands(config); @@ -29,7 +29,7 @@ class MultiHashHandler { } /** - * @param {import("../../").Ace.Command} command + * @param {import("../../ace-internal").Ace.Command} command */ addCommand(command) { if (this.commands[command.name]) @@ -42,7 +42,7 @@ class MultiHashHandler { } /** - * @param {import("../../").Ace.Command | string} command + * @param {import("../../ace-internal").Ace.Command | string} command * @param {boolean} [keepCommand] */ removeCommand(command, keepCommand) { @@ -71,7 +71,7 @@ class MultiHashHandler { /** * @param {string | { win?: string; mac?: string; position?:number}} key - * @param {import("../../").Ace.CommandLike | string} command + * @param {import("../../ace-internal").Ace.CommandLike | string} command * @param {number} [position] */ bindKey(key, command, position) { @@ -138,7 +138,7 @@ class MultiHashHandler { } /** - * @param {Record | import("../../").Ace.Command[]} [commands] + * @param {Record | import("../../ace-internal").Ace.Command[]} [commands] */ addCommands(commands) { commands && Object.keys(commands).forEach(function(name) { @@ -163,7 +163,7 @@ class MultiHashHandler { } /** - * @param {Record} commands + * @param {Record} commands */ removeCommands(commands) { Object.keys(commands).forEach(function(name) { @@ -172,7 +172,7 @@ class MultiHashHandler { } /** - * @param {Record} keyList + * @param {Record} keyList */ bindKeys(keyList) { Object.keys(keyList).forEach(function(key) { @@ -218,7 +218,7 @@ class MultiHashHandler { /** * @param {number} hashId * @param {string} keyString - * @returns {import("../../").Ace.Command} + * @returns {import("../../ace-internal").Ace.Command} */ findKeyCommand(hashId, keyString) { var key = KEY_MODS[hashId] + keyString; @@ -276,7 +276,7 @@ function getPosition(command) { class HashHandler extends MultiHashHandler { /** - * @param {Record | import("../../").Ace.Command[]} [config] + * @param {Record | import("../../ace-internal").Ace.Command[]} [config] * @param {string} [platform] */ constructor(config, platform) { diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 1c9aa9ee20a..7ea0d2b7058 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -13,13 +13,13 @@ class KeyBinding { constructor(editor) { this.$editor = editor; this.$data = {editor: editor}; - /**@type {(import("../../").Ace.KeyboardHandler)[]}*/ + /**@type {(import("../../ace-internal").Ace.KeyboardHandler)[]}*/ this.$handlers = []; this.setDefaultHandler(editor.commands); } /** - * @param {import("../../").Ace.KeyboardHandler} kb + * @param {import("../../ace-internal").Ace.KeyboardHandler} kb */ setDefaultHandler(kb) { this.removeKeyboardHandler(this.$defaultHandler); @@ -28,7 +28,7 @@ class KeyBinding { } /** - * @param {import("../../").Ace.KeyboardHandler} kb + * @param {import("../../ace-internal").Ace.KeyboardHandler} kb */ setKeyboardHandler(kb) { var h = this.$handlers; @@ -42,7 +42,7 @@ class KeyBinding { } /** - * @param {import("../../").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] + * @param {import("../../ace-internal").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] * @param {number} [pos] */ addKeyboardHandler(kb, pos) { @@ -66,7 +66,7 @@ class KeyBinding { } /** - * @param {import("../../").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb + * @param {import("../../ace-internal").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb * @returns {boolean} */ removeKeyboardHandler(kb) { @@ -79,7 +79,7 @@ class KeyBinding { } /** - * @return {import("../../").Ace.KeyboardHandler} + * @return {import("../../ace-internal").Ace.KeyboardHandler} */ getKeyboardHandler() { return this.$handlers[this.$handlers.length - 1]; diff --git a/src/layer/cursor.js b/src/layer/cursor.js index 5bb4913c4f0..873f8022949 100644 --- a/src/layer/cursor.js +++ b/src/layer/cursor.js @@ -171,7 +171,7 @@ class Cursor { } /** - * @param {import("../../").Ace.Point} [position] + * @param {import("../../ace-internal").Ace.Point} [position] * @param {boolean} [onScreen] */ getPixelPosition(position, onScreen) { diff --git a/src/layer/gutter.js b/src/layer/gutter.js index 5ebbd60de4f..bfecc0a0899 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -94,7 +94,7 @@ class Gutter{ } /** - * @param {import("../../").Ace.Delta} delta + * @param {import("../../ace-internal").Ace.Delta} delta */ $updateAnnotations(delta) { if (!this.$annotations.length) @@ -113,7 +113,7 @@ class Gutter{ } /** - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config */ update(config) { this.config = config; @@ -166,7 +166,7 @@ class Gutter{ } /** - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config */ $updateGutterWidth(config) { var session = this.session; @@ -234,7 +234,7 @@ class Gutter{ } /** - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config */ scrollLines(config) { var oldConfig = this.config; @@ -280,7 +280,7 @@ class Gutter{ } /** - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config * @param {number} firstRow * @param {number} lastRow */ @@ -311,8 +311,8 @@ class Gutter{ /** * @param {any} cell - * @param {import("../../").Ace.LayerConfig} config - * @param {import("../../").Ace.IRange | undefined} fold + * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.IRange | undefined} fold * @param {number} row */ $renderCell(cell, config, fold, row) { diff --git a/src/layer/lines.js b/src/layer/lines.js index 2c49d058ec6..ad54099d1aa 100644 --- a/src/layer/lines.js +++ b/src/layer/lines.js @@ -20,15 +20,15 @@ class Lines { } /** - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config */ moveContainer(config) { dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient); } /** - * @param {import("../../").Ace.LayerConfig} oldConfig - * @param {import("../../").Ace.LayerConfig} newConfig + * @param {import("../../ace-internal").Ace.LayerConfig} oldConfig + * @param {import("../../ace-internal").Ace.LayerConfig} newConfig */ pageChanged(oldConfig, newConfig) { return ( @@ -39,7 +39,7 @@ class Lines { /** * @param {number} row - * @param {Partial} config + * @param {Partial} config * @param {EditSession} session */ computeLineTop(row, config, session) { @@ -51,7 +51,7 @@ class Lines { /** * @param {number} row - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config * @param {EditSession} session */ computeLineHeight(row, config, session) { diff --git a/src/layer/marker.js b/src/layer/marker.js index 916f3ada2e1..21e3da1c981 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -31,7 +31,7 @@ class Marker { } /** - * @param {{ [x: number]: import("../../").Ace.MarkerLike; }} markers + * @param {{ [x: number]: import("../../ace-internal").Ace.MarkerLike; }} markers */ setMarkers(markers) { this.markers = markers; @@ -56,7 +56,7 @@ class Marker { } /** - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config */ update(config) { if (!config) return; @@ -102,7 +102,7 @@ class Marker { /** * @param {number} row - * @param {Partial} layerConfig + * @param {Partial} layerConfig */ $getTop(row, layerConfig) { return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; @@ -114,7 +114,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} layerConfig + * @param {Partial} layerConfig * @param {string} [extraStyle] */ drawTextMarker(stringBuilder, range, clazz, layerConfig, extraStyle) { @@ -145,7 +145,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {import("../../").Ace.LayerConfig} config + * @param {import("../../ace-internal").Ace.LayerConfig} config * @param {string} [extraStyle] */ drawMultiLineMarker(stringBuilder, range, clazz, config, extraStyle) { @@ -207,7 +207,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {number} [extraLength] * @param {string} [extraStyle] */ @@ -234,7 +234,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {number} extraLength * @param {string} extraStyle */ @@ -257,7 +257,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {undefined} [extraStyle] */ drawFullLineMarker(stringBuilder, range, clazz, config, extraStyle) { @@ -278,7 +278,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {undefined} [extraStyle] */ drawScreenLineMarker(stringBuilder, range, clazz, config, extraStyle) { diff --git a/src/layer/text.js b/src/layer/text.js index 6782a5c4329..6502a387af4 100644 --- a/src/layer/text.js +++ b/src/layer/text.js @@ -689,7 +689,7 @@ class Text { /** * @param {any} row * @param {{ walk: (arg0: (placeholder: any, row: any, column: any, lastColumn: any, isNewRow: any) => void, arg1: any, arg2: any) => void; end: { row: any; }; }} foldLine - * @return {import("../../").Ace.Token[]} + * @return {import("../../ace-internal").Ace.Token[]} */ $getFoldLineTokens(row, foldLine) { var session = this.session; diff --git a/src/lib/app_config.js b/src/lib/app_config.js index fe624dc146c..3ca8dfb5725 100644 --- a/src/lib/app_config.js +++ b/src/lib/app_config.js @@ -28,6 +28,7 @@ var optionsProvider = { setOption: function(name, value) { if (this["$" + name] === value) return; + //@ts-ignore var opt = this.$options[name]; if (!opt) { return warn('misspelled option "' + name + '"'); diff --git a/src/line_widgets.js b/src/line_widgets.js index 5085a55576e..ba920c64aa7 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -138,7 +138,7 @@ class LineWidgets { /** * - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ updateOnChange(delta) { var lineWidgets = this.session.lineWidgets; @@ -190,8 +190,8 @@ class LineWidgets { /** * - * @param {import("../").Ace.LineWidget} w - * @return {import("../").Ace.LineWidget} + * @param {import("../ace-internal").Ace.LineWidget} w + * @return {import("../ace-internal").Ace.LineWidget} */ $registerLineWidget(w) { if (!this.session.lineWidgets) @@ -212,8 +212,8 @@ class LineWidgets { /** * - * @param {import("../").Ace.LineWidget} w - * @return {import("../").Ace.LineWidget} + * @param {import("../ace-internal").Ace.LineWidget} w + * @return {import("../ace-internal").Ace.LineWidget} */ addLineWidget(w) { this.$registerLineWidget(w); @@ -270,7 +270,7 @@ class LineWidgets { } /** - * @param {import("../").Ace.LineWidget} w + * @param {import("../ace-internal").Ace.LineWidget} w */ removeLineWidget(w) { w._inDocument = false; @@ -303,7 +303,7 @@ class LineWidgets { /** * * @param {number} row - * @return {import("../").Ace.LineWidget[]} + * @return {import("../ace-internal").Ace.LineWidget[]} */ getWidgetsAtRow(row) { var lineWidgets = this.session.lineWidgets; @@ -317,7 +317,7 @@ class LineWidgets { } /** - * @param {import("../").Ace.LineWidget} w + * @param {import("../ace-internal").Ace.LineWidget} w */ onWidgetChanged(w) { this.session._changedWidgets.push(w); diff --git a/src/marker_group.js b/src/marker_group.js index b09b121f8fb..39f8d28c25b 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -28,8 +28,8 @@ class MarkerGroup { /** * Finds the first marker containing pos - * @param {import("../").Ace.Point} pos - * @returns import("../").Ace.MarkerGroupItem + * @param {import("../ace-internal").Ace.Point} pos + * @returns import("../ace-internal").Ace.MarkerGroupItem */ getMarkerAtPosition(pos) { return this.markers.find(function(marker) { diff --git a/src/mode/text.js b/src/mode/text.js index 0550ea7ce1e..da1ce98c4bb 100644 --- a/src/mode/text.js +++ b/src/mode/text.js @@ -23,7 +23,7 @@ Mode = function() { this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "\\$_]|\\s])+", "g"); /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.getTokenizer = function() { if (!this.$tokenizer) { @@ -37,7 +37,7 @@ Mode = function() { this.blockComment = ""; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.toggleCommentLines = function(state, session, startRow, endRow) { var doc = session.doc; @@ -170,7 +170,7 @@ Mode = function() { }; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.toggleBlockComment = function(state, session, range, cursor) { var comment = this.blockComment; @@ -276,7 +276,7 @@ Mode = function() { var functionName = delegations[i]; var defaultHandler = scope[functionName]; scope[delegations[i]] = - /** @this {import("../../").Ace.SyntaxMode} */ + /** @this {import("../../ace-internal").Ace.SyntaxMode} */ function () { return this.$delegator(functionName, arguments, defaultHandler); }; @@ -285,7 +285,7 @@ Mode = function() { }; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.$delegator = function(method, args, defaultHandler) { var state = args[0] || "start"; @@ -314,7 +314,7 @@ Mode = function() { }; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.transformAction = function(state, action, editor, session, param) { if (this.$behaviour) { @@ -331,7 +331,7 @@ Mode = function() { }; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.getKeywords = function(append) { // this is for autocompletion to pick up regexp'ed keywords @@ -365,7 +365,7 @@ Mode = function() { }; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.$createKeywordList = function() { if (!this.$highlightRules) @@ -374,7 +374,7 @@ Mode = function() { }; /** - * @this {import("../../").Ace.SyntaxMode} + * @this {import("../../ace-internal").Ace.SyntaxMode} */ this.getCompletions = function(state, session, pos, prefix) { var keywords = this.$keywordList || this.$createKeywordList(); diff --git a/src/mode/text_highlight_rules.js b/src/mode/text_highlight_rules.js index af5589c9d79..a866846445e 100644 --- a/src/mode/text_highlight_rules.js +++ b/src/mode/text_highlight_rules.js @@ -2,7 +2,7 @@ const deepCopy = require("../lib/deep_copy").deepCopy; -/**@type {(new() => Partial) & {prototype: import("../../").Ace.HighlightRules}}*/ +/**@type {(new() => Partial) & {prototype: import("../../ace-internal").Ace.HighlightRules}}*/ var TextHighlightRules; TextHighlightRules = function() { @@ -22,9 +22,9 @@ TextHighlightRules = function() { (function() { /** - * @param {import("../../").Ace.HighlightRulesMap} rules + * @param {import("../../ace-internal").Ace.HighlightRulesMap} rules * @param {string} [prefix] - * @this {import("../../").Ace.HighlightRules} + * @this {import("../../ace-internal").Ace.HighlightRules} */ this.addRules = function(rules, prefix) { if (!prefix) { @@ -50,8 +50,8 @@ TextHighlightRules = function() { }; /** - * @returns {import("../../").Ace.HighlightRulesMap} - * @this {import("../../").Ace.HighlightRules} + * @returns {import("../../ace-internal").Ace.HighlightRulesMap} + * @this {import("../../ace-internal").Ace.HighlightRules} */ this.getRules = function() { return this.$rules; @@ -63,7 +63,7 @@ TextHighlightRules = function() { * @param escapeRules * @param states * @param append - * @this {import("../../").Ace.HighlightRules} + * @this {import("../../ace-internal").Ace.HighlightRules} */ this.embedRules = function (HighlightRules, prefix, escapeRules, states, append) { var embedRules = typeof HighlightRules == "function" @@ -92,7 +92,7 @@ TextHighlightRules = function() { }; /** - * @this {import("../../").Ace.HighlightRules} + * @this {import("../../ace-internal").Ace.HighlightRules} */ this.getEmbeds = function() { return this.$embeds; @@ -110,7 +110,7 @@ TextHighlightRules = function() { }; /** - * @this {import("../../").Ace.HighlightRules} + * @this {import("../../ace-internal").Ace.HighlightRules} */ this.normalizeRules = function() { var id = 0; @@ -229,7 +229,7 @@ TextHighlightRules = function() { }; /** - * @this {import("../../").Ace.HighlightRules} + * @this {import("../../ace-internal").Ace.HighlightRules} */ this.getKeywords = function() { return this.$keywords; diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index edc2244246f..1b0c9c4d63a 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -81,7 +81,7 @@ class DefaultHandlers { /** * - * @param {import("../../").Ace.Position} [pos] + * @param {import("../../ace-internal").Ace.Position} [pos] * @param {boolean} [waitForClickSelection] * @this {MouseHandler} */ diff --git a/src/multi_select.js b/src/multi_select.js index e94869f1d59..9b265b614c4 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -150,7 +150,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Removes a Range containing pos (if it exists). - * @param {import("../").Ace.Point} pos The position to remove, as a `{row, column}` object + * @param {import("../ace-internal").Ace.Point} pos The position to remove, as a `{row, column}` object * @this {Selection} **/ this.substractPoint = function(pos) { @@ -300,8 +300,8 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { * * Gets list of ranges composing rectangular block on the screen * - * @param {import("../").Ace.ScreenCoordinates} screenCursor The cursor to use - * @param {import("../").Ace.ScreenCoordinates} screenAnchor The anchor to use + * @param {import("../ace-internal").Ace.ScreenCoordinates} screenCursor The cursor to use + * @param {import("../ace-internal").Ace.ScreenCoordinates} screenAnchor The anchor to use * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping * @returns {Range[]} * @this {Selection} @@ -638,7 +638,7 @@ var Editor = require("./editor").Editor; /** * Finds and selects all the occurrences of `needle`. * @param {String} [needle] The text to find - * @param {Partial} [options] The search options + * @param {Partial} [options] The search options * @param {Boolean} [additive] keeps * * @returns {Number} The cumulative count of all found matches @@ -940,8 +940,8 @@ var Editor = require("./editor").Editor; /** - * @param {import("../").Ace.Point} p1 - * @param {import("../").Ace.Point} p2 + * @param {import("../ace-internal").Ace.Point} p1 + * @param {import("../ace-internal").Ace.Point} p2 */ function isSamePoint(p1, p2) { return p1.row == p2.row && p1.column == p2.column; diff --git a/src/occur.js b/src/occur.js index 92146f10b37..6c5ed7ca986 100644 --- a/src/occur.js +++ b/src/occur.js @@ -66,7 +66,7 @@ class Occur extends Search { /** * @param {Editor} editor - * @param {Partial} options + * @param {Partial} options */ displayOccurContent(editor, options) { // this.setSession(session || new EditSession("")) @@ -97,8 +97,8 @@ class Occur extends Search { * the document or the beginning if the doc {row: 0, column: 0} if not * found. * @param {EditSession} session The occur session - * @param {import("../").Ace.Point} pos The position in the original document - * @return {import("../").Ace.Point} position in occur doc + * @param {import("../ace-internal").Ace.Point} pos The position in the original document + * @return {import("../ace-internal").Ace.Point} position in occur doc **/ originalToOccurPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -115,8 +115,8 @@ class Occur extends Search { * Translates the position from the occur document to the original document * or `pos` if not found. * @param {EditSession} session The occur session - * @param {import("../").Ace.Point} pos The position in the occur session document - * @return {import("../").Ace.Point} position + * @param {import("../ace-internal").Ace.Point} pos The position in the occur session document + * @return {import("../ace-internal").Ace.Point} position **/ occurToOriginalPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -127,7 +127,7 @@ class Occur extends Search { /** * @param {EditSession} session - * @param {Partial} options + * @param {Partial} options */ matchingLines(session, options) { options = oop.mixin({}, options); diff --git a/src/placeholder.js b/src/placeholder.js index e9fdfa52830..a3e84f76e78 100644 --- a/src/placeholder.js +++ b/src/placeholder.js @@ -10,7 +10,7 @@ class PlaceHolder { /** * @param {EditSession} session * @param {Number} length - * @param {import("../").Ace.Point} pos + * @param {import("../ace-internal").Ace.Point} pos * @param {any[]} others * @param {String} mainClass * @param {String} othersClass @@ -105,7 +105,7 @@ class PlaceHolder { * PlaceHolder@onUpdate(e) * * Emitted when the place holder updates. - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ onUpdate(delta) { if (this.$updating) @@ -145,7 +145,7 @@ class PlaceHolder { } /** - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ updateAnchors(delta) { this.pos.onChange(delta); diff --git a/src/range.js b/src/range.js index 0bb9b6a7baa..c483d57207a 100644 --- a/src/range.js +++ b/src/range.js @@ -16,12 +16,12 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { - /**@type {import("../").Ace.Point}*/ + /**@type {import("../ace-internal").Ace.Point}*/ this.start = { row: startRow, column: startColumn }; - /**@type {import("../").Ace.Point}*/ + /**@type {import("../ace-internal").Ace.Point}*/ this.end = { row: endRow, column: endColumn @@ -30,7 +30,7 @@ class Range { /** * Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`. - * @param {import("../").Ace.IRange} range A range to check against + * @param {import("../ace-internal").Ace.IRange} range A range to check against * @return {Boolean} **/ isEqual(range) { @@ -70,7 +70,7 @@ class Range { /** * Compares `this` range (A) with another range (B). - * @param {import("../").Ace.IRange} range A range to compare with + * @param {import("../ace-internal").Ace.IRange} range A range to compare with * @related [[Range.compare]] * @returns {Number} This method returns one of the following numbers: * * `-2`: (B) is in front of (A), and doesn't intersect with (A) @@ -111,7 +111,7 @@ class Range { /** * Compares the row and column of `p` with the starting and ending [[Point]]'s of the calling range (by calling [[Range.compare]]). - * @param {import("../").Ace.Point} p A point to compare with + * @param {import("../ace-internal").Ace.Point} p A point to compare with * @related [[Range.compare]] * @returns {Number} **/ @@ -121,7 +121,7 @@ class Range { /** * Checks the start and end [[Point]]'s of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range. - * @param {import("../").Ace.IRange} range A range to compare with + * @param {import("../ace-internal").Ace.IRange} range A range to compare with * @returns {Boolean} * @related [[Range.comparePoint]] **/ @@ -131,7 +131,7 @@ class Range { /** * Returns `true` if passed in `range` intersects with the one calling this method. - * @param {import("../").Ace.IRange} range A range to compare with + * @param {import("../ace-internal").Ace.IRange} range A range to compare with * @returns {Boolean} **/ intersects(range) { @@ -161,7 +161,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|import("../").Ace.Point} row A row to set + * @param {Number|import("../ace-internal").Ace.Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -177,7 +177,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|import("../").Ace.Point} row A row to set + * @param {Number|import("../ace-internal").Ace.Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -442,8 +442,8 @@ class Range { /** * Creates and returns a new `Range` based on the `start` [[Point]] and `end` [[Point]] of the given parameters. - * @param {import("../").Ace.Point} start A starting point to use - * @param {import("../").Ace.Point} end An ending point to use + * @param {import("../ace-internal").Ace.Point} start A starting point to use + * @param {import("../ace-internal").Ace.Point} end An ending point to use * @returns {Range} **/ Range.fromPoints = function(start, end) { @@ -452,8 +452,8 @@ Range.fromPoints = function(start, end) { /** * Compares `p1` and `p2` [[Point]]'s, useful for sorting - * @param {import("../").Ace.Point} p1 - * @param {import("../").Ace.Point} p2 + * @param {import("../ace-internal").Ace.Point} p1 + * @param {import("../ace-internal").Ace.Point} p2 * @returns {Number} */ Range.comparePoints = function(p1, p2) { diff --git a/src/range_list.js b/src/range_list.js index 3f70938c932..2120c97a446 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -13,7 +13,7 @@ class RangeList { } /** - * @param {import("../").Ace.Point} pos + * @param {import("../ace-internal").Ace.Point} pos * @param {boolean} [excludeEdges] * @param {number} [startIndex] * @return {number} @@ -67,7 +67,7 @@ class RangeList { } /** - * @param {import("../").Ace.Point} pos + * @param {import("../ace-internal").Ace.Point} pos */ substractPoint(pos) { var i = this.pointIndex(pos); @@ -121,14 +121,14 @@ class RangeList { } /** - * @param {import("../").Ace.Point} pos + * @param {import("../ace-internal").Ace.Point} pos */ containsPoint(pos) { return this.pointIndex(pos) >= 0; } /** - * @param {import("../").Ace.Point} pos + * @param {import("../ace-internal").Ace.Point} pos */ rangeAtPoint(pos) { var i = this.pointIndex(pos); @@ -186,7 +186,7 @@ class RangeList { } /** - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta */ $onChange(delta) { var start = delta.start; diff --git a/src/search.js b/src/search.js index 05c766a30dc..5b1117feb45 100644 --- a/src/search.js +++ b/src/search.js @@ -21,7 +21,7 @@ class Search { * @property {boolean} [wholeWord] - Whether the search matches only on whole words * @property {Range|null} [range] - The [[Range]] to search within. Set this to `null` for the whole document * @property {boolean} [regExp] - Whether the search is a regular expression or not - * @property {Range|import("../").Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search + * @property {Range|import("../ace-internal").Ace.Position} [start] - The starting [[Range]] or cursor position to begin the search * @property {boolean} [skipCurrent] - Whether or not to include the current line in the search * @property {boolean} [$isMultiLine] - true, if needle has \n or \r\n * @property {boolean} [preserveCase] @@ -37,7 +37,7 @@ class Search { /** * Sets the search options via the `options` parameter. - * @param {Partial} options An object containing all the new search properties + * @param {Partial} options An object containing all the new search properties * @returns {Search} * @chainable **/ @@ -48,7 +48,7 @@ class Search { /** * [Returns an object containing all the search options.]{: #Search.getOptions} - * @returns {Partial} + * @returns {Partial} **/ getOptions() { return lang.copyObject(this.$options); diff --git a/src/search_highlight.js b/src/search_highlight.js index 8d53bfb3bb4..4fb2faec625 100644 --- a/src/search_highlight.js +++ b/src/search_highlight.js @@ -30,7 +30,7 @@ class SearchHighlight { * @param {any} html * @param {Marker} markerLayer * @param {EditSession} session - * @param {Partial} config + * @param {Partial} config */ update(html, markerLayer, session, config) { if (!this.regExp) diff --git a/src/selection.js b/src/selection.js index 5f8402d6c45..45e357288b6 100644 --- a/src/selection.js +++ b/src/selection.js @@ -69,7 +69,7 @@ class Selection { /** * Returns an object containing the `row` and `column` current position of the cursor. - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} **/ getCursor() { return this.lead.getPosition(); @@ -90,7 +90,7 @@ class Selection { /** * Returns an object containing the `row` and `column` of the calling selection anchor. * - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} * @related Anchor.getPosition **/ getAnchor() { @@ -154,7 +154,7 @@ class Selection { /** * Sets the selection to the provided range. - * @param {import("../").Ace.IRange} range The range of text to select + * @param {import("../ace-internal").Ace.IRange} range The range of text to select * @param {Boolean} [reverse] Indicates if the range should go backwards (`true`) or not **/ setRange(range, reverse) { @@ -207,7 +207,7 @@ class Selection { /** * Moves the selection cursor to the row and column indicated by `pos`. - * @param {import("../").Ace.Point} pos An object containing the row and column + * @param {import("../ace-internal").Ace.Point} pos An object containing the row and column **/ selectToPosition(pos) { this.$moveSelection(function() { @@ -376,7 +376,7 @@ class Selection { /** * * Returns `true` if moving the character next to the cursor in the specified direction is a soft tab. - * @param {import("../").Ace.Point} cursor the current cursor position + * @param {import("../ace-internal").Ace.Point} cursor the current cursor position * @param {Number} tabSize the tab size * @param {Number} direction 1 for right, -1 for left */ @@ -433,7 +433,7 @@ class Selection { else { var tabSize = this.session.getTabSize(); /** - * @type {import("../").Ace.Point} + * @type {import("../ace-internal").Ace.Point} */ var cursor = this.lead; if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) { @@ -749,7 +749,7 @@ class Selection { /** * Moves the selection to the position indicated by its `row` and `column`. - * @param {import("../").Ace.Point} position The position to move to + * @param {import("../ace-internal").Ace.Point} position The position to move to **/ moveCursorToPosition(position) { this.moveCursorTo(position.row, position.column); diff --git a/src/split.js b/src/split.js index e6349b91a8a..c1a8cbdcb66 100644 --- a/src/split.js +++ b/src/split.js @@ -8,7 +8,7 @@ var Renderer = require("./virtual_renderer").VirtualRenderer; var EditSession = require("./edit_session").EditSession; /** - * @typedef {import("../").Ace.EventEmitter & {[key: string]: any}} ISplit + * @typedef {import("../ace-internal").Ace.EventEmitter & {[key: string]: any}} ISplit */ var Split; diff --git a/src/token_iterator.js b/src/token_iterator.js index f3fbd9c49b3..3e3ffee8854 100644 --- a/src/token_iterator.js +++ b/src/token_iterator.js @@ -26,7 +26,7 @@ class TokenIterator { /** * Moves iterator position to the start of previous token. - * @returns {import("../").Ace.Token|null} + * @returns {import("../ace-internal").Ace.Token|null} **/ stepBackward() { this.$tokenIndex -= 1; @@ -47,7 +47,7 @@ class TokenIterator { /** * Moves iterator position to the start of next token. - * @returns {import("../").Ace.Token|null} + * @returns {import("../ace-internal").Ace.Token|null} **/ stepForward() { this.$tokenIndex += 1; @@ -71,7 +71,7 @@ class TokenIterator { /** * * Returns current token. - * @returns {import("../").Ace.Token} + * @returns {import("../ace-internal").Ace.Token} **/ getCurrentToken() { return this.$rowTokens[this.$tokenIndex]; @@ -111,7 +111,7 @@ class TokenIterator { /** * Return the current token position. - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} */ getCurrentTokenPosition() { return {row: this.$row, column: this.getCurrentTokenColumn()}; diff --git a/src/tokenizer.js b/src/tokenizer.js index 846a276d486..900651d7ca3 100644 --- a/src/tokenizer.js +++ b/src/tokenizer.js @@ -111,7 +111,7 @@ class Tokenizer { /** * @param {string} str - * @return {import("../").Ace.Token[]} + * @return {import("../ace-internal").Ace.Token[]} */ $applyToken(str) { var values = this.splitRegex.exec(str).slice(1); @@ -135,7 +135,7 @@ class Tokenizer { /** * @param {string} str - * @return {import("../").Ace.Token[] | string} + * @return {import("../ace-internal").Ace.Token[] | string} */ $arrayTokens(str) { if (!str) @@ -215,7 +215,7 @@ class Tokenizer { * Returns an object containing two properties: `tokens`, which contains all the tokens; and `state`, the current state. * @param {string} line * @param {string | string[]} startState - * @returns {{tokens:import("../").Ace.Token[], state: string|string[]}} + * @returns {{tokens:import("../ace-internal").Ace.Token[], state: string|string[]}} */ getLineTokens(line, startState) { if (startState && typeof startState != "string") { diff --git a/src/tooltip.js b/src/tooltip.js index 3702e4d6265..2afbbddadef 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -70,7 +70,7 @@ class Tooltip { } /** - * @param {import("../").Ace.Theme} theme + * @param {import("../ace-internal").Ace.Theme} theme */ setTheme(theme) { this.$element.className = CLASSNAME + " " + diff --git a/src/undomanager.js b/src/undomanager.js index 49d9958b612..a5e2d71efe1 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -4,11 +4,11 @@ */ /** - * @typedef {import("../").Ace.Delta} Delta + * @typedef {import("../ace-internal").Ace.Delta} Delta */ /** - * @typedef {import("../").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.Point} Point */ /** @@ -40,7 +40,7 @@ class UndoManager { * - `args[0]` is an array of deltas * - `args[1]` is the document to associate with * - * @param {import("../").Ace.Delta} delta + * @param {import("../ace-internal").Ace.Delta} delta * @param {boolean} allowMerge * @param {EditSession} [session] **/ @@ -126,7 +126,7 @@ class UndoManager { * * @param {number} from * @param {number} [to] - * @return {import("../").Ace.Delta[]} + * @return {import("../ace-internal").Ace.Delta[]} */ getDeltas(from, to) { if (to == null) to = this.$rev + 1; @@ -602,8 +602,8 @@ function xform(d1, c1) { /** * - * @param {import("../").Ace.IRange} d1 - * @param {import("../").Ace.IRange} d2 + * @param {import("../ace-internal").Ace.IRange} d1 + * @param {import("../ace-internal").Ace.IRange} d2 * @param {number} dir */ function shift(d1, d2, dir) { diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 49314dbb83c..58298e8e9e2 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1269,7 +1269,7 @@ class VirtualRenderer { /** * Sets annotations for the gutter. - * @param {import("../").Ace.Annotation[]} annotations An array containing annotations + * @param {import("../ace-internal").Ace.Annotation[]} annotations An array containing annotations * **/ setAnnotations(annotations) { @@ -1303,8 +1303,8 @@ class VirtualRenderer { /** * - * @param {import("../").Ace.Point} anchor - * @param {import("../").Ace.Point} lead + * @param {import("../ace-internal").Ace.Point} anchor + * @param {import("../ace-internal").Ace.Point} lead * @param {number} [offset] */ scrollSelectionIntoView(anchor, lead, offset) { @@ -1316,7 +1316,7 @@ class VirtualRenderer { /** * * Scrolls the cursor into the first visibile area of the editor - * @param {import("../").Ace.Point} [cursor] + * @param {import("../ace-internal").Ace.Point} [cursor] * @param {number} [offset] * @param {{ top?: any; bottom?: any; }} [$viewMargin] */ @@ -1417,7 +1417,7 @@ class VirtualRenderer { /** * - * @param {import("../").Ace.Point} cursor + * @param {import("../ace-internal").Ace.Point} cursor * @param {number} [alignment] * @returns {number} */ @@ -1604,7 +1604,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {import("../").Ace.ScreenCoordinates} + * @returns {import("../ace-internal").Ace.ScreenCoordinates} */ pixelToScreenCoordinates(x, y) { @@ -1630,7 +1630,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {import("../").Ace.Point} + * @returns {import("../ace-internal").Ace.Point} */ screenToTextCoordinates(x, y) { @@ -1749,7 +1749,7 @@ class VirtualRenderer { /** * @param {string} text - * @param {import("../").Ace.Point} [position] + * @param {import("../ace-internal").Ace.Point} [position] */ setGhostText(text, position) { var cursor = this.session.selection.cursor; @@ -1828,7 +1828,7 @@ class VirtualRenderer { /** * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} - * @param {String | import("../").Ace.Theme} [theme] The path to a theme + * @param {String | import("../ace-internal").Ace.Theme} [theme] The path to a theme * @param {() => void} [cb] optional callback **/ @@ -1847,7 +1847,7 @@ class VirtualRenderer { } /** - * @param {import("../").Ace.Theme} module + * @param {import("../ace-internal").Ace.Theme} module */ function afterLoad(module) { if (_self.$themeId != theme) @@ -1961,9 +1961,9 @@ class VirtualRenderer { delete this.$scrollDecorator; } if (val === true) { - /**@type {import("../").Ace.VScrollbar}*/ + /**@type {import("../ace-internal").Ace.VScrollbar}*/ this.scrollBarV = new VScrollBarCustom(this.container, this); - /**@type {import("../").Ace.HScrollbar}*/ + /**@type {import("../ace-internal").Ace.HScrollbar}*/ this.scrollBarH = new HScrollBarCustom(this.container, this); this.scrollBarV.setHeight(this.$size.scrollerHeight); this.scrollBarH.setWidth(this.$size.scrollerWidth); @@ -2037,7 +2037,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { useResizeObserver: { /** * @param value - + * @this{VirtualRenderer} */ set: function(value) { if (!value && this.$resizeObserver) { @@ -2068,7 +2068,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { printMargin: { /** * @param val - + * @this{VirtualRenderer} */ set: function(val) { if (typeof val == "number") @@ -2175,7 +2175,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { minLines: { /** * @param val - + * @this{VirtualRenderer} */ set: function(val) { if (!(this.$minLines < 0x1ffffffffffff)) @@ -2192,7 +2192,7 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", { scrollPastEnd: { /** * @param val - + * @this{VirtualRenderer} */ set: function(val) { val = +val || 0; From cc476991ab0815e98eb3a35b73d893123d8f0148 Mon Sep 17 00:00:00 2001 From: mkslanc Date: Mon, 4 Dec 2023 18:48:08 +0400 Subject: [PATCH 35/36] resolve merge conflicts --- ace-internal.d.ts | 3 ++- src/autocomplete.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ace-internal.d.ts b/ace-internal.d.ts index 9e0300552d6..82ce9e9eb82 100644 --- a/ace-internal.d.ts +++ b/ace-internal.d.ts @@ -940,7 +940,8 @@ export namespace Ace { callback: CompleterCallback): void; getDocTooltip?(item: Completion): void | string | Completion; - + onSeen?: (editor: Ace.Editor, completion: Completion) => void; + onInsert?: (editor: Ace.Editor, completion: Completion) => void; cancel?(): void; id?: string; diff --git a/src/autocomplete.js b/src/autocomplete.js index f735e3c838e..6a28491faca 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -28,7 +28,7 @@ var event = require("./lib/event"); * @property {string} [command] - A command to be executed after the completion is inserted (experimental) * @property {string} [snippet] - a text snippet that would be inserted when the completion is selected * @property {string} [value] - The text that would be inserted when selecting this completion. - * @property {{insertMatch:(editor: Editor, data: Completion) => void}} [completer] + * @property {import("../ace-internal").Ace.Completer & {insertMatch:(editor: Editor, data: Completion) => void}} [completer] * @property {boolean} [hideInlinePreview] * @export */ From 07b02410b28edbc47adf04bf744eb4bd9a8e6837 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 6 Dec 2023 01:09:35 +0400 Subject: [PATCH 36/36] cleanup --- .github/workflows/nodejs.yml | 1 + Makefile.dryice.js | 2 +- package.json | 1 + src/ace.js | 5 +- src/autocomplete.js | 12 +- src/autocomplete/popup.js | 141 +++++++++----------- src/background_tokenizer.js | 10 +- src/clipboard.js | 3 +- src/commands/incremental_search_commands.js | 1 - src/config.js | 31 ++--- src/document.js | 87 ++++++------ src/edit_session.js | 69 +++++----- src/edit_session/bracket_match.js | 17 +-- src/edit_session/fold.js | 22 +-- src/edit_session/fold_line.js | 1 - src/edit_session/folding.js | 5 +- src/editor.js | 28 ++-- src/ext/code_lens.js | 2 - src/ext/command_bar.js | 5 +- src/keyboard/hash_handler.js | 26 ++-- src/keyboard/keybinding.js | 13 +- src/layer/gutter.js | 11 +- src/layer/lines.js | 11 +- src/layer/marker.js | 17 +-- src/lib/event.js | 60 +++------ src/line_widgets.js | 19 ++- src/marker_group.js | 2 - src/mouse/default_handlers.js | 2 - src/multi_select.js | 64 +-------- src/occur.js | 14 +- src/range.js | 28 ++-- src/range_list.js | 9 +- src/search_highlight.js | 2 - src/selection.js | 15 +-- src/tooltip.js | 4 - src/undomanager.js | 11 +- src/virtual_renderer.js | 19 +-- tsconfig.json | 3 +- 38 files changed, 333 insertions(+), 440 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index c83654e177e..56a36d8505b 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -52,6 +52,7 @@ jobs: fi # - run: npm run lint - run: node_modules/.bin/tsc --noImplicitAny --strict --noUnusedLocals --noImplicitReturns --noUnusedParameters --noImplicitThis ace.d.ts + - run: npm run typecheck - uses: codecov/codecov-action@v3 with: token: d8edca4b-8e97-41e5-b54e-34c7cf3b2d47 diff --git a/Makefile.dryice.js b/Makefile.dryice.js index a745e15fe76..734423fc83f 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -179,7 +179,7 @@ function buildTypes() { var aceCodeExtensionDefinitions = '/// '; // ace-builds package has different structure and can't use mode types defined for the ace-code. // ace-builds modes are declared along with other modules in the ace-modules.d.ts file below. - var definitions = fs.readFileSync(ACE_HOME + '/ace-internal.d.ts', 'utf8').replace(aceCodeModeDefinitions, '').replace(aceCodeExtensionDefinitions, ''); + var definitions = fs.readFileSync(ACE_HOME + '/ace.d.ts', 'utf8').replace(aceCodeModeDefinitions, '').replace(aceCodeExtensionDefinitions, ''); var paths = fs.readdirSync(BUILD_DIR + '/src-noconflict'); var moduleRef = '/// '; diff --git a/package.json b/package.json index e5d7df8a7fa..d5e9b724bc7 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "cover": "istanbul cover src/test/all.js", "lint": "eslint \"src/**/*.js\"", "fix": "eslint --fix \"src/**/*.js\"", + "typecheck": "tsc -p tsconfig.json", "changelog": "standard-version", "prepack": "node tool/esm_resolver_generator.js && node Makefile.dryice.js css --target build-styles && rm -rf styles && mv build-styles/css styles" }, diff --git a/src/ace.js b/src/ace.js index 21f67f98ea7..86ea484a156 100644 --- a/src/ace.js +++ b/src/ace.js @@ -9,8 +9,8 @@ var dom = require("./lib/dom"); var Range = require("./range").Range; -var EditSession = require("./edit_session").EditSession; var Editor = require("./editor").Editor; +var EditSession = require("./edit_session").EditSession; var UndoManager = require("./undomanager").UndoManager; var Renderer = require("./virtual_renderer").VirtualRenderer; @@ -86,5 +86,4 @@ exports.Editor = Editor; exports.EditSession = EditSession; exports.UndoManager = UndoManager; exports.VirtualRenderer = Renderer; -let version= exports.config.version; -exports.version = version; +exports.version = exports.config.version; diff --git a/src/autocomplete.js b/src/autocomplete.js index 6a28491faca..01d2762c8b7 100644 --- a/src/autocomplete.js +++ b/src/autocomplete.js @@ -1,6 +1,8 @@ "use strict"; /** * @typedef {import("./editor").Editor} Editor + * @typedef {import("../ace-internal").Ace.CompletionProviderOptions} CompletionProviderOptions + * @typedef {import("../ace-internal").Ace.CompletionOptions} CompletionOptions */ var HashHandler = require("./keyboard/hash_handler").HashHandler; var AcePopup = require("./autocomplete/popup").AcePopup; @@ -450,7 +452,7 @@ class Autocomplete { /** * This is the entry point for the autocompletion class, triggers the actions which collect and display suggestions * @param {Editor} editor - * @param {import("../ace-internal").Ace.CompletionOptions} options + * @param {CompletionOptions} options */ showPopup(editor, options) { if (this.editor) @@ -490,7 +492,7 @@ class Autocomplete { /** * @param {boolean} keepPopupPosition - * @param {import("../ace-internal").Ace.CompletionOptions} options + * @param {CompletionOptions} options */ updateCompletions(keepPopupPosition, options) { if (keepPopupPosition && this.base && this.completions) { @@ -783,7 +785,7 @@ class CompletionProvider { /** * @param {Editor} editor * @param {number} index - * @param {import("../ace-internal").Ace.CompletionProviderOptions} [options] + * @param {CompletionProviderOptions} [options] * @returns {boolean} */ insertByIndex(editor, index, options) { @@ -796,7 +798,7 @@ class CompletionProvider { /** * @param {Editor} editor * @param {Completion} data - * @param {import("../ace-internal").Ace.CompletionProviderOptions} [options] + * @param {CompletionProviderOptions} [options] * @returns {boolean} */ insertMatch(editor, data, options) { @@ -898,7 +900,7 @@ class CompletionProvider { * This is the entry point to the class, it gathers, then provides the completions asynchronously via callback. * The callback function may be called multiple times, the last invokation is marked with a `finished` flag * @param {Editor} editor - * @param {import("../ace-internal").Ace.CompletionProviderOptions} options + * @param {CompletionProviderOptions} options * @param {(err: Error | undefined, completions: FilteredList | [], finished: boolean) => void} callback */ provideCompletions(editor, options, callback) { diff --git a/src/autocomplete/popup.js b/src/autocomplete/popup.js index 079988ee2fd..fb4abbe8f31 100644 --- a/src/autocomplete/popup.js +++ b/src/autocomplete/popup.js @@ -17,7 +17,7 @@ var getAriaId = function (index) { * @param {HTMLElement} [el] * @return {Editor} */ -var $singleLineEditor = function (el) { +var $singleLineEditor = function(el) { var renderer = new Renderer(el); renderer.$maxLines = 4; @@ -64,8 +64,7 @@ class AcePopup { popup.setOption("displayIndentGuides", false); popup.setOption("dragDelay", 150); - var noop = function () { - }; + var noop = function(){}; popup.focus = noop; popup.$isFocused = true; @@ -82,7 +81,7 @@ class AcePopup { popup.session.highlight(""); popup.session.$searchHighlight.clazz = "ace_highlight-marker"; - popup.on("mousedown", function (e) { + popup.on("mousedown", function(e) { var pos = e.getDocumentPosition(); popup.selection.moveToPosition(pos); selectionMarker.start.row = selectionMarker.end.row = pos.row; @@ -96,14 +95,13 @@ class AcePopup { popup.setSelectOnHover = function (val) { if (!val) { hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine"); - } - else if (hoverMarker.id) { + } else if (hoverMarker.id) { popup.session.removeMarker(hoverMarker.id); hoverMarker.id = null; } }; popup.setSelectOnHover(false); - popup.on("mousemove", function (e) { + popup.on("mousemove", function(e) { if (!lastMouseEvent) { lastMouseEvent = e; return; @@ -116,15 +114,17 @@ class AcePopup { popup.isMouseOver = true; var row = lastMouseEvent.getDocumentPosition().row; if (hoverMarker.start.row != row) { - if (!hoverMarker.id) popup.setRow(row); + if (!hoverMarker.id) + popup.setRow(row); setHoverMarker(row); } }); - popup.renderer.on("beforeRender", function () { + popup.renderer.on("beforeRender", function() { if (lastMouseEvent && hoverMarker.start.row != -1) { lastMouseEvent.$pos = null; var row = lastMouseEvent.getDocumentPosition().row; - if (!hoverMarker.id) popup.setRow(row); + if (!hoverMarker.id) + popup.setRow(row); setHoverMarker(row, true); } }); @@ -156,17 +156,16 @@ class AcePopup { selected.setAttribute("aria-selected", "true"); } }); - var hideHoverMarker = function () { - setHoverMarker(-1); - }; - var setHoverMarker = function (row, suppressRedraw) { + var hideHoverMarker = function() { setHoverMarker(-1); }; + var setHoverMarker = function(row, suppressRedraw) { if (row !== hoverMarker.start.row) { hoverMarker.start.row = hoverMarker.end.row = row; - if (!suppressRedraw) popup.session._emit("changeBackMarker"); + if (!suppressRedraw) + popup.session._emit("changeBackMarker"); popup._emit("changeHoverMarker"); } }; - popup.getHoveredRow = function () { + popup.getHoveredRow = function() { return hoverMarker.start.row; }; @@ -177,22 +176,25 @@ class AcePopup { popup.on("hide", hideHoverMarker); popup.on("changeSelection", hideHoverMarker); - popup.session.doc.getLength = function () { + popup.session.doc.getLength = function() { return popup.data.length; }; - popup.session.doc.getLine = function (i) { + popup.session.doc.getLine = function(i) { var data = popup.data[i]; - if (typeof data == "string") return data; + if (typeof data == "string") + return data; return (data && data.value) || ""; }; var bgTokenizer = popup.session.bgTokenizer; - bgTokenizer.$tokenizeRow = function (row) { + bgTokenizer.$tokenizeRow = function(row) { /**@type {import("../../ace-internal").Ace.Completion &{name?, className?, matchMask?, message?}}*/ var data = popup.data[row]; var tokens = []; - if (!data) return tokens; - if (typeof data == "string") data = {value: data}; + if (!data) + return tokens; + if (typeof data == "string") + data = {value: data}; var caption = data.caption || data.value || data.name; function addToken(value, className) { @@ -219,25 +221,18 @@ class AcePopup { } addToken(caption.slice(lastIndex, caption.length), ""); - tokens.push({ - type: "completion-spacer", - value: " " - }); - if (data.meta) tokens.push({ - type: "completion-meta", - value: data.meta - }); - if (data.message) tokens.push({ - type: "completion-message", - value: data.message - }); + tokens.push({type: "completion-spacer", value: " "}); + if (data.meta) + tokens.push({type: "completion-meta", value: data.meta}); + if (data.message) + tokens.push({type: "completion-message", value: data.message}); return tokens; }; bgTokenizer.$updateOnChange = noop; bgTokenizer.start = noop; - popup.session.$computeWidth = function () { + popup.session.$computeWidth = function() { return this.screenWidth = 0; }; @@ -249,36 +244,38 @@ class AcePopup { popup.isMouseOver = false; popup.data = []; - popup.setData = function (list, filterText) { + popup.setData = function(list, filterText) { popup.filterText = filterText || ""; popup.setValue(lang.stringRepeat("\n", list.length), -1); popup.data = list || []; popup.setRow(0); }; - popup.getData = function (row) { + popup.getData = function(row) { return popup.data[row]; }; - popup.getRow = function () { + popup.getRow = function() { return selectionMarker.start.row; }; - popup.setRow = function (line) { + popup.setRow = function(line) { line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line)); if (selectionMarker.start.row != line) { popup.selection.clearSelection(); selectionMarker.start.row = selectionMarker.end.row = line || 0; popup.session._emit("changeBackMarker"); popup.moveCursorTo(line || 0, 0); - if (popup.isOpen) popup._signal("select"); + if (popup.isOpen) + popup._signal("select"); } }; - popup.on("changeSelection", function () { - if (popup.isOpen) popup.setRow(popup.selection.lead.row); + popup.on("changeSelection", function() { + if (popup.isOpen) + popup.setRow(popup.selection.lead.row); popup.renderer.scrollCursorIntoView(); }); - popup.hide = function () { + popup.hide = function() { this.container.style.display = "none"; popup.anchorPos = null; popup.anchor = null; @@ -293,15 +290,17 @@ class AcePopup { * If the anchor is not specified it tries to align to bottom and right as much as possible. * If the popup does not have enough space to be rendered with the given anchors, it returns false without rendering the popup. * The forceShow flag can be used to render the popup in these cases, which slides the popup so it entirely fits on the screen. - * @param {any} pos + * @param {{top: number, left: number}} pos * @param {number} lineHeight * @param {"top" | "bottom" | undefined} anchor * @param {boolean} forceShow * @returns {boolean} */ - popup.tryShow = function (pos, lineHeight, anchor, forceShow) { - if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor && popup.anchorPos.top === pos.top - && popup.anchorPos.left === pos.left && popup.anchor === anchor) { + popup.tryShow = function(pos, lineHeight, anchor, forceShow) { + if (!forceShow && popup.isOpen && popup.anchorPos && popup.anchor && + popup.anchorPos.top === pos.top && popup.anchorPos.left === pos.left && + popup.anchor === anchor + ) { return true; } @@ -311,19 +310,14 @@ class AcePopup { var renderer = this.renderer; // var maxLines = Math.min(renderer.$maxLines, this.session.getLength()); var maxH = renderer.$maxLines * lineHeight * 1.4; - var dims = { - top: 0, - bottom: 0, - left: 0 - }; + var dims = { top: 0, bottom: 0, left: 0 }; var spaceBelow = screenHeight - pos.top - 3 * this.$borderSize - lineHeight; var spaceAbove = pos.top - 3 * this.$borderSize; if (!anchor) { if (spaceAbove <= spaceBelow || spaceBelow >= maxH) { anchor = "bottom"; - } - else { + } else { anchor = "top"; } } @@ -331,8 +325,7 @@ class AcePopup { if (anchor === "top") { dims.bottom = pos.top - this.$borderSize; dims.top = dims.bottom - maxH; - } - else if (anchor === "bottom") { + } else if (anchor === "bottom") { dims.top = pos.top + lineHeight + this.$borderSize; dims.bottom = dims.top + maxH; } @@ -346,12 +339,10 @@ class AcePopup { if (!fitsX) { if (anchor === "top") { renderer.$maxPixelHeight = spaceAbove; - } - else { + } else { renderer.$maxPixelHeight = spaceBelow; } - } - else { + } else { renderer.$maxPixelHeight = null; } @@ -360,8 +351,7 @@ class AcePopup { el.style.top = ""; el.style.bottom = (screenHeight - dims.bottom) + "px"; popup.isTopdown = false; - } - else { + } else { el.style.top = dims.top + "px"; el.style.bottom = ""; popup.isTopdown = true; @@ -370,7 +360,8 @@ class AcePopup { el.style.display = ""; var left = pos.left; - if (left + el.offsetWidth > screenWidth) left = screenWidth - el.offsetWidth; + if (left + el.offsetWidth > screenWidth) + left = screenWidth - el.offsetWidth; el.style.left = left + "px"; el.style.right = ""; @@ -387,34 +378,26 @@ class AcePopup { return true; }; - popup.show = function (pos, lineHeight, topdownOnly) { + popup.show = function(pos, lineHeight, topdownOnly) { this.tryShow(pos, lineHeight, topdownOnly ? "bottom" : undefined, true); }; - popup.goTo = function (where) { + popup.goTo = function(where) { var row = this.getRow(); var max = this.session.getLength() - 1; - switch (where) { - case "up": - row = row <= 0 ? max : row - 1; - break; - case "down": - row = row >= max ? -1 : row + 1; - break; - case "start": - row = 0; - break; - case "end": - row = max; - break; + switch(where) { + case "up": row = row <= 0 ? max : row - 1; break; + case "down": row = row >= max ? -1 : row + 1; break; + case "start": row = 0; break; + case "end": row = max; break; } this.setRow(row); }; - popup.getTextLeftOffset = function () { + popup.getTextLeftOffset = function() { return this.$borderSize + this.renderer.$padding + this.$imageSize; }; diff --git a/src/background_tokenizer.js b/src/background_tokenizer.js index 016b344187f..f52649caea8 100644 --- a/src/background_tokenizer.js +++ b/src/background_tokenizer.js @@ -1,11 +1,7 @@ "use strict"; /** * @typedef {import("./document").Document} Document - */ -/** - * @typedef {import("./editor").Editor} Editor - */ -/** + * @typedef {import("./edit_session").EditSession} EditSession * @typedef {import("./tokenizer").Tokenizer} Tokenizer */ var oop = require("./lib/oop"); @@ -21,9 +17,9 @@ class BackgroundTokenizer { /** * Creates a new `BackgroundTokenizer` object. * @param {Tokenizer} tokenizer The tokenizer to use - * @param {any} [editor] The editor to associate with + * @param {EditSession} [session] The editor session to associate with **/ - constructor(tokenizer, editor) { + constructor(tokenizer, session) { /**@type {false|number}*/ this.running = false; this.lines = []; diff --git a/src/clipboard.js b/src/clipboard.js index ff4ace683c9..73bb845a680 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -2,7 +2,8 @@ var $cancelT; module.exports = { - /** @type {string|false} */lineMode: false, + /** @type {string|false} */ + lineMode: false, pasteCancelled: function() { if ($cancelT && $cancelT > Date.now() - 50) return true; diff --git a/src/commands/incremental_search_commands.js b/src/commands/incremental_search_commands.js index cc73714a3b7..6c992f98fac 100644 --- a/src/commands/incremental_search_commands.js +++ b/src/commands/incremental_search_commands.js @@ -170,7 +170,6 @@ oop.inherits(IncrementalSearchKeyboardHandler, HashHandler); var handleKeyboard$super = this.handleKeyboard; /** - * * @param data * @param hashId * @param key diff --git a/src/config.js b/src/config.js index ab7e9173004..56b22687fe9 100644 --- a/src/config.js +++ b/src/config.js @@ -111,32 +111,33 @@ exports.dynamicModules = Object.create(null); exports.$loading = {}; exports.$loaded = {}; /** - * @param {string | [string, string]} moduleName + * @param {string | [string, string]} moduleId * @param {(module: any) => void} onLoad */ -exports.loadModule = function(moduleName, onLoad) { - var loadedModule, moduleType; - if (Array.isArray(moduleName)) { - moduleType = moduleName[0]; - moduleName = moduleName[1]; +exports.loadModule = function(moduleId, onLoad) { + var loadedModule; + if (Array.isArray(moduleId)) { + var moduleType = moduleId[0]; + var moduleName = moduleId[1]; + } else if (typeof moduleId == "string") { + var moduleName = moduleId; } - var load = function (module) { // require(moduleName) can return empty object if called after require([moduleName], callback) - if (module && !exports.$loading[/**@type {string}*/(moduleName)]) return onLoad && onLoad(module); + if (module && !exports.$loading[moduleName]) return onLoad && onLoad(module); - if (!exports.$loading[/**@type {string}*/(moduleName)]) exports.$loading[/**@type {string}*/(moduleName)] = []; + if (!exports.$loading[moduleName]) exports.$loading[moduleName] = []; - exports.$loading[/**@type {string}*/(moduleName)].push(onLoad); + exports.$loading[moduleName].push(onLoad); - if (exports.$loading[/**@type {string}*/(moduleName)].length > 1) return; + if (exports.$loading[moduleName].length > 1) return; var afterLoad = function() { loader(moduleName, function(err, module) { - if (module) exports.$loaded[/**@type {string}*/(moduleName)] = module; + if (module) exports.$loaded[moduleName] = module; exports._emit("load.module", {name: moduleName, module: module}); - var listeners = exports.$loading[/**@type {string}*/(moduleName)]; - exports.$loading[/**@type {string}*/(moduleName)] = null; + var listeners = exports.$loading[moduleName]; + exports.$loading[moduleName] = null; listeners.forEach(function(onLoad) { onLoad && onLoad(module); }); @@ -145,7 +146,7 @@ exports.loadModule = function(moduleName, onLoad) { if (!exports.get("packaged")) return afterLoad(); - net.loadScript(exports.moduleUrl(/**@type {string}*/(moduleName), moduleType), afterLoad); + net.loadScript(exports.moduleUrl(moduleName, moduleType), afterLoad); reportErrorIfPathIsNotConfigured(); }; diff --git a/src/document.js b/src/document.js index 56571e3d45a..0d8d243f107 100644 --- a/src/document.js +++ b/src/document.js @@ -1,4 +1,11 @@ "use strict"; + +/** + * @typedef {import("../ace-internal").Ace.Delta} Delta + * @typedef {import("../ace-internal").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.IRange} IRange + * @typedef {import("../ace-internal").Ace.NewLineMode} NewLineMode + */ var oop = require("./lib/oop"); var applyDelta = require("./apply_delta").applyDelta; var EventEmitter = require("./lib/event_emitter").EventEmitter; @@ -34,7 +41,6 @@ class Document { * Replaces all the lines in the current `Document` with the value of `text`. * * @param {String} text The text to use - **/ setValue(text) { var len = this.getLength() - 1; @@ -62,7 +68,6 @@ class Document { /** * @param {string} text - */ $detectNewLine(text) { var match = text.match(/^.*?(\r\n|\r|\n)/m); @@ -90,7 +95,7 @@ class Document { /** * [Sets the new line mode.]{: #Document.setNewLineMode.desc} - * @param {import("../ace-internal").Ace.NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} + * @param {NewLineMode} newLineMode [The newline mode to use; can be either `windows`, `unix`, or `auto`]{: #Document.setNewLineMode.param} **/ setNewLineMode(newLineMode) { @@ -103,7 +108,7 @@ class Document { /** * [Returns the type of newlines being used; either `windows`, `unix`, or `auto`]{: #Document.getNewLineMode} - * @returns {import("../ace-internal").Ace.NewLineMode} + * @returns {NewLineMode} **/ getNewLineMode() { return this.$newLineMode; @@ -155,7 +160,7 @@ class Document { /** * Returns all the text within `range` as a single string. - * @param {import("../ace-internal").Ace.IRange} range The range to work with. + * @param {IRange} range The range to work with. * * @returns {String} **/ @@ -165,7 +170,7 @@ class Document { /** * Returns all the text within `range` as an array of lines. - * @param {import("../ace-internal").Ace.IRange} range The range to work with. + * @param {IRange} range The range to work with. * * @returns {string[]} **/ @@ -198,7 +203,6 @@ class Document { } /** - * * @param firstRow * @param lastRow * @returns {String[]} @@ -212,7 +216,7 @@ class Document { /** * @param position - * @returns {import("../ace-internal").Ace.Point} + * @returns {Point} * @deprecated */ @@ -223,9 +227,9 @@ class Document { /** * Inserts a block of `text` at the indicated `position`. - * @param {import("../ace-internal").Ace.Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` + * @param {Point} position The position to start inserting at; it's an object that looks like `{ row: row, column: column}` * @param {String} text A chunk of text to insert - * @returns {import("../ace-internal").Ace.Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. + * @returns {Point} The position ({row, column}) of the last line of `text`. If the length of `text` is 0, this function simply returns `position`. **/ insert(position, text) { @@ -243,13 +247,9 @@ class Document { * 1. This does NOT handle newline characters (single-line text only). * 2. This is faster than the `insert` method for single-line text insertions. * - * @param {import("../ace-internal").Ace.Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` - * @param {String} text A chunk of text - * @returns {import("../ace-internal").Ace.Point} Returns an object containing the final row and column, like this: - * ``` - * {row: endRow, column: 0} - * ``` - + * @param {Point} position The position to insert at; it's an object that looks like `{ row: row, column: column}` + * @param {String} text A chunk of text without new lines + * @returns {Point} Returns the position of the end of the inserted text **/ insertInLine(position, text) { var start = this.clippedPos(position.row, position.column); @@ -269,7 +269,7 @@ class Document { * * @param {number} row * @param {number} column - * @return {import("../ace-internal").Ace.Point} + * @return {Point} */ clippedPos(row, column) { var length = this.getLength(); @@ -289,8 +289,8 @@ class Document { } /** - * @param {import("../ace-internal").Ace.Point} pos - * @return {import("../ace-internal").Ace.Point} + * @param {Point} pos + * @return {Point} */ clonePos(pos) { return {row: pos.row, column: pos.column}; @@ -299,15 +299,15 @@ class Document { /** * @param {number} row * @param {number} column - * @return {import("../ace-internal").Ace.Point} + * @return {Point} */ pos(row, column) { return {row: row, column: column}; } /** - * @param {import("../ace-internal").Ace.Point} position - * @return {import("../ace-internal").Ace.Point} + * @param {Point} position + * @return {Point} * @private */ $clipPosition(position) { @@ -352,9 +352,9 @@ class Document { /** * Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event. - * @param {import("../ace-internal").Ace.Position} position + * @param {Point} position * @param {string[]} lines An array of strings - * @returns {import("../ace-internal").Ace.Point} Contains the final row and column, like this: + * @returns {Point} Contains the final row and column, like this: * ``` * {row: endRow, column: 0} * ``` @@ -362,7 +362,6 @@ class Document { * ``` * {row: row, column: 0} * ``` - **/ insertMergedLines(position, lines) { var start = this.clippedPos(position.row, position.column); @@ -383,8 +382,8 @@ class Document { /** * Removes the `range` from the document. - * @param {import("../ace-internal").Ace.IRange} range A specified Range to remove - * @returns {import("../ace-internal").Ace.Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. + * @param {IRange} range A specified Range to remove + * @returns {Point} Returns the new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -404,7 +403,7 @@ class Document { * @param {Number} row The row to remove from * @param {Number} startColumn The column to start removing at * @param {Number} endColumn The column to stop removing at - * @returns {import("../ace-internal").Ace.Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. + * @returns {Point} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.
If `startColumn` is equal to `endColumn`, this function returns nothing. **/ removeInLine(row, startColumn, endColumn) { @@ -461,7 +460,7 @@ class Document { /** * Removes the new line between `row` and the row immediately following it. This method also triggers the `"change"` event. * @param {Number} row The row to check - + * **/ removeNewLine(row) { if (row < this.getLength() - 1 && row >= 0) { @@ -476,13 +475,13 @@ class Document { /** * Replaces a range in the document with the new `text`. - * @param {Range | import("../ace-internal").Ace.IRange} range A specified Range to replace + * @param {Range | IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement - * @returns {import("../ace-internal").Ace.Point} Returns an object containing the final row and column, like this: + * @returns {Point} Returns an object containing the final row and column, like this: * {row: endRow, column: 0} * If the text and range are empty, this function returns an object containing the current `range.start` value. * If the text is the exact same as what currently exists, this function returns an object containing the current `range.end` value. - + * **/ replace(range, text) { if (!(range instanceof Range)) @@ -510,8 +509,7 @@ class Document { /** * Applies all changes in `deltas` to the document. - * @param {import("../ace-internal").Ace.Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) - + * @param {Delta[]} deltas An array of delta objects (can include "insert" and "remove" actions) **/ applyDeltas(deltas) { for (var i=0; i=0; i--) { @@ -532,9 +529,8 @@ class Document { /** * Applies `delta` to the document. - * @param {import("../ace-internal").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) + * @param {Delta} delta A delta object (can include "insert" and "remove" actions) * @param {boolean} [doNotValidate] - **/ applyDelta(delta, doNotValidate) { var isInsert = delta.action == "insert"; @@ -554,8 +550,7 @@ class Document { } /** - * @param {import("../ace-internal").Ace.Delta} delta - + * @param {Delta} delta */ $safeApplyDelta(delta) { var docLength = this.$lines.length; @@ -570,9 +565,8 @@ class Document { /** * - * @param {import("../ace-internal").Ace.Delta} delta + * @param {Delta} delta * @param {number} MAX - */ $splitAndapplyLargeDelta(delta, MAX) { // Split large insert deltas. This is necessary because: @@ -608,8 +602,7 @@ class Document { /** * Reverts `delta` from the document. - * @param {import("../ace-internal").Ace.Delta} delta A delta object (can include "insert" and "remove" actions) - + * @param {Delta} delta A delta object (can include "insert" and "remove" actions) **/ revertDelta(delta) { this.$safeApplyDelta({ @@ -634,7 +627,7 @@ class Document { * * @param {Number} index An index to convert * @param {Number} [startRow=0] The row from which to start the conversion - * @returns {import("../ace-internal").Ace.Point} A `{row, column}` object of the `index` position + * @returns {Point} A `{row, column}` object of the `index` position */ indexToPosition(index, startRow) { var lines = this.$lines || this.getAllLines(); @@ -659,7 +652,7 @@ class Document { * * Here, `y` is an index 15: 11 characters for the first row, and 5 characters until `y` in the second. * - * @param {import("../ace-internal").Ace.Point} pos The `{row, column}` to convert + * @param {Point} pos The `{row, column}` to convert * @param {Number} [startRow=0] The row from which to start the conversion * @returns {Number} The index position in the document */ diff --git a/src/edit_session.js b/src/edit_session.js index db0d7f65874..3a14f596977 100644 --- a/src/edit_session.js +++ b/src/edit_session.js @@ -1,12 +1,11 @@ "use strict"; /** + * @typedef {import("./layer/font_metrics").FontMetrics} FontMetrics * @typedef {import("./edit_session/fold_line").FoldLine} FoldLine - */ -/** * @typedef {import("../ace-internal").Ace.Point} Point - */ -/** - * @typedef {import("./layer/font_metrics").FontMetrics} FontMetrics + * @typedef {import("../ace-internal").Ace.Delta} Delta + * @typedef {import("../ace-internal").Ace.IRange} IRange + * @typedef {import("../ace-internal").Ace.SyntaxMode} SyntaxMode */ var oop = require("./lib/oop"); @@ -24,7 +23,7 @@ var UndoManager = require("./undomanager").UndoManager; /** * @typedef TextMode - * @type {import("../ace-internal").Ace.SyntaxMode} + * @type {SyntaxMode} */ /** @@ -36,7 +35,7 @@ class EditSession { /** * Sets up a new `EditSession` and associates it with the given `Document` and `Mode`. * @param {Document | String} [text] [If `text` is a `Document`, it associates the `EditSession` with it. Otherwise, a new `Document` is created, with the initial text]{: #textParam} - * @param {import("../ace-internal").Ace.SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} + * @param {SyntaxMode} [mode] [The initial language mode to use for the document]{: #modeParam} **/ constructor(text, mode) { /**@type {Document}*/this.doc; @@ -160,7 +159,7 @@ class EditSession { /** * - * @param {import("../ace-internal").Ace.Delta} delta + * @param {Delta} delta */ onChange(delta) { this.$modified = true; @@ -203,28 +202,29 @@ class EditSession { /** * Returns a new instance of EditSession with state from JSON. * @method fromJSON - * @param {string} session The EditSession state. + * @param {string|object} session The EditSession state. * @returns {EditSession} */ - static fromJSON(session) { - session = JSON.parse(session); + static fromJSON(session) { + if (typeof session == "string") + session = JSON.parse(session); const undoManager = new UndoManager(); - undoManager.$undoStack = /**@type{Object}*/(session).history.undo; - undoManager.$redoStack = /**@type{Object}*/(session).history.redo; - undoManager.mark = /**@type{Object}*/(session).history.mark; - undoManager.$rev = /**@type{Object}*/(session).history.rev; + undoManager.$undoStack = session.history.undo; + undoManager.$redoStack = session.history.redo; + undoManager.mark = session.history.mark; + undoManager.$rev = session.history.rev; - const editSession = new EditSession(/**@type{Object}*/(session).value); - /**@type{Object}*/(session).folds.forEach(function(fold) { + const editSession = new EditSession(session.value); + session.folds.forEach(function(fold) { editSession.addFold("...", Range.fromPoints(fold.start, fold.end)); }); - editSession.setAnnotations(/**@type{Object}*/(session).annotations); - editSession.setBreakpoints(/**@type{Object}*/(session).breakpoints); - editSession.setMode(/**@type{Object}*/(session).mode); - editSession.setScrollLeft(/**@type{Object}*/(session).scrollLeft); - editSession.setScrollTop(/**@type{Object}*/(session).scrollTop); + editSession.setAnnotations(session.annotations); + editSession.setBreakpoints(session.breakpoints); + editSession.setMode(session.mode); + editSession.setScrollLeft(session.scrollLeft); + editSession.setScrollTop(session.scrollTop); editSession.setUndoManager(undoManager); - editSession.selection.fromJSON(/**@type{Object}*/(session).selection); + editSession.selection.fromJSON(session.selection); return editSession; } @@ -604,7 +604,6 @@ class EditSession { } /** - * * @param {RegExp} re */ highlight(re) { @@ -784,7 +783,7 @@ class EditSession { /** * Sets a new text mode for the `EditSession`. This method also emits the `'changeMode'` event. If a [[BackgroundTokenizer `BackgroundTokenizer`]] is set, the `'tokenizerUpdate'` event is also emitted. - * @param {import("../ace-internal").Ace.SyntaxMode | string} mode Set a new text mode + * @param {SyntaxMode | string} mode Set a new text mode * @param {() => void} [cb] optional callback **/ setMode(mode, cb) { @@ -830,7 +829,6 @@ class EditSession { } /** - * * @param mode * @param [$isPlaceholder] */ @@ -1033,7 +1031,7 @@ class EditSession { /** * {:Document.getTextRange.desc} - * @param {import("../ace-internal").Ace.IRange} [range] The range to work with + * @param {IRange} [range] The range to work with * * @returns {String} **/ @@ -1053,7 +1051,7 @@ class EditSession { /** * Removes the `range` from the document. - * @param {import("../ace-internal").Ace.IRange} range A specified Range to remove + * @param {IRange} range A specified Range to remove * @returns {Point} The new `start` property of the range, which contains `startRow` and `startColumn`. If `range` is empty, this function returns the unmodified value of `range.start`. **/ remove(range) { @@ -1075,7 +1073,7 @@ class EditSession { /** * Reverts previous changes to your document. - * @param {import("../ace-internal").Ace.Delta[]} deltas An array of previous changes + * @param {Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] [If `true`, doesn't select the range of where the change occured]{: #dontSelect} **/ undoChanges(deltas, dontSelect) { @@ -1104,7 +1102,7 @@ class EditSession { /** * Re-implements a previously undone change to your document. - * @param {import("../ace-internal").Ace.Delta[]} deltas An array of previous changes + * @param {Delta[]} deltas An array of previous changes * @param {Boolean} [dontSelect] {:dontSelect} **/ redoChanges(deltas, dontSelect) { @@ -1141,7 +1139,7 @@ class EditSession { /** * - * @param {import("../ace-internal").Ace.Delta[]} deltas + * @param {Delta[]} deltas * @param {boolean} [isUndo] * @return {Range} */ @@ -1186,7 +1184,7 @@ class EditSession { /** * Replaces a range in the document with the new `text`. * - * @param {import("../ace-internal").Ace.IRange} range A specified Range to replace + * @param {IRange} range A specified Range to replace * @param {String} text The new text to use as a replacement * @returns {Point} An object containing the final row and column, like this: * ``` @@ -1410,7 +1408,6 @@ class EditSession { } /** - * * @param {Range} range * @returns {Range} */ @@ -1563,8 +1560,7 @@ class EditSession { } /** - * - * @param {import("../ace-internal").Ace.Delta} delta + * @param {Delta} delta */ $updateInternalDataOnChange(delta) { var useWrapMode = this.$useWrapMode; @@ -1675,7 +1671,6 @@ class EditSession { } /** - * * @param {number} firstRow * @param {number} lastRow */ @@ -1685,7 +1680,6 @@ class EditSession { } /** - * * @param {number} firstRow * @param {number} lastRow */ @@ -1734,7 +1728,6 @@ class EditSession { } /** - * * @param {number[]}tokens * @param {number} wrapLimit * @param {number} tabSize diff --git a/src/edit_session/bracket_match.js b/src/edit_session/bracket_match.js index ebe0c0deb76..53c182c417e 100644 --- a/src/edit_session/bracket_match.js +++ b/src/edit_session/bracket_match.js @@ -1,6 +1,7 @@ "use strict"; /** * @typedef {import("../edit_session").EditSession} EditSession + * @typedef {import("../edit_session").Point} Point */ var TokenIterator = require("../token_iterator").TokenIterator; var Range = require("../range").Range; @@ -9,7 +10,7 @@ function BracketMatch() { /** * - * @param {import("../../ace-internal").Ace.Point} position + * @param {Point} position * @param {string} [chr] * @this {EditSession} */ @@ -30,7 +31,7 @@ function BracketMatch() { }; /** - * @param {import("../../ace-internal").Ace.Point} pos + * @param {Point} pos * @return {null|Range} * @this {EditSession} */ @@ -80,7 +81,7 @@ function BracketMatch() { * * two Ranges if there is opening and closing brackets; * * one Range if there is only one bracket * - * @param {import("../../ace-internal").Ace.Point} pos + * @param {Point} pos * @param {boolean} [isBackwards] * @returns {null|Range[]} * @this {EditSession} @@ -126,9 +127,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {import("../../ace-internal").Ace.Point} position + * @param {Point} position * @param {RegExp} [typeRe] - * @return {import("../../ace-internal").Ace.Point|null} + * @return {Point|null} * @this {EditSession} */ this.$findOpeningBracket = function(bracket, position, typeRe) { @@ -192,9 +193,9 @@ function BracketMatch() { /** * * @param {string} bracket - * @param {import("../../ace-internal").Ace.Point} position + * @param {Point} position * @param {RegExp} [typeRe] - * @return {import("../../ace-internal").Ace.Point|null} + * @return {Point|null} * @this {EditSession} */ this.$findClosingBracket = function(bracket, position, typeRe) { @@ -257,7 +258,7 @@ function BracketMatch() { /** * Returns [[Range]]'s for matching tags and tag names, if there are any - * @param {import("../../ace-internal").Ace.Point} pos + * @param {Point} pos * @returns {{closeTag: Range, closeTagName: Range, openTag: Range, openTagName: Range} | undefined} * @this {EditSession} */ diff --git a/src/edit_session/fold.js b/src/edit_session/fold.js index bcb3616593e..fe2b9d5dc6c 100644 --- a/src/edit_session/fold.js +++ b/src/edit_session/fold.js @@ -1,9 +1,9 @@ "use strict"; /** * @typedef {import("./fold_line").FoldLine} FoldLine - */ -/** * @typedef {import("../range").Range} Range + * @typedef {import("../../ace-internal").Ace.Point} Point + * @typedef {import("../../ace-internal").Ace.IRange} IRange */ var RangeList = require("../range_list").RangeList; @@ -98,7 +98,7 @@ class Fold extends RangeList { } /** - * @param {import("../../ace-internal").Ace.IRange} range + * @param {IRange} range */ restoreRange(range) { return restoreRange(range, this.start); @@ -107,8 +107,8 @@ class Fold extends RangeList { } /** - * @param {import("../../ace-internal").Ace.Point} point - * @param {import("../../ace-internal").Ace.Point} anchor + * @param {Point} point + * @param {Point} anchor */ function consumePoint(point, anchor) { point.row -= anchor.row; @@ -116,16 +116,16 @@ function consumePoint(point, anchor) { point.column -= anchor.column; } /** - * @param {import("../../ace-internal").Ace.IRange} range - * @param {import("../../ace-internal").Ace.Point} anchor + * @param {IRange} range + * @param {Point} anchor */ function consumeRange(range, anchor) { consumePoint(range.start, anchor); consumePoint(range.end, anchor); } /** - * @param {import("../../ace-internal").Ace.Point} point - * @param {import("../../ace-internal").Ace.Point} anchor + * @param {Point} point + * @param {Point} anchor */ function restorePoint(point, anchor) { if (point.row == 0) @@ -133,8 +133,8 @@ function restorePoint(point, anchor) { point.row += anchor.row; } /** - * @param {import("../../ace-internal").Ace.IRange} range - * @param {import("../../ace-internal").Ace.Point} anchor + * @param {IRange} range + * @param {Point} anchor */ function restoreRange(range, anchor) { restorePoint(range.start, anchor); diff --git a/src/edit_session/fold_line.js b/src/edit_session/fold_line.js index f105835e6bc..892fd128e73 100644 --- a/src/edit_session/fold_line.js +++ b/src/edit_session/fold_line.js @@ -44,7 +44,6 @@ class FoldLine { } /** - * * @param {Fold} fold */ addFold(fold) { diff --git a/src/edit_session/folding.js b/src/edit_session/folding.js index 627932d9f1c..a4c6b3959ce 100644 --- a/src/edit_session/folding.js +++ b/src/edit_session/folding.js @@ -9,6 +9,7 @@ var MouseEvent = require("../mouse/mouse_event").MouseEvent; /** * @typedef {import("../edit_session").EditSession & import("../../ace-internal").Ace.Folding} IFolding + * @typedef {import("../ace-internal").Ace.Delta } Delta */ /** @@ -46,7 +47,7 @@ function Folding() { /** * Returns all folds in the given range. Note, that this will return folds - * @param {Range| import("../../ace-internal").Ace.Delta} range + * @param {Range| Delta} range * @returns {Fold[]} **/ this.getFoldsInRange = function(range) { @@ -1005,7 +1006,7 @@ function Folding() { }; /** - * @param {import("../../ace-internal").Ace.Delta} delta + * @param {Delta} delta */ this.updateFoldWidgets = function(delta) { var firstRow = delta.start.row; diff --git a/src/editor.js b/src/editor.js index 3f8368aab82..b088521e0cb 100644 --- a/src/editor.js +++ b/src/editor.js @@ -2,9 +2,9 @@ /** * @typedef {import("./virtual_renderer").VirtualRenderer} VirtualRenderer - */ -/** * @typedef {import("./selection").Selection} Selection + * @typedef {import("../ace-internal").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.SearchOptions} SearchOptions */ var oop = require("./lib/oop"); @@ -653,7 +653,7 @@ class Editor { */ $updateHighlightActiveLine() { var session = this.getSession(); - /**@type {import("../ace-internal").Ace.Point|false}*/ + /**@type {Point|false}*/ var highlight; if (this.$highlightActiveLine) { if (this.$selectionStyle != "line" || !this.selection.isMultiLine()) @@ -1462,7 +1462,7 @@ class Editor { * inline in the editor such as, for example, code completions. * * @param {String} text Text to be inserted as "ghost" text - * @param {import("../ace-internal").Ace.Point} [position] Position to insert text to + * @param {Point} [position] Position to insert text to */ setGhostText(text, position) { if (!this.session.widgetManager) { @@ -1850,7 +1850,7 @@ class Editor { * { row: newRowLocation, column: newColumnLocation } * ``` * @param {Range} range The range of text you want moved within the document - * @param {import("../ace-internal").Ace.Point} toPosition The location (row and column) where you want to move the text to + * @param {Point} toPosition The location (row and column) where you want to move the text to * @param {boolean} [copy] * * @returns {Range} The new range where the text was moved to. @@ -2113,7 +2113,7 @@ class Editor { /** * Gets the current position of the cursor. - * @returns {import("../ace-internal").Ace.Point} An object that looks something like this: + * @returns {Point} An object that looks something like this: * * ```json * { row: currRow, column: currCol } @@ -2127,7 +2127,7 @@ class Editor { /** * Returns the screen position of the cursor. - * @returns {import("../ace-internal").Ace.Point} + * @returns {Point} * @related EditSession.documentToScreenPosition **/ getCursorPositionScreen() { @@ -2171,7 +2171,7 @@ class Editor { /** * Moves the cursor to the position indicated by `pos.row` and `pos.column`. - * @param {import("../ace-internal").Ace.Point} pos An object with two properties, row and column + * @param {Point} pos An object with two properties, row and column * @related Selection.moveCursorToPosition **/ moveCursorToPosition(pos) { @@ -2480,7 +2480,7 @@ class Editor { /** * Replaces the first occurrence of `options.needle` with the value in `replacement`. * @param {String} [replacement] The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replace(replacement, options) { @@ -2505,7 +2505,7 @@ class Editor { /** * Replaces all occurrences of `options.needle` with the value in `replacement`. * @param {String} [replacement] The text to replace with - * @param {Partial} [options] The [[Search `Search`]] options to use + * @param {Partial} [options] The [[Search `Search`]] options to use * @return {number} **/ replaceAll(replacement, options) { @@ -2550,7 +2550,7 @@ class Editor { /** * {:Search.getOptions} For more information on `options`, see [[Search `Search`]]. * @related Search.getOptions - * @returns {Partial} + * @returns {Partial} **/ getLastSearchOptions() { return this.$search.getOptions(); @@ -2559,7 +2559,7 @@ class Editor { /** * Attempts to find `needle` within the document. For more information on `options`, see [[Search `Search`]]. * @param {String|RegExp|Object} needle The text to search for (optional) - * @param {Partial} [options] An object defining various search properties + * @param {Partial} [options] An object defining various search properties * @param {Boolean} [animate] If `true` animate scrolling * @related Search.find **/ @@ -2604,7 +2604,7 @@ class Editor { /** * Performs another search for `needle` in the document. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find @@ -2615,7 +2615,7 @@ class Editor { /** * Performs a search for `needle` backwards. For more information on `options`, see [[Search `Search`]]. - * @param {Partial} [options] search options + * @param {Partial} [options] search options * @param {Boolean} [animate] If `true` animate scrolling * * @related Editor.find diff --git a/src/ext/code_lens.js b/src/ext/code_lens.js index b6fee2355a1..7a2c89a1228 100644 --- a/src/ext/code_lens.js +++ b/src/ext/code_lens.js @@ -1,8 +1,6 @@ "use strict"; /** * @typedef {import("../edit_session").EditSession} EditSession - */ -/** * @typedef {import("../virtual_renderer").VirtualRenderer & {$textLayer: import("../layer/text").Text &{$lenses}}} VirtualRenderer */ diff --git a/src/ext/command_bar.js b/src/ext/command_bar.js index 8c60280b69d..4ee68c31e07 100644 --- a/src/ext/command_bar.js +++ b/src/ext/command_bar.js @@ -1,5 +1,6 @@ /** * @typedef {import("../editor").Editor} Editor + * @typedef {import("../../ace-internal").Ace.TooltipCommand} TooltipCommand */ var Tooltip = require("../tooltip").Tooltip; var EventEmitter = require("../lib/event_emitter").EventEmitter; @@ -90,7 +91,7 @@ class CommandBarTooltip { * toolbar, the remaining elements are added to the overflow menu. * * @param {string} id - * @param {import("../../ace-internal").Ace.TooltipCommand} command + * @param {TooltipCommand} command */ registerCommand(id, command) { var registerForMainTooltip = Object.keys(this.commands).length < this.maxElementsOnTooltip; @@ -288,7 +289,7 @@ class CommandBarTooltip { /** * @param {string} id - * @param {import("../../ace-internal").Ace.TooltipCommand} command + * @param {TooltipCommand} command * @param {boolean} forMainTooltip */ $createCommand(id, command, forMainTooltip) { diff --git a/src/keyboard/hash_handler.js b/src/keyboard/hash_handler.js index edd8b2d6b0b..d445f5f2924 100644 --- a/src/keyboard/hash_handler.js +++ b/src/keyboard/hash_handler.js @@ -1,5 +1,9 @@ "use strict"; +/** + * @typedef {import("../../ace-internal").Ace.Command} Command + * @typedef {import("../../ace-internal").Ace.CommandLike} CommandLike +*/ /** @type {any} */var keyUtil = require("../lib/keys"); var useragent = require("../lib/useragent"); @@ -7,7 +11,7 @@ var KEY_MODS = keyUtil.KEY_MODS; class MultiHashHandler { /** - * @param {Record | import("../../ace-internal").Ace.Command[]} [config] + * @param {Record | Command[]} [config] * @param {string} [platform] */ constructor(config, platform) { @@ -15,13 +19,13 @@ class MultiHashHandler { } /** - * @param {Record | import("../../ace-internal").Ace.Command[]} config + * @param {Record | Command[]} config * @param {string} [platform] * @param {boolean} [$singleCommand] */ $init(config, platform, $singleCommand) { this.platform = platform || (useragent.isMac ? "mac" : "win"); - /**@type {Record}*/ + /**@type {Record}*/ this.commands = {}; this.commandKeyBinding = {}; this.addCommands(config); @@ -29,7 +33,7 @@ class MultiHashHandler { } /** - * @param {import("../../ace-internal").Ace.Command} command + * @param {Command} command */ addCommand(command) { if (this.commands[command.name]) @@ -42,7 +46,7 @@ class MultiHashHandler { } /** - * @param {import("../../ace-internal").Ace.Command | string} command + * @param {Command | string} command * @param {boolean} [keepCommand] */ removeCommand(command, keepCommand) { @@ -71,7 +75,7 @@ class MultiHashHandler { /** * @param {string | { win?: string; mac?: string; position?:number}} key - * @param {import("../../ace-internal").Ace.CommandLike | string} command + * @param {CommandLike | string} command * @param {number} [position] */ bindKey(key, command, position) { @@ -138,7 +142,7 @@ class MultiHashHandler { } /** - * @param {Record | import("../../ace-internal").Ace.Command[]} [commands] + * @param {Record | Command[]} [commands] */ addCommands(commands) { commands && Object.keys(commands).forEach(function(name) { @@ -163,7 +167,7 @@ class MultiHashHandler { } /** - * @param {Record} commands + * @param {Record} commands */ removeCommands(commands) { Object.keys(commands).forEach(function(name) { @@ -172,7 +176,7 @@ class MultiHashHandler { } /** - * @param {Record} keyList + * @param {Record} keyList */ bindKeys(keyList) { Object.keys(keyList).forEach(function(key) { @@ -218,7 +222,7 @@ class MultiHashHandler { /** * @param {number} hashId * @param {string} keyString - * @returns {import("../../ace-internal").Ace.Command} + * @returns {Command} */ findKeyCommand(hashId, keyString) { var key = KEY_MODS[hashId] + keyString; @@ -276,7 +280,7 @@ function getPosition(command) { class HashHandler extends MultiHashHandler { /** - * @param {Record | import("../../ace-internal").Ace.Command[]} [config] + * @param {Record | Command[]} [config] * @param {string} [platform] */ constructor(config, platform) { diff --git a/src/keyboard/keybinding.js b/src/keyboard/keybinding.js index 7ea0d2b7058..5de3ab8251c 100644 --- a/src/keyboard/keybinding.js +++ b/src/keyboard/keybinding.js @@ -1,6 +1,7 @@ "use strict"; /** * @typedef {import("../editor").Editor} Editor + * @typedef {import("../../ace-internal").Ace.KeyboardHandler} KeyboardHandler */ var keyUtil = require("../lib/keys"); var event = require("../lib/event"); @@ -13,13 +14,13 @@ class KeyBinding { constructor(editor) { this.$editor = editor; this.$data = {editor: editor}; - /**@type {(import("../../ace-internal").Ace.KeyboardHandler)[]}*/ + /**@type {(KeyboardHandler)[]}*/ this.$handlers = []; this.setDefaultHandler(editor.commands); } /** - * @param {import("../../ace-internal").Ace.KeyboardHandler} kb + * @param {KeyboardHandler} kb */ setDefaultHandler(kb) { this.removeKeyboardHandler(this.$defaultHandler); @@ -28,7 +29,7 @@ class KeyBinding { } /** - * @param {import("../../ace-internal").Ace.KeyboardHandler} kb + * @param {KeyboardHandler} kb */ setKeyboardHandler(kb) { var h = this.$handlers; @@ -42,7 +43,7 @@ class KeyBinding { } /** - * @param {import("../../ace-internal").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] + * @param {KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} [kb] * @param {number} [pos] */ addKeyboardHandler(kb, pos) { @@ -66,7 +67,7 @@ class KeyBinding { } /** - * @param {import("../../ace-internal").Ace.KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb + * @param {KeyboardHandler & {attach?: (editor: any) => void, detach?: (editor: any) => void;}} kb * @returns {boolean} */ removeKeyboardHandler(kb) { @@ -79,7 +80,7 @@ class KeyBinding { } /** - * @return {import("../../ace-internal").Ace.KeyboardHandler} + * @return {KeyboardHandler} */ getKeyboardHandler() { return this.$handlers[this.$handlers.length - 1]; diff --git a/src/layer/gutter.js b/src/layer/gutter.js index bfecc0a0899..4b87b803bf1 100644 --- a/src/layer/gutter.js +++ b/src/layer/gutter.js @@ -1,6 +1,7 @@ "use strict"; /** * @typedef {import("../edit_session").EditSession} EditSession + * @typedef {import("../../ace-internal").Ace.LayerConfig} LayerConfig */ var dom = require("../lib/dom"); var oop = require("../lib/oop"); @@ -113,7 +114,7 @@ class Gutter{ } /** - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config */ update(config) { this.config = config; @@ -166,7 +167,7 @@ class Gutter{ } /** - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config */ $updateGutterWidth(config) { var session = this.session; @@ -234,7 +235,7 @@ class Gutter{ } /** - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config */ scrollLines(config) { var oldConfig = this.config; @@ -280,7 +281,7 @@ class Gutter{ } /** - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config * @param {number} firstRow * @param {number} lastRow */ @@ -311,7 +312,7 @@ class Gutter{ /** * @param {any} cell - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config * @param {import("../../ace-internal").Ace.IRange | undefined} fold * @param {number} row */ diff --git a/src/layer/lines.js b/src/layer/lines.js index ad54099d1aa..ae0cb71e262 100644 --- a/src/layer/lines.js +++ b/src/layer/lines.js @@ -1,6 +1,7 @@ "use strict"; /** * @typedef {import("../edit_session").EditSession} EditSession + * @typedef {import("../../ace-internal").Ace.LayerConfig} LayerConfig */ var dom = require("../lib/dom"); @@ -20,15 +21,15 @@ class Lines { } /** - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config */ moveContainer(config) { dom.translate(this.element, 0, -((config.firstRowScreen * config.lineHeight) % this.canvasHeight) - config.offset * this.$offsetCoefficient); } /** - * @param {import("../../ace-internal").Ace.LayerConfig} oldConfig - * @param {import("../../ace-internal").Ace.LayerConfig} newConfig + * @param {LayerConfig} oldConfig + * @param {LayerConfig} newConfig */ pageChanged(oldConfig, newConfig) { return ( @@ -39,7 +40,7 @@ class Lines { /** * @param {number} row - * @param {Partial} config + * @param {Partial} config * @param {EditSession} session */ computeLineTop(row, config, session) { @@ -51,7 +52,7 @@ class Lines { /** * @param {number} row - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config * @param {EditSession} session */ computeLineHeight(row, config, session) { diff --git a/src/layer/marker.js b/src/layer/marker.js index 21e3da1c981..935e1b8a4c4 100644 --- a/src/layer/marker.js +++ b/src/layer/marker.js @@ -1,6 +1,7 @@ "use strict"; /** * @typedef {import("../edit_session").EditSession} EditSession + * @typedef {import("../../ace-internal").Ace.LayerConfig} LayerConfig */ var Range = require("../range").Range; var dom = require("../lib/dom"); @@ -56,7 +57,7 @@ class Marker { } /** - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config */ update(config) { if (!config) return; @@ -102,7 +103,7 @@ class Marker { /** * @param {number} row - * @param {Partial} layerConfig + * @param {Partial} layerConfig */ $getTop(row, layerConfig) { return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; @@ -114,7 +115,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} layerConfig + * @param {Partial} layerConfig * @param {string} [extraStyle] */ drawTextMarker(stringBuilder, range, clazz, layerConfig, extraStyle) { @@ -145,7 +146,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {import("../../ace-internal").Ace.LayerConfig} config + * @param {LayerConfig} config * @param {string} [extraStyle] */ drawMultiLineMarker(stringBuilder, range, clazz, config, extraStyle) { @@ -207,7 +208,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {number} [extraLength] * @param {string} [extraStyle] */ @@ -234,7 +235,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {number} extraLength * @param {string} extraStyle */ @@ -257,7 +258,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {undefined} [extraStyle] */ drawFullLineMarker(stringBuilder, range, clazz, config, extraStyle) { @@ -278,7 +279,7 @@ class Marker { * @param {undefined} stringBuilder * @param {Range} range * @param {string} clazz - * @param {Partial} config + * @param {Partial} config * @param {undefined} [extraStyle] */ drawScreenLineMarker(stringBuilder, range, clazz, config, extraStyle) { diff --git a/src/lib/event.js b/src/lib/event.js index ecf7566cf21..3c7c5504647 100644 --- a/src/lib/event.js +++ b/src/lib/event.js @@ -96,7 +96,6 @@ exports.capture = function(el, eventHandler, releaseCaptureHandler) { }; /** - * * @param el * @param callback * @param [destroyer] @@ -128,7 +127,6 @@ exports.addMouseWheelListener = function(el, callback, destroyer) { }; /** - * * @param elements * @param timeouts * @param eventHandler @@ -249,52 +247,34 @@ function normalizeCommandKeys(callback, e, keyCode) { } /** - * * @param el * @param callback * @param [destroyer] */ exports.addCommandKeyListener = function(el, callback, destroyer) { - // @ts-expect-error TODO: property is missing in useragent - if (useragent.isOldGecko || (useragent.isOpera && !("KeyboardEvent" in window))) { - // Old versions of Gecko aka. Firefox < 4.0 didn't repeat the keydown - // event if the user pressed the key for a longer time. Instead, the - // keydown event was fired once and later on only the keypress event. - // To emulate the 'right' keydown behavior, the keyCode of the initial - // keyDown event is stored and in the following keypress events the - // stores keyCode is used to emulate a keyDown event. - var lastKeyDownKeyCode = null; - addListener(el, "keydown", function(e) { - lastKeyDownKeyCode = e.keyCode; - }, destroyer); - addListener(el, "keypress", function(e) { - return normalizeCommandKeys(callback, e, lastKeyDownKeyCode); - }, destroyer); - } else { - var lastDefaultPrevented = null; - - addListener(el, "keydown", function(e) { - pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1; - var result = normalizeCommandKeys(callback, e, e.keyCode); - lastDefaultPrevented = e.defaultPrevented; - return result; - }, destroyer); - - addListener(el, "keypress", function(e) { - if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) { - exports.stopEvent(e); - lastDefaultPrevented = null; - } - }, destroyer); + var lastDefaultPrevented = null; - addListener(el, "keyup", function(e) { - pressedKeys[e.keyCode] = null; - }, destroyer); + addListener(el, "keydown", function(e) { + pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1; + var result = normalizeCommandKeys(callback, e, e.keyCode); + lastDefaultPrevented = e.defaultPrevented; + return result; + }, destroyer); - if (!pressedKeys) { - resetPressedKeys(); - addListener(window, "focus", resetPressedKeys); + addListener(el, "keypress", function(e) { + if (lastDefaultPrevented && (e.ctrlKey || e.altKey || e.shiftKey || e.metaKey)) { + exports.stopEvent(e); + lastDefaultPrevented = null; } + }, destroyer); + + addListener(el, "keyup", function(e) { + pressedKeys[e.keyCode] = null; + }, destroyer); + + if (!pressedKeys) { + resetPressedKeys(); + addListener(window, "focus", resetPressedKeys); } }; function resetPressedKeys() { diff --git a/src/line_widgets.js b/src/line_widgets.js index ba920c64aa7..55db6f6ccc9 100644 --- a/src/line_widgets.js +++ b/src/line_widgets.js @@ -1,12 +1,9 @@ "use strict"; /** * @typedef {import("./edit_session").EditSession} EditSession - */ -/** * @typedef {import("./editor").Editor} Editor - */ -/** * @typedef {import("./virtual_renderer").VirtualRenderer} VirtualRenderer + * @typedef {import("../ace-internal").Ace.LineWidget} LineWidget */ var dom = require("./lib/dom"); @@ -190,8 +187,8 @@ class LineWidgets { /** * - * @param {import("../ace-internal").Ace.LineWidget} w - * @return {import("../ace-internal").Ace.LineWidget} + * @param {LineWidget} w + * @return {LineWidget} */ $registerLineWidget(w) { if (!this.session.lineWidgets) @@ -212,8 +209,8 @@ class LineWidgets { /** * - * @param {import("../ace-internal").Ace.LineWidget} w - * @return {import("../ace-internal").Ace.LineWidget} + * @param {LineWidget} w + * @return {LineWidget} */ addLineWidget(w) { this.$registerLineWidget(w); @@ -270,7 +267,7 @@ class LineWidgets { } /** - * @param {import("../ace-internal").Ace.LineWidget} w + * @param {LineWidget} w */ removeLineWidget(w) { w._inDocument = false; @@ -303,7 +300,7 @@ class LineWidgets { /** * * @param {number} row - * @return {import("../ace-internal").Ace.LineWidget[]} + * @return {LineWidget[]} */ getWidgetsAtRow(row) { var lineWidgets = this.session.lineWidgets; @@ -317,7 +314,7 @@ class LineWidgets { } /** - * @param {import("../ace-internal").Ace.LineWidget} w + * @param {LineWidget} w */ onWidgetChanged(w) { this.session._changedWidgets.push(w); diff --git a/src/marker_group.js b/src/marker_group.js index 39f8d28c25b..07b431724bd 100644 --- a/src/marker_group.js +++ b/src/marker_group.js @@ -1,8 +1,6 @@ "use strict"; /** * @typedef {import("./edit_session").EditSession} EditSession - */ -/** * @typedef {{range: import("./range").Range, className: string}} MarkerGroupItem */ /** diff --git a/src/mouse/default_handlers.js b/src/mouse/default_handlers.js index 1b0c9c4d63a..d04954df8a9 100644 --- a/src/mouse/default_handlers.js +++ b/src/mouse/default_handlers.js @@ -1,8 +1,6 @@ "use strict"; /** * @typedef {import("./mouse_handler").MouseHandler} MouseHandler - */ -/** * @typedef {import("./mouse_event").MouseEvent} MouseEvent */ var useragent = require("../lib/useragent"); diff --git a/src/multi_select.js b/src/multi_select.js index 9b265b614c4..d639f359ff5 100644 --- a/src/multi_select.js +++ b/src/multi_select.js @@ -1,5 +1,7 @@ /** * @typedef {import("./anchor").Anchor} Anchor + * @typedef {import("../ace-internal").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.ScreenCoordinates} ScreenCoordinates */ var RangeList = require("./range_list").RangeList; @@ -38,51 +40,6 @@ var EditSession = require("./edit_session").EditSession; }; }).call(EditSession.prototype); - - -/** - * - * @type {RangeList|null} - */ -Selection.prototype.rangeList = null; - -Selection.prototype.addRange = function(range, $blockChangeEvents) { - if (!range) - return; - - if (!this.inMultiSelectMode && this.rangeCount === 0) { - var oldRange = this.toOrientedRange(); - this.rangeList.add(oldRange); - this.rangeList.add(range); - if (this.rangeList.ranges.length != 2) { - this.rangeList.removeAll(); - return $blockChangeEvents || this.fromOrientedRange(range); - } - this.rangeList.removeAll(); - this.rangeList.add(oldRange); - this.$onAddRange(oldRange); - } - - if (!range.cursor) - range.cursor = range.end; - - var removed = this.rangeList.add(range); - - this.$onAddRange(range); - - if (removed.length) - this.$onRemoveRange(removed); - - if (this.rangeCount > 1 && !this.inMultiSelectMode) { - this._signal("multiSelect"); - this.inMultiSelectMode = true; - this.session.$undoSelect = false; - this.rangeList.attach(this.session); - } - - return $blockChangeEvents || this.fromOrientedRange(range); -}; - // extend Selection (function() { // list of ranges in reverse addition order @@ -150,7 +107,7 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { /** * Removes a Range containing pos (if it exists). - * @param {import("../ace-internal").Ace.Point} pos The position to remove, as a `{row, column}` object + * @param {Point} pos The position to remove, as a `{row, column}` object * @this {Selection} **/ this.substractPoint = function(pos) { @@ -182,7 +139,6 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { }; /** - * * @param {Range[]} removed * @this {Selection} */ @@ -297,11 +253,10 @@ Selection.prototype.addRange = function(range, $blockChangeEvents) { }; /** - * * Gets list of ranges composing rectangular block on the screen * - * @param {import("../ace-internal").Ace.ScreenCoordinates} screenCursor The cursor to use - * @param {import("../ace-internal").Ace.ScreenCoordinates} screenAnchor The anchor to use + * @param {ScreenCoordinates} screenCursor The cursor to use + * @param {ScreenCoordinates} screenAnchor The anchor to use * @param {Boolean} [includeEmptyLines] If true, this includes ranges inside the block which are empty due to clipping * @returns {Range[]} * @this {Selection} @@ -425,7 +380,6 @@ var Editor = require("./editor").Editor; }; /** - * * @param {(Range & {marker?})[]} ranges * @this {Editor} */ @@ -547,7 +501,6 @@ var Editor = require("./editor").Editor; var reg = selection._eventRegistry; selection._eventRegistry = {}; - /**@type {Selection}*/ var tmpSel = new Selection(session); this.inVirtualSelectionMode = true; for (var i = ranges.length; i--;) { @@ -614,7 +567,6 @@ var Editor = require("./editor").Editor; }; /** - * * @param e * @param {Anchor} anchor * @this {Editor} @@ -878,7 +830,6 @@ var Editor = require("./editor").Editor; }; /** - * * @param {string[]} lines * @param {boolean} [forceLeft] * @return {*} @@ -939,10 +890,7 @@ var Editor = require("./editor").Editor; }).call(Editor.prototype); -/** - * @param {import("../ace-internal").Ace.Point} p1 - * @param {import("../ace-internal").Ace.Point} p2 - */ +/** @param {Point} p1 @param {Point} p2 */ function isSamePoint(p1, p2) { return p1.row == p2.row && p1.column == p2.column; } diff --git a/src/occur.js b/src/occur.js index 6c5ed7ca986..734cd07b86e 100644 --- a/src/occur.js +++ b/src/occur.js @@ -1,6 +1,8 @@ "use strict"; /** * @typedef {import("./editor").Editor} Editor + * @typedef {import("../ace-internal").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.SearchOptions} SearchOptions */ var oop = require("./lib/oop"); @@ -66,7 +68,7 @@ class Occur extends Search { /** * @param {Editor} editor - * @param {Partial} options + * @param {Partial} options */ displayOccurContent(editor, options) { // this.setSession(session || new EditSession("")) @@ -97,8 +99,8 @@ class Occur extends Search { * the document or the beginning if the doc {row: 0, column: 0} if not * found. * @param {EditSession} session The occur session - * @param {import("../ace-internal").Ace.Point} pos The position in the original document - * @return {import("../ace-internal").Ace.Point} position in occur doc + * @param {Point} pos The position in the original document + * @return {Point} position in occur doc **/ originalToOccurPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -115,8 +117,8 @@ class Occur extends Search { * Translates the position from the occur document to the original document * or `pos` if not found. * @param {EditSession} session The occur session - * @param {import("../ace-internal").Ace.Point} pos The position in the occur session document - * @return {import("../ace-internal").Ace.Point} position + * @param {Point} pos The position in the occur session document + * @return {Point} position **/ occurToOriginalPosition(session, pos) { var lines = session.$occurMatchingLines; @@ -127,7 +129,7 @@ class Occur extends Search { /** * @param {EditSession} session - * @param {Partial} options + * @param {Partial} options */ matchingLines(session, options) { options = oop.mixin({}, options); diff --git a/src/range.js b/src/range.js index c483d57207a..321ad67d2d6 100644 --- a/src/range.js +++ b/src/range.js @@ -2,6 +2,8 @@ /** * @typedef {import("./edit_session").EditSession} EditSession + * @typedef {import("../ace-internal").Ace.IRange} IRange + * @typedef {import("../ace-internal").Ace.Point} Point */ /** * This object is used in various places to indicate a region within the editor. To better visualize how this works, imagine a rectangle. Each quadrant of the rectangle is analogous to a range, as ranges contain a starting row and starting column, and an ending row, and ending column. @@ -16,12 +18,12 @@ class Range { * @constructor **/ constructor(startRow, startColumn, endRow, endColumn) { - /**@type {import("../ace-internal").Ace.Point}*/ + /**@type {Point}*/ this.start = { row: startRow, column: startColumn }; - /**@type {import("../ace-internal").Ace.Point}*/ + /**@type {Point}*/ this.end = { row: endRow, column: endColumn @@ -30,7 +32,7 @@ class Range { /** * Returns `true` if and only if the starting row and column, and ending row and column, are equivalent to those given by `range`. - * @param {import("../ace-internal").Ace.IRange} range A range to check against + * @param {IRange} range A range to check against * @return {Boolean} **/ isEqual(range) { @@ -70,7 +72,7 @@ class Range { /** * Compares `this` range (A) with another range (B). - * @param {import("../ace-internal").Ace.IRange} range A range to compare with + * @param {IRange} range A range to compare with * @related [[Range.compare]] * @returns {Number} This method returns one of the following numbers: * * `-2`: (B) is in front of (A), and doesn't intersect with (A) @@ -111,7 +113,7 @@ class Range { /** * Compares the row and column of `p` with the starting and ending [[Point]]'s of the calling range (by calling [[Range.compare]]). - * @param {import("../ace-internal").Ace.Point} p A point to compare with + * @param {Point} p A point to compare with * @related [[Range.compare]] * @returns {Number} **/ @@ -121,7 +123,7 @@ class Range { /** * Checks the start and end [[Point]]'s of `range` and compares them to the calling range. Returns `true` if the `range` is contained within the caller's range. - * @param {import("../ace-internal").Ace.IRange} range A range to compare with + * @param {IRange} range A range to compare with * @returns {Boolean} * @related [[Range.comparePoint]] **/ @@ -131,7 +133,7 @@ class Range { /** * Returns `true` if passed in `range` intersects with the one calling this method. - * @param {import("../ace-internal").Ace.IRange} range A range to compare with + * @param {IRange} range A range to compare with * @returns {Boolean} **/ intersects(range) { @@ -161,7 +163,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|import("../ace-internal").Ace.Point} row A row to set + * @param {Number|Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -177,7 +179,7 @@ class Range { /** * Sets the starting row and column for the range. - * @param {Number|import("../ace-internal").Ace.Point} row A row to set + * @param {Number|Point} row A row to set * @param {Number} [column] A column to set * **/ @@ -442,8 +444,8 @@ class Range { /** * Creates and returns a new `Range` based on the `start` [[Point]] and `end` [[Point]] of the given parameters. - * @param {import("../ace-internal").Ace.Point} start A starting point to use - * @param {import("../ace-internal").Ace.Point} end An ending point to use + * @param {Point} start A starting point to use + * @param {Point} end An ending point to use * @returns {Range} **/ Range.fromPoints = function(start, end) { @@ -452,8 +454,8 @@ Range.fromPoints = function(start, end) { /** * Compares `p1` and `p2` [[Point]]'s, useful for sorting - * @param {import("../ace-internal").Ace.Point} p1 - * @param {import("../ace-internal").Ace.Point} p2 + * @param {Point} p1 + * @param {Point} p2 * @returns {Number} */ Range.comparePoints = function(p1, p2) { diff --git a/src/range_list.js b/src/range_list.js index 2120c97a446..463aea29a9e 100644 --- a/src/range_list.js +++ b/src/range_list.js @@ -1,6 +1,7 @@ "use strict"; /** * @typedef {import("./edit_session").EditSession} EditSession + * @typedef {import("../ace-internal").Ace.Point} Point */ var Range = require("./range").Range; var comparePoints = Range.comparePoints; @@ -13,7 +14,7 @@ class RangeList { } /** - * @param {import("../ace-internal").Ace.Point} pos + * @param {Point} pos * @param {boolean} [excludeEdges] * @param {number} [startIndex] * @return {number} @@ -67,7 +68,7 @@ class RangeList { } /** - * @param {import("../ace-internal").Ace.Point} pos + * @param {Point} pos */ substractPoint(pos) { var i = this.pointIndex(pos); @@ -121,14 +122,14 @@ class RangeList { } /** - * @param {import("../ace-internal").Ace.Point} pos + * @param {Point} pos */ containsPoint(pos) { return this.pointIndex(pos) >= 0; } /** - * @param {import("../ace-internal").Ace.Point} pos + * @param {Point} pos */ rangeAtPoint(pos) { var i = this.pointIndex(pos); diff --git a/src/search_highlight.js b/src/search_highlight.js index 4fb2faec625..6a5e864c74d 100644 --- a/src/search_highlight.js +++ b/src/search_highlight.js @@ -1,8 +1,6 @@ "use strict"; /** * @typedef {import("./layer/marker").Marker} Marker - */ -/** * @typedef {import("./edit_session").EditSession} EditSession */ var lang = require("./lib/lang"); diff --git a/src/selection.js b/src/selection.js index 45e357288b6..6ab284305af 100644 --- a/src/selection.js +++ b/src/selection.js @@ -6,9 +6,8 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter; var Range = require("./range").Range; /** * @typedef {import("./edit_session").EditSession} EditSession - */ -/** * @typedef {import("./anchor").Anchor} Anchor + * @typedef {import("../ace-internal").Ace.Point} Point */ class Selection { @@ -69,7 +68,7 @@ class Selection { /** * Returns an object containing the `row` and `column` current position of the cursor. - * @returns {import("../ace-internal").Ace.Point} + * @returns {Point} **/ getCursor() { return this.lead.getPosition(); @@ -90,7 +89,7 @@ class Selection { /** * Returns an object containing the `row` and `column` of the calling selection anchor. * - * @returns {import("../ace-internal").Ace.Point} + * @returns {Point} * @related Anchor.getPosition **/ getAnchor() { @@ -207,7 +206,7 @@ class Selection { /** * Moves the selection cursor to the row and column indicated by `pos`. - * @param {import("../ace-internal").Ace.Point} pos An object containing the row and column + * @param {Point} pos An object containing the row and column **/ selectToPosition(pos) { this.$moveSelection(function() { @@ -376,7 +375,7 @@ class Selection { /** * * Returns `true` if moving the character next to the cursor in the specified direction is a soft tab. - * @param {import("../ace-internal").Ace.Point} cursor the current cursor position + * @param {Point} cursor the current cursor position * @param {Number} tabSize the tab size * @param {Number} direction 1 for right, -1 for left */ @@ -433,7 +432,7 @@ class Selection { else { var tabSize = this.session.getTabSize(); /** - * @type {import("../ace-internal").Ace.Point} + * @type {Point} */ var cursor = this.lead; if (this.wouldMoveIntoSoftTab(cursor, tabSize, 1) && !this.session.getNavigateWithinSoftTabs()) { @@ -749,7 +748,7 @@ class Selection { /** * Moves the selection to the position indicated by its `row` and `column`. - * @param {import("../ace-internal").Ace.Point} position The position to move to + * @param {Point} position The position to move to **/ moveCursorToPosition(position) { this.moveCursorTo(position.row, position.column); diff --git a/src/tooltip.js b/src/tooltip.js index 511aae9d280..da6badf4092 100644 --- a/src/tooltip.js +++ b/src/tooltip.js @@ -1,11 +1,7 @@ "use strict"; /** * @typedef {import("./editor").Editor} Editor - */ -/** * @typedef {import("./mouse/mouse_event").MouseEvent} MouseEvent - */ -/** * @typedef {import("./edit_session").EditSession} EditSession */ diff --git a/src/undomanager.js b/src/undomanager.js index a5e2d71efe1..92c40fd3800 100644 --- a/src/undomanager.js +++ b/src/undomanager.js @@ -1,14 +1,9 @@ "use strict"; /** * @typedef {import("./edit_session").EditSession} EditSession - */ - -/** * @typedef {import("../ace-internal").Ace.Delta} Delta - */ - -/** * @typedef {import("../ace-internal").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.IRange} IRange */ /** @@ -602,8 +597,8 @@ function xform(d1, c1) { /** * - * @param {import("../ace-internal").Ace.IRange} d1 - * @param {import("../ace-internal").Ace.IRange} d2 + * @param {IRange} d1 + * @param {IRange} d2 * @param {number} dir */ function shift(d1, d2, dir) { diff --git a/src/virtual_renderer.js b/src/virtual_renderer.js index 3122de203b0..4ef7553caac 100644 --- a/src/virtual_renderer.js +++ b/src/virtual_renderer.js @@ -1,7 +1,8 @@ "use strict"; /** - * * @typedef {import("./edit_session").EditSession} EditSession + * @typedef {import("../ace-internal").Ace.Point} Point + * @typedef {import("../ace-internal").Ace.Theme} Theme */ var oop = require("./lib/oop"); var dom = require("./lib/dom"); @@ -1303,8 +1304,8 @@ class VirtualRenderer { /** * - * @param {import("../ace-internal").Ace.Point} anchor - * @param {import("../ace-internal").Ace.Point} lead + * @param {Point} anchor + * @param {Point} lead * @param {number} [offset] */ scrollSelectionIntoView(anchor, lead, offset) { @@ -1316,7 +1317,7 @@ class VirtualRenderer { /** * * Scrolls the cursor into the first visibile area of the editor - * @param {import("../ace-internal").Ace.Point} [cursor] + * @param {Point} [cursor] * @param {number} [offset] * @param {{ top?: any; bottom?: any; }} [$viewMargin] */ @@ -1417,7 +1418,7 @@ class VirtualRenderer { /** * - * @param {import("../ace-internal").Ace.Point} cursor + * @param {Point} cursor * @param {number} [alignment] * @returns {number} */ @@ -1630,7 +1631,7 @@ class VirtualRenderer { * * @param {number} x * @param {number} y - * @returns {import("../ace-internal").Ace.Point} + * @returns {Point} */ screenToTextCoordinates(x, y) { @@ -1749,7 +1750,7 @@ class VirtualRenderer { /** * @param {string} text - * @param {import("../ace-internal").Ace.Point} [position] + * @param {Point} [position] */ setGhostText(text, position) { var cursor = this.session.selection.cursor; @@ -1847,7 +1848,7 @@ class VirtualRenderer { /** * [Sets a new theme for the editor. `theme` should exist, and be a directory path, like `ace/theme/textmate`.]{: #VirtualRenderer.setTheme} - * @param {String | import("../ace-internal").Ace.Theme} [theme] The path to a theme + * @param {String | Theme} [theme] The path to a theme * @param {() => void} [cb] optional callback **/ @@ -1866,7 +1867,7 @@ class VirtualRenderer { } /** - * @param {import("../ace-internal").Ace.Theme} module + * @param {Theme} module */ function afterLoad(module) { if (_self.$themeId != theme) diff --git a/tsconfig.json b/tsconfig.json index 977a3d93d14..2f50ebab64c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -20,7 +20,8 @@ "src/keyboard/sublime.js", "src/keyboard/vscode.js", "src/mode", - "./ace-internal.d.ts" + "./ace-internal.d.ts", + "src/**/* *" ], "include": [ "./src/**/*",