-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: 增加代码编辑器插入文本方法 #902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: 增加代码编辑器插入文本方法 #902
Conversation
|
Thanks for your PR, @kimdiego2098. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Reviewer's GuideAdds a new text insertion API to the CodeEditor component and wires it to a corresponding JavaScript function that inserts text at the current Monaco editor selection and refocuses the editor. Sequence diagram for CodeEditor.InsertText interactionsequenceDiagram
actor User
participant BlazorCodeEditor as CodeEditorComponent
participant JSRuntime as BlazorJSInterop
participant CodeEditorJs as CodeEditor_razor_js
participant Monaco as MonacoEditor
User->>BlazorCodeEditor: Invoke InsertText(data)
BlazorCodeEditor->>JSRuntime: InvokeVoidAsync insertText Id, data
JSRuntime->>CodeEditorJs: insertText id, insertData
CodeEditorJs->>CodeEditorJs: wrapper = Data.get id
CodeEditorJs->>Monaco: editor.getSelection()
CodeEditorJs->>Monaco: executeEdits insert-custom-text, range, text
CodeEditorJs->>Monaco: focus()
Class diagram for updated CodeEditor text insertion APIclassDiagram
class CodeEditorComponent {
+string Id
+Task Resize()
+Task InsertText(string data)
}
class CodeEditor_razor_js {
+init(id, interop, options)
+insertText(id, insertData)
+monacoSetOptions(id, options)
}
class MonacoEditor {
+getSelection()
+executeEdits(source, edits)
+focus()
}
class DataStore {
+get(id)
}
CodeEditorComponent --> CodeEditor_razor_js : uses_via_JSInterop
CodeEditor_razor_js --> DataStore : uses
CodeEditor_razor_js --> MonacoEditor : manipulates
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've found 1 issue, and left some high level feedback:
- In
insertText, consider guarding against missingwrapper.editororeditor.getSelection()returning null, and explicitly updating the selection afterexecuteEditsto address the cursor-position bug noted in the comment. - In the C#
InsertTextmethod, you may want to skip invoking JS whendatais null or empty to avoid unnecessary interop calls and potential JS-side edge cases.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `insertText`, consider guarding against missing `wrapper.editor` or `editor.getSelection()` returning null, and explicitly updating the selection after `executeEdits` to address the cursor-position bug noted in the comment.
- In the C# `InsertText` method, you may want to skip invoking JS when `data` is null or empty to avoid unnecessary interop calls and potential JS-side edge cases.
## Individual Comments
### Comment 1
<location> `src/components/BootstrapBlazor.CodeEditor/Components/CodeEditor/CodeEditor.razor.cs:125` </location>
<code_context>
+ /// </summary>
+ /// <param name="data"></param>
+ /// <returns></returns>
+ public async Task InsertText(string data) => await InvokeVoidAsync("insertText",Id,data);
+
/// <summary>
</code_context>
<issue_to_address>
**suggestion:** Consider null/empty input handling for `InsertText` to avoid unnecessary JS interop calls
If `data` can be `null` or empty, consider short-circuiting with `string.IsNullOrEmpty(data)` so you avoid a no-op interop call or having to add extra defensive checks on the JS side (unless the JS layer is explicitly expected to validate this).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| /// </summary> | ||
| /// <param name="data"></param> | ||
| /// <returns></returns> | ||
| public async Task InsertText(string data) => await InvokeVoidAsync("insertText",Id,data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider null/empty input handling for InsertText to avoid unnecessary JS interop calls
If data can be null or empty, consider short-circuiting with string.IsNullOrEmpty(data) so you avoid a no-op interop call or having to add extra defensive checks on the JS side (unless the JS layer is explicitly expected to validate this).
|
@kimdiego2098 测试没有发现问题 |
|
@Vision-Zhang 已添加复现demo |
feat: 增加代码编辑器插入文本方法
Summary by Sourcery
Add a new API to insert custom text into the code editor at the current selection via JS interop.
New Features: