Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/

Expand Down Expand Up @@ -117,6 +117,13 @@ protected override async Task InvokeInitAsync()
/// <returns></returns>
public async Task Resize() => await InvokeVoidAsync("resize");

/// <summary>
///
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public async Task InsertText(string data) => await InvokeVoidAsync("insertText",Id,data);
Copy link
Copy Markdown

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).


/// <summary>
///
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addLink, addScript } from '../../../BootstrapBlazor/modules/utility.js'
import { addLink, addScript } from '../../../BootstrapBlazor/modules/utility.js'
import Data from '../../../BootstrapBlazor/modules/data.js'
import EventHandler from "../../../BootstrapBlazor/modules/event-handler.js"

Expand Down Expand Up @@ -76,6 +76,29 @@ export async function init(id, interop, options) {
});
}

export function insertText(id, insertData) {

const wrapper = Data.get(id);
if (!wrapper) return;

const editor = wrapper.editor;

const selection = editor.getSelection();

editor.executeEdits('insert-custom-text', [
{
range: selection,
text: insertData,
forceMoveMarkers: true
}
]);
//bug: 插入文本后,虽然光标显示正常,但是再次插入文本,实际位置是第一行第一列

editor.focus();
}



// Update the editor options
export function monacoSetOptions(id, options) {
var editor = Data.get(id);
Expand Down