fzhangtj
6 年前
当前提交
4da440ff
共有 9 个文件被更改,包括 395 次插入 和 300 次删除
-
351Runtime/service/text_input.cs
-
117Runtime/widgets/editable_text.cs
-
22Samples/UIWidgetSample/ToDoAppCanvas.cs
-
8Runtime/material.meta
-
11Runtime/material/text_selection.cs.meta
-
11Runtime/service/clipboard.cs.meta
-
153Runtime/service/text_input_utils.cs
-
11Runtime/service/text_input_utils.cs.meta
-
11Runtime/widgets/text_selection.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: ba4b5dab38db54970bf74725b5642400 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 33685d6edaab14322aa1b854fdd7c3e6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: e5edc4624d81f4f78846c2d0b1f1beec |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.UIWidgets.service { |
|||
|
|||
public class TextInputUtils { |
|||
|
|||
static Dictionary<Event, TextInputAction> _keyToOperations; |
|||
|
|||
public static TextInputAction? getInputAction(Event evt) { |
|||
if (_keyToOperations == null) { |
|||
initKeyToOperations(); |
|||
} |
|||
EventModifiers m = evt.modifiers; |
|||
evt.modifiers &= ~EventModifiers.CapsLock; |
|||
TextInputAction result; |
|||
var exists = _keyToOperations.TryGetValue(evt, out result); |
|||
evt.modifiers = m; |
|||
if (exists) { |
|||
return result; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public static void initKeyToOperations() { |
|||
if (_keyToOperations != null) { |
|||
return; |
|||
} |
|||
_keyToOperations = new Dictionary<Event, TextInputAction>(); |
|||
|
|||
// key mappings shared by the platforms
|
|||
mapKey("return", TextInputAction.newline); |
|||
mapKey("left", TextInputAction.moveLeft); |
|||
mapKey("right", TextInputAction.moveRight); |
|||
mapKey("up", TextInputAction.moveUp); |
|||
mapKey("down", TextInputAction.moveDown); |
|||
|
|||
mapKey("#left", TextInputAction.selectLeft); |
|||
mapKey("#right", TextInputAction.selectRight); |
|||
mapKey("#up", TextInputAction.selectUp); |
|||
mapKey("#down", TextInputAction.selectDown); |
|||
|
|||
mapKey("delete", TextInputAction.delete); |
|||
mapKey("backspace", TextInputAction.backspace); |
|||
mapKey("#backspace", TextInputAction.backspace); |
|||
|
|||
// OSX is the special case for input shortcuts
|
|||
if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) { |
|||
// Keyboard mappings for mac
|
|||
// TODO mapKey ("home", TextInputAction.scrollStart);
|
|||
// TODO mapKey ("end", TextInputAction.scrollEnd);
|
|||
// TODO mapKey ("page up", TextInputAction.scrollPageUp);
|
|||
// TODO mapKey ("page down", TextInputAction.scrollPageDown);
|
|||
|
|||
mapKey("^left", TextInputAction.moveGraphicalLineStart); |
|||
mapKey("^right", TextInputAction.moveGraphicalLineEnd); |
|||
// TODO mapKey ("^up", TextInputAction.scrollPageUp);
|
|||
// TODO mapKey ("^down", TextInputAction.scrollPageDown);
|
|||
|
|||
mapKey("&left", TextInputAction.moveWordLeft); |
|||
mapKey("&right", TextInputAction.moveWordRight); |
|||
mapKey("&up", TextInputAction.moveParagraphBackward); |
|||
mapKey("&down", TextInputAction.moveParagraphForward); |
|||
|
|||
mapKey("%left", TextInputAction.moveGraphicalLineStart); |
|||
mapKey("%right", TextInputAction.moveGraphicalLineEnd); |
|||
mapKey("%up", TextInputAction.moveTextStart); |
|||
mapKey("%down", TextInputAction.moveTextEnd); |
|||
|
|||
mapKey("#home", TextInputAction.selectTextStart); |
|||
mapKey("#end", TextInputAction.selectTextEnd); |
|||
// TODO mapKey ("#page up", TextInputAction.selectPageUp);
|
|||
// TODO mapKey ("#page down", TextInputAction.selectPageDown);
|
|||
|
|||
mapKey("#^left", TextInputAction.expandSelectGraphicalLineStart); |
|||
mapKey("#^right", TextInputAction.expandSelectGraphicalLineEnd); |
|||
mapKey("#^up", TextInputAction.selectParagraphBackward); |
|||
mapKey("#^down", TextInputAction.selectParagraphForward); |
|||
|
|||
mapKey("#&left", TextInputAction.selectWordLeft); |
|||
mapKey("#&right", TextInputAction.selectWordRight); |
|||
mapKey("#&up", TextInputAction.selectParagraphBackward); |
|||
mapKey("#&down", TextInputAction.selectParagraphForward); |
|||
|
|||
mapKey("#%left", TextInputAction.expandSelectGraphicalLineStart); |
|||
mapKey("#%right", TextInputAction.expandSelectGraphicalLineEnd); |
|||
mapKey("#%up", TextInputAction.selectTextStart); |
|||
mapKey("#%down", TextInputAction.selectTextEnd); |
|||
|
|||
mapKey("%a", TextInputAction.selectAll); |
|||
mapKey("%x", TextInputAction.cut); |
|||
mapKey("%c", TextInputAction.copy); |
|||
mapKey("%v", TextInputAction.paste); |
|||
|
|||
// emacs-like keybindings
|
|||
mapKey("^d", TextInputAction.delete); |
|||
mapKey("^h", TextInputAction.backspace); |
|||
mapKey("^b", TextInputAction.moveLeft); |
|||
mapKey("^f", TextInputAction.moveRight); |
|||
mapKey("^a", TextInputAction.moveLineStart); |
|||
mapKey("^e", TextInputAction.moveLineEnd); |
|||
|
|||
mapKey("&delete", TextInputAction.deleteWordForward); |
|||
mapKey("&backspace", TextInputAction.deleteWordBack); |
|||
mapKey("%backspace", TextInputAction.deleteLineBack); |
|||
} else { |
|||
// Windows/Linux keymappings
|
|||
mapKey("home", TextInputAction.moveGraphicalLineStart); |
|||
mapKey("end", TextInputAction.moveGraphicalLineEnd); |
|||
// TODO mapKey ("page up", TextInputAction.movePageUp);
|
|||
// TODO mapKey ("page down", TextInputAction.movePageDown);
|
|||
|
|||
mapKey("%left", TextInputAction.moveWordLeft); |
|||
mapKey("%right", TextInputAction.moveWordRight); |
|||
mapKey("%up", TextInputAction.moveParagraphBackward); |
|||
mapKey("%down", TextInputAction.moveParagraphForward); |
|||
|
|||
mapKey("^left", TextInputAction.moveToEndOfPreviousWord); |
|||
mapKey("^right", TextInputAction.moveToStartOfNextWord); |
|||
mapKey("^up", TextInputAction.moveParagraphBackward); |
|||
mapKey("^down", TextInputAction.moveParagraphForward); |
|||
|
|||
mapKey("#^left", TextInputAction.selectToEndOfPreviousWord); |
|||
mapKey("#^right", TextInputAction.selectToStartOfNextWord); |
|||
mapKey("#^up", TextInputAction.selectParagraphBackward); |
|||
mapKey("#^down", TextInputAction.selectParagraphForward); |
|||
|
|||
mapKey("#home", TextInputAction.selectGraphicalLineStart); |
|||
mapKey("#end", TextInputAction.selectGraphicalLineEnd); |
|||
// TODO mapKey ("#page up", TextInputAction.selectPageUp);
|
|||
// TODO mapKey ("#page down", TextInputAction.selectPageDown);
|
|||
|
|||
mapKey("^delete", TextInputAction.deleteWordForward); |
|||
mapKey("^backspace", TextInputAction.deleteWordBack); |
|||
mapKey("%backspace", TextInputAction.deleteLineBack); |
|||
|
|||
mapKey("^a", TextInputAction.selectAll); |
|||
mapKey("^x", TextInputAction.cut); |
|||
mapKey("^c", TextInputAction.copy); |
|||
mapKey("^v", TextInputAction.paste); |
|||
mapKey("#delete", TextInputAction.cut); |
|||
mapKey("^insert", TextInputAction.copy); |
|||
mapKey("#insert", TextInputAction.paste); |
|||
} |
|||
|
|||
} |
|||
|
|||
static void mapKey(string key, TextInputAction action) { |
|||
_keyToOperations[Event.KeyboardEvent(key)] = action; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2288dc63570aa4d8db1bd6673b12634f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: af25b0b118f7847c1980a3e9914392f3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue