repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
libro | github_2023 | weavefox | typescript | CodeEditorView.onResize | protected onResize(): void {
if (this.isVisible) {
this.editor.resizeToFit();
}
} | /**
* A message handler invoked on a `'resize'` message.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx#L243-L247 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorView._onSelectionsChanged | protected _onSelectionsChanged(): void {
const { start, end } = this.editor.getSelection();
if (start.column !== end.column || start.line !== end.line) {
// a selection was made
this.addClass(HAS_SELECTION_CLASS);
this.removeClass(HAS_IN_LEADING_WHITESPACE_CLASS);
} else {
// the cu... | /**
* Handle a change in model selections.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx#L263-L282 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeEditorView._evtDragEnter | protected _evtDragEnter = (event: DragEvent): void => {
if (this.editor.getOption('readOnly') === true) {
return;
}
const data = findTextData(event);
if (data === undefined) {
return;
}
event.preventDefault();
event.stopPropagation();
this.addClass('jp-mod-dropTarget');
} | /**
* Handle the `'lm-dragenter'` event for the widget.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | findTextData | function findTextData(event: DragEvent): string | undefined {
const items = event.dataTransfer?.items;
if (!items) {
return;
}
const textTypeItem = Array.from(items).find((t) => t.type.indexOf('text') === 0);
if (textTypeItem === undefined) {
return undefined;
}
return event.dataTransfer.getData(t... | /**
* Given a MimeData instance, extract the first text data, if any.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/code-editor-view.tsx#L424-L434 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LanguageSpecRegistry.registerLanguageSpec | registerLanguageSpec(spec: LanguageSpec) {
const index = this.languageSpecsData.findIndex(
(item) => item.language === spec.language,
);
if (index >= 0) {
this.languageSpecsData.splice(index, 1, spec);
} else {
this.languageSpecsData.push(spec);
}
} | /**
* 注册语言元信息,代码编辑器根据这些信息来设置语言;使用代码编辑器的cell一般需要注册语言元信息
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-code-editor/src/language-specs.ts#L53-L62 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | createForwarderBuilder | function createForwarderBuilder<T extends Extension>(): IConfigurableBuilder {
return new ConfigurableBuilder(new ExtensionForwarder<T>());
} | /**
* Creates a ConfigurableBuilder based on an ExtensionForwarder.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L376-L378 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | createConfigurableBuilder | function createConfigurableBuilder<T, U>(facet: Facet<T, U>): IConfigurableBuilder {
return new ConfigurableBuilder(new FacetWrapper<T, U>(facet));
} | /**
* Creates a ConfigurableBuilder based on a Facet.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L383-L385 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | createConditionalBuilder | function createConditionalBuilder(
truthy: Extension,
falsy: Extension = [],
): IConfigurableBuilder {
return new ConfigurableBuilder(new ConditionalExtension(truthy, falsy));
} | /**
* Creates a ConditionalBuilder from two extensions.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L390-L395 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | createGenConditionalBuilder | function createGenConditionalBuilder<T>(
fn: (value: T) => boolean,
truthy: Extension,
falsy: Extension = [],
): IConfigurableBuilder {
return new ConfigurableBuilder(new GenConditionalExtension<T>(fn, truthy, falsy));
} | /**
* Creates a ConditionalBuilder based on two extensions and a
* conditional function.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L401-L407 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | createThemeBuilder | function createThemeBuilder() {
return new ThemeBuilder();
} | /**
* Creates a theme builder.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L412-L414 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | createPlaceHolderBuilder | function createPlaceHolderBuilder() {
return new PlaceHolderBuilder();
} | /**
* Creates a theme builder.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L419-L421 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | EditorConfiguration.reconfigureExtension | reconfigureExtension<T>(view: EditorView, key: string, value: T): void {
const builder = this.get(key);
if (builder) {
view.dispatch({
effects: builder.reconfigure(value),
});
} else {
const config: Record<string, any> = {};
config[key] = value;
const themeOverload = th... | /**
* Reconfigures the extension mapped with key with the provided value.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L541-L555 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | EditorConfiguration.reconfigureExtensions | reconfigureExtensions(view: EditorView, config: Partial<CodeMirrorConfig>): void {
const eff = [];
for (const [key, value] of Object.entries(config)) {
const builder = this.get(key);
if (builder) {
eff.push(builder.reconfigure(value));
}
}
const themeOverload = this.updateThem... | /**
* Reconfigures all the extensions mapped with the options from the
* provided partial configuration.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L561-L576 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | EditorConfiguration.injectExtension | injectExtension(view: EditorView, ext: Extension): void {
view.dispatch({
effects: StateEffect.appendConfig.of(ext),
});
} | /**
* Appends extensions to the top-level configuration of the
* editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L582-L586 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | EditorConfiguration.getInitialExtensions | getInitialExtensions(config: CodeMirrorConfig): Extension[] {
const keys = Object.keys(config).filter(
(v) => v !== 'insertSpaces' && v !== 'extraKeys',
);
const extensions = [];
for (const k of keys) {
const builder = this.get(k);
if (builder) {
const value = config[k as keyof... | /**
* Returns the list of initial extensions of an editor
* based on the provided configuration.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/config.ts#L592-L648 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditorContribution.canHandle | canHandle(mime: string): number {
const mimes = [MIME.codemirror, MIME.text] as string[];
if (mimes.includes(mime)) {
return 50 + 1;
}
return 10;
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor-contribution.ts#L12-L18 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.constructor | constructor(options: IOptions) {
this._editorConfig = new EditorConfiguration(options);
const host = (this.host = options.host);
host.classList.add(EDITOR_CLASS);
host.classList.add('jp-Editor');
host.addEventListener('focus', this, true);
host.addEventListener('blur', this, true);
host.add... | /**
* Construct a CodeMirror editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L162-L348 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.uuid | get uuid(): string {
return this._uuid;
} | /**
* The uuid of this editor;
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L383-L385 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.selectionStyle | get selectionStyle(): IEditorSelectionStyle {
return this._selectionStyle;
} | /**
* The selection style of this editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L399-L401 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.editor | get editor(): EditorView {
return this._editor;
} | /**
* Get the codemirror editor wrapped by the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L409-L411 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.doc | get doc(): Text {
return this._editor.state.doc;
} | /**
* Get the codemirror doc wrapped by the widget.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L416-L418 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.lineCount | get lineCount(): number {
return this.doc.lines;
} | /**
* Get the number of lines in the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L423-L425 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.model | get model(): IModel {
return this._model;
} | /**
* Returns a model for this editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L430-L432 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.lineHeight | get lineHeight(): number {
return this._editor.defaultLineHeight;
} | /**
* The height of a line in the editor in pixels.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L437-L439 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.charWidth | get charWidth(): number {
return this._editor.defaultCharacterWidth;
} | /**
* The widget of a character in the editor in pixels.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L444-L446 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.disposed | get disposed(): boolean {
return this._isDisposed;
} | /**
* Tests whether the editor is disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L451-L453 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.dispose | dispose = (): void => {
if (this.disposed) {
return;
}
this._isDisposed = true;
this.host.removeEventListener('focus', this, true);
this.host.removeEventListener('blur', this, true);
this.host.removeEventListener('scroll', this, true);
this._keydownHandlers.length = 0;
this.editor.... | /**
* Dispose of the resources held by the widget.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getOption | getOption<K extends keyof IConfig>(option: K): IConfig[K] {
return this._config[option];
} | /**
* Get a config option for the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L473-L475 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.setOption | setOption<K extends keyof IEditorConfig>(option: K, value: IEditorConfig[K]): void {
// Don't bother setting the option if it is already the same.
if (this._config[option] !== value) {
this._config[option] = value;
if (!this.disposed) {
this._editorConfig.reconfigureExtension(this._editor, o... | /**
* Set a config option for the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L480-L496 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.setOptions | setOptions(options: Partial<IEditorConfig>): void {
this._config = { ...this._config, ...options };
this._editorConfig.reconfigureExtensions(this._editor, options);
} | /**
* Set config options for the editor.
*
* This method is preferred when setting several options. The
* options are set within an operation, which only performs
* the costly update at the end, and not after every option
* is set.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L505-L508 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getLine | getLine(line: number): string | undefined {
// TODO: CM6 remove +1 when CM6 first line number has propagated
return line <= this.doc.lines ? this.doc.line(line).text : undefined;
} | /**
* Returns the content for the given line number.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L517-L520 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getOffsetAt | getOffsetAt(position: IPosition): number {
// TODO: CM6 remove +1 when CM6 first line number has propagated
return this.doc.line(position.line).from + position.column - 1;
} | /**
* Find an offset for the given position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L525-L528 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getPositionAt | getPositionAt(offset: number): IPosition {
// TODO: CM6 remove -1 when CM6 first line number has propagated
const line = this.doc.lineAt(offset);
return { line: line.number - 1, column: offset - line.from };
} | /**
* Find a position for the given offset.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L533-L537 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.undo | undo(): void {
undo({
state: getOrigin(this.state),
dispatch: this.editor.dispatch,
});
} | /**
* Undo one edit (if any undo events are stored).
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L542-L547 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.redo | redo(): void {
redo({
state: getOrigin(this.state),
dispatch: this.editor.dispatch,
});
} | /**
* Redo one undone edit.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L552-L557 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.clearHistory | clearHistory(): void {
// this._yeditorBinding?.undoManager?.clear();
} | /**
* Clear the undo history.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L562-L564 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.focus | focus(): void {
getOrigin(this._editor).focus();
} | /**
* Brings browser focus to this editor text.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L569-L571 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.hasFocus | hasFocus(): boolean {
return getOrigin(this._editor).hasFocus;
} | /**
* Test whether the editor has keyboard focus.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L576-L578 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.blur | blur(): void {
this._editor.contentDOM.blur();
} | /**
* Explicitly blur the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L583-L585 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.resizeToFit | resizeToFit(): void {
this._clearHover();
} | /**
* Refresh the editor if it is focused;
* otherwise postpone refreshing till focusing.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L591-L593 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.addKeydownHandler | addKeydownHandler(handler: KeydownHandler): Disposable {
this._keydownHandlers.push(handler);
return Disposable.create(() => {
removeAllWhereFromArray(this._keydownHandlers, (val) => val === handler);
});
} | /**
* Add a keydown handler to the editor.
*
* @param handler - A keydown handler.
*
* @returns A disposable that can be used to remove the handler.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L645-L650 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.revealPosition | revealPosition(position: IPosition): void {
const offset = this.getOffsetAt(position);
this._editor.dispatch({
effects: EditorView.scrollIntoView(offset),
});
} | /**
* Reveal the given position in the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L655-L660 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.revealSelection | revealSelection(selection: IRange): void {
const start = this.getOffsetAt(selection.start);
const end = this.getOffsetAt(selection.end);
this._editor.dispatch({
effects: EditorView.scrollIntoView(EditorSelection.range(start, end)),
});
} | /**
* Reveal the given selection in the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L665-L671 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getCoordinateForPosition | getCoordinateForPosition(position: IPosition): ICoordinate {
const offset = this.getOffsetAt(position);
const rect = this.editor.coordsAtPos(offset);
return rect as ICoordinate;
} | /**
* Get the window coordinates given a cursor position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L676-L680 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getPositionForCoordinate | getPositionForCoordinate(coordinate: ICoordinate): IPosition | null {
const offset = this.editor.posAtCoords({
x: coordinate.left,
y: coordinate.top,
});
return this.getPositionAt(offset!) || null;
} | /**
* Get the cursor position given window coordinates.
*
* @param coordinate - The desired coordinate.
*
* @returns The position of the coordinates, or null if not
* contained in the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L689-L695 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getCursorPosition | getCursorPosition(): IPosition {
const offset = this.state.selection.main.head;
return this.getPositionAt(offset);
} | /**
* Returns the primary position of the cursor, never `null`.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L700-L703 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.setCursorPosition | setCursorPosition(
position: IPosition,
// options?: { bias?: number; origin?: string; scroll?: boolean },
): void {
const offset = this.getOffsetAt(position);
this.editor.dispatch({
selection: { anchor: offset },
scrollIntoView: true,
});
// If the editor does not have focus, this... | /**
* Set the primary position of the cursor.
*
* #### Notes
* This will remove any secondary cursors.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L711-L726 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getSelection | getSelection(): ITextSelection {
return this.getSelections()[0];
} | /**
* Returns the primary selection, never `null`.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L731-L733 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.setSelection | setSelection(selection: IRange): void {
this.setSelections([selection]);
} | /**
* Set the primary selection. This will remove any secondary cursors.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L738-L740 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getSelections | getSelections(): ITextSelection[] {
const selections = this.state.selection.ranges; //= [{anchor: number, head: number}]
if (selections.length > 0) {
const sel = selections.map((r) => ({
anchor: this._toCodeMirrorPosition(this.getPositionAt(r.from)),
head: this._toCodeMirrorPosition(this.g... | /**
* Gets the selections for all the cursors, never `null` or empty.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L745-L759 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.setSelections | setSelections(selections: IRange[]): void {
const sel = selections.length
? selections.map((r) =>
EditorSelection.range(this.getOffsetAt(r.start), this.getOffsetAt(r.end)),
)
: [EditorSelection.range(0, 0)];
this.editor.dispatch({ selection: EditorSelection.create(sel) });
} | /**
* Sets the selections for all the cursors, should not be empty.
* Cursors will be removed or added, as necessary.
* Passing an empty array resets a cursor position to the start of a document.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L766-L773 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.replaceSelection | replaceSelection(text: string, range: IRange): void {
this.editor.dispatch({
changes: {
from: this.getOffsetAt(range.start),
to: this.getOffsetAt(range.end),
insert: text,
},
});
} | /**
* Replaces the current selection with the given text.
*
* @param text The text to be inserted.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L780-L788 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getTokens | getTokens(): IToken[] {
const tokens: IToken[] = [];
const tree = ensureSyntaxTree(this.state, this.doc.length);
if (tree) {
tree.iterate({
enter: (node: SyntaxNodeRef) => {
tokens.push({
value: this.state.sliceDoc(node.from, node.to),
offset: node.from,
... | /**
* Get a list of tokens for the current editor text content.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L818-L834 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getTokenAt | getTokenAt(offset: number): IToken {
const tree = ensureSyntaxTree(this.state, offset);
if (tree) {
const node = tree.resolveInner(offset);
return {
value: this.state.sliceDoc(node.from, node.to),
offset: node.from,
type: node.name,
};
} else {
return {
... | /**
* Get the token at a given editor position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L839-L854 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.getTokenAtCursor | getTokenAtCursor(): IToken {
return this.getTokenAt(this.state.selection.main.head);
} | /**
* Get the token a the cursor position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L859-L861 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.newIndentedLine | newIndentedLine(): void {
insertNewlineAndIndent({
state: this.state,
dispatch: this.editor.dispatch,
});
} | /**
* Insert a new indented line at the current cursor position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L866-L871 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.execCommand | execCommand(command: Command | StateCommand): void {
command(this.editor);
} | /**
* Execute a codemirror command on the editor.
*
* @param command - The name of the command to execute.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L878-L880 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.onKeydown | protected onKeydown(event: KeyboardEvent): boolean {
const position = this.state.selection.main.head;
if (position === 0 && event.keyCode === UP_ARROW) {
if (!event.shiftKey) {
// this.edgeRequested.emit('top');
this.edgeRequestedEmitter.fire('top');
}
return false;
}
... | /**
* Handle keydown events from the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L887-L917 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._onMimeTypeChanged | protected _onMimeTypeChanged(): void {
const mime = this._model.mimeType;
// TODO: should we provide a hook for when the mode is done being set?
void codemirrorEnsure(mime).then((spec) => {
if (spec) {
this._editorConfig.reconfigureExtension(
this._editor,
'language',
... | /**
* Handles a mime type change.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L922-L935 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._onSelectionsChanged | protected _onSelectionsChanged(args: ITextSelection[]): void {
// const uuid = args.key;
// if (uuid !== this.uuid) {
// this._cleanSelections(uuid);
// if (args.type !== 'remove' && args.newValue) {
// this._markSelections(uuid, args.newValue);
// }
// }
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L941-L949 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._cleanSelections | protected _cleanSelections(uuid: string) {
this.editor.dispatch({
effects: this._removeMark.of({
uuid: uuid,
decorations: this._selectionMarkers[uuid],
}),
});
} | /**
* Clean selections for the given uuid.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L954-L961 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._markSelections | protected _markSelections(uuid: string, selections: ITextSelection[]) {
const sel = selections.map((selection) => ({
from: this.getOffsetAt(selection.start),
to: this.getOffsetAt(selection.end),
style: selection.style,
}));
this.editor.dispatch({
effects: this._addMark.of({ uuid: uui... | /**
* Marks selections.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1046-L1055 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._onCursorActivity | protected _onCursorActivity(): void {
// Only add selections if the editor has focus. This avoids unwanted
// triggering of cursor activity due to collaborator actions.
if (this._editor.hasFocus) {
const selections = this.getSelections();
this.model.selections = selections;
}
} | /**
* Handles a cursor activity event.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1060-L1067 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._toSelection | protected _toSelection(selection: {
anchor: { line: number; ch: number };
head: { line: number; ch: number };
}): ITextSelection {
return {
uuid: this.uuid,
start: this._toPosition(selection.anchor),
end: this._toPosition(selection.head),
style: this.selectionStyle,
};
} | /**
* Converts a code mirror selection to an editor selection.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1072-L1082 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._toPosition | protected _toPosition(position: { line: number; ch: number }) {
return {
line: position.line,
column: position.ch,
};
} | /**
* Convert a code mirror position to an editor position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1086-L1091 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._toCodeMirrorPosition | protected _toCodeMirrorPosition(position: IPosition) {
return {
line: position.line,
ch: position.column,
};
} | /**
* Convert an editor position to a code mirror position.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1096-L1101 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._onDocChanged | protected _onDocChanged(update: ViewUpdate) {
if (update.transactions.length && update.transactions[0].selection) {
this._onCursorActivity();
}
if (update.docChanged) {
this._lastChange = update.changes;
}
this.model.value = update.state.doc.toJSON().join('\n');
this.host.style.heig... | /**
* Handles document changes.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1106-L1116 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor.handleEvent | handleEvent(event: Event): void {
switch (event.type) {
case 'focus':
this._evtFocus();
break;
case 'blur':
this._evtBlur();
break;
case 'scroll':
this._evtScroll();
break;
default:
break;
}
} | /**
* Handle the DOM events for the editor.
*
* @param event - The DOM event sent to the editor.
*
* #### Notes
* This method implements the DOM `EventListener` interface and is
* called in response to events on the editor's DOM node. It should
* not be called directly by user code.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1127-L1141 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._evtFocus | protected _evtFocus(): // event: FocusEvent
void {
this.host.classList.add('jp-mod-focused');
// Update the selections on editor gaining focus because
// the onCursorActivity function filters usual cursor events
// based on the editor's focus.
this._onCursorActivity();
} | /**
* Handle `focus` events for the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1146-L1154 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._evtBlur | protected _evtBlur(): // event: FocusEvent
void {
this.host.classList.remove('jp-mod-focused');
} | /**
* Handle `blur` events for the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1159-L1162 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._evtScroll | protected _evtScroll(): void {
// Remove any active hover.
this._clearHover();
} | /**
* Handle `scroll` events for the editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1167-L1170 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._clearHover | protected _clearHover(): void {
if (this._caretHover) {
window.clearTimeout(this._hoverTimeout);
document.body.removeChild(this._caretHover);
this._caretHover = null;
}
} | /**
* Clear the hover for a caret, due to things like
* scrolling, resizing, deactivation, etc, where
* the position is no longer valid.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1177-L1183 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorEditor._checkSync | protected _checkSync(): void {
const change = this._lastChange;
if (!change) {
return;
}
this._lastChange = null;
const doc = this.doc;
if (doc.toString() === this._model.value) {
return;
}
// void showDialog({
// title: this._trans.__('Code Editor out of Sync'),
/... | /**
* Check for an out of sync editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/editor.ts#L1187-L1217 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorMimeTypeService.getMimeTypeByLanguage | getMimeTypeByLanguage(info: ILanguageInfoMetadata): string {
const ext = info.file_extension || '';
const mode = findBest(
(info.codemirror_mode as any) || {
mimetype: info.mimetype,
name: info.name,
ext: [ext.split('.').slice(-1)[0]],
},
);
return mode ? (mode.mime a... | /**
* Returns a mime type for the given language info.
*
* #### Notes
* If a mime type cannot be found returns the default mime type `text/plain`, never `null`.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/mimetype.ts#L21-L31 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodeMirrorMimeTypeService.getMimeTypeByFilePath | getMimeTypeByFilePath(path: string): string {
const ext = extname(path);
if (ext === '.ipy') {
return 'text/x-python';
} else if (ext === '.md') {
return 'text/x-ipythongfm';
}
const mode = findByFileName(path) || findBest('');
return mode ? (mode.mime as string) : defaultMimeType;
... | /**
* Returns a mime type for the given file path.
*
* #### Notes
* If a mime type cannot be found returns the default mime type `text/plain`, never `null`.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/mimetype.ts#L39-L48 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | makeSpec | function makeSpec(spec: ISpec): ISpec {
const res = LanguageDescription.of(spec) as unknown as ISpec;
res.mime = spec.mime;
return res;
} | // Code mirror uses two similar structures, a plain object with optional fields, | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/mode.ts#L28-L32 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | handleSame | function handleSame(
state: EditorState,
token: string,
allowTriple: boolean,
config: CloseBracketConfig,
) {
const stringPrefixes = config.stringPrefixes || defaults.stringPrefixes;
let dont = null;
const changes = state.changeByRange((range) => {
if (!range.empty) {
return {
changes: [... | // Handles cases where the open and close token are the same, and | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/closebrackets.ts#L285-L357 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodemirrorCompletionContext.constructor | constructor(
/// The editor state that the completion happens in.
readonly state: EditorState,
/// The position at which the completion is happening.
readonly pos: number,
/// Indicates whether completion was activated explicitly, or
/// implicitly by typing. The usual way to respond to this is ... | /// these for you.) | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/completion.ts#L59-L69 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodemirrorCompletionContext.tokenBefore | tokenBefore(types: readonly string[]) {
let token: SyntaxNode | null = syntaxTree(this.state).resolveInner(this.pos, -1);
while (token && types.indexOf(token.name) < 0) {
token = token.parent;
}
return token
? {
from: token.from,
to: this.pos,
text: this.state.s... | /// token before `this.pos`. | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/completion.ts#L73-L86 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodemirrorCompletionContext.matchBefore | matchBefore(expr: RegExp) {
const line = this.state.doc.lineAt(this.pos);
const start = Math.max(line.from, this.pos - 250);
const str = line.text.slice(start - line.from, this.pos - line.from);
const found = str.search(ensureAnchor(expr, false));
return found < 0
? null
: { from: start ... | /// cursor. | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/completion.ts#L90-L98 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodemirrorCompletionContext.aborted | get aborted() {
return this.abortListeners === null;
} | /// asynchronous queries to avoid doing work that will be ignored. | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/completion.ts#L102-L104 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | CodemirrorCompletionContext.addEventListener | addEventListener(type: 'abort', listener: () => void) {
if (type === 'abort' && this.abortListeners) {
this.abortListeners.push(listener);
}
} | /// [aborted](#autocomplete.CodemirrorCompletionContext.aborted). | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/completion.ts#L109-L113 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | FuzzyMatcher.match | match(word: string): number[] | null {
if (this.pattern.length === 0) {
return [0];
}
if (word.length < this.pattern.length) {
return null;
}
const { chars, folded, any, precise, byWord } = this;
// For single-character queries, only match when they occur right
// at the start
... | // is. See `Penalty` above. | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/filter.ts#L54-L198 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | score | function score(option: Completion) {
return (
(option.boost || 0) * 100 +
(option.apply ? 10 : 0) +
(option.info ? 5 : 0) +
(option.type ? 1 : 0)
);
} | // Used to pick a preferred option when two options with the same | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/auto-complete/state.ts#L22-L29 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.constructor | constructor(
lines: Set<Line>,
state: EditorState,
unitWidth: number,
markerType: 'fullScope' | 'codeOnly',
) {
this.lines = lines;
this.state = state;
this.map = new Map();
this.unitWidth = unitWidth;
this.markerType = markerType;
for (const line of this.lines) {
this.a... | /**
* @param lines - The set of lines to get the indentation map for.
* @param state - The {@link EditorState} to derive the indentation map from.
* @param unitWidth - The width of the editor's indent unit.
* @param markerType - The type of indentation to use (terminate at end of scope vs last line of code ... | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L45-L64 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.has | has(line: Line | number) {
return this.map.has(typeof line === 'number' ? line : line.number);
} | /**
* Checks if the indentation map has an entry for the given line.
*
* @param line - The {@link Line} or line number to check for.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L71-L73 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.get | get(line: Line | number) {
const entry = this.map.get(typeof line === 'number' ? line : line.number);
if (!entry) {
throw new Error('Line not found in indentation map');
}
return entry;
} | /**
* Returns the {@link IndentEntry} for the given line.
*
* Note that this function will throw an error if the line does not exist in the map.
*
* @param line - The {@link Line} or line number to get the entry for.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L82-L90 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.set | protected set(line: Line, col: number, level: number) {
const empty = !line.text.trim().length;
const entry: IndentEntry = { line, col, level, empty };
this.map.set(entry.line.number, entry);
return entry;
} | /**
* Sets the {@link IndentEntry} for the given line.
*
* @param line - The {@link Line} to set the entry for.
* @param col - The visual beginning whitespace width of the line.
* @param level - The indentation level of the line.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L99-L105 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.add | protected add(line: Line) {
if (this.has(line)) {
return this.get(line);
}
// empty lines continue their indentation from surrounding lines
if (!line.length || !line.text.trim().length) {
// the very first line, if empty, is just ignored and set as a 0 indent level
if (line.number ===... | /**
* Adds a line to the indentation map.
*
* @param line - The {@link Line} to add to the map.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L112-L160 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.closestNonEmpty | protected closestNonEmpty(from: Line, dir: -1 | 1) {
let lineNo = from.number + dir;
while (dir === -1 ? lineNo >= 1 : lineNo <= this.state.doc.lines) {
if (this.has(lineNo)) {
const entry = this.get(lineNo);
if (!entry.empty) {
return entry;
}
}
// we can c... | /**
* Finds the closest non-empty line, starting from the given line.
*
* @param from - The {@link Line} to start from.
* @param dir - The direction to search in. Either `1` or `-1`.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L168-L202 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | IndentationMap.findAndSetActiveLines | protected findAndSetActiveLines() {
const currentLine = getCurrentLine(this.state);
if (!this.has(currentLine)) {
return;
}
let current = this.get(currentLine);
// check if the current line is starting a new block, if yes, we want to
// start from inside the block.
if (this.has(curr... | /**
* Finds the state's active block (via the current selection) and sets all
* the active indent level for the lines in the block.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-codemirror/src/indentation-markers/map.ts#L208-L272 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | MonacoEnvironment.preLoadModule | static async preLoadModule(loader: ModuleLoader) {
MonacoEnvironment.preLoaders.push(loader);
} | // 提前加载(懒加载模式下需要提前加载的模块) | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor-core/src/monaco-environment.ts#L112-L114 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | MonacoLoader.initMonaco | initMonaco() {
return new Promise((resolve, reject) => {
if (this.cdnUrl) {
const beforeExist = document.getElementById('e2-monaco-id');
if (beforeExist) {
if (window._Monaco) {
const global: any = window;
global.monaco = window._Monaco;
this.loade... | // 初始化,将monaco挂在到window上 | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor-core/src/monaco-loader.ts#L48-L99 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2Editor.uuid | get uuid(): string {
return this._uuid;
} | /**
* The uuid of this editor;
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor/src/libro-e2-editor.ts#L344-L346 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2Editor.model | get model(): IModel {
return this._model;
} | /**
* Returns a model for this editor.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor/src/libro-e2-editor.ts#L355-L357 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2Editor.handleCommand | protected handleCommand(commandRegistry: CommandRegistry) {
// need monaco 0.34
editor.addKeybindingRules([
{
// disable show command center
keybinding: KeyCode.F1,
command: null,
},
{
// disable show error command
keybinding: KeyCode.F8,
command... | /**
* 解决e2与libro快捷键冲突
* @param commandRegistry
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor/src/libro-e2-editor.ts#L623-L686 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2Editor.getPositionForCoordinate | protected onMimeTypeChanged = () => {
const model = this.monacoEditor?.getModel();
if (this.languageSpec && model) {
editor.setModelLanguage(model, this.languageSpec.language);
}
} | /**
* Handles a mime type change.
* 切换语言
* cell 切换没走这里
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor/src/libro-e2-editor.ts | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2Editor.onCursorActivity | protected onCursorActivity(): void {
// Only add selections if the editor has focus. This avoids unwanted
// triggering of cursor activity due to collaborator actions.
if (this.hasFocus()) {
// const selections = this.getSelections();
// this.model.selections = selections;
}
} | /**
* Handles a cursor activity event.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor/src/libro-e2-editor.ts#L715-L722 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | LibroE2Editor.disposed | get disposed(): boolean {
return this._isDisposed;
} | /**
* Tests whether the editor is disposed.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-cofine-editor/src/libro-e2-editor.ts#L995-L997 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
libro | github_2023 | weavefox | typescript | ArrayIterator.constructor | constructor(source: ArrayLike<T>) {
this._source = source;
} | /**
* Construct a new array iterator.
*
* @param source - The array-like object of interest.
*/ | https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/iter.ts#L76-L78 | 371f9fa4903254d60ed3142e335dbf3f6d8d03e4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.