浏览代码

ime composing

/main
fzhangtj 6 年前
当前提交
d51d845b
共有 3 个文件被更改,包括 56 次插入21 次删除
  1. 4
      Assets/UIWidgets/editor/editor_window.cs
  2. 5
      Assets/UIWidgets/rendering/editable.cs
  3. 68
      Assets/UIWidgets/service/text_input.cs

4
Assets/UIWidgets/editor/editor_window.cs


}
public void Update() {
if (_textInput != null)
{
_textInput.Update();
}
this.flushMicrotasks();
this._timerProvider.update();

5
Assets/UIWidgets/rendering/editable.cs


}
}
if (_hasFocus) {
var caretOffset = _textPainter.getOffsetForCaret(_selection.extendPos, Rect.fromLTWH(0, 0, 1, preferredLineHeight));
var caretRec = _caretPrototype.shift(caretOffset + effectiveOffset);
Input.compositionCursorPos = new Vector2((float)caretRec.left, (float)caretRec.bottom);
}
_textPainter.paint(context.canvas, effectiveOffset);
}

68
Assets/UIWidgets/service/text_input.cs


offset = Math.Min(offset, text.Length);
return this.copyWith(selection: TextSelection.collapsed(offset));
}
public TextEditingValue compose(string composeText)
{
D.assert(string.IsNullOrEmpty(composeText));
var composeStart = composing == TextRange.empty ? selection.start : composing.start;
var lastComposeEnd =composing == TextRange.empty ? selection.end : composing.end;
var newText = text.Substring(0, composeStart) + composeText + text.Substring(lastComposeEnd);
var componseEnd = composeStart + composeText.Length;
return new TextEditingValue(
text: newText, selection: TextSelection.collapsed(componseEnd),
composing: new TextRange(composeStart, componseEnd)
);
}
public TextEditingValue clearCompose()
{
if (composing == TextRange.empty)
{
return this;
}
return new TextEditingValue(
text: text.Substring(0, composing.start) + text.Substring(composing.end),
selection: TextSelection.collapsed(composing.start),
composing: TextRange.empty
);
}
public static readonly TextEditingValue empty = new TextEditingValue();

_textInput._value = value;
}
public void setCompositionCursorPos(double x, double y)
{
D.assert(attached);
_textInput.setCompositionCursorPos(x, y);
}
public void close()
{
if (attached)

Input.imeCompositionMode = IMECompositionMode.Auto;
}
D.assert(!attached);
}

internal TextEditingValue _value;
private List<char> inputValue = new List<char>();
static Dictionary<Event, TextEditOp> s_Keyactions;
private string _lastCompositionString;
public TextInputConnection attach(TextInputClient client)
{

Input.imeCompositionMode = IMECompositionMode.On;
return connection;
}

if (currentEvent.type == EventType.KeyDown)
{
bool handled = handleKeyEvent(currentEvent);
if (!handled && currentEvent.keyCode == KeyCode.None)
if (!handled)
inputValue.Add(currentEvent.character);
if (currentEvent.keyCode == KeyCode.None)
{
_value = _value.clearCompose().insert(new string(currentEvent.character, 1));
_currentConnection._client.updateEditingValue(_value);
}
}
public void Update()
{
if (_currentConnection == null)
if (!string.IsNullOrEmpty(Input.compositionString) && _lastCompositionString != Input.compositionString)
return;
_value = _value.compose(Input.compositionString);
_currentConnection._client.updateEditingValue(_value);
if (inputValue.Count == 0)
{
return;
}
_lastCompositionString = Input.compositionString;
}
_value = _value.insert(new string(inputValue.ToArray()));
//_value = _value.copyWith(text: _value.text + new string(inputValue.ToArray()));
_currentConnection._client.updateEditingValue(_value);
inputValue.Clear();
public void setCompositionCursorPos(double x, double y)
{
Input.compositionCursorPos = new Vector2((float)x, (float)y);
private bool handleKeyEvent(Event e)
{
initKeyActions();

正在加载...
取消
保存