<commit_before>package de.onyxbits.remotekeyboard;

import net.wimpi.telnetd.io.TerminalIO;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.widget.Toast;

/**
 * Models a key event sent from the remote keyboard via the telnet protocol and
 * provides a method for replaying that input on the UI thread (possibly
 * translating it from telnet to android semantics).
 * 
 * @author patrick
 * 
 */
class CtrlInputAction implements Runnable {

	public static final String TAG = "InputAction";

	/**
	 * A control character (anything thats not printable)
	 */
	protected int function;

	/**
	 * For sending raw key presses to the editor
	 */
	private RemoteKeyboardService myService;

	public CtrlInputAction(RemoteKeyboardService myService) {
		this.myService = myService;
	}

	// @Override
	public void run() {
		InputConnection con = myService.getCurrentInputConnection();
		if (con == null) {
			return;
		}

		switch (function) {
		// FIXME: Dirty hack! Most telnet clients send DELETE instead of BACKSPACE
		// when the physical backspace key is pressed. This is usually
		// configurable but difficult to explain. So instead of explaining the
		// issue, we just make both symbols semantically equivalent.
			case TerminalIO.DEL:
			case TerminalIO.DELETE:
			case TerminalIO.BACKSPACE: {
				typeKey(con, KeyEvent.KEYCODE_DEL);
				break;
			}
			case TerminalIO.ENTER:
			case '\n': {
				// NOTE: Workaround for a bug in the telnet library! It should return
				// ENTER, but does return LF.
				handleEnterKey(con);
				break;
			}
			case TerminalIO.TABULATOR: {
				typeKey(con, KeyEvent.KEYCODE_TAB);
				break;
			}
			case Decoder.SYM_CURSOR_LEFT: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_LEFT);
				break;
			}
			case Decoder.SYM_CURSOR_RIGHT: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_RIGHT);
				break;
			}
			case Decoder.SYM_CURSOR_UP: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_UP);
				break;
			}
			case Decoder.SYM_CURSOR_DOWN: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_DOWN);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_LEFT: {
				markText(con,KeyEvent.KEYCODE_DPAD_LEFT);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_RIGHT: {
				markText(con,KeyEvent.KEYCODE_DPAD_RIGHT);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_UP: {
				markText(con,KeyEvent.KEYCODE_DPAD_UP);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_DOWN: {
				markText(con,KeyEvent.KEYCODE_DPAD_DOWN);
				break;
			}
			case Decoder.SYM_CTRL_CURSOR_LEFT: {
				jumpBackward(con, ' ');
				break;
			}
			case Decoder.SYM_CTRL_CURSOR_RIGHT: {
				jumpForward(con, ' ');
				break;
			}
			case Decoder.SYM_INSERT: {
				replaceText(con);
				break;
			}
			case Decoder.SYM_DELETE: {
				if (con.getSelectedText(0) == null) {
					con.deleteSurroundingText(0, 1);
				}
				else {
					typeKey(con, KeyEvent.KEYCODE_DEL);
				}
				break;
			}
			case Decoder.SYM_HOME: {
				jumpBackward(con, '\n');
				break;
			}
			case Decoder.SYM_END: {
				jumpForward(con, '\n');
				break;
			}

			// Hacky time! We redefine ASCII control chars to our needs.
			case TerminalIO.COLORINIT: { // CTRL-A
				con.performContextMenuAction(android.R.id.selectAll);
				break;
			}
			case 3: { // CTRL-C
				con.performContextMenuAction(android.R.id.copy);
				break;
			}
			case 12: { // CTRL-L
				con.performEditorAction(EditorInfo.IME_ACTION_SEND);
				break;
			}
			case 18: { // CTRL-R
				scramble(con);
				break;
			}
			case 17: { // CTRL-Q
				typeKey(con, KeyEvent.KEYCODE_BACK);
				break;
			}
			case 19: { // CTRL-S
				con.performEditorAction(EditorInfo.IME_ACTION_SEARCH);<commit_msg>Linked CTRL-S to the search key instead of the IME search action.<commit_after>package de.onyxbits.remotekeyboard;

import net.wimpi.telnetd.io.TerminalIO;
import android.os.SystemClock;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.widget.Toast;

/**
 * Models a key event sent from the remote keyboard via the telnet protocol and
 * provides a method for replaying that input on the UI thread (possibly
 * translating it from telnet to android semantics).
 * 
 * @author patrick
 * 
 */
class CtrlInputAction implements Runnable {

	public static final String TAG = "InputAction";

	/**
	 * A control character (anything thats not printable)
	 */
	protected int function;

	/**
	 * For sending raw key presses to the editor
	 */
	private RemoteKeyboardService myService;

	public CtrlInputAction(RemoteKeyboardService myService) {
		this.myService = myService;
	}

	// @Override
	public void run() {
		InputConnection con = myService.getCurrentInputConnection();
		if (con == null) {
			return;
		}

		switch (function) {
		// FIXME: Dirty hack! Most telnet clients send DELETE instead of BACKSPACE
		// when the physical backspace key is pressed. This is usually
		// configurable but difficult to explain. So instead of explaining the
		// issue, we just make both symbols semantically equivalent.
			case TerminalIO.DEL:
			case TerminalIO.DELETE:
			case TerminalIO.BACKSPACE: {
				typeKey(con, KeyEvent.KEYCODE_DEL);
				break;
			}
			case TerminalIO.ENTER:
			case '\n': {
				// NOTE: Workaround for a bug in the telnet library! It should return
				// ENTER, but does return LF.
				handleEnterKey(con);
				break;
			}
			case TerminalIO.TABULATOR: {
				typeKey(con, KeyEvent.KEYCODE_TAB);
				break;
			}
			case Decoder.SYM_CURSOR_LEFT: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_LEFT);
				break;
			}
			case Decoder.SYM_CURSOR_RIGHT: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_RIGHT);
				break;
			}
			case Decoder.SYM_CURSOR_UP: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_UP);
				break;
			}
			case Decoder.SYM_CURSOR_DOWN: {
				typeKey(con, KeyEvent.KEYCODE_DPAD_DOWN);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_LEFT: {
				markText(con,KeyEvent.KEYCODE_DPAD_LEFT);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_RIGHT: {
				markText(con,KeyEvent.KEYCODE_DPAD_RIGHT);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_UP: {
				markText(con,KeyEvent.KEYCODE_DPAD_UP);
				break;
			}
			case Decoder.SYM_SHIFT_CURSOR_DOWN: {
				markText(con,KeyEvent.KEYCODE_DPAD_DOWN);
				break;
			}
			case Decoder.SYM_CTRL_CURSOR_LEFT: {
				jumpBackward(con, ' ');
				break;
			}
			case Decoder.SYM_CTRL_CURSOR_RIGHT: {
				jumpForward(con, ' ');
				break;
			}
			case Decoder.SYM_INSERT: {
				replaceText(con);
				break;
			}
			case Decoder.SYM_DELETE: {
				if (con.getSelectedText(0) == null) {
					con.deleteSurroundingText(0, 1);
				}
				else {
					typeKey(con, KeyEvent.KEYCODE_DEL);
				}
				break;
			}
			case Decoder.SYM_HOME: {
				jumpBackward(con, '\n');
				break;
			}
			case Decoder.SYM_END: {
				jumpForward(con, '\n');
				break;
			}

			// Hacky time! We redefine ASCII control chars to our needs.
			case TerminalIO.COLORINIT: { // CTRL-A
				con.performContextMenuAction(android.R.id.selectAll);
				break;
			}
			case 3: { // CTRL-C
				con.performContextMenuAction(android.R.id.copy);
				break;
			}
			case 12: { // CTRL-L
				con.performEditorAction(EditorInfo.IME_ACTION_SEND);
				break;
			}
			case 18: { // CTRL-R
				scramble(con);
				break;
			}
			case 17: { // CTRL-Q
				typeKey(con, KeyEvent.KEYCODE_BACK);
				break;
			}
			case 19: { // CTRL-S
				//con.performEditorAction(EditorInfo.IME_ACTION_SEARCH);
				typeKey(con,KeyEvent.KEYCODE_SEARCH);
{'fraction_non_alphanumeric': 0.10331005947763124, 'fraction_numerical': 0.0031031807602792862, 'mean_word_length': 3.1856060606060606, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5825804', 'n_tokens_mistral': 3309, 'n_tokens_neox': 2652, 'n_words': 585}