浏览代码

[TextView] add mouse handling

miguel 7 年之前
父节点
当前提交
49818d3058
共有 1 个文件被更改,包括 13 次插入10 次删除
  1. 13 10
      Terminal.Gui/Views/TextView.cs

+ 13 - 10
Terminal.Gui/Views/TextView.cs

@@ -1050,26 +1050,29 @@ namespace Terminal.Gui {
 			return null;
 			return null;
 		}
 		}
 
 
-#if false
 		public override bool MouseEvent (MouseEvent ev)
 		public override bool MouseEvent (MouseEvent ev)
 		{
 		{
-			if (!ev.Flags.HasFlag (MouseFlags.Button1Clicked))
+			if (!ev.Flags.HasFlag (MouseFlags.Button1Clicked)) {
 				return false;
 				return false;
+			}
 
 
 			if (!HasFocus)
 			if (!HasFocus)
 				SuperView.SetFocus (this);
 				SuperView.SetFocus (this);
 
 
-			// We could also set the cursor position.
-			point = first + ev.X;
-			if (point > text.Length)
-				point = text.Length;
-			if (point < first)
-				point = 0;
+			if (ev.Y + topRow >= model.Count) {
+				currentRow = model.Count - topRow;
+			} else {
+				currentRow = ev.Y + topRow;
+			}
+			var r = GetCurrentLine ();
+			if (ev.X - leftColumn >= r.Count)
+				currentColumn = r.Count - leftColumn;
+			else
+				currentColumn = ev.X - leftColumn;
 
 
-			SetNeedsDisplay ();
+			PositionCursor ();
 			return true;
 			return true;
 		}
 		}
-#endif
 	}
 	}
 
 
 }
 }