浏览代码

on a multi-line input, pressing the enter key now inserts a new line
one-line inputs are now not resizable, and pressing enter does nothing

Simon Van Mierlo 9 年之前
父节点
当前提交
037fd19d02
共有 3 个文件被更改,包括 23 次插入15 次删除
  1. 19 14
      client/gui_utils.js
  2. 3 0
      client/styles.css
  3. 1 1
      client/window_event.js

+ 19 - 14
client/gui_utils.js

@@ -385,7 +385,7 @@ GUIUtils = function(){
 			return GUIUtils.getInputField(__specialTypes[type],value);
 	
 		else
-			var input 	 = GUIUtils.getTextInput(value,undefined,1),
+			var input 	 = GUIUtils.getTextInput(value,"code_style string_input",1),
 				 getinput = (type == 'string' ?
 						 function(_){return _.val();} :
 						 function(_){return utils.jsonp(_.val());});
@@ -453,6 +453,7 @@ GUIUtils = function(){
 	this.getTextInput = function(code,className,rows){
 		var input = $('<textarea>');
 		input.attr("cols", 80);
+        rows = rows || 7;
 		input.attr("rows", (rows || 7));
 		input.val(code);
 		input.attr("class", className || 'code_style');
@@ -474,24 +475,28 @@ GUIUtils = function(){
 				
 				return true;
 			}
-			else if( event.keyCode == KEY_ENTER /* ENTER */ && currentKeys[ KEY_SHIFT ] == 1) // HUSEYIN-ENTER
+			else if( event.keyCode == KEY_ENTER )
 			{
-				var cursorPos = event.target.selectionStart;
-				input.val( 
-						input.val().substring(0,cursorPos)+'\r\n'+
-					  	input.val().substring(cursorPos));
-				input.get(0).setSelectionRange(cursorPos+1,cursorPos+1);
+                if (rows > 1) {
+                    // only for multi-line input fields
+                    var cursorPos = event.target.selectionStart;
+                    input.val( 
+                            input.val().substring(0,cursorPos)+'\r\n'+
+                            input.val().substring(cursorPos));
+                    input.get(0).setSelectionRange(cursorPos+1,cursorPos+1);
+                }
 				event.stopPropagation();
-				event.preventDefault();
-				return false;
+                event.preventDefault();
+				return true;
 			}
-			else if( event.keyCode == KEY_ENTER ) // HUSEYIN-ENTER
+		});
+        input.keyup( function (event) {
+			if( event.keyCode == KEY_ENTER )
 			{
 				event.stopPropagation();
-				event.preventDefault();
-				return false;
-			}
-		});
+                event.preventDefault();
+            }
+        });
 		return input;
 	};
 	

+ 3 - 0
client/styles.css

@@ -4,6 +4,9 @@ div, span {
 input, textarea {
 	cursor:/*url('media/cursor_text.png'),*/text;
 }
+textarea.string_input {
+    resize: none;
+}
 select, option, button {
 	cursor:/*url('media/cursor_pointer.png'),*/pointer;
 }

+ 1 - 1
client/window_event.js

@@ -110,7 +110,7 @@ WindowEventHelper = function(){
 	 * Ignore the right click by default
 	 */
 	this.onMouseDown = function(){
-		if (event.which == MOUSE_RIGHT) {
+		if (event.button == MOUSE_RIGHT) {
 			return false;
 		}