浏览代码

fix Editable: missing onSubmitted event implement

/main
fzhangtj 6 年前
当前提交
4da440ff
共有 9 个文件被更改,包括 395 次插入300 次删除
  1. 351
      Runtime/service/text_input.cs
  2. 117
      Runtime/widgets/editable_text.cs
  3. 22
      Samples/UIWidgetSample/ToDoAppCanvas.cs
  4. 8
      Runtime/material.meta
  5. 11
      Runtime/material/text_selection.cs.meta
  6. 11
      Runtime/service/clipboard.cs.meta
  7. 153
      Runtime/service/text_input_utils.cs
  8. 11
      Runtime/service/text_input_utils.cs.meta
  9. 11
      Runtime/widgets/text_selection.cs.meta

351
Runtime/service/text_input.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;

public interface TextInputClient {
void updateEditingValue(TextEditingValue value);
TextEditingValue getValueForOperation(TextEditOp operation);
// void performAction(TextInputAction action);
void performAction(TextInputAction action);
none,
unspecified,
go,
search,
send,
next,
previous,
continueAction,
join,
route,
emergencyCall,
moveLeft,
moveRight,
moveUp,
moveDown,
moveLineStart,
moveLineEnd,
moveTextStart,
moveTextEnd,
movePageUp,
movePageDown,
moveGraphicalLineStart,
moveGraphicalLineEnd,
moveWordLeft,
moveWordRight,
moveParagraphForward,
moveParagraphBackward,
moveToStartOfNextWord,
moveToEndOfPreviousWord,
selectLeft,
selectRight,
selectUp,
selectDown,
selectTextStart,
selectTextEnd,
selectPageUp,
selectPageDown,
expandSelectGraphicalLineStart,
expandSelectGraphicalLineEnd,
selectGraphicalLineStart,
selectGraphicalLineEnd,
selectWordLeft,
selectWordRight,
selectToEndOfPreviousWord,
selectToStartOfNextWord,
selectParagraphBackward,
selectParagraphForward,
delete,
backspace,
deleteWordBack,
deleteWordForward,
deleteLineBack,
cut,
copy,
paste,
selectAll,
selectNone,
scrollStart,
scrollEnd,
scrollPageUp,
scrollPageDown,
// text client
public class TextInputConnection {
internal TextInputConnection(TextInputClient client, TextInput textInput) {

public class TextInput {
internal TextInputConnection _currentConnection;
internal TextEditingValue _value;
static Dictionary<Event, TextEditOp> s_Keyactions;
string _lastCompositionString;
public TextInputConnection attach(TextInputClient client) {

var currentEvent = Event.current;
if (currentEvent.type == EventType.KeyDown) {
bool handled = this.handleKeyEvent(currentEvent);
if (!handled) {
var action = TextInputUtils.getInputAction(currentEvent);
if (action != null) {
this._performAction(this._currentConnection._id, action.Value);
}
if (action == null || action == TextInputAction.newline) {
this._currentConnection._client.updateEditingValue(this._value);
this._updateEditingState(this._currentConnection._id, this._value);
}
}
currentEvent.Use();

this._lastCompositionString != Input.compositionString) {
this._value = this._value.compose(Input.compositionString);
this._currentConnection._client.updateEditingValue(this._value);
this._updateEditingState(this._currentConnection._id, this._value);
}
this._lastCompositionString = Input.compositionString;

Input.compositionCursorPos = new Vector2((float) x, (float) y);
}
bool handleKeyEvent(Event e) {
initKeyActions();
EventModifiers m = e.modifiers;
e.modifiers &= ~EventModifiers.CapsLock;
if (s_Keyactions.ContainsKey(e)) {
TextEditOp op = s_Keyactions[e];
var newValue = this._currentConnection._client.getValueForOperation(op);
if (this._value != newValue) {
this._value = newValue;
this._currentConnection._client.updateEditingValue(this._value);
void _updateEditingState(int client, TextEditingValue value) {
Window.instance.run(() => {
if (this._currentConnection == null) {
return;
e.modifiers = m;
return true;
}
e.modifiers = m;
return false;
}
TextEditingValue performOperation(TextEditOp operation) {
switch (operation) {
case TextEditOp.MoveLeft:
return this._value.moveLeft();
case TextEditOp.MoveRight:
return this._value.moveRight();
// case TextEditOp.MoveUp: MoveUp(); break;
// case TextEditOp.MoveDown: MoveDown(); break;
// case TextEditOp.MoveLineStart: MoveLineStart(); break;
// case TextEditOp.MoveLineEnd: MoveLineEnd(); break;
// case TextEditOp.MoveWordRight: MoveWordRight(); break;
// case TextEditOp.MoveToStartOfNextWord: MoveToStartOfNextWord(); break;
// case TextEditOp.MoveToEndOfPreviousWord: MoveToEndOfPreviousWord(); break;
// case TextEditOp.MoveWordLeft: MoveWordLeft(); break;
// case TextEditOp.MoveTextStart: MoveTextStart(); break;
// case TextEditOp.MoveTextEnd: MoveTextEnd(); break;
// case TextEditOp.MoveParagraphForward: MoveParagraphForward(); break;
// case TextEditOp.MoveParagraphBackward: MoveParagraphBackward(); break;
// case TextEditOp.MoveGraphicalLineStart: MoveGraphicalLineStart(); break;
// case TextEditOp.MoveGraphicalLineEnd: MoveGraphicalLineEnd(); break;
case TextEditOp.SelectLeft:
return this._value.extendLeft();
case TextEditOp.SelectRight:
return this._value.extendRight();
// case TextEditOp.SelectUp: SelectUp(); break;
// case TextEditOp.SelectDown: SelectDown(); break;
// case TextEditOp.SelectWordRight: SelectWordRight(); break;
// case TextEditOp.SelectWordLeft: SelectWordLeft(); break;
// case TextEditOp.SelectToEndOfPreviousWord: SelectToEndOfPreviousWord(); break;
// case TextEditOp.SelectToStartOfNextWord: SelectToStartOfNextWord(); break;
//
// case TextEditOp.SelectTextStart: SelectTextStart(); break;
// case TextEditOp.SelectTextEnd: SelectTextEnd(); break;
// case TextEditOp.ExpandSelectGraphicalLineStart: ExpandSelectGraphicalLineStart(); break;
// case TextEditOp.ExpandSelectGraphicalLineEnd: ExpandSelectGraphicalLineEnd(); break;
// case TextEditOp.SelectParagraphForward: SelectParagraphForward(); break;
// case TextEditOp.SelectParagraphBackward: SelectParagraphBackward(); break;
// case TextEditOp.SelectGraphicalLineStart: SelectGraphicalLineStart(); break;
// case TextEditOp.SelectGraphicalLineEnd: SelectGraphicalLineEnd(); break;
// case TextEditOp.Delete: return Delete();
case TextEditOp.Backspace:
return this._value.deleteSelection();
// _value.composing
// _value = _value.
// case TextEditOp.Cut: return Cut();
// case TextEditOp.Copy: Copy(); break;
// case TextEditOp.Paste: return Paste();
// case TextEditOp.SelectAll: SelectAll(); break;
// case TextEditOp.SelectNone: SelectNone(); break;
// case TextEditOp.DeleteWordBack: return DeleteWordBack(); // break; // The uncoditional return makes the "break;" issue a warning about unreachable code
// case TextEditOp.DeleteLineBack: return DeleteLineBack();
// case TextEditOp.DeleteWordForward: return DeleteWordForward(); // break; // The uncoditional return makes the "break;" issue a warning about unreachable code
default:
Debug.Log("Unimplemented: " + operation);
break;
}
return this._value;
if (client != this._currentConnection._id) {
return;
}
this._currentConnection._client.updateEditingValue(value);
});
void _performAction(int client, TextInputAction action) {
Window.instance.run(() => {
if (this._currentConnection == null) {
return;
}
static void initKeyActions() {
if (s_Keyactions != null) {
return;
}
s_Keyactions = new Dictionary<Event, TextEditOp>();
// key mappings shared by the platforms
mapKey("left", TextEditOp.MoveLeft);
mapKey("right", TextEditOp.MoveRight);
mapKey("up", TextEditOp.MoveUp);
mapKey("down", TextEditOp.MoveDown);
mapKey("#left", TextEditOp.SelectLeft);
mapKey("#right", TextEditOp.SelectRight);
mapKey("#up", TextEditOp.SelectUp);
mapKey("#down", TextEditOp.SelectDown);
mapKey("delete", TextEditOp.Delete);
mapKey("backspace", TextEditOp.Backspace);
mapKey("#backspace", TextEditOp.Backspace);
// OSX is the special case for input shortcuts
if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) {
// Keyboard mappings for mac
// TODO mapKey ("home", TextEditOp.ScrollStart);
// TODO mapKey ("end", TextEditOp.ScrollEnd);
// TODO mapKey ("page up", TextEditOp.ScrollPageUp);
// TODO mapKey ("page down", TextEditOp.ScrollPageDown);
mapKey("^left", TextEditOp.MoveGraphicalLineStart);
mapKey("^right", TextEditOp.MoveGraphicalLineEnd);
// TODO mapKey ("^up", TextEditOp.ScrollPageUp);
// TODO mapKey ("^down", TextEditOp.ScrollPageDown);
mapKey("&left", TextEditOp.MoveWordLeft);
mapKey("&right", TextEditOp.MoveWordRight);
mapKey("&up", TextEditOp.MoveParagraphBackward);
mapKey("&down", TextEditOp.MoveParagraphForward);
mapKey("%left", TextEditOp.MoveGraphicalLineStart);
mapKey("%right", TextEditOp.MoveGraphicalLineEnd);
mapKey("%up", TextEditOp.MoveTextStart);
mapKey("%down", TextEditOp.MoveTextEnd);
mapKey("#home", TextEditOp.SelectTextStart);
mapKey("#end", TextEditOp.SelectTextEnd);
// TODO mapKey ("#page up", TextEditOp.SelectPageUp);
// TODO mapKey ("#page down", TextEditOp.SelectPageDown);
mapKey("#^left", TextEditOp.ExpandSelectGraphicalLineStart);
mapKey("#^right", TextEditOp.ExpandSelectGraphicalLineEnd);
mapKey("#^up", TextEditOp.SelectParagraphBackward);
mapKey("#^down", TextEditOp.SelectParagraphForward);
mapKey("#&left", TextEditOp.SelectWordLeft);
mapKey("#&right", TextEditOp.SelectWordRight);
mapKey("#&up", TextEditOp.SelectParagraphBackward);
mapKey("#&down", TextEditOp.SelectParagraphForward);
mapKey("#%left", TextEditOp.ExpandSelectGraphicalLineStart);
mapKey("#%right", TextEditOp.ExpandSelectGraphicalLineEnd);
mapKey("#%up", TextEditOp.SelectTextStart);
mapKey("#%down", TextEditOp.SelectTextEnd);
mapKey("%a", TextEditOp.SelectAll);
mapKey("%x", TextEditOp.Cut);
mapKey("%c", TextEditOp.Copy);
mapKey("%v", TextEditOp.Paste);
// emacs-like keybindings
mapKey("^d", TextEditOp.Delete);
mapKey("^h", TextEditOp.Backspace);
mapKey("^b", TextEditOp.MoveLeft);
mapKey("^f", TextEditOp.MoveRight);
mapKey("^a", TextEditOp.MoveLineStart);
mapKey("^e", TextEditOp.MoveLineEnd);
mapKey("&delete", TextEditOp.DeleteWordForward);
mapKey("&backspace", TextEditOp.DeleteWordBack);
mapKey("%backspace", TextEditOp.DeleteLineBack);
} else {
// Windows/Linux keymappings
mapKey("home", TextEditOp.MoveGraphicalLineStart);
mapKey("end", TextEditOp.MoveGraphicalLineEnd);
// TODO mapKey ("page up", TextEditOp.MovePageUp);
// TODO mapKey ("page down", TextEditOp.MovePageDown);
mapKey("%left", TextEditOp.MoveWordLeft);
mapKey("%right", TextEditOp.MoveWordRight);
mapKey("%up", TextEditOp.MoveParagraphBackward);
mapKey("%down", TextEditOp.MoveParagraphForward);
mapKey("^left", TextEditOp.MoveToEndOfPreviousWord);
mapKey("^right", TextEditOp.MoveToStartOfNextWord);
mapKey("^up", TextEditOp.MoveParagraphBackward);
mapKey("^down", TextEditOp.MoveParagraphForward);
mapKey("#^left", TextEditOp.SelectToEndOfPreviousWord);
mapKey("#^right", TextEditOp.SelectToStartOfNextWord);
mapKey("#^up", TextEditOp.SelectParagraphBackward);
mapKey("#^down", TextEditOp.SelectParagraphForward);
mapKey("#home", TextEditOp.SelectGraphicalLineStart);
mapKey("#end", TextEditOp.SelectGraphicalLineEnd);
// TODO mapKey ("#page up", TextEditOp.SelectPageUp);
// TODO mapKey ("#page down", TextEditOp.SelectPageDown);
mapKey("^delete", TextEditOp.DeleteWordForward);
mapKey("^backspace", TextEditOp.DeleteWordBack);
mapKey("%backspace", TextEditOp.DeleteLineBack);
mapKey("^a", TextEditOp.SelectAll);
mapKey("^x", TextEditOp.Cut);
mapKey("^c", TextEditOp.Copy);
mapKey("^v", TextEditOp.Paste);
mapKey("#delete", TextEditOp.Cut);
mapKey("^insert", TextEditOp.Copy);
mapKey("#insert", TextEditOp.Paste);
}
if (client != this._currentConnection._id) {
return;
}
this._currentConnection._client.performAction(action);
});
static void mapKey(string key, TextEditOp action) {
s_Keyactions[Event.KeyboardEvent(key)] = action;
}
public enum TextEditOp {
MoveLeft,
MoveRight,
MoveUp,
MoveDown,
MoveLineStart,
MoveLineEnd,
MoveTextStart,
MoveTextEnd,
MovePageUp,
MovePageDown,
MoveGraphicalLineStart,
MoveGraphicalLineEnd,
MoveWordLeft,
MoveWordRight,
MoveParagraphForward,
MoveParagraphBackward,
MoveToStartOfNextWord,
MoveToEndOfPreviousWord,
SelectLeft,
SelectRight,
SelectUp,
SelectDown,
SelectTextStart,
SelectTextEnd,
SelectPageUp,
SelectPageDown,
ExpandSelectGraphicalLineStart,
ExpandSelectGraphicalLineEnd,
SelectGraphicalLineStart,
SelectGraphicalLineEnd,
SelectWordLeft,
SelectWordRight,
SelectToEndOfPreviousWord,
SelectToStartOfNextWord,
SelectParagraphBackward,
SelectParagraphForward,
Delete,
Backspace,
DeleteWordBack,
DeleteWordForward,
DeleteLineBack,
Cut,
Copy,
Paste,
SelectAll,
SelectNone,
ScrollStart,
ScrollEnd,
ScrollPageUp,
ScrollPageDown,
}
}

117
Runtime/widgets/editable_text.cs


public readonly TextSelectionControls selectionControls;
public readonly ValueChanged<string> onChanged;
public readonly VoidCallback onEditingComplete;
public readonly ValueChanged<string> onSubmitted;
public readonly SelectionChangedCallback onSelectionChanged;

TextAlign textAlign = TextAlign.left, TextDirection? textDirection = null,
double textScaleFactor = 1.0, int maxLines = 1,
bool autofocus = false, Color selectionColor = null, TextSelectionControls selectionControls = null,
ValueChanged<string> onChanged = null,
ValueChanged<string> onChanged = null, VoidCallback onEditingComplete = null,
ValueChanged<string> onSubmitted = null, SelectionChangedCallback onSelectionChanged = null,
List<TextInputFormatter> inputFormatters = null, bool rendererIgnoresPointer = false,
EdgeInsets scrollPadding = null,

this.onChanged = onChanged;
this.onSubmitted = onSubmitted;
this.onSelectionChanged = onSelectionChanged;
this.onEditingComplete = onEditingComplete;
this.rendererIgnoresPointer = rendererIgnoresPointer;
this.selectionControls = selectionControls;
if (maxLines == 1) {

this._formatAndSetValue(value);
}
public TextEditingValue getValueForOperation(TextEditOp operation) {
public TextEditingValue getValueForAction(TextInputAction operation) {
TextPosition newPosition = null;
TextPosition newExtend = null;
TextEditingValue newValue = null;

case TextEditOp.MoveLeft:
case TextInputAction.moveLeft:
case TextEditOp.MoveRight:
case TextInputAction.moveRight:
case TextEditOp.MoveUp:
case TextInputAction.moveUp:
case TextEditOp.MoveDown:
case TextInputAction.moveDown:
case TextEditOp.MoveLineStart:
case TextInputAction.moveLineStart:
case TextEditOp.MoveLineEnd:
case TextInputAction.moveLineEnd:
case TextEditOp.MoveWordRight:
case TextInputAction.moveWordRight:
case TextEditOp.MoveWordLeft:
case TextInputAction.moveWordLeft:
// case TextEditOp.MoveToStartOfNextWord: MoveToStartOfNextWord(); break;
// case TextEditOp.MoveToEndOfPreviousWord: MoveToEndOfPreviousWord(); break;
case TextEditOp.MoveTextStart:
// case TextInputAction.MoveToStartOfNextWord: MoveToStartOfNextWord(); break;
// case TextInputAction.MoveToEndOfPreviousWord: MoveToEndOfPreviousWord(); break;
case TextInputAction.moveTextStart:
case TextEditOp.MoveTextEnd:
case TextInputAction.moveTextEnd:
case TextEditOp.MoveParagraphForward:
case TextInputAction.moveParagraphForward:
case TextEditOp.MoveParagraphBackward:
case TextInputAction.moveParagraphBackward:
case TextEditOp.MoveGraphicalLineStart:
case TextInputAction.moveGraphicalLineStart:
case TextEditOp.MoveGraphicalLineEnd:
case TextInputAction.moveGraphicalLineEnd:
case TextEditOp.SelectLeft:
case TextInputAction.selectLeft:
case TextEditOp.SelectRight:
case TextInputAction.selectRight:
case TextEditOp.SelectUp:
case TextInputAction.selectUp:
case TextEditOp.SelectDown:
case TextInputAction.selectDown:
case TextEditOp.SelectWordRight:
case TextInputAction.selectWordRight:
case TextEditOp.SelectWordLeft:
case TextInputAction.selectWordLeft:
// case TextEditOp.SelectToEndOfPreviousWord: SelectToEndOfPreviousWord(); break;
// case TextEditOp.SelectToStartOfNextWord: SelectToStartOfNextWord(); break;
// case TextInputAction.SelectToEndOfPreviousWord: SelectToEndOfPreviousWord(); break;
// case TextInputAction.SelectToStartOfNextWord: SelectToStartOfNextWord(); break;
case TextEditOp.SelectTextStart:
case TextInputAction.selectTextStart:
case TextEditOp.SelectTextEnd:
case TextInputAction.selectTextEnd:
case TextEditOp.ExpandSelectGraphicalLineStart:
case TextInputAction.expandSelectGraphicalLineStart:
if (this._value.selection.isCollapsed ||
!this.renderEditable.isLineEndOrStart(this._value.selection.start)) {
newSelection = new TextSelection(this.renderEditable.getLineStartPosition(startPos).offset,

break;
case TextEditOp.ExpandSelectGraphicalLineEnd:
case TextInputAction.expandSelectGraphicalLineEnd:
if (this._value.selection.isCollapsed ||
!this.renderEditable.isLineEndOrStart(this._value.selection.end)) {
newSelection = new TextSelection(this._value.selection.start,

break;
case TextEditOp.SelectParagraphForward:
case TextInputAction.selectParagraphForward:
case TextEditOp.SelectParagraphBackward:
case TextInputAction.selectParagraphBackward:
case TextEditOp.SelectGraphicalLineStart:
case TextInputAction.selectGraphicalLineStart:
case TextEditOp.SelectGraphicalLineEnd:
case TextInputAction.selectGraphicalLineEnd:
case TextEditOp.Delete:
case TextInputAction.delete:
case TextEditOp.Backspace:
case TextInputAction.backspace:
case TextEditOp.SelectAll:
case TextInputAction.selectAll:
newSelection = this._value.selection.copyWith(baseOffset: 0, extentOffset: this._value.text.Length);
break;
}

return this._value;
}
public void performAction(TextInputAction action) {
TextEditingValue newValue;
switch (action) {
case TextInputAction.newline:
if (this.widget.maxLines == 1) this._finalizeEditing(true);
break;
case TextInputAction.done:
case TextInputAction.go:
case TextInputAction.send:
case TextInputAction.search:
this._finalizeEditing(true);
break;
case TextInputAction.next:
case TextInputAction.previous:
case TextInputAction.continueAction:
case TextInputAction.join:
case TextInputAction.route:
case TextInputAction.emergencyCall:
this._finalizeEditing(false);
break;
default:
newValue = this.getValueForAction(action);
if (newValue != this.textEditingValue) {
this.textEditingValue = newValue;
}
break;
}
}
void _finalizeEditing(bool shouldUnfocus) {
if (this.widget.onEditingComplete != null) {
this.widget.onEditingComplete();
} else {
this.widget.controller.clearComposing();
if (shouldUnfocus) this.widget.focusNode.unfocus();
}
if (this.widget.onSubmitted != null) this.widget.onSubmitted(this._value.text);
}
void _updateRemoteEditingValueIfNeeded() {
if (!this._hasInputConnection) {
return;

22
Samples/UIWidgetSample/ToDoAppCanvas.cs


using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgetsSample {

padding: EdgeInsets.fromLTRB(8, 0, 8, 0),
child: new EditableText(maxLines: 1,
controller: this.controller,
onSubmitted: (text) => {
this.controller.clear();
this._addItem(text);
},
selectionControls: MaterialUtils.materialTextSelectionControls,
autofocus: true,
focusNode: new FocusNode(),

child: new Text("Add", style: new TextStyle(
fontSize: 20, color: Color.fromARGB(255, 255, 255, 255), fontWeight: FontWeight.w700
)), onPressed: () => {
this.setState(() => {
if (this.controller.text != "") {
this.items.Add(new ToDoItem()
{id = this.nextId++, content = this.controller.text});
}
});
this._addItem();
}
void _addItem(string text = null) {
this.setState(() => {
text = text ?? this.controller.text;
if (text != "") {
this.items.Add(new ToDoItem()
{id = this.nextId++, content = text});
}
});
}
Widget contents() {

8
Runtime/material.meta


fileFormatVersion: 2
guid: ba4b5dab38db54970bf74725b5642400
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/material/text_selection.cs.meta


fileFormatVersion: 2
guid: 33685d6edaab14322aa1b854fdd7c3e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/service/clipboard.cs.meta


fileFormatVersion: 2
guid: e5edc4624d81f4f78846c2d0b1f1beec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

153
Runtime/service/text_input_utils.cs


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;
}
}
}

11
Runtime/service/text_input_utils.cs.meta


fileFormatVersion: 2
guid: 2288dc63570aa4d8db1bd6673b12634f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Runtime/widgets/text_selection.cs.meta


fileFormatVersion: 2
guid: af25b0b118f7847c1980a3e9914392f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存