浏览代码

TextInput shortcuts (#825)

Rudy Ges 5 年之前
父节点
当前提交
0995edab6a
共有 1 个文件被更改,包括 21 次插入1 次删除
  1. 21 1
      h2d/TextInput.hx

+ 21 - 1
h2d/TextInput.hx

@@ -121,9 +121,22 @@ class TextInput extends Text {
 		var oldText = text;
 
 		switch( e.keyCode ) {
+		case K.LEFT if (K.isDown(K.CTRL)):
+			if (cursorIndex > 0) {
+				var charset = hxd.Charset.getDefault();
+				while (cursorIndex > 0 && charset.isSpace(StringTools.fastCodeAt(text, cursorIndex - 1))) cursorIndex--;
+				while (cursorIndex > 0 && !charset.isSpace(StringTools.fastCodeAt(text, cursorIndex - 1))) cursorIndex--;
+			}
 		case K.LEFT:
 			if( cursorIndex > 0 )
 				cursorIndex--;
+		case K.RIGHT if (K.isDown(K.CTRL)):
+			var len = text.length;
+			if (cursorIndex < text.length) {
+				var charset = hxd.Charset.getDefault();
+				while (cursorIndex < len && charset.isSpace(StringTools.fastCodeAt(text, cursorIndex))) cursorIndex++;
+				while (cursorIndex < len && !charset.isSpace(StringTools.fastCodeAt(text, cursorIndex))) cursorIndex++;
+			}
 		case K.RIGHT:
 			if( cursorIndex < text.length )
 				cursorIndex++;
@@ -149,7 +162,7 @@ class TextInput extends Text {
 				text = text.substr(0, cursorIndex) + text.substr(cursorIndex + 1);
 				onChange();
 			}
-		case K.ENTER, K.NUMPAD_ENTER:
+		case K.ESCAPE, K.ENTER, K.NUMPAD_ENTER:
 			cursorIndex = -1;
 			interactive.blur();
 			return;
@@ -165,6 +178,13 @@ class TextInput extends Text {
 				setState(redo.pop());
 			}
 			return;
+		case K.A if (K.isDown(K.CTRL)):
+			if (text != "") {
+				cursorIndex = text.length;
+				selectionRange = {start: 0, length: text.length};
+				selectionSize = 0;
+			}
+			return;
 		default:
 			if( e.kind == EKeyDown )
 				return;