feat: improve editor layout flow
- split editor implementation by responsibility - add editor submit events and soft wrap layout - support modified enter input for editor submission
This commit is contained in:
+14
-6
@@ -290,7 +290,8 @@ file sealed class EditorOverlay : IInputComponent
|
||||
{
|
||||
Height = 6,
|
||||
Placeholder = "在这里输入内容",
|
||||
OnCanceled = SubmitAndClose,
|
||||
OnSubmitted = SubmitAndClose,
|
||||
OnCanceled = CancelAndClose,
|
||||
};
|
||||
_editor.SetHistory(_history);
|
||||
_box = new Box(
|
||||
@@ -302,7 +303,8 @@ file sealed class EditorOverlay : IInputComponent
|
||||
"Home/End 行首行尾 Ctrl+Left/Right 按词移动\n" +
|
||||
"Ctrl+Backspace/Delete 按词删除 Ctrl+Z/Y 撤销重做\n" +
|
||||
"Ctrl+C 清空当前内容但保留历史记录\n" +
|
||||
"空内容时 Up/Down 浏览历史 Esc 提交并关闭"),
|
||||
"Enter 换行 Ctrl+Enter 或 Esc 提交并关闭\n" +
|
||||
"长行会按弹层宽度软换行 Up/Down 按视觉行移动"),
|
||||
new Text(),
|
||||
_editor,
|
||||
},
|
||||
@@ -319,23 +321,29 @@ file sealed class EditorOverlay : IInputComponent
|
||||
{
|
||||
if (input is { Kind: TuiInputEventKind.Key, Value: KeyNames.Escape })
|
||||
{
|
||||
SubmitAndClose();
|
||||
_editor.Submit();
|
||||
return;
|
||||
}
|
||||
|
||||
_editor.HandleInput(input);
|
||||
}
|
||||
|
||||
private void SubmitAndClose()
|
||||
private void SubmitAndClose(string text)
|
||||
{
|
||||
var value = _editor.Value.Trim();
|
||||
var value = text.Trim();
|
||||
if (value.Length > 0)
|
||||
{
|
||||
_history.Remove(value);
|
||||
_history.Insert(0, value);
|
||||
}
|
||||
|
||||
_addEvent($"Edited {Math.Max(1, _editor.Value.Split('\n').Length)} line(s)");
|
||||
_addEvent($"Editor submitted {Math.Max(1, text.Split('\n').Length)} line(s)");
|
||||
_runtime.HideOverlay();
|
||||
}
|
||||
|
||||
private void CancelAndClose()
|
||||
{
|
||||
_addEvent("Editor canceled");
|
||||
_runtime.HideOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user