Browse Source

Ctrl~W (word deletion) by rse.engelschall. Fix Ctrl~U UTF-8 problems.

git-svn-id: https://klish.googlecode.com/svn/trunk@536 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 12 years ago
parent
commit
66404e829b
1 changed files with 26 additions and 2 deletions
  1. 26 2
      tinyrl/tinyrl.c

+ 26 - 2
tinyrl/tinyrl.c

@@ -298,6 +298,26 @@ static bool_t tinyrl_key_backspace(tinyrl_t *this, int key)
 	return result;
 }
 
+/*-------------------------------------------------------- */
+static bool_t tinyrl_key_backword(tinyrl_t *this, int key)
+{
+	bool_t result = BOOL_FALSE;
+
+    /* remove current whitespace before cursor */
+	while (this->point > 0 && isspace(this->line[this->point - 1]))
+        tinyrl_key_backspace(this, KEY_BS);
+
+    /* delete word before cusor */
+	while (this->point > 0 && !isspace(this->line[this->point - 1]))
+        tinyrl_key_backspace(this, KEY_BS);
+
+	result = BOOL_TRUE;
+
+	/* keep the compiler happy */
+	key = key;
+	return result;
+}
+
 /*-------------------------------------------------------- */
 static bool_t tinyrl_key_delete(tinyrl_t * this, int key)
 {
@@ -330,8 +350,11 @@ static bool_t tinyrl_key_clear_screen(tinyrl_t * this, int key)
 static bool_t tinyrl_key_erase_line(tinyrl_t * this, int key)
 {
 
-	tinyrl_delete_text(this, 0, this->point);
-	this->point = 0;
+	if (this->point) {
+		unsigned end = this->point - 1;
+		tinyrl_delete_text(this, 0, end);
+		this->point = 0;
+	}
 
 	/* keep the compiler happy */
 	key = key;
@@ -441,6 +464,7 @@ tinyrl_init(tinyrl_t * this,
 	this->handlers[KEY_VT] = tinyrl_key_kill;
 	this->handlers[KEY_EM] = tinyrl_key_yank;
 	this->handlers[KEY_HT] = tinyrl_key_tab;
+	this->handlers[KEY_ETB] = tinyrl_key_backword;
 
 	this->line = NULL;
 	this->max_line_length = 0;