<commit_before>package jycessing.mode;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import processing.app.Editor;
import processing.app.Sketch;
import processing.app.syntax.JEditTextArea;
import processing.mode.java.PdeKeyListener;

/**
 * 
 */
public class PyKeyListener extends PdeKeyListener {
  final PyEditor peditor;
  final JEditTextArea textArea;

  // ctrl-alt on windows & linux, cmd-alt on os x
  private static int CTRL_ALT = ActionEvent.ALT_MASK
      | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

  // 4 spaces per pep8
  private static final String TAB = "    ";
  private static final int TAB_SIZE = TAB.length();

  public PyKeyListener(final Editor editor, final JEditTextArea textarea) {
    super(editor, textarea);

    peditor = (PyEditor)editor;
    textArea = textarea;
  }

  @Override
  public boolean keyPressed(final KeyEvent event) {
    final char c = event.getKeyChar();
    final int code = event.getKeyCode();

    final Sketch sketch = peditor.getSketch();

    // things that change the content of the text area
    if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_TAB)
        || (code == KeyEvent.VK_ENTER) || ((c >= 32) && (c < 128))) {
      sketch.setModified(true);
    }

    // ctrl-alt-[arrow] switches sketch tab
    if ((event.getModifiers() & CTRL_ALT) == CTRL_ALT) {
      if (code == KeyEvent.VK_LEFT) {
        sketch.handlePrevCode();
        return true;
      } else if (code == KeyEvent.VK_RIGHT) {
        sketch.handleNextCode();
        return true;
      }
    }

    switch (code) {
      case KeyEvent.VK_BACK_SPACE:
        final LineInfo currentLine = new LineInfo(textArea.getCaretLine());
        if (currentLine.caretInText) {
          // The caret is in the text; let the text editor handle this backspace.
          break;
        }
        // The caret is not in the text; treat it as a request to unindent.
        indent(-1);
        return true;

      case KeyEvent.VK_TAB:
        indent(event.isShiftDown() ? -1 : 1);
        return true;

      case KeyEvent.VK_ENTER: // return
        final String text = textArea.getText(); // text
        final int cursor = textArea.getCaretPosition();
        textArea.setSelectedText(getIndent(cursor, text));
        break;
    }
<commit_msg>Fix a bug that prevented backspace from backspacing at column 0.<commit_after>package jycessing.mode;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import processing.app.Editor;
import processing.app.Sketch;
import processing.app.syntax.JEditTextArea;
import processing.mode.java.PdeKeyListener;

/**
 * This class provides Pythonic handling of TAB, BACKSPACE, and ENTER keys.
 */
public class PyKeyListener extends PdeKeyListener {
  final PyEditor peditor;
  final JEditTextArea textArea;

  // ctrl-alt on windows & linux, cmd-alt on os x
  private static int CTRL_ALT = ActionEvent.ALT_MASK
      | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

  // 4 spaces per pep8
  private static final String TAB = "    ";
  private static final int TAB_SIZE = TAB.length();

  public PyKeyListener(final Editor editor, final JEditTextArea textarea) {
    super(editor, textarea);

    peditor = (PyEditor)editor;
    textArea = textarea;
  }

  @Override
  public boolean keyPressed(final KeyEvent event) {
    final char c = event.getKeyChar();
    final int code = event.getKeyCode();

    final Sketch sketch = peditor.getSketch();

    // things that change the content of the text area
    if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_TAB)
        || (code == KeyEvent.VK_ENTER) || ((c >= 32) && (c < 128))) {
      sketch.setModified(true);
    }

    // ctrl-alt-[arrow] switches sketch tab
    if ((event.getModifiers() & CTRL_ALT) == CTRL_ALT) {
      if (code == KeyEvent.VK_LEFT) {
        sketch.handlePrevCode();
        return true;
      } else if (code == KeyEvent.VK_RIGHT) {
        sketch.handleNextCode();
        return true;
      }
    }

    final int thisLine = textArea.getCaretLine();
    final int thisPos = textArea.getCaretPosition();

    switch (code) {
      case KeyEvent.VK_BACK_SPACE:
        if (thisPos == textArea.getLineStartOffset(thisLine)) {
          // Let the user backspace onto the previous line.
          break;
        }
        final LineInfo currentLine = new LineInfo(thisLine);
        if (currentLine.caretInText) {
          // The caret is in the text; let the text editor handle this backspace.
          break;
        }
        // The caret is not in the text; treat it as a request to unindent.
        indent(-1);
        return true;

      case KeyEvent.VK_TAB:
        indent(event.isShiftDown() ? -1 : 1);
        return true;

      case KeyEvent.VK_ENTER: // return
        final String text = textArea.getText(); // text
        final int cursor = thisPos;
        textArea.setSelectedText(getIndent(cursor, text));
        break;
    }

{'fraction_non_alphanumeric': 0.10539645431521527, 'fraction_numerical': 0.004091174751607247, 'mean_word_length': 2.7694566813509547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3739610', 'n_tokens_mistral': 1609, 'n_tokens_neox': 1552, 'n_words': 435}