<commit_before>declare const $: any;

import { delay } from "awaiting";

import { React, Component, Rendered } from "../app-framework";
import { Map as ImmutableMap } from "immutable";
import { JupyterActions } from "./browser-actions";
import { NotebookFrameActions } from "../frame-editors/jupyter-editor/cell-notebook/actions";

interface CompleteProps {
  actions: JupyterActions;
  frame_actions : NotebookFrameActions;
  id: string;
  complete: ImmutableMap<string, any>;
}

// WARNING: Complete closing when clicking outside the complete box
// is handled in cell-list on_click.  This is ugly code (since not localized),
// but seems to work well for now.  Could move.
export class Complete extends Component<CompleteProps> {
  private node: HTMLElement;

  private async select(item: any): Promise<void> {
    this.props.frame_actions.set_mode("edit");
    // We don't actually make the completion until the next render loop,
    // so that the editor is already in edit mode.  This way the cursor is
    // in the right position after making the change.
    await delay(0);
    this.props.actions.select_complete(this.props.id, item);
    this.props.frame_actions.set_mode("edit");
  }

  private render_item(item: string): Rendered {
    return (
      <li key={item}>
        <a role="menuitem" tabIndex={-1} onClick={() => this.select(item)}>
          {item}
        </a>
      </li>
    );
  }

  private keypress = (evt: any) => {
    this.props.actions.complete_handle_key(this.props.id, evt.keyCode);
  };

  public componentDidMount(): void {
    $(window).on("keypress", this.keypress);
    $(this.node)
      .find("a:first")
      .focus();
  }

  public componentDidUpdate(): void {
    $(this.node)
      .find("a:first")
      .focus();
  }<commit_msg>jupyter: fix bug when selecting completion with mouse<commit_after>declare const $: any;

import { React, Component, Rendered } from "../app-framework";
import { Map } from "immutable";
import { JupyterActions } from "./browser-actions";
import { NotebookFrameActions } from "../frame-editors/jupyter-editor/cell-notebook/actions";

interface CompleteProps {
  actions: JupyterActions;
  frame_actions : NotebookFrameActions;
  id: string;
  complete: Map<string, any>;
}

// WARNING: Complete closing when clicking outside the complete box
// is handled in cell-list on_click.  This is ugly code (since not localized),
// but seems to work well for now.  Could move.
export class Complete extends Component<CompleteProps> {
  private node: HTMLElement;

  private select(item: string): void {
    this.props.actions.select_complete(this.props.id, item);
    this.props.frame_actions.set_mode("edit");
  }

  private render_item(item: string): Rendered {
    return (
      <li key={item}>
        <a role="menuitem" tabIndex={-1} onClick={() => this.select(item)}>
          {item}
        </a>
      </li>
    );
  }

  private keypress = (evt: any) => {
    this.props.actions.complete_handle_key(this.props.id, evt.keyCode);
  };

  public componentDidMount(): void {
    $(window).on("keypress", this.keypress);
    $(this.node)
      .find("a:first")
      .focus();
  }

  public componentDidUpdate(): void {
    $(this.node)
      .find("a:first")
      .focus();
  }
{'fraction_non_alphanumeric': 0.13688095970470623, 'fraction_numerical': 0.0009227929867733005, 'mean_word_length': 3.3651006711409397, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1063373', 'n_tokens_mistral': 1010, 'n_tokens_neox': 1003, 'n_words': 274}