How to use the @jupyterlab/coreutils.Text.jsIndexToCharIndex function in @jupyterlab/coreutils

To help you get started, we’ve selected a few @jupyterlab/coreutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab-data-explorer / packages / inspector / src / handler.ts View on Github external
protected onEditorChange(): void {
    // If the handler is in standby mode, bail.
    if (this._standby) {
      return;
    }

    const editor = this.editor;

    if (!editor) {
      return;
    }

    const text = editor.model.value.text;
    const position = editor.getCursorPosition();
    const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), text);
    const update: IInspector.IInspectorUpdate = { content: null };

    const pending = ++this._pending;

    void this._connector
      .fetch({ offset, text })
      .then(reply => {
        // If handler has been disposed or a newer request is pending, bail.
        if (this.isDisposed || pending !== this._pending) {
          this._inspected.emit(update);
          return;
        }

        const { data } = reply;
        const mimeType = this._rendermime.preferredMimeType(data);
github jupyterlab / jupyterlab / packages / inspector / src / handler.ts View on Github external
protected onEditorChange(): void {
    // If the handler is in standby mode, bail.
    if (this._standby) {
      return;
    }

    const editor = this.editor;

    if (!editor) {
      return;
    }

    const text = editor.model.value;
    const position = editor.getCursorPosition();
    const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), text);
    const update: IInspector.IInspectorUpdate = { content: null };

    const pending = ++this._pending;

    void this._connector
      .fetch({ offset, text })
      .then(reply => {
        // If handler has been disposed or a newer request is pending, bail.
        if (this.isDisposed || pending !== this._pending) {
          this._inspected.emit(update);
          return;
        }

        const { data } = reply;
        const mimeType = this._rendermime.preferredMimeType(data);
github yuvipanda / simplest-notebook / packages / inspector / src / handler.ts View on Github external
protected onTextChanged(): void {
    // If the handler is in standby mode, bail.
    if (this._standby) {
      return;
    }

    const editor = this.editor;
    const code = editor.model.value.text;
    const position = editor.getCursorPosition();
    const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), code);
    let update: IInspector.IInspectorUpdate = { content: null, type: 'hints' };

    // Clear hints if the new text value is empty or kernel is unavailable.
    if (!code || !this.session.kernel) {
      this._inspected.emit(update);
      return;
    }

    const contents: KernelMessage.IInspectRequest = {
      code,
      cursor_pos: offset,
      detail_level: 0
    };
    const pending = ++this._pending;

    this.session.kernel.requestInspect(contents).then(msg => {
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / completer / src / handler.ts View on Github external
private _makeRequest(position: CodeEditor.IPosition): Promise {
    const editor = this.editor;

    if (!editor) {
      return Promise.reject(new Error('No active editor'));
    }

    const text = editor.model.value.text;
    const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), text);
    const pending = ++this._pending;
    const state = this.getState(editor, position);
    const request: CompletionHandler.IRequest = { text, offset };

    return this._connector
      .fetch(request)
      .then(reply => {
        if (this.isDisposed) {
          throw new Error('Handler is disposed');
        }

        // If a newer completion request has created a pending request, bail.
        if (pending !== this._pending) {
          throw new Error('A newer completion request is pending');
        }
github jupyterlab / jupyterlab / packages / completer / src / handler.ts View on Github external
private _makeRequest(position: CodeEditor.IPosition): Promise {
    const editor = this.editor;

    if (!editor) {
      return Promise.reject(new Error('No active editor'));
    }

    const text = editor.model.value.text;
    const offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), text);
    const pending = ++this._pending;
    const state = this.getState(editor, position);
    const request: CompletionHandler.IRequest = { text, offset };

    return this._connector.fetch(request).then(reply => {
      if (this.isDisposed) {
        throw new Error('Handler is disposed');
      }

      // If a newer completion request has created a pending request, bail.
      if (pending !== this._pending) {
        throw new Error('A newer completion request is pending');
      }

      this._onReply(state, reply);
    }).catch(reason => {
github jupyterlab / jupyterlab / packages / tooltip-extension / src / index.ts View on Github external
export function fetch(options: IFetchOptions): Promise {
    let { detail, editor, kernel } = options;
    let code = editor.model.value;
    let position = editor.getCursorPosition();
    let offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), code);

    // Clear hints if the new text value is empty or kernel is unavailable.
    if (!code || !kernel) {
      return Promise.reject(void 0);
    }

    let contents: KernelMessage.IInspectRequestMsg['content'] = {
      code,
      cursor_pos: offset,
      detail_level: detail || 0
    };
    let current = ++pending;

    return kernel.requestInspect(contents).then(msg => {
      let value = msg.content;
github jupyterlab / jupyterlab / packages / tooltip-extension / src / index.ts View on Github external
export function fetch(options: IFetchOptions): Promise {
    let { detail, editor, kernel } = options;
    let code = editor.model.value.text;
    let position = editor.getCursorPosition();
    let offset = Text.jsIndexToCharIndex(editor.getOffsetAt(position), code);

    // Clear hints if the new text value is empty or kernel is unavailable.
    if (!code || !kernel) {
      return Promise.reject(void 0);
    }

    let contents: KernelMessage.IInspectRequest = {
      code,
      cursor_pos: offset,
      detail_level: detail || 0
    };
    let current = ++pending;

    return kernel.requestInspect(contents).then(msg => {
      let value = msg.content;