/// <summary> /// Display a Text Area GUILayout element with the processed source /// </summary> public bool OnGUILayout_MardkDownTextArea(string style = null) { if (_markdownSkin == null) { _markdownSkin = Utils.GetGuiSkin(__guiSkinName__); } if (Event.current.type == EventType.MouseDown && Event.current.button == 0) { _isMouseDown = true; } GUISkin _currentSkin = GUI.skin; GUI.skin = UserSkin != null?UserSkin:_markdownSkin; string _style = "MarkdownTextArea" + (EditorGUIUtility.isProSkin?"Dark":"Light"); if (!string.IsNullOrEmpty(style)) { _style = style; } GUILayout.TextArea(_processedText, _style); Rect rect = GUILayoutUtility.GetLastRect(); GUI.skin = _currentSkin; TextEditor editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl); /* * GUILayout.Label(string.Format("Selected text: {0}\nPos: {1}\nSelect pos: {2}", * editor.SelectedText, * editor.pos, * editor.selectPos)); */ if (_markdownParser != null && _isMouseDown) { if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition)) { //Debug.Log("MouseDown "+Event.current.mousePosition+" on"+rect); _isMouseDown = false; #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 if (editor.pos == editor.selectPos) { bool isDownOnLink; HyperTextLUT _link = _markdownParser.TryGetHyperLinkAt(editor.pos, out isDownOnLink); if (isDownOnLink) { Application.OpenURL(_link.url); } } #else if (editor.cursorIndex == editor.selectIndex) { bool isDownOnLink; HyperTextLUT _link = _markdownParser.TryGetHyperLinkAt(editor.cursorIndex, out isDownOnLink); if (isDownOnLink) { Application.OpenURL(_link.url); } } #endif } //editor.pos = 0; //editor.selectPos = 0; editor.SelectNone(); return(true); } else { if (!string.IsNullOrEmpty(editor.SelectedText)) { //editor.pos = 0; //editor.selectPos = 0; editor.SelectNone(); } } return(false); }