From a033f08e89cbcb38704a2c99440b7db70522864b Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Thu, 14 Nov 2019 01:13:55 +0800 Subject: [PATCH 1/3] fix conflict between drag & scroll --- Runtime/editor/editor_window.cs | 2 +- Runtime/gestures/binding.cs | 3 +++ Runtime/gestures/pointer_router.cs | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Runtime/editor/editor_window.cs b/Runtime/editor/editor_window.cs index 21b10dff..99b7182d 100644 --- a/Runtime/editor/editor_window.cs +++ b/Runtime/editor/editor_window.cs @@ -404,7 +404,7 @@ void _doOnGUI(Event evt) { -evt.delta.y * this._devicePixelRatio, evt.mousePosition.x * this._devicePixelRatio, evt.mousePosition.y * this._devicePixelRatio, - InputUtils.getMouseButtonKey(evt.button) + InputUtils.getScrollButtonKey() ); } else if (evt.type == EventType.DragUpdated) { diff --git a/Runtime/gestures/binding.cs b/Runtime/gestures/binding.cs index 768d5f0c..d463591d 100644 --- a/Runtime/gestures/binding.cs +++ b/Runtime/gestures/binding.cs @@ -109,6 +109,9 @@ evt is PointerDragFromEditorReleaseEvent void _handlePointerScrollEvent(PointerEvent evt) { this.pointerRouter.clearScrollRoute(evt.pointer); + if (!this.pointerRouter.acceptScroll()) { + return; + } HitTestResult result = new HitTestResult(); this.hitTest(result, evt.position); diff --git a/Runtime/gestures/pointer_router.cs b/Runtime/gestures/pointer_router.cs index c8db6c4a..f78439ec 100644 --- a/Runtime/gestures/pointer_router.cs +++ b/Runtime/gestures/pointer_router.cs @@ -25,6 +25,10 @@ public void removeRoute(int pointer, PointerRoute route) { this._routeMap.Remove(pointer); } } + + public bool acceptScroll() { + return this._routeMap.Count == 0; + } public void clearScrollRoute(int pointer) { if (this._routeMap.ContainsKey(pointer)) { From 5a49be68d60dcb8c62ec56eaa49e443447d4681c Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Thu, 14 Nov 2019 12:16:29 +0800 Subject: [PATCH 2/3] fix crash when editor closes --- Runtime/editor/editor_window.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Runtime/editor/editor_window.cs b/Runtime/editor/editor_window.cs index 99b7182d..94079dbf 100644 --- a/Runtime/editor/editor_window.cs +++ b/Runtime/editor/editor_window.cs @@ -15,10 +15,33 @@ namespace Unity.UIWidgets.editor { #if UNITY_EDITOR public abstract class UIWidgetsEditorWindow : EditorWindow, WindowHost { WindowAdapter _windowAdapter; - + + static readonly List _activeEditorWindows = new List(); + + [InitializeOnLoadMethod] + static void _OnBaseEditorWindowLoaded() + { + EditorApplication.quitting += () => + { + foreach (var editorWindow in _activeEditorWindows) { + editorWindow.OnDisable(); + } + + _activeEditorWindows.Clear(); + }; + } + public UIWidgetsEditorWindow() { this.wantsMouseMove = true; this.wantsMouseEnterLeaveWindow = true; + + _activeEditorWindows.Add(this); + } + + void OnDestroy() { + if (_activeEditorWindows.Contains(this)) { + _activeEditorWindows.Remove(this); + } } protected virtual void OnEnable() { From 5101d2575317473b67772e7ea8f852957f127d65 Mon Sep 17 00:00:00 2001 From: "xingwei.zhu" Date: Thu, 14 Nov 2019 13:09:30 +0800 Subject: [PATCH 3/3] add protection for textediting composition --- Runtime/service/text_input.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Runtime/service/text_input.cs b/Runtime/service/text_input.cs index 640bd7d1..3f4ab70b 100644 --- a/Runtime/service/text_input.cs +++ b/Runtime/service/text_input.cs @@ -345,6 +345,9 @@ public TextEditingValue compose(string composeText) { D.assert(!string.IsNullOrEmpty(composeText)); var composeStart = this.composing == TextRange.empty ? this.selection.start : this.composing.start; var lastComposeEnd = this.composing == TextRange.empty ? this.selection.end : this.composing.end; + + composeStart = Mathf.Clamp(composeStart, 0, this.text.Length); + lastComposeEnd = Mathf.Clamp(lastComposeEnd, 0, this.text.Length); var newText = this.text.Substring(0, composeStart) + composeText + this.text.Substring(lastComposeEnd); var componseEnd = composeStart + composeText.Length; return new TextEditingValue(